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

 include("db.php");
 include("../jdf.php");
   $get_id=$_GET['editID'];
    
   $table=$_GET['table'];
   $targetPage=$_GET['targetPage'];
   
      $customerRetriveSql="select * from `$table` where id='$get_id'   ";
	 $customerRetriveQuery=$db ->query($customerRetriveSql);
	 $customerRetriveRow=$customerRetriveQuery ->fetch_array();
	 $retrive_date=$customerRetriveRow['date'];
	 $referenceNoretrive=$customerRetriveRow['referenceNo'];
	 $status=$customerRetriveRow['transacttype'];
	 $transactCurrency_retrive=$customerRetriveRow['transactCurrency'];
	  
	 $customerassetretrive=$customerRetriveRow['customerasset'];
	 $amount_retrive=$customerRetriveRow['amount'];
	 $dollarTotal_retrive=$customerRetriveRow['dollarTotal'];
	 $description_retrive=$customerRetriveRow['description'];
	 $customerId_retrive=$customerRetriveRow['customerId'];
	 $dollarRate_retrive=$customerRetriveRow['dollarRate'];
	 if($status==1){$retrive_reference="رسیدگی مشتری";}
	 if($status==2){$retrive_reference="بردگی مشتری";}
	 
	   
?>  
<html>
<head>
	<title>ویرایش معاملات پــولی</title>
	 
  <link rel="stylesheet" type="text/css" href="../css/style.css">
  <script src="dist/sweetalert-dev.js"></script>
  <link rel="stylesheet" href="dist/sweetalert.css"> 
  
  
<!---==========================================================================-->
 
 <script type="text/javascript" src="../js/decimal.js"></script>
 <script type="text/javascript" src="../js/NumberFormat.js"></script>
