<?php
session_start();
 include("db.php");
  $currency_id_sql="select distinct currencyId from customerbalance  ";
  $currency_id_Query= $db ->query($currency_id_sql);
  while($currency_id_Row=$currency_id_Query ->fetch_array()){
         $currency_id=$currency_id_Row['currencyId'];
	 
	    //پــولهــــای مشتـــــریان
	     $customerTotal_sql="select sum(amount) from customerbalance where currencyId='$currency_id' and amount>0";
         $customerTotal_query= $db ->query($customerTotal_sql);
         $customerTotal_row=$customerTotal_query ->fetch_array();
		 $customerTotal=$customerTotal_row['sum(amount)'];
		  
		//==========================قیمت ها
		 $currencyRate_sql="select * from crrencyrate where counterCurrency	='$currency_id' and baseCurrency='1' order by id DESC  limit 1";
		 $currencyRate_query= $db ->query($currencyRate_sql);
		 $currencyRate_Row=$currencyRate_query ->fetch_array();
		 $currencyRate=$currencyRate_Row['rate'];
		//==========================قیمت ها
		 $customerRecivable=$currencyRate*$customerTotal;
		 $totalCustomer=+$customerRecivable ;
		 $sum_accountReciveable+= $customerRecivable;
	 } 
         echo $sum_accountReciveable;
		 $_SESSION['sum_accountReceivable']=$sum_accountReciveable;
		 header("location:customer_accountPayable.php"); 
  ?>