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

 include("db.php");
 include("../pdate.php");
 
   echo  $get_id=$_GET['editID']; 
   echo "<br>";   
   echo $table=$_GET['table'];
   
    
  $information_sql="select * from `$table` where id='$get_id'";
  $information_query= $db->query($information_sql);
  $information_row=$information_query->fetch_array();
  
  $customerId_retrive=$information_row['customerId'];
  $currencyId_retrive=$information_row['currencyId'];
  $amount_retrive=$information_row['amount'];
  $rate_retrive	=$information_row['rate'];
  $dollarAmount_retrive=$information_row['dollarAmount'];
  
  if($amount_retrive<0){
       $status = "2";
	   echo $other_openingBalance_retrive=-$amount_retrive; 
	    
  }
  if($amount_retrive>0){
       
	   $status = "1";
	   $other_openingBalance_retrive=$amount_retrive;
	}
	
	
       $checking_Sql="select * from customerbalance where customerId='$customerId_retrive' and currencyId='$currencyId_retrive' ";
       $checking_Query=$db ->query($checking_Sql);
	   $checking_Row=$checking_Query ->fetch_array();
	   
	   $checking_amount=$checking_Row['amount'];
	   $checking_dollarAmount=$checking_Row['dollarAmount'];
	   
	   $total_checking_amount=$checking_amount-$amount_retrive;
	   $total_checking_dollarAmount=$checking_dollarAmount-$dollarAmount_retrive;
	   
	   $updateCustomerBalance="update customerbalance set amount='$total_checking_amount',dollarAmount='$total_checking_dollarAmount'  where customerId='$customerId_retrive' and currencyId='$currencyId_retrive'  ";
	   $updateCustomerBalanceQuery=$db ->query($updateCustomerBalance);
	   
	   $updateOpeningBalance="update customeropeningbalance set remove='1'   where customerId='$customerId_retrive' and currencyId='$currencyId_retrive'  ";
	   $updateOpeningBalanceQuery=$db ->query($updateOpeningBalance);
	   
	   	     //delete statement
	      $deleteStatement = $db->query("delete from customer_statement where transaction_id ='$get_id' and reference ='بلانس افتتاحیه'");

      
    
    header("location:../openingBalance.php");	
?>  