<!---==========================================================================-->
<link href="css/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="../js/jquery.autocomplete.pack.js"></script>
<script type="text/javascript" src="../js/script.js"></script>
<!---==========================================================================-->
<!--========================================================================-->
<script>
	     
 	   
      
      
  function changeCurrency(){
	    $('#existingcurrencyBalance').hide();
		   $.post('../customerPaymentBalance.php', {
		   currencyId:form.counterCurrency.value
		   },
			function(output){
				$('#existingcurrencyBalance').html(output).fadeIn(10);
		})
	
	}
	//===============================================================
 
	function dollarsRate(){
	//========================================
	    transactType=document.getElementById('transactType').value;
	   if(transactType=='1'){
			$('#rateOfdollar').hide();
			   $.post('../customerDollarRate.php', {
			   rateOfDollar:form.counterCurrency.value,
			   dateFind:form.newdate.value
			   },
				function(output){
					$('#rateOfdollar').html(output).fadeIn(10);
			})
	
	    }//end ofif(transactType=='1')
        //-----------		
		if(transactType=='2'){
			$('#rateOfdollar').hide();
			   $.post('../customerDollarRate.php', {
			   rateOfDollar:form.counterCurrency.value,
			   dateFind:form.newdate.value
			   },
				function(output){
					$('#rateOfdollar').html(output).fadeIn(10);
			})
	
	    }//end ofif(transactType=='2') 
	
	
	}
 
	//=======================================================================
	function existingCustomerBalance(){
	    $('#customerBalance').hide();
		$.post('../customerBalance.php', {
		   currencyId:form.counterCurrency.value,
		   customerNumber:form.customerId.value 
		    
		   },
			function(output){
				$('#customerBalance').html(output).fadeIn(10);
		})
	
	}
	
	//=========================================================
	function hekmat(){

       interval = setInterval("calculate()",1);

      }  
	function calculate(){
	   //=====================================================================
										//Dollar
	   //=====================================================================
	   customerOfBalanceDollar=document.getElementById('customerdollarAmount').value;
	   /* var decimalCharacter = ".",
       regex = new RegExp("[\\d" + decimalCharacter + "]+", "g"),
       num_Dollarprice=customerOfBalanceDollarP;  
       var customerOfBalanceDollar=+num_Dollarprice.match(regex).join(""); */
	   
	   
	   customerOfPaymentDollarP=document.getElementById('sumDollar').value;
	   var decimalCharacter = ".",
       regex = new RegExp("[\\d" + decimalCharacter + "]+", "g"),
       num_Dollarpayment=customerOfPaymentDollarP;  
       var customerOfPaymentDollar=+num_Dollarpayment.match(regex).join("");
	  //====================================================================== 
	   
	   customerOfBalance=document.getElementById('customerAmount').value;
	   /*
	   var decimalCharacter = ".",
       regex = new RegExp("[\\d" + decimalCharacter + "]+", "g"),
       num_price=customerOfBalanceP;  
       var customerOfBalance=+num_price.match(regex).join(""); */
		
		
	   currencyAmountP=document.getElementById('currencyAmount').value;
	   var decimalCharacter = ".",
       regex = new RegExp("[\\d" + decimalCharacter + "]+", "g"),
       num_price=currencyAmountP;  
       var currencyAmount=+num_price.match(regex).join("");
	   
	   transactType=document.getElementById('transactType').value;
	   
	   
	   if(transactType=='1'){
	    
		  newAmountDollar=(customerOfBalanceDollar*1)+(customerOfPaymentDollar*1);
		  newAmount=(customerOfBalance*1)+(currencyAmount*1);
		  //محاسبه موجودی مشتری به حساب پول مورد نظر خودش
	      customerRemain=document.getElementById('customerRemain').value=FormatNumberBy3(newAmount*1);
		  //==================================
		  newamountDollarResult=newAmountDollar.toFixed(5);
	      customerRemaindollar=document.getElementById('customerRemaindollar').value=(newamountDollarResult*1);
	   } if(transactType=='2'){
	      newAmountDollar=(customerOfBalanceDollar*1)-(customerOfPaymentDollar*1);
	      newAmount      =(customerOfBalance*1)-(currencyAmount*1);
		  
		  //محاسبه موجودی مشتری به حساب پول مورد نظر خودش
	      customerRemain=document.getElementById('customerRemain').value=FormatNumberBy3(newAmount*1);
		  
		  newamountDollarResult=newAmountDollar.toFixed(5);
		  customerRemaindollar=document.getElementById('customerRemaindollar').value=(newamountDollarResult*1);
	   
	   }
	    
	}
	//==========================================================
	function calculatDollar(){

       interval = setInterval("dollar()",1);

      }  
	function dollar(){
	
	   
	    currencyAmountP=document.getElementById('currencyAmount').value;
	   var decimalCharacter = ".",
       regex = new RegExp("[\\d" + decimalCharacter + "]+", "g"),
       num_price=currencyAmountP;  
       var currencyAmount=+num_price.match(regex).join("");  
	    
	   //dollarRate=document.getElementById('dollarRate').value;
	    // نرخ قدیم
		  mixData=document.getElementById('dollarmixData').value; 
		  takeData=mixData.split('/');
		  mainrate=takeData[0];
		  unit=takeData[1];
		  
		  var exactresult=currencyAmount/unit;
		    
		  
		    //نرخ جدید
		   changeMixData  =document.getElementById('new_dollarRate').value;
		   changetakeData=changeMixData.split('/');
		   changemainrate=changetakeData[0];
		   changeunit   =changetakeData[1];
		  
		   var changeexactresult=currencyAmount/changeunit;
	     
	   
	   
	    
	    new_dollarRate=document.getElementById('new_dollarRate').value;  
	  
	     
	      if(new_dollarRate!=0){
	       row=(changeexactresult*1)*(changemainrate*1);
		   pourCalculat=row.toFixed(2);
	       document.getElementById('sumDollar').value= (pourCalculat*1);
	   } 
	     if(new_dollarRate==""){
	       row=(exactresult*1)*(mainrate*1);
		   pourCalculat=row.toFixed(2)
	       document.getElementById('sumDollar').value=(pourCalculat*1)  ;
	
	   }     
	   
	} 
	//======================================
	 /* function newrate(){
	   profe=document.getElementById('take').value;
	   finalResult=document.getElementById('dollarRate').value=(profe*1);
	 }
	 */
	
	
	</script>
   
