<?php

//جدوالی  که باید تغییر پیدا کنند
/*
    customeropeningbalance
	customerbalance
	customer_statement
*/

  include("db.php");
 

 $select_sql="select * from table_28  ";
 $select_query =$db ->query($select_sql);
 while($select_row=$select_query ->fetch_array()){
     /*
	af=1
	usd=2
	euro=3
	caldar=4
	toman=5
	
	*/
    //$afn=$select_row['euro'];
    //مقدار زیر به تناسب واحد پولی تغییر خواهد کرد
	
    echo $amount=$select_row['irr'];
    echo $customer_id=$select_row['customer_id'];
    echo $date=$select_row['date'];
	     $currencyId='5';
    echo "<br>";
	//currencyId
	//این مقدار بر اساس نمبر واحد های پولی تعریف شده تغییر میکند
	
	if($amount!=0){
	echo $insert_sql="insert into customeropeningbalance(date,customerId,currencyId,amount) values ('$date','$customer_id','$currencyId','$amount')";
    $insert_query=$db ->query($insert_sql);
	echo "<br>================================================</br>";
	//customerbalance
	
	echo $insert_customerBalance_sql="insert into customerbalance(customerId,currencyId,amount) values ('$customer_id','$currencyId','$amount')";
	$insert_customerBalance_query=$db ->query($insert_customerBalance_sql);
	echo "<br>*********************************</br>";
	//customer_statment
	
	$take_id_customerOP_Balanse_sql="select id from customeropeningbalance order by id DESC limit 1 ";
	$take_id_customerOP_Balanse_query=$db ->query($take_id_customerOP_Balanse_sql);
	$take_id_customerOP_Balanse_row=$take_id_customerOP_Balanse_query ->fetch_array();
	$transaction_id=$take_id_customerOP_Balanse_row['id'];
	
	if($amount>0){
	  $transaction_type=1;
	 }
	 if($amount<0){
	  $transaction_type=2;
	 }
	 
	echo $insert_customerStatment_sql="insert into customer_statement (reference,transaction_id,customerId,currency_id,amount,date,transaction_type) 
	   values
	   ('بلانس افتتاحیه','$transaction_id','$customer_id','$currencyId','$amount','$date','$transaction_type')";
	   echo "<br>========================================</br>";
	$insert_customerStatment_query=$db ->query($insert_customerStatment_sql);  
   }
 }

?>











