<?php
 include("jdf.php");
 $pdate1=jdate("Y-m-d");
    include("today_assets_date_plagin.php");
 session_start();
 
  $start_day=$_POST['day'];
  $start_month=$_POST['month'];
  $start_year=$_POST['year'];
				 
  $start_Date=$start_year."-".$start_month."-".$start_day;
  $end_day=$_POST['eday'];
  $end_month=$_POST['emonth'];
  $end_year=$_POST['eyear'];
				 
  $endDate=$end_year."-".$end_month."-".$end_day;
  
  $get_start_Date=$_GET['start_Date'];
  $get_end_Date=$_GET['endDate'];
  if($get_start_Date!=null){$start_Date= $get_start_Date;}
  if($get_end_Date!=null){$endDate= $get_end_Date;}
?>
<html>
<head>
 <title></title>
 <head>
 <!---==========================================================================-->
<link   href="css/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.5.2.min.js" type="text/javascript" ></script>
<script src="js/assets/global/plugins/jquery.min.js" type="text/javascript"></script>
<script src="js/jquery.autocomplete.pack.js" type="text/javascript" ></script>
<script src="js/script.js" type="text/javascript" ></script>
<script src="js/jquery-migrate.min.js" type="text/javascript"></script>
 
<!---==========================================================================-->
   <link rel="icon" href="images/favicon.ico" type="image/png"/>  
   
   <link href="css/pagenation.css" rel="stylesheet" type="text/css" /> 
 
 
<link rel="stylesheet" type="text/css" href="css/print.css" /> 
 
 <style>
 body{
	 background-color: #fff;
	  
 }
 #content{
   width: 100%;
   margin: auto;
	 
	 
 }
  
 a:link {
    text-decoration: none;
	color: #000;
}

 a:hover {
    color: blue;
	text-decoration: underline;
}
a:active {
     
    color: #000;
}

@font-face {
	  font-family: 'hekmat';
	  src: url('font/BHoma.ttf'); /* IE */
      src: local('BHoma'), url('font/BHoma.ttf') format('truetype'); /* non-IE */
      font-weight:normal;
}
.font{
    color: #000;
    font-family: 'hekmat'; 
    font-size: 17px;	
    

}
@media print {

   .dontPrint {
       display:none;
    }

    }
	
	@media all{
.page-break{display:none;}
}
@media print{
.page-break{display:block;page-break-after:always;}
.dote img {visibility: visible;}
}
 