</head>
<body onload="changeCurrency();existingCustomerBalance();dollarsRate();hekmat();calculatDollar()">

	<div id="wrap">
		 
		<div id="contentt">
			 
			<div id="menu">
				<?php  //include("menu.php") ;   ?>
			</div>
		    <div id="matlab" >
			<div id="title"><p>ویــرایــش معـامــلات پـــولـی</p> </div>
			<div id="picture">
					<table border="0" width="400px">
						<tr>
							<td style="width:180px;"><img src="../img/mony.png" width="150px" height="120px">  </td>
							<td > </td>
						</tr>
					</table>
			   </div>
		    	<form method="post" action="" name="form">
               <table border="0"   id="rgistera_cart" width="800px" class="font">
		    		<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">تاریخ </th>
						<td style="width:250px" >
						  <?php include("datepicker.php"); ?>
							<input type="hidden" name="customerId" id="customerId" placeholder="" class="form-control" value="<?php echo $customerId_retrive  ;?>"/>
						</td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr>
					<!--<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">نمبر شناسایی</th>
						<td style="width:250px" ><input type="text" name="refrenceNumber"   value='<?php  echo $referenceNoretrive;   ?>'></td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr>-->
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">نوعیت معامله </th>
						<td style="width:250px" > 
							<select name="transactType" id="transactType"  style="width: 100%" onchange="dollarsRate()" onclick="dollarsRate()">
								<option value="1" <?php if($status == "1"){ echo"selected"; } ?>>رسیدگی</option>
			                    <option value="2" <?php if($status == "2"){ echo"selected"; } ?>>بردگی</option>
							</select>
						</td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr>
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">ارز مورد معاوضه</th>
						<td style="width:250px" >
						 <select name="counterCurrency"  id='counterCurrency'  style="width:100%" onchange="changeCurrency();existingCustomerBalance();dollarsRate()" onclick="changeCurrency();existingCustomerBalance();dollarsRate()">
							<option></option>
							<?php
							//include("config/views/db_const.php");
							$sql="select * from currencies";
							$query=$db ->query($sql);
							while($row=$query ->fetch_array()){
							$id=$row['id'];
							$name=$row['name'];
							//echo "<option value='$id'>$name</option>";

                            if($transactCurrency_retrive == $row['id']){
								echo "<option value=$row[id] selected>$row[name] </option>";
								}else{
								    echo "<option value=$row[id]>$row[name]</option>";
								}


							
							}
							echo "</select>";
														
							?>
						 
						 </td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr>
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">موجودی پول</th>
						<td style="width:250px" > 
							<div id="existingcurrencyBalance"><input type="text"   placeholder="" class="form-control"  /></div>
						</td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr>
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">مقدار مورد معاوضه</th>
						<td style="width:250px" >
							<input type="text" name="currencyAmount" autocomplete="off" value="<?php echo number_format($amount_retrive,2); ?>" onkeyup="addSeparator(this)" id="currencyAmount" placeholder="" class="form-control" onclick="hekmat();calculatDollar()" onChange="hekmat();calculatDollar()"  />
						</td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr>
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">موجودی مشتری</th>
						<td style="width:250px" >
							<div id="customerBalance"><input type="text"   placeholder="" class="form-control"  /></div>
						</td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr>
					<!--<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">باقی حساب مشتری</th>
						<td style="width:250px" >
							<input type="text" name="customerRemain" id="customerRemain" placeholder="" class="form-control"  />
						</td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr>-->
					 <!--<tr>
						<td style="width:190px">&nbsp;</td>
		    			<!--<th style="width:150px">نرخ بر اساس دالر</th>
						<td style="width:250px" >-->
							<div id='rateOfdollar'><input type="hidden"  placeholder="" class="form-control"  /></div>
						<!--</td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr> 
					<!--<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">نرخ جدید به دالر</th>
						<td style="width:250px" >
							<input type="text" name="new_dollarRate" autocomplete="off" id="new_dollarRate" class="form-control" placeholder="نرخ جدید نسبت به دالر"  style='background: #ccffff;' onchange="calculatDollar()" onclick="calculatDollar()" value="<?php //echo $dollarRate_retrive ?>" />
						</td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr>-->
					<!--<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">مجموع به دالر</th>
						<td style="width:250px" >-->
							<input type="hidden" name="sumDollar" id="sumDollar" placeholder="" class="form-control"  />
						<!--</td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr>-->
					<!--<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">باقی حساب مشتری به دالر</th>
						<td style="width:250px" >
							<input type="text" name="customerRemaindollar" id="customerRemaindollar" placeholder="" class="form-control"  />
						</td>
						<td style="width:280px;">
							 
						 </td>
		    		</tr>-->
					 <tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">ارسال پیامک</th>
						<td style="width:250px"><input type="checkbox" name="send_sms"></td>
						<td style="width:280px;"> </td> 
		    		</tr>
					  <tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px">توضیحات</th>
						<td style="width:250px"><textarea rows="3" cols="23"  name="desc"  ><?php echo $description_retrive;  ?></textarea></td>
						<td style="width:280px;"> </td> 
		    		</tr>
					 
					<tr>
						<td style="width:190px">&nbsp;</td>
		    			<th style="width:150px"> </th>
						<td style="width:230px"> 
						    <input type="submit" id="save"   name="save"  value="ذخیره">
							<input type="submit" id="back"   name="back"  value="انصراف">
							
						</td>
						<td style="width:300px;"> </td> 
		    		</tr>
                    
		    	</table>
		    	 
				</form>
		    </div>


		</div>
		 
	</div>
