<?php
 include("db.php");
  
    
  
	 //=========================موجودی اولیه دخل=========================================
	 //==================================================================================
	//موجودی دخل کنونی
	   
	 //OpeningBalance (1)
	   $assets_af_sql="select  * from assetopeningbalance where currencyUnit='$money'  ";
	   $assets_af_query= $db ->query($assets_af_sql);
	   $assets_af_row=$assets_af_query ->fetch_array(); 
	   $openingBalance=$assets_af_row['amount'];
		   
	//=====================opening Balance dakhle========================
       $cr_befor_sql="select sum(amount) as amount from journal where dr_cr='1' and currency='$money' and   date<'$startDate'";
	   $cr_befor_query= $db ->query($cr_befor_sql);
	   $cr_befor_row=$cr_befor_query ->fetch_array();
	   $cr_befor=$cr_befor_row['amount'];
	    
	   $dr_befor_sql="select sum(amount) as amount from journal where dr_cr='2' and currency='$money' and   date<'$startDate'";
	   $dr_befor_query= $db ->query($dr_befor_sql);
	   $dr_befor_row=$dr_befor_query ->fetch_array();
	   $dr_befor=$dr_befor_row['amount'];
	    
	   $befor_bank=($openingBalance+$cr_befor)-$dr_befor;
?>