@page 
{
   size: auto;   /* auto is the initial value */
    margin: 3mm;  /* this affects the margin in the printer settings */
 }
  @media print {
    html, body {
        height: 99%;    
    }
}
td{
	text-align: center;
	 
	
	
}

   table { page-break-inside:auto }
   tr    { page-break-inside:avoid; page-break-after:auto }

 </style>

 
 </head>
 <body>
 <div id="content">
   <table border='0' width="90%" cellpadding="0" cellspacing="0" dir="rtl" class="font" style='font-size: 22px;font-weight: bold'>
   <tr>
       <td><?php include("info/companyName.php")?></td>
	</tr>
		<td><?php echo jdate("Y-n-j")   ?></td>
	</table>
	<form action="" class="form-horizontal" id="submit_form" method="POST">
	<table border="0" align="right" dir="rtl" class="dontPrint">
	<tr>
	    <td>نــــام مـشـتــــری:</td>
	    <td><input type="text"    id="customerName" name="customerName"/></td>
	    <td><input type="submit" name="search" value="جستجـــــــــو"></td>
		
		
		
	</tr>
	</table>
	</form>
	 
	 <?php
	       include("db.php");
	       include("findCurrencyRate.php");
		   //dollar
		   $cr_customerAmount_usd_sql="select sum(amount) as amount from customer_statement where   transaction_type='1' and (date between '$start_Date' and '$endDate') and currency_id='2' ";
		   $cr_customerAmount_usd_query= $db ->query($cr_customerAmount_usd_sql);
           $cr_customerAmount_usd_row=$cr_customerAmount_usd_query ->fetch_array();
           $cr_customerAmount_usd=$cr_customerAmount_usd_row['amount'];
                             
		  $dr_customerAmount_usd_sql="select sum(amount) as amount from customer_statement where  transaction_type='2' and (date between '$start_Date' and '$endDate') and currency_id='2' ";
		  $dr_customerAmount_usd_query= $db ->query($dr_customerAmount_usd_sql);
          $dr_customerAmount_usd_row=$dr_customerAmount_usd_query ->fetch_array();
          $dr_customerAmount_usd=$dr_customerAmount_usd_row['amount'];

          $dollar_Currency=$cr_customerAmount_usd-$dr_customerAmount_usd;
		   
		   
	      /*  $dollar_Currency_sql="select  sum(amount) from customerbalance where currencyId='2'  and amount!='0'";
	       $dollar_Currency_query= $db ->query($dollar_Currency_sql);
		   $dollar_Currency_row=$dollar_Currency_query ->fetch_array(); 
		   $dollar_Currency=$dollar_Currency_row['sum(amount)']; */
	       
		   $change_to_dollar_dollar_currency=$dollar_Currency/$select_Currency_dollar;
		   //*******************************************************************************
		   //AFN
			$cr_customerAmount_afn_sql="select sum(amount) as amount from customer_statement where transaction_type='1' and (date between '$start_Date' and '$endDate') and currency_id='1' ";
			$cr_customerAmount_afn_query= $db ->query($cr_customerAmount_afn_sql);
            $cr_customerAmount_afn_row=$cr_customerAmount_afn_query ->fetch_array();
            $cr_customerAmount_afn=$cr_customerAmount_afn_row['amount'];
                            
		    $dr_customerAmount_afn_sql="select sum(amount) as amount from customer_statement where transaction_type='2' and (date between '$start_Date' and '$endDate') and currency_id='1' ";
			$dr_customerAmount_afn_query= $db ->query($dr_customerAmount_afn_sql);
            $dr_customerAmount_afn_row=$dr_customerAmount_afn_query ->fetch_array();
            $dr_customerAmount_afn=$dr_customerAmount_afn_row['amount'];

            $af_Currency=$cr_customerAmount_afn-$dr_customerAmount_afn;
                             							
            
	      /*  $af_Currency_sql="select  sum(amount) from customerbalance where currencyId='1'  and amount!='0'";
	       $af_Currency_query= $db ->query($af_Currency_sql);
		   $af_Currency_row=$af_Currency_query ->fetch_array(); 
		   $af_Currency=$af_Currency_row['sum(amount)'];
	        */
		    
            $change_to_dollar_af_currency=$af_Currency/$today_finalAccount_AFN;	
            $afghaniRate= $today_finalAccount_AFN;
            //END OF AFN
            //********************************************************************************************			
	       //toman(5)
		   $cr_customerAmount_irr_sql="select sum(amount) as amount from customer_statement where   transaction_type='1' and (date between '$start_Date' and '$endDate') and currency_id='5' ";
		   $cr_customerAmount_irr_query= $db ->query($cr_customerAmount_irr_sql);
           $cr_customerAmount_irr_row=$cr_customerAmount_irr_query ->fetch_array();
           $cr_customerAmount_irr=$cr_customerAmount_irr_row['amount'];
                            
			$dr_customerAmount_irr_sql="select sum(amount) as amount from customer_statement where   transaction_type='2' and (date between '$start_Date' and '$endDate') and currency_id='5' ";
			$dr_customerAmount_irr_query= $db ->query($dr_customerAmount_irr_sql);
            $dr_customerAmount_irr_row=$dr_customerAmount_irr_query ->fetch_array();
            $dr_customerAmount_irr=$dr_customerAmount_irr_row['amount'];

            $iran_Currency=$cr_customerAmount_irr-$dr_customerAmount_irr;	
		   
		   
		   /* 
	       $iran_Currency_sql="select  sum(amount) from customerbalance where currencyId='5'  and amount!='0'";
	       $iran_Currency_query= $db ->query($iran_Currency_sql);
		   $iran_Currency_row=$iran_Currency_query ->fetch_array(); 
		   $iran_Currency=$iran_Currency_row['sum(amount)']; */
	
	       $change_to_dollar_iran_currency=$iran_Currency/$select_Currency_toman;
		   //END OF TOMAN
          //***************************************************************************************************		   
	      //Pakistan(4)
		  $cr_customerAmount_pk_sql="select sum(amount) as amount from customer_statement where transaction_type='1' and (date between '$start_Date' and '$endDate') and currency_id='4' ";
		  $cr_customerAmount_pk_query= $db ->query($cr_customerAmount_pk_sql);
          $cr_customerAmount_pk_row=$cr_customerAmount_pk_query ->fetch_array();
          $cr_customerAmount_pk=$cr_customerAmount_pk_row['amount'];
                            
		  $dr_customerAmount_pk_sql="select sum(amount) as amount from customer_statement where  transaction_type='2' and (date between '$start_Date' and '$endDate') and currency_id='4' ";
		  $dr_customerAmount_pk_query= $db ->query($dr_customerAmount_pk_sql);
          $dr_customerAmount_pk_row=$dr_customerAmount_pk_query ->fetch_array();
          $dr_customerAmount_pk=$dr_customerAmount_pk_row['amount'];

          $pakistan_Currency=$cr_customerAmount_pk-$dr_customerAmount_pk;
	       /* $pakistan_Currency_sql="select  sum(amount) from customerbalance where currencyId='4'  and amount!='0'";
	       $pakistan_Currency_query= $db ->query($pakistan_Currency_sql);
		   $pakistan_Currency_row=$pakistan_Currency_query ->fetch_array(); 
		   $pakistan_Currency=$pakistan_Currency_row['sum(amount)']; */
	       
		   $change_to_dollar_pakistan_Currency=$pakistan_Currency/$select_Currency_caldar;
           //END OF PAKISTAN		   
	      //***********************************************************************************
		  $cr_customerAmount_euro_sql="select sum(amount) as amount from customer_statement where transaction_type='1' and (date between '$start_Date' and '$endDate') and currency_id='3' ";
		  $cr_customerAmount_euro_query= $db ->query($cr_customerAmount_euro_sql);
          $cr_customerAmount_euro_row=$cr_customerAmount_euro_query ->fetch_array();
          $cr_customerAmount_euro=$cr_customerAmount_euro_row['amount'];
                            
		  $dr_customerAmount_euro_sql="select sum(amount) as amount from customer_statement where transaction_type='2' and (date between '$start_Date' and '$endDate') and currency_id='3' ";
		  $dr_customerAmount_euro_query= $db ->query($dr_customerAmount_euro_sql);
          $dr_customerAmount_euro_row=$dr_customerAmount_euro_query ->fetch_array();
          $dr_customerAmount_euro=$dr_customerAmount_euro_row['amount'];

          $euro_Currency=$cr_customerAmount_euro-$dr_customerAmount_euro;	
		  
		  
	       //Euro(3)
	       /* $euro_Currency_sql="select  sum(amount) from customerbalance where currencyId='3'  and amount!='0'";
	       $euro_Currency_query= $db ->query($euro_Currency_sql);
		   $euro_Currency_row=$euro_Currency_query ->fetch_array(); 
		   $euro_Currency=$euro_Currency_row['sum(amount)']; */
	       
		   $change_to_dollar_euro_Currency=$euro_Currency*$select_Currency_euro;	
	       
	   
	      $total_customer_RecivePayment=($change_to_dollar_euro_Currency+$change_to_dollar_pakistan_Currency+$change_to_dollar_iran_currency+$change_to_dollar_af_currency+$change_to_dollar_dollar_currency);
	 
	 //====================================================================================================
	  
	 //=================================================================================
	 $resent_USD_cash=($dollar_Currency+(-$today_finalAccount_dollar));
	 
	 $resent_afghani_cash=($af_Currency+(-$assets_af_amount));
	 //$resent_afghani_cash=($assets_af_amount);
	 
	 
	 $resent_toman_cash=($iran_Currency+(-$today_finalAccount_toman));
	 $resent_pakistan_cash=($pakistan_Currency+(-$today_finalAccount_pakistan));
	 $resent_Euro_cash=($euro_Currency+(-$today_finalAccount_euro));
	 include("today_assets_date_plagin.php");
	 //================دخل کنــــــــــــــــونــــی بــــــه دالــــــــــــــــــــــــر
	  $assets_now_dollar=$today_finalAccount_dollar/$select_Currency_dollar;
	  //$assets_now_afn=$today_finalAccount_AFN/$today_finalAccount_AFN;
	  
	 //================دخل کنــــــــــــــــونــــی بــــــه دالــــــــــــــــــــــــر
	 
	 //==============همه دخل ها تبدیل به دالر شود=========================================================
	    $dalketdollar_change_dollar=$today_finalAccount_dollar/$select_Currency_dollar;
	    $dalketafghani_change_dollar=$today_finalAccount_AFN/$afghaniRate;
	    $dalkhelToman_change_dollar=$today_finalAccount_toman/$select_Currency_toman;
	    $dalkhel_kaldar_change_dollar=$today_finalAccount_pakistan/$select_Currency_caldar;
	    $dalkhel_Euro_change_dollar=$today_finalAccount_euro*$select_Currency_euro;
		
		$alldakhleto_dollar= ((-$dalketdollar_change_dollar)+(-$dalketafghani_change_dollar)+(-$dalkhelToman_change_dollar)+(-$dalkhel_kaldar_change_dollar)+(-$dalkhel_Euro_change_dollar));
		 
	  
	  //==============همه دخل ها تبدیل به دالر شود=========================================================
	   //====================وضعیت کنونی به دالر==============================================================
	   //vazeiyat kononi dollar
	   $vaziyat_dollar_to_dollar=$resent_USD_cash/1;
	   
	  //vazeiyat Kononi Afghani
	   $finde_vazeiyatAfghnai=($af_Currency)+(-$today_finalAccount_AFN);
	   $vaziyat_afghani_to_dollar=$finde_vazeiyatAfghnai/$afghaniRate;
	   $resent_afghani_cash=$vaziyat_afghani_to_dollar ;
	   
	   
	   //vazeiyat kononi toman
	   $finde_vazeiyatToman=($iran_Currency)+(-$today_finalAccount_toman);
	   $vaziyat_toman_to_dollar=$finde_vazeiyatToman/$select_Currency_toman;
	   $resent_toman_cash=$vaziyat_toman_to_dollar ;
	    
	   //vazeiyat kononi kaldar
	   $finde_vazeiyatKaldar=($pakistan_Currency)+(-$today_finalAccount_pakistan);
	   $vaziyat_kaldar_to_dollar=$finde_vazeiyatKaldar/$select_Currency_caldar;
	   $resent_pakistan_cash=$vaziyat_kaldar_to_dollar ;
	   
	   //vazeiyat kononi euro
	   $finde_vazeiyatEuro=($euro_Currency)+(-$today_finalAccount_euro);
	   $vaziyat_Euro_to_dollar=$finde_vazeiyatEuro*$select_Currency_euro;
	   $resent_Euro_cash=$vaziyat_Euro_to_dollar ;
	   
	    
	   $all_vaziyattoDollar=($vaziyat_dollar_to_dollar+$resent_afghani_cash+$resent_toman_cash+$resent_pakistan_cash+$resent_Euro_cash);
	   //$all_vaziyattoDollar= 
	   //====================وضعیت کنونی به دالر==============================================================






	?>
	
	
   <table border='1' width="100%" cellpadding="0" cellspacing="0" dir="rtl" class="font" style="margin-top: 10px">
	    <tr>
	    
	   <th colspan='2' style="height: 50px;background: #ffff99">مجموع برد وآورد مشتریان</th>
	   <th style="background: #ffffcc" dir="ltr" ><?php  echo number_format($dollar_Currency)   ?> </th>
	   <th style="background: #ffdf80" dir="ltr"><?php  echo number_format($af_Currency)       ?></th>
	   <th style="background: #b3ffb3" dir="ltr"><?php  echo number_format($iran_Currency)     ?></th>
	   <th style="background: #1affa3" dir="ltr"><?php  echo number_format($pakistan_Currency) ?></th>
	   <th style="background: #bfff00" dir="ltr"><?php  echo number_format($euro_Currency)     ?></th>
	   <th style="background: #b3ecff" dir="ltr"><?php  echo number_format($total_customer_RecivePayment)     ?></th>
	   </tr> 
	   
	   <tr>
	   <th colspan='2' style="height: 50px;background: #ffdf80">موجودی دخل کنونی</th>
	   <th style="background: #ffffcc" dir="ltr"><?php echo number_format($today_finalAccount_dollar)   ?></th>
	   <th style="background: #ffdf80" dir="ltr"><?php echo number_format($today_finalAccount_AFN)      ?></th>
	   <th style="background: #b3ffb3" dir="ltr"><?php echo number_format($today_finalAccount_toman)    ?></th>
	   <th style="background: #1affa3" dir="ltr"><?php echo number_format($today_finalAccount_pakistan) ?></th>
	   <th style="background: #bfff00" dir="ltr"><?php echo number_format($today_finalAccount_euro)     ?></th>
	   <th style="background: #b3ecff" dir="ltr" ><?php  echo number_format($alldakhleto_dollar)     ?></th>
	   </tr> 
	   <tr>
	    
	   <th colspan='2' style="height: 50px;background: #b3ffb3">وضعیت کنونی</th>
	   <th style="background: #ffffcc" dir="ltr"><?php echo number_format($resent_USD_cash)       ?></th>
	   <th style="background: #ffdf80" dir="ltr"><?php echo number_format($finde_vazeiyatAfghnai)   ?></th>
	   <th style="background: #b3ffb3" dir="ltr"><?php echo number_format($finde_vazeiyatToman)     ?></th>
	   <th style="background: #1affa3" dir="ltr"><?php echo number_format($finde_vazeiyatKaldar)  ?></th>
	   <th style="background: #bfff00" dir="ltr"><?php echo number_format($finde_vazeiyatEuro)      ?></th>
	   <th style="background: #b3ecff" dir="ltr"><?php echo number_format($all_vaziyattoDollar)      ?></th>
	   <tr> 
	   <tr>
	   <th style="padding: 5px;background-color: #e6e6ff;width: 10px">شماره</th>
	   <th style="padding: 5px;background-color: #e6e6ff;width: 80px">نام مشتری</th>
	   <th style="padding: 5px;background-color: #ffffcc;width: 80px">الباقی دالر</th>
	   <th style="padding: 5px;background-color: #ffdf80;width: 80px">الباقی افغانی</th>
	   <th style="padding: 5px;background-color: #b3ffb3;width: 80px">الباقی تومان</th>
	   <th style="padding: 5px;background-color: #1affa3;width: 80px">الباقی کالدار</th>
	   <th style="padding: 5px;background-color: #bfff00;width: 80px">الباقی یورو</th>
	   <th style="padding: 5px;background-color: #b3ecff;width: 80px">حساب به دالر</th>
	   <tr>
	   <!--======================================================================================
	   <======================================================================================-->
	   <?php
   if($_POST['search']){
     
	   include('db.php');
	    $today=jdate("Y-m-d");
	   $name=$_POST['customerName'];
	   $splite=split('-',$name);
	   $findingcustomer_id=$splite[0];
	   //===================customerName========================
		    $customerName_sql="select name from customers where id='$findingcustomer_id'";
		    $customerName_query= $db ->query($customerName_sql);
			$customerName_Row=$customerName_query ->fetch_array();
			$customerName=$customerName_Row['name'];
		   
		   //===================customerName========================
		   
		  //=======================دالر
		   $first_findingCurrency_sql="select * from customerbalance where currencyId='2' and customerId='$findingcustomer_id' and amount!='0'";
	       $first_findingCurrency_Query= $db ->query($first_findingCurrency_sql);
		   $first_findingCurrency_Row=$first_findingCurrency_Query ->fetch_array(); 
		   $findingCurrency=$first_findingCurrency_Row['amount'];
		   $customerId=$first_findingCurrency_Row['customerId'];
	       
		  /*  $select_Currency_dollar_sql="select * from crrencyrate  where counterCurrency='2' and baseCurrency='2'  and date='$today'  ";
		   $select_Currency_dollar_query= $db ->query($select_Currency_dollar_sql);
		   $select_Currency_dollar_row=$select_Currency_dollar_query ->fetch_array();
		   $select_Currency_dollar=$select_Currency_dollar_row['rate']; */
		   $select_Currency_dollar=1;
		   
 
		   //Change to dollar
		   $dollarDollar=$findingCurrency/$select_Currency_dollar;
		   //==========================================افغانی
		   $first_findingCurrency_sql_2="select * from customerbalance where currencyId='1' and customerId='$findingcustomer_id' and amount!='0'";
	       $first_findingCurrency_Query_2= $db ->query($first_findingCurrency_sql_2);
		   $first_findingCurrency_Row_2=$first_findingCurrency_Query_2 ->fetch_array(); 
		   $findingCurrency_2=$first_findingCurrency_Row_2['amount']; 
		   
		   /* $select_Currency_afghani_sql="select * from crrencyrate  where counterCurrency='2' and baseCurrency='1'  and date='$today'  ";
		   $select_Currency_afghani_query= $db ->query($select_Currency_afghani_sql);
		   $select_Currency_afghani_row=$select_Currency_afghani_query ->fetch_array();
		   $select_Currency_afghani=$select_Currency_afghani_row['rate']; */
		   
		      
		   //Change to dollar
		   $dollarAfghani=$findingCurrency_2/$today_finalAccount_AFN;
		    if($findingCurrency_2==""){
			  $findingCurrency_2="0.00"; 
		   }
		   //============================================انتهای افغانی
		   //============================================تومان
		   $first_findingCurrency_sql_3="select * from customerbalance where currencyId='5' and customerId='$findingcustomer_id' and amount!='0'";
	       $first_findingCurrency_Query_3= $db ->query($first_findingCurrency_sql_3);
		   $first_findingCurrency_Row_3=$first_findingCurrency_Query_3 ->fetch_array(); 
		   $findingCurrency_3=$first_findingCurrency_Row_3['amount']; 
		   
		  /*  $select_Currency_toman_sql="select * from crrencyrate  where counterCurrency='2' and baseCurrency='5'  and date='$today'  ";
		   $select_Currency_toaman_query= $db ->query($select_Currency_toman_sql);
		   $select_Currency_toman_row=$select_Currency_toaman_query ->fetch_array();
		   $select_Currency_toman=$select_Currency_toman_row['rate'];
		   
		   if(!isset($select_Currency_toman)){
		   
		       echo "<span style='color: red'>لطفا قیمت تومان به دالر را مشخص کنید</span>";
			   die;
		   }			    */
		   $dollarToman=$findingCurrency_3/$select_Currency_toman;
		    if($findingCurrency_3==""){
			  $findingCurrency_3="0.00"; 
		   }
		   //================================================انتهای تومان
		   //================================================ کالدار
		   $first_findingCurrency_sql_4="select * from customerbalance where currencyId='4' and customerId='$findingcustomer_id' and amount!='0'";
	       $first_findingCurrency_Query_4= $db ->query($first_findingCurrency_sql_4);
		   $first_findingCurrency_Row_4=$first_findingCurrency_Query_4 ->fetch_array(); 
		   $findingCurrency_4=$first_findingCurrency_Row_4['amount'];
		   
		  /*  $select_Currency_caldar_sql="select * from crrencyrate  where counterCurrency='2' and baseCurrency='4'  and date='$today'  ";
		   $select_Currency_caldar_query= $db ->query($select_Currency_caldar_sql);
		   $select_Currency_caldar_row=$select_Currency_caldar_query ->fetch_array();
		   $select_Currency_caldar=$select_Currency_caldar_row['rate']; */
		   
		    
		    //Change to dollar
		     $dollarCaldar=$findingCurrency_4/$select_Currency_caldar;
		   if($findingCurrency_4==""){
			  $findingCurrency_4="0.00"; 
		   }
		   //=========================================================انتهای کالدار
		   //=========================================================یورو
		   $first_findingCurrency_sql_5="select * from customerbalance where currencyId='3' and customerId='$findingcustomer_id' and amount!='0'";
	       $first_findingCurrency_Query_5= $db ->query($first_findingCurrency_sql_5);
		   $first_findingCurrency_Row_5=$first_findingCurrency_Query_5 ->fetch_array(); 
		   $findingCurrency_5=$first_findingCurrency_Row_5['amount'];
		   
		  /*  $select_Currency_euro_sql="select * from crrencyrate  where counterCurrency='3' and baseCurrency='2'  and date='$today'  ";
		   $select_Currency_euro_query= $db ->query($select_Currency_euro_sql);
		   $select_Currency_euro_row=$select_Currency_euro_query ->fetch_array();
		   $select_Currency_euro=$select_Currency_euro_row['rate']; */
		   
		   //Change to dollar
		    $dollarEuro=$findingCurrency_5*$select_Currency_euro;
			
			/**********************************************************************************/
			//=================================change all to dollar============================
		    $totalChangeDollar=($dollarEuro+ $dollarCaldar+$dollarToman+$dollarAfghani+$dollarDollar);
			
			
            //=================================change all to dollar============================
			/**********************************************************************************/
			
		   if($findingCurrency_5==""){
			  $findingCurrency_5="0.00"; 
		   }
		   //===================================================
		   if($findingCurrency_5!=0 or $findingCurrency_4!=0 or $findingCurrency_3!=0 or $findingCurrency_2!=0 or  $findingCurrency!=0){
			 $i++;

       			 
			echo "<td style='width: 5px'>$ii</td> ";
		    echo "<td style='width: 200px'>$customerName</a></td> ";
		    echo "<td style='width: 100px;font-size: 22px; ' >".number_format($findingCurrency)."</td> ";
			if($findingCurrency_2<0){ echo "<td style='font-size: 22px;color: red'><a href='customer_statement.php'>".number_format($findingCurrency_2)."</a></td> ";} 
			else{  echo "<td style='font-size: 22px;'><a href='customer_statement.php'>".number_format($findingCurrency_2)."</a></td> ";}
			
	        if($findingCurrency_3<0){ echo "<td style='font-size: 22px;color: red'>".number_format($findingCurrency_3)."</td> ";}
	        else{ echo "<td style='font-size: 22px '>".number_format($findingCurrency_3)."</td> ";}
			
	        if($findingCurrency_4<0){echo "<td style='font-size: 22px;color: red'>".number_format($findingCurrency_4)."</td>";}
	        else{echo "<td style='font-size: 22px '>".number_format($findingCurrency_4)."</td>";}
	       
		    if($findingCurrency_5<0){echo "<td style='font-size: 22px;color: red'>".number_format($findingCurrency_5)."</td>";}
		    else{echo "<td style='font-size: 22px '>".number_format($findingCurrency_5)."</td>";}
			
	        echo "<td style='font-size: 22px;background-color: #e6e6ff; '>".number_format($totalChangeDollar)."</td></tr>";
		   
		      
			   
		   }
	   die;
   }

