<?php
 session_start();
    
   include("../pdate.php");
    include("../db.php"); 
  
    $endDate = $_POST['eyear']."-".$_POST['emonth']."-".$_POST['eday'];
	 
    $startDate = $_POST['year']."-".$_POST['month']."-".$_POST['day'];
	 
    $counterCurrency_kind=$_POST['counterCurrency']; 
    if($startDate=="" and $endDate=="" and $counterCurrency_kind==""){
     $startDate=$_GET['startDate'];
	    
	 $endDate=$_GET['endDate'];
	  
	 $counterCurrency_kind=trim($_GET['counterCurrency_kind']);
	 
	  
	 }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<title>Customer Payment List</title>
<head>
    
 
 <style>
 a:link {
    text-decoration: none;
	color: #000;
}

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

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

}
@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%;    
    }
}
 </style>

</head>
	<body onkeydown = "onKeyDown()" onKeyPress="return disableEnterKey(event)">
  
<div id="wrap">
 
 <div id='content'>
  <?php
  //==================opening Balance======================================================
  include("db.php");
  $opening_sql="select * from assetopeningbalance where currencyUnit='$counterCurrency_kind'";
  $opening_query=$db ->query($opening_sql);
  $opening_row=$opening_query ->fetch_array();
  echo $opening=$opening_row['amount'];
  echo "<br>froshat:";
    //==================opening Balance===============================================================   
   //====================فروشات از یک پول=============================================================
   $froosh_sql="SELECT   sum(counterAmount)  FROM `transaction` where counterCurrency='$counterCurrency_kind'  AND treatment='2'   and  (date >='$startDate' AND date <='$endDate') ";
   $froosh_query=$db ->query($froosh_sql);
   $froosh_row=$froosh_query ->fetch_array();
   echo $froosh=$froosh_row['sum(counterAmount)'];
    
   //=================================================================================================== 
  
  //====================بردگی از یک پول=============================================================
   $bordegi_sql="SELECT   sum(amount)  FROM `customerpayment` where remove='0' and transacttype='2' and transactCurrency='$counterCurrency_kind'  and  (date >='$startDate' AND date <='$endDate') ";
   $bordegi_query=$db ->query($bordegi_sql);
   $bordegi_row=$bordegi_query ->fetch_array();
   echo "<br>Bordegiha:";
   echo $bordegi=$bordegi_row['sum(amount)'];
    
   //=================================================================================================== 
    
   //====================مصارف=============================================================
   $masaref_sql="SELECT sum(amount) FROM `others` where currencyId='$counterCurrency_kind' and typeOthers='1'   and  (date >='$startDate' AND date <='$endDate') ";
   $masaref_query=$db ->query($masaref_sql);
   $masaref_row=$masaref_query ->fetch_array();
   echo "<br>Masaref:";
   echo $masaref=$masaref_row['sum(amount)'];
   //=================================================================================================== 
  echo "<br>Majmoo Mohasebe:";
  echo $colReftegiha=$froosh+$bordegi+$masaref;
   
  echo "<br>=================================================================</br>";
//==========================================================================================================  
//==========================================================================================================  
//==========================================================================================================  
 //====================خریداری از یک پول=============================================================
   $kharid_sql="SELECT   sum(counterAmount)  FROM `transaction` where counterCurrency='$counterCurrency_kind'  AND treatment='1' and extra='0'  and  (date >='$startDate' AND date <='$endDate') ";
   $kharid_query=$db ->query($kharid_sql);
   $kharid_row=$kharid_query ->fetch_array();
   echo "kharid:";
   echo $kharid=$kharid_row['sum(counterAmount)'];
    
   //=================================================================================================== 
  //====================آوردگی ها از یک پول=============================================================
   $avordegi_sql="SELECT   sum(amount)  FROM `customerpayment` where remove='0' and transacttype='1' and transactCurrency='$counterCurrency_kind'  and  (date >='$startDate' AND date <='$endDate') ";
   $avordegi_query=$db ->query($avordegi_sql);
   $avordegi_row=$avordegi_query ->fetch_array();
   echo "<br>Avordegi:";
   echo $avordegi=$avordegi_row['sum(amount)'];
    
   //=================================================================================================== 
  
  //====================آوردگی ها از یک پول=============================================================
   $amadegi_change_pool_sql="SELECT sum(baseAmount) FROM `transaction` where treatment='2' and baseCurrency='$counterCurrency_kind'  and  (date >='$startDate' AND date <='$endDate') ";
   $amadegi_change_pool_query=$db ->query($amadegi_change_pool_sql);
   $amadegi_change_pool_row=$amadegi_change_pool_query ->fetch_array();
   echo "<br> Moamelat Deigar:";
   echo $amadegi_change_pool=$amadegi_change_pool_row['sum(baseAmount)'];
    
   //=================================================================================================== 
   echo "<br>Hameye Avordegiha";
   echo $colAvordegiha=$amadegi_change_pool+$avordegi+$kharid+$opening;
   echo "<br>===========================</br>";
   echo $tafvot=$colAvordegiha-$colReftegiha;
  
  
  
  ?>
			
 </tbody></table>
</div>
</div>  
 </body>
 </form>
 </html>  
  
 
     