</body>
</html>
<?php
if($_POST['back']){
  header("location:../report/customerPaymentReport.php");
}
if($_POST['save']){

  $targetPage=$_GET['targetPage'];
  $amount_retrive;//مقدار قدیم 
 
 
 $transactCurrency_retrive;// نوعیت پولی قدیم
 $dollarTotal_retrive;//مجموع به دلار
 $status;   //نوعیت پرداختی رسیدگی /بردگی
 $customerId_retrive;//نمبر شناسایی مشتری 
//===============================================
    $date = $_POST['year']."-".$_POST['month']."-".$_POST['day'];
 $target=$_POST['target'];
 $customerId=$_POST['customerId'];
  
 $refrenceNumber=$_POST['refrenceNumber'];
 
 $transactType=$_POST['transactType'];
 echo "<br>";
 //===================================================================================
 $new_dollarRatePriceRow=$_POST['new_dollarRate'];  // نرخ  جدید به دالر
 $new_dollarPriceRowmix=explode("/",$new_dollarRatePriceRow);
	$first_NewdollarPrice =$new_dollarPriceRowmix[0];
	$second_NewdollarPrice=$new_dollarPriceRowmix[1]; 
	 
//================================================================================
 
 
 
 echo "<br>";
 $counterCurrency=$_POST['counterCurrency'];
 echo "<br>";
 $amountP=$_POST['amount'];//مـــــوجــــودی صنـــــــدوق
 $amount = preg_replace('/[^\d\.-]/', '', $amountP);
echo "<br>"; 
 $currencyAmountP=$_POST['currencyAmount']; //مقدار ارز مورد معاوضه
 $currencyAmount = preg_replace('/[^\d\.-]/', '', $currencyAmountP);
 echo "<br>";

  $customerAmount=$_POST['customerAmount']; // موجودی مشتری به ارز موجود
 echo "<br>";
 $customerRemainP=$_POST['customerRemain']; //  الباقی حساب مشتری
 $customerRemain = preg_replace('/[^\d\.-]/', '', $customerRemainP);
 echo "<br>";
 //===================================================================================
     $dollarRateRow=$_POST['dollarRatePrice']; //  قیمت به دلار
     $dollarRatePriceRowmix=explode("/",$dollarRateRow);
	 $first_dollarRatePrice =$dollarRatePriceRowmix[0];
	 $second_dollarRatePrice=$dollarRatePriceRowmix[1]; 
	 echo "<br>";
	 
 //==================================================================================
  
 
 $dollarAmount=$_POST['dollarAmount'];//موجودی بانک به دلار   
 $customerdollarAmount=$_POST['sumDollar']; // موجودی مشتری به دلار
 $customerRemaindollar=$_POST['customerRemaindollar']; //  الباقی حساب مشتری به دالر
 
 
 $desc=$_POST['desc']; //  توضیحات
 
 /* if($new_dollarRatePriceRow!=0){
 
    $dollarRate=($first_NewdollarPrice/$second_NewdollarPrice);
 } */
 
 //===============================check bank====================================
    $asset_Sql="select * from `assets`  where  currencies_id='$counterCurrency'";
	$asset_Query=$db ->query($asset_Sql);
	$asset_Row=$asset_Query ->fetch_array();
    $asset_Amount=$asset_Row['amount'];
	$asset_Dollar_Amount=$asset_Row['dollarAmount'];
  if(strlen(trim($customerId))==0 or strlen(trim($transactType))==0 or strlen(trim($currencyAmount))==0){
		echo' <script>
					 sweetAlert("اخطا ر... ", "لطفا جاهای خالی را پرکنید !", "error");
				  </script>';

         echo '<meta http-equiv="refresh" content ="1; url=../customerAccount.php" >';
		die;


}
	if(!isset($asset_Amount)){
	    echo' <script>
					sweetAlert("هشــدار...", "لطفا ابتدا پول را در قسمت دارییها ثبت کنید!", "error");
			   </script>'; 
		 echo '<meta http-equiv="refresh" content ="2; url=../assetRegistration.php" >';
         die;
	
	}
 //===============================check bank====================================

	 
            
	 //=========================End of Back Asset================================ 
	 //=========================Back CustomerBalance================================
	      $oldCustomerSql="select * from customerbalance where customerId='$customerId_retrive' and currencyId='$transactCurrency_retrive'"; 
		  $oldCustomerQuery= $db ->query($oldCustomerSql);
		  $oldCustomerRow=$oldCustomerQuery ->fetch_array();
		  $oldCustomerAmount=$oldCustomerRow['amount'];
		  
		  $oldCustomerDollarAmount=$oldCustomerRow['dollarAmount'];
		   
		  if($status==1){
		    
			$oldCustomerAmounUpdate=$oldCustomerAmount-$amount_retrive;
			$oldCustomerdollarAmounUpdate=$oldCustomerDollarAmount-$dollarTotal_retrive;
		   
		  } if($status==2){
		    $oldCustomerAmounUpdate=$oldCustomerAmount+$amount_retrive;
		    $oldCustomerdollarAmounUpdate=$oldCustomerDollarAmount+$dollarTotal_retrive;
		  
		  }
		   
		  $backUpdateCustomerSql="update customerbalance set amount='$oldCustomerAmounUpdate',dollarAmount='$oldCustomerdollarAmounUpdate' where currencyId='$transactCurrency_retrive' and customerId='$customerId_retrive'";
	      $backUpdateCustomerQuery=$db ->query($backUpdateCustomerSql);
          
	//=========================End of CustomerBalance================================
	//===============================================================================
	//===============================================================================
	//===============================================================================
						 /* =============ASSET BANK======================  */
	 
	  $newAssetSql="select * from assets where currencies_id='$counterCurrency'";
	  $newAssetQuery= $db ->query($newAssetSql);
	  $newAssetRow=$newAssetQuery ->fetch_array();
	  
	  $newAssetAmount=$newAssetRow['amount'];
	  $newAssetDollarAmount=$newAssetRow['dollarAmount'];
	 
	  
				/*============== END OF ASSET BANK===============  */				
	 //=================================================================================			
	 //=================================================================================
						/*============== CUSTOMER BALANCE ===============  */

             
	 $customerRemainSql="select amount,dollarAmount from `customerbalance` 
	                                       where
	 customerId='$customerId' and currencyId='$counterCurrency' ";
	 $customerRemainQuery=$db ->query($customerRemainSql);
	 $customerRemainRow=$customerRemainQuery ->fetch_array();
	 $customerRemainAmount=$customerRemainRow['amount'];
	    
	 $customerRemaindollarAmount=$customerRemainRow['dollarAmount'];
      
     //=====================================================================
	 
      if($transactType=='1'){
	  
	              /////==========
				 
				  $newUpateAssetAmount=$newAssetAmount+$currencyAmount;
	              
				  $newUpateAssetDollarAmount=$newAssetDollarAmount+$sumDollar; 
	               
				  $udateAssetSql="update assets set amount='$newUpateAssetAmount',dollarAmount='$newUpateAssetDollarAmount' where currencies_id='$counterCurrency'";
				  $udateAssetQuery=$db ->query($udateAssetSql);
 				 
         
				/////============
				 if(isset($customerRemainAmount)){
				  
				  $newCustomerRemain=$customerRemainAmount+$currencyAmount;
				  
				  $newCustomerdollarRemain=$customerRemaindollarAmount+$sumDollar;
				  
				  $updateSql="update customerbalance set amount='$newCustomerRemain',dollarAmount='$newCustomerdollarRemain' where customerId='$customerId' and currencyId='$counterCurrency'";
				     
				  $updatequery=$db ->query($updateSql);
				 }
				 
				 if(!isset($customerRemainAmount)){
				 
				    $remainInsertionSql="insert into customerbalance (customerId,currencyId,amount,dollarAmount)
					values('$customerId','$counterCurrency','$currencyAmount','$sumDollar')";
				     
				    $remainInsertionquery=$db ->query($remainInsertionSql);
				 }
				 //header("location:customerAccount.php");
				 
		}
		 
	 //===============================================================
	 //=====================================================================
      if($transactType=='2'){
	     
	             /////===================================================================
				 
				    
				   $newUpateAssetAmount=$newAssetAmount-$currencyAmount;
	               $newUpateAssetDollarAmount=$newAssetDollarAmount-$sumDollar;
				   $udateAssetSql="update assets set amount='$newUpateAssetAmount',dollarAmount='$newUpateAssetDollarAmount' where currencies_id='$counterCurrency'";
				   $udateAssetQuery=$db ->query($udateAssetSql);
				  
				  /////===================================================================

	  
	  
	  
				 if(isset($customerRemainAmount)){
				  
				   $customerRemaindollarAmount;
				   
				   $sumDollar;
				   $newCustomerRemain=$customerRemainAmount-$currencyAmount;
				   
				   $newCustomerdollarRemain=$customerRemaindollarAmount-$sumDollar;
				  
				   $updateSql="update customerbalance set amount='$newCustomerRemain',dollarAmount='$newCustomerdollarRemain' where customerId='$customerId' and currencyId='$counterCurrency'";
				   
				  $updatequery=$db ->query($updateSql);
				 }
				 
				 if(!isset($customerRemainAmount)){
				 
				     $remainInsertionSql="insert into customerbalance (customerId,currencyId,amount,dollarAmount)
					 values('$customerId','$counterCurrency','$customerRemain','$customerdollarAmount')";
					 $remainInsertionquery=$db ->query($remainInsertionSql);
				 }
			 
		}
	 //===============================================================
   
      $updatecustomerPaymentSql="update customerpayment set customerId='$customerId',date='$date',referenceNo='$refrenceNumber',transacttype='$transactType',transactCurrency='$counterCurrency',
	  amount='$currencyAmount',customerRemain='$pureRemainCustomer',dollarRate='$dollarRate',dollarTotal='$sumDollar',description='$desc'  where id='$get_id'";
      $updatecustomerPaymentQury=$db ->query($updatecustomerPaymentSql);
	  
	  
	  //update Customer Statement =
      $updateCustomerStatement = "update customer_statement set date='$date',currency_id ='$counterCurrency',amount ='$currencyAmount',transaction_type='$transactType',description='$desc' where transaction_id ='$get_id' and reference='معاملات مشتری'";
	 $updateCustomerStatementQuery = $db->query($updateCustomerStatement);
	  
	  //update journal=============================
	   //نام مشتری رو بگیر
		  $selectCustomer = "select name from customers where id =$customerId";
		  $selectCusetomerQeury = $db->query($selectCustomer);
		  $selectCustomerRow = $selectCusetomerQeury->fetch_array();
		  $customerName = $selectCustomerRow['name'];
		  
		  //========
		  if($transactType=="1"){
			  $reference ='رسیدگی مشتری';
			  $dr_cr=1;
		  }
		  if($transactType=="2"){
			  $reference ='بردگی مشتری';
			  $dr_cr=2;
		  }
	  $updateCustomerJournal = "update journal set dr_cr ='$dr_cr',name ='$customerName', date='$date', reference='$reference',currency ='$counterCurrency',amount ='$currencyAmount',description='$desc',threadment ='$reference' where reference_id ='$get_id' and reference='$retrive_reference'";
      $updateCustomerQuery = $db->query($updateCustomerJournal);

      if($targetPage!=""){
	  
	        
	       header("location:../$targetPage");	
		   die;
	  }
     else{
	 
	   
     header("location:../report/customerPaymentReport.php");	
	
        }	

}



?>