<?php
include("db.php");
     $findCurrency_Sql="select distinct baseAmount	 from customerssell";
     $findCurrency_Query= $db ->query($findCurrency_Sql);
	while($findCurrency_Row=$findCurrency_Query ->fetch_array()){
        $findCurrency=$findCurrency_Row['baseAmount'];
	  
//==========================finding Currency Rate=========================
	    $checkRate_sql="select * from crrencyrate where  counterCurrency='$findCurrency' and baseCurrency='1' order by id desc limit 1";
		$checkRate_query= $db ->query($checkRate_sql);
		$checkRate_Row=$checkRate_query ->fetch_array();
		$checkRate=$checkRate_Row['rate'];

		$unit=$checkRate_Row['unit'];

		$first=$checkRate;
		$second=$unit;
		if(isset($checkRate)){
		  $rate= $first/$second;
		   
	}
		//===============================================================================
		if(!isset($checkRate)){
		 
		 $checkRate1_sql="select * from crrencyrate where  counterCurrency='1' and baseCurrency='$findCurrency' order by id desc limit 1";
		 $checkRate1_query= $db ->query($checkRate1_sql);
		 $checkRate1_Row=$checkRate1_query ->fetch_array();
		 $unit1=$checkRate1_Row['unit'];
		 $checkRate1=$checkRate1_Row['rate'];
		 
		 $first=$unit1;
		 $second=$checkRate1;
         $rate= $first/$second;
		 
		 
	}
	  
	  //==========================finding Currency Rate=========================
     //============================account Payable============================
		 $sumProfit_sql="select sum(profit) from customerssell where date='$date' and  baseAmount='$findCurrency'";	
	     $sumProfit_Query= $db ->query($sumProfit_sql);
	     $sumProfit_Row=$sumProfit_Query ->fetch_array();
	     $sumProfit=$sumProfit_Row['sum(profit)'];
	      
	     $sumDollarProfit=$sumProfit*$rate;
	     $customer_Buy_Sale+=$sumDollarProfit;
		    
	}
	     $customer_Buy_Sale;
	  

?>