<?php
ob_start();
ini_set('session.bug_compat_warn', 0);
ini_set('session.bug_compat_42', 1);

 include("db.php");
 include("../pdate.php");
    $get_id=$_GET['editID'];
    echo "<br>";
    $table=$_GET['table'];    
	echo "<br>";
 
    $customerId_retrive=$_GET['customerId'];
	
	 $customerRetriveSql="select * from `$table` where id='$get_id'   ";
	 $customerRetriveQuery=$db ->query($customerRetriveSql);
	 $customerRetriveRow=$customerRetriveQuery ->fetch_array();
	 $id_retrive=$customerRetriveRow['id'];
	 $dateretrive=$customerRetriveRow['date'];
	 $counterCurrency_retrive=$customerRetriveRow['counterCurrency'];
	 $baseCurrency_retrive=$customerRetriveRow['baseAmount'];
	 $amount_retrive=$customerRetriveRow['amount'];
	 $sellRate_retrive=$customerRetriveRow['sellRate'];
	 $buyRate_retrive=$customerRetriveRow['buyRate'];
	 $totalSell_retrive=$customerRetriveRow['totalSell'];
	 $totalBuy_retrive=$customerRetriveRow['totalBuy'];
	 $dollartotalsell_retrive=$customerRetriveRow['dollartotalsell'];
	 $dollartotalbuy_retrive=$customerRetriveRow['dollartotalbuy'];
	 $profit_retrive=$customerRetriveRow['profit'];
	 $description_retrive=$customerRetriveRow['descr'];
   
   
 
	 
	 
	 
	 //=========================خروج پول خریداری شده از صندوق========================
	      $oldBuycustomermoneySql="select * from customerbalance where currencyId='$counterCurrency_retrive' and customerId='$customerId_retrive'";
		  $oldBuycustomermoneyQuery= $db ->query($oldBuycustomermoneySql);
		  $oldBuycustomermoneyRow=$oldBuycustomermoneyQuery ->fetch_array();
		  $oldcustomerAmount=$oldBuycustomermoneyRow['amount'];
		  echo "<br>";
		  $oldcustomerDollarAmount=$oldBuycustomermoneyRow['dollarAmount'];
		  //echo"<br>-------------</br>";
		  $backcustomerbaseAmount=$oldcustomerAmount-$amount_retrive;
		  $backcustomerbaseDollarAmount=$oldcustomerDollarAmount-$dollartotalbuy_retrive;
		  
		   $backUpdateCustomerBaseMoneySql="update customerbalance set amount='$backcustomerbaseAmount',dollarAmount='$backcustomerbaseDollarAmount' where currencyId='$counterCurrency_retrive' and customerId='$customerId_retrive'";
	       $backUpdateCustomerBaseMoneyQuery=$db ->query($backUpdateCustomerBaseMoneySql);
          
		  
		   
	//=========================برگشت پول فروخته شده به صندوق========================  
	      $oldSellcustomermoneySql="select * from customerbalance where currencyId='$baseCurrency_retrive' and customerId='$customerId_retrive'";
		  $oldSellcustomermoneyQuery= $db ->query($oldSellcustomermoneySql);
		  $oldSuycustomermoneyRow=$oldSellcustomermoneyQuery ->fetch_array();
		  $oldcustomerSellAmount=$oldSuycustomermoneyRow['amount'];
		   
		  $oldcustomerSellDollarAmount=$oldSuycustomermoneyRow['dollarAmount'];
		   
		  //echo"<br>-------------</br>";
		  $backcustomerSellAmount=$oldcustomerSellAmount+$totalSell_retrive;
		  $backcustomerSellDollarAmount=$oldcustomerSellDollarAmount+$dollartotalbuy_retrive;
		  
		  $backUpdateCustomerBaseMoneySql="update customerbalance set amount='$backcustomerSellAmount',dollarAmount='$backcustomerSellDollarAmount' where currencyId='$baseCurrency_retrive' and customerId='$customerId_retrive'";
	      $backUpdateCustomerBaseMoneyQuery=$db ->query($backUpdateCustomerBaseMoneySql);
         //======================================
		 /*پاک کردن Customer Sell*/
	       $customerSellDelete_Sql="update customerssell set remove='1' where id='$get_id'";
           $customerSellDelete_Query=$db ->query($customerSellDelete_Sql);
		   
		   /*پاک کردن customerpayment*/
	       echo $customerPaymentDelete_Sql="update customerpayment set remove='1' where customersell_id='$get_id' and customerId='$customerId_retrive'";
           $customerPaymentDelete_Query=$db ->query($customerPaymentDelete_Sql);
		   
		   
		   
		   
	    header("location:../report/customerSealsgeneralreport.php");	
?>  