<head>
<script src="dist/sweetalert-dev.js"></script>
<link rel="stylesheet" href="dist/sweetalert.css">
</head>
<?php
    include("db.php");
	if($_POST['back']){
	  header("location: index.php");
	}
	if($_POST['save']){
    $length=$_POST['length'];
    $date=$_POST['date'];
   // $page= $_POST['page'];
  // $checkpage=strlen($_POST['page']);
    echo "<br>";
     
           
 			  
	$delete_Sql="delete from dailyasset where date='$date'";
    $delete_Query= $db ->query($delete_Sql);
	
	//===============DELETE DAILY PROFIT====================================
	$deleteDaillyProfit_Sql="delete from dailyprofit where date='$date'";
    $deleteDaillyProfit_Query= $db ->query($deleteDaillyProfit_Sql);
	
	
	//===============DELETE DAILY PROFIT====================================
	 
//============================================================================	 
 for($i=0;$i<$length;$i++){
 
   
   
    
     $amountp=$_POST['amount'][$i];
	 $amount = preg_replace('/[^\d\.-]/', '', $amountp);
    
	 $currencyId=$_POST['currencyId'][$i];
   
     $ratep=$_POST['rate'][$i];
     $rate = preg_replace('/[^\d\.-]/', '', $ratep);
    
    
   
    if(strlen(trim($amount))==0  or strlen(trim($currencyId))==0 or strlen(trim($rate))==0){
    
	
	       echo "You have Problem";
      /*   echo' <script>
			 	 
					
				   swal("ذخیره موفق!", "اطلاعات وارده با موفقیت ثبت سیستم شد", "success")
			  </script>'; */
	    echo '<meta http-equiv="refresh" content ="1; url=assetRegistrationCheck.php" >';
                  
			 
         die;


}
    $total=$amount/$rate;
	 echo "<br>";
	  include("payable_Receivable_Account.php");
     $totalAsset+=$total;
 $insert_sql="insert into dailyAsset (currencyId,amount,rate,dollarTotal,date) 
                  values 
   ('$currencyId','$amount','$rate','$total','$date')";
   
  $insert_query = $db ->query($insert_sql);
 	     
			} 

            	
			 
	 
	 		 $equity=($totalAsset+(-$allDollarRecivable))-($allDollarPayable);
  //===========================INSERT DAILY PROFIT ==================================
                $insert_Profit_sql="insert into dailyprofit(totalAsset,dariyaft,pardakht,equity,date) 
							values
							('$totalAsset','$allDollarRecivable','$allDollarPayable','$equity','$date') ";
     
                $insert_Profit_query= $db ->query($insert_Profit_sql);
				
				echo' <script>
			 	 
				
			
				   swal("ذخیره موفق!", "اطلاعات وارده با موفقیت ثبت سیستم شد", "success")
				</script>';			 
             echo '<meta http-equiv="refresh" content ="1; url=index.php" >';
   
   //===========================END OFINSERT DAILY PROFIT=============================
			    
     }     

 ?>