<?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'];
    
   $table=$_GET['table'];
   
  $information_sql="select * from `$table` where id='$get_id'";
  $information_query= $db->query($information_sql);
  $information_row=$information_query->fetch_array();
  
  $date_retrive=$information_row['date'];
  $expensesId_retrive=$information_row['expensesId'];
  $currencyId_retrive=$information_row['currencyId'];
  $currencyAsset_retrive=$information_row['currencyAsset'];
  $amount_retrive=$information_row['amount'];
  $dollarRate_retrive=$information_row['dollarRate'];
  $dollarTotal_retrive=$information_row['dollarTotal'];
  //===============================================================================
       $backAsset_Sql="select amount,dollarAmount from assets where currencies_id='$currencyId_retrive'";
	   $backAsset_Query= $db ->query($backAsset_Sql);
	   $backAsset_Row=$backAsset_Query ->fetch_array();
	   
	   $backAsset_Amount=$backAsset_Row['amount'];
	   $backAsset_DollarAmount=$backAsset_Row['dollarAmount'];
	   
	   $updateBackAmoun=$backAsset_Amount+$amount_retrive;
	   $updateBackdollarAmoun=$backAsset_DollarAmount+$dollarTotal_retrive;
	   
	   $update_Asset_Sql="update assets set  amount='$updateBackAmoun',dollarAmount='$updateBackdollarAmoun' where currencies_id='$currencyId_retrive'";
	   $update_Asset_Query= $db ->query($update_Asset_Sql);
    
	   if($update_Asset_Query){
	   
	    $update_others_Sql="update others set remover='1' where id='$get_id'";
	    $update_others_Query= $db ->query($update_others_Sql);
		// delete from journal ==================================
		
		$delet_journal  =$db->query("delete from journal where reference_id ='$get_id' and reference ='مصرف'");
		header("location:../defineExpenses.php");

       }	
?>  