?> 
	   <?php
	     
	    include('db.php');	
		 $today=jdate("Y-m-d");
		 
	     //=========================================checking dollar rate=======================================
		 $dollarChacking_sql="select * from crrencyrate where date='$today' 
		 and (counterCurrency='2' and baseCurrency='2') and (counterCurrency='2' and baseCurrency='1') and (counterCurrency='3' and baseCurrency='2')
		 and (counterCurrency='2' and baseCurrency='4') and (counterCurrency='2' and baseCurrency='5')";
		 
		 $dollarChacking_query= $db ->query($dollarChacking_sql);
		 $dollarChacking_row=$dollarChacking_query ->fetch_array();
		 $dollarChacking=$dollarChacking_row['rate'];
		 
		 /* if(!isset($dollarChacking)){
		   echo "Please currency";
		    die;
		 } */
		 
	     //=========================================checking dollar rate=======================================
		 
		 
		 
 
	   
	       $findingCustomer_sql="select * from  customers ";
	       $findingCustomer_Query= $db ->query($findingCustomer_sql);
		   $ii=$countId;
   		  while($findingCustomer_Row=$findingCustomer_Query ->fetch_array()){
             $ii++;			  
		   $customerid=$findingCustomer_Row['id'];
		   $customerName=$findingCustomer_Row['name'];
		   
		    
		   
		   //===========usd====================================
			$cr_customerAmount_usd_sql="select sum(amount) as amount from customer_statement where customerId='$customerid' and transaction_type='1' and (date between '$start_Date' and '$endDate') and currency_id='2' ";
			$cr_customerAmount_usd_query= $db ->query($cr_customerAmount_usd_sql);
            $cr_customerAmount_usd_row=$cr_customerAmount_usd_query ->fetch_array();
            $cr_customerAmount_usd=$cr_customerAmount_usd_row['amount'];
                           
		    $dr_customerAmount_usd_sql="select sum(amount) as amount from customer_statement where customerId='$customerid' and transaction_type='2' and (date between '$start_Date' and '$endDate') and currency_id='2' ";
		    $dr_customerAmount_usd_query= $db ->query($dr_customerAmount_usd_sql);
            $dr_customerAmount_usd_row=$dr_customerAmount_usd_query ->fetch_array();
            $dr_customerAmount_usd=$dr_customerAmount_usd_row['amount'];
             
            $findingCurrency=$cr_customerAmount_usd-$dr_customerAmount_usd;
                         			
           //=============usd=======================================
		  /*  $first_findingCurrency_sql="select * from customerbalance where currencyId='2' and customerId='$findingcustomer_id' and amount!='0'";
	       $first_findingCurrency_Query= $db ->query($first_findingCurrency_sql);
		   $first_findingCurrency_Row=$first_findingCurrency_Query ->fetch_array(); 
		   $findingCurrency=$first_findingCurrency_Row['amount'];
		   $customerId=$first_findingCurrency_Row['customerId']; */
	       
		   $select_Currency_dollar=1;
		   //Change to dollar
		   $dollarDollar=$findingCurrency/$select_Currency_dollar;
		   
		   //==========================================افغانی
		   //===========afn====================================
			$cr_customerAmount_afn_sql="select sum(amount) as amount from customer_statement where customerId='$customerid' and transaction_type='1' and (date between '$start_Date' and '$endDate') and currency_id='1' ";
			$cr_customerAmount_afn_query= $db ->query($cr_customerAmount_afn_sql);
            $cr_customerAmount_afn_row=$cr_customerAmount_afn_query ->fetch_array();
            $cr_customerAmount_afn=$cr_customerAmount_afn_row['amount'];
                            
			$dr_customerAmount_afn_sql="select sum(amount) as amount from customer_statement where customerId='$customerid' and transaction_type='2' and (date between '$start_Date' and '$endDate') and currency_id='1' ";
			$dr_customerAmount_afn_query= $db ->query($dr_customerAmount_afn_sql);
            $dr_customerAmount_afn_row=$dr_customerAmount_afn_query ->fetch_array();
            $dr_customerAmount_afn=$dr_customerAmount_afn_row['amount'];

           $findingCurrency_2=$cr_customerAmount_afn-$dr_customerAmount_afn;
                             							
            //=============afn=======================================
		  /*  
		   $first_findingCurrency_sql_2="select * from customerbalance where currencyId='1' and customerId='$findingcustomer_id' and amount!='0'";
	       $first_findingCurrency_Query_2= $db ->query($first_findingCurrency_sql_2);
		   $first_findingCurrency_Row_2=$first_findingCurrency_Query_2 ->fetch_array(); 
		   $findingCurrency_2=$first_findingCurrency_Row_2['amount'];  */
		   
		   $select_Currency_afghani_sql="select * from crrencyrate  where counterCurrency='2' and baseCurrency='1' order by id desc limit 1 ";
		   $select_Currency_afghani_query= $db ->query($select_Currency_afghani_sql);
		   $select_Currency_afghani_row=$select_Currency_afghani_query ->fetch_array();
		   $select_Currency_afghani=$select_Currency_afghani_row['rate'];
		   
		 
		   //Change to dollar
		   $dollarAfghani=$findingCurrency_2/$select_Currency_afghani;
		   
			if($findingCurrency_2==""){
			  $findingCurrency_2="0.00"; 
		   }
		   //============================================انتهای افغانی
		   //============================================تومان
		   //===========IRR====================================
			$cr_customerAmount_irr_sql="select sum(amount) as amount from customer_statement where customerId='$customerid' and transaction_type='1' and (date between '$start_Date' and '$endDate') and currency_id='5' ";
			$cr_customerAmount_irr_query= $db ->query($cr_customerAmount_irr_sql);
            $cr_customerAmount_irr_row=$cr_customerAmount_irr_query ->fetch_array();
            $cr_customerAmount_irr=$cr_customerAmount_irr_row['amount'];
                            
			$dr_customerAmount_irr_sql="select sum(amount) as amount from customer_statement where customerId='$customerid' and transaction_type='2' and (date between '$start_Date' and '$endDate') and currency_id='5' ";
			$dr_customerAmount_irr_query= $db ->query($dr_customerAmount_irr_sql);
            $dr_customerAmount_irr_row=$dr_customerAmount_irr_query ->fetch_array();
            $dr_customerAmount_irr=$dr_customerAmount_irr_row['amount'];

            $findingCurrency_3=$cr_customerAmount_irr-$dr_customerAmount_irr;	
           //=============irr=======================================
		   /* $first_findingCurrency_sql_3="select * from customerbalance where currencyId='5' and customerId='$findingcustomer_id' and amount!='0'";
	       $first_findingCurrency_Query_3= $db ->query($first_findingCurrency_sql_3);
		   $first_findingCurrency_Row_3=$first_findingCurrency_Query_3 ->fetch_array(); 
		   $findingCurrency_3=$first_findingCurrency_Row_3['amount'];  */
		   
		   $select_Currency_toman_sql="select * from crrencyrate  where counterCurrency='2' and baseCurrency='5'  order by id desc limit 1  ";
		   $select_Currency_toaman_query= $db ->query($select_Currency_toman_sql);
		   $select_Currency_toman_row=$select_Currency_toaman_query ->fetch_array();
		   $select_Currency_toman=$select_Currency_toman_row['rate'];
		   
		   
		   $dollarToman=$findingCurrency_3/$select_Currency_toman;
		    
		    if($findingCurrency_3==""){
			  $findingCurrency_3="0.00"; 
		   }
		   //================================================انتهای تومان
		   //================================================ کالدار
		   //===========pkk====================================
	        $cr_customerAmount_pk_sql="select sum(amount) as amount from customer_statement where customerId='$customerid' and transaction_type='1' and (date between '$start_Date' and '$endDate') and currency_id='4' ";
			$cr_customerAmount_pk_query= $db ->query($cr_customerAmount_pk_sql);
            $cr_customerAmount_pk_row=$cr_customerAmount_pk_query ->fetch_array();
            $cr_customerAmount_pk=$cr_customerAmount_pk_row['amount'];
                            
			$dr_customerAmount_pk_sql="select sum(amount) as amount from customer_statement where customerId='$customerid' and transaction_type='2' and (date between '$start_Date' and '$endDate') and currency_id='4' ";
			$dr_customerAmount_pk_query= $db ->query($dr_customerAmount_pk_sql);
            $dr_customerAmount_pk_row=$dr_customerAmount_pk_query ->fetch_array();
            $dr_customerAmount_pk=$dr_customerAmount_pk_row['amount'];

            $findingCurrency_4=$cr_customerAmount_pk-$dr_customerAmount_pk;	
            //=============pkk=======================================
		   
		   /* $first_findingCurrency_sql_4="select * from customerbalance where currencyId='4' and customerId='$findingcustomer_id' and amount!='0'";
	       $first_findingCurrency_Query_4= $db ->query($first_findingCurrency_sql_4);
		   $first_findingCurrency_Row_4=$first_findingCurrency_Query_4 ->fetch_array(); 
		   $findingCurrency_4=$first_findingCurrency_Row_4['amount']; */
		   
		   $select_Currency_caldar_sql="select * from crrencyrate  where counterCurrency='2' and baseCurrency='4'  order by id desc limit 1 ";
		   $select_Currency_caldar_query= $db ->query($select_Currency_caldar_sql);
		   $select_Currency_caldar_row=$select_Currency_caldar_query ->fetch_array();
		   $select_Currency_caldar=$select_Currency_caldar_row['rate'];
		   
		    
		    //Change to dollar
		     $dollarCaldar=$findingCurrency_4/$select_Currency_caldar;
		    
		   if($findingCurrency_4==""){
			  $findingCurrency_4="0.00"; 
		   }
		   //=========================================================انتهای کالدار
		   //=========================================================یورو
		   //===========Euro====================================
		   $cr_customerAmount_euro_sql="select sum(amount) as amount from customer_statement where customerId='$customerid' and transaction_type='1' and (date between '$start_Date' and '$endDate') and currency_id='3' ";
		   $cr_customerAmount_euro_query= $db ->query($cr_customerAmount_euro_sql);
           $cr_customerAmount_euro_row=$cr_customerAmount_euro_query ->fetch_array();
           $cr_customerAmount_euro=$cr_customerAmount_euro_row['amount'];
                            
		   $dr_customerAmount_euro_sql="select sum(amount) as amount from customer_statement where customerId='$customerid' and transaction_type='2' and (date between '$start_Date' and '$endDate') and currency_id='3' ";
		   $dr_customerAmount_euro_query= $db ->query($dr_customerAmount_euro_sql);
           $dr_customerAmount_euro_row=$dr_customerAmount_euro_query ->fetch_array();
           $dr_customerAmount_euro=$dr_customerAmount_euro_row['amount'];

           $findingCurrency_5=$cr_customerAmount_euro-$dr_customerAmount_euro;	
           //=============Euro=======================================
		   /* $first_findingCurrency_sql_5="select * from customerbalance where currencyId='3' and customerId='$findingcustomer_id' and amount!='0'";
	       $first_findingCurrency_Query_5= $db ->query($first_findingCurrency_sql_5);
		   $first_findingCurrency_Row_5=$first_findingCurrency_Query_5 ->fetch_array(); 
		   $findingCurrency_5=$first_findingCurrency_Row_5['amount']; */
		    
		   $select_Currency_euro_sql="select * from crrencyrate  where counterCurrency='3' and baseCurrency='2'  order by id desc limit 1  ";
		   $select_Currency_euro_query= $db ->query($select_Currency_euro_sql);
		   $select_Currency_euro_row=$select_Currency_euro_query ->fetch_array();
		   $select_Currency_euro=$select_Currency_euro_row['rate'];
		   //Change to dollar
		    $dollarEuro=$findingCurrency_5*$select_Currency_euro;
			
		    $totalChangeDollar=($dollarEuro+ $dollarCaldar+$dollarToman+$dollarAfghani+$dollarDollar);
			if($totalChangeDollar<0){
			   $sum_dollarManfi+=$totalChangeDollar;
			}
			if($totalChangeDollar>0){
			   $sum_dollarMosbat+=$totalChangeDollar;
			}
			
		    
			//echo "<br>==========================</br>"; 
		   if($findingCurrency_5==""){
			  $findingCurrency_5="0.00"; 
		   }
		   //===================================================
		   //if($findingCurrency_5!=0 or $findingCurrency_4!=0 or $findingCurrency_3!=0 or $findingCurrency_2!=0 or  $findingCurrency!=0){ 
			 $i++;  
			echo "<td style='width: 5px'>$i</td> ";
		    echo "<td style='width: 200px'>$customerName</td> ";
		     
	       if($findingCurrency<0){ echo "<td style='font-size: 22px;text-align: right' dir='ltr'><a href='report/customer_statement.php?currency_id=2&customerID=$customerid' target='_'><span style='color: red'>".number_format($findingCurrency)."</span></a></td> ";} 
			else{  echo "<td style='font-size: 22px;text-align: right' dir='ltr'><a href='report/customer_statement.php?currency_id=2&customerID=$customerid' target='_'>".number_format($findingCurrency)."</a></td> ";}
			
		   if($findingCurrency_2<0){ echo "<td style='font-size: 22px;color: red;text-align: right' dir='ltr'><a href='report/customer_statement.php?currency_id=1&customerID=$customerid' target='_'><span style='color: red'>".number_format($findingCurrency_2)."</span></a></td> ";} 
			else{  echo "<td style='font-size: 22px;text-align: right' dir='ltr'><a href='report/customer_statement.php?currency_id=1&customerID=$customerid' target='_'>".number_format($findingCurrency_2)."</a></td> ";}
			
			
	        if($findingCurrency_3<0){ echo "<td style='font-size: 22px;color: red;text-align: right' dir='ltr'><a href='report/customer_statement.php?currency_id=5&customerID=$customerid' target='_'><span style='color: red'>".number_format($findingCurrency_3)."</span></a></td> ";}
	        else{ echo "<td style='font-size: 22px ;text-align: right' dir='ltr'><a href='report/customer_statement.php?currency_id=5&customerID=$customerid' target='_'>".number_format($findingCurrency_3)."</a></td> ";}
			
	        if($findingCurrency_4<0){echo "<td style='font-size: 22px;color: red;text-align: right' dir='ltr'><a href='report/customer_statement.php?currency_id=4&customerID=$customerid' target='_'><span style='color: red'>".number_format($findingCurrency_4)."</span></a></td>";}
	        else{echo "<td style='font-size: 22px;text-align: right' dir='ltr'><a href='report/customer_statement.php?currency_id=4&customerID=$customerid' target='_'>".number_format($findingCurrency_4)."</a></td>";}
	       
		    if($findingCurrency_5<0){echo "<td style='font-size: 22px;color: red;text-align: right' dir='ltr'><a href='report/customer_statement.php?currency_id=3&customerID=$customerid' target='_'><span style='color: red;'>".number_format($findingCurrency_5)."</span></a></td>";}
		    else{echo "<td style='font-size: 22px;text-align: right' dir='ltr'><a href='report/customer_statement.php?currency_id=3&customerID=$customerid' target='_'>".number_format($findingCurrency_5)."</a></td>";}
			
	        echo "<td style='background-color: #e6e6ff;width: 120px;text-align: right' dir='ltr'><a href='report/customer_statement.php?currency_id=3&customerID=$customerid' target='_'>".number_format($totalChangeDollar)."</td></tr>";
		   
		      
			   
		   //}
		   
		   
		    
		   
		   
		    
		   }
		    
	    
	   echo "<tr>
	   </tr>";
	   $albaqi=$sum_dollarMosbat-(-$sum_dollarManfi);
	   echo "<tr>
	            <td colspan='2'> </td>
	            <td style='background-color: #99ddff'>مجموع مثبت دالر</td>
	            <td dir='ltr' style='txt-align: right;background-color: #99ddff'>".number_format($sum_dollarMosbat,2)."</td>
	            <td style='background-color: #ffffcc'>مجموع دالر منفی</td>
	            <td dir='ltr' style='txt-align: right;background-color: #ffffcc'>".number_format($sum_dollarManfi,2)."</td>
	            <td style='background-color: silver'>الباقی</td>";
				
				if($albaqi>0){
	             echo "<td dir='ltr' style='txt-align: right;background:#99ffd6'>".number_format($albaqi,2)."</td>";
				}
				if($albaqi<0){
	             echo "<td dir='ltr' style='txt-align: right;background:#ffad99'>".number_format($albaqi,2)."</td>";
				}
				
				
	   echo"</tr>";
	   
  echo'    	</table>';
 
?>

<ul>

<?php 
 echo "<form method='post' action='report/excelFile.php'>
       <table border='1'>
       <tr>
			<td><input type='submit' name='excel' value='تبدیل به اکسل'>
		</td>
		</tr>
		</table>
		</form>";
 
	
	
	?>
</ul>
 
</body>
</html>
 
	
	
	
	
	 
    