<?php
 session_start();
    
   include("../jdf.php");
   include("db.php");
/*     $startDate_gross=$_POST['startDate'];
	$start_explide=explode("/",$startDate_gross);
	 
	 $start_year=$start_explide[0];
	 
	 $start_month=$start_explide[1];
	 
	$start_day=$start_explide[2];
	  
	  if($start_day<10 and $start_day>=1){
					 $start_day ="0".$start_day;
	 }
	
	
	
	 $startDate=$start_year."-".$start_month."-".$start_day;
      
     $endDate_gross=$_POST['endDate'];
	 $end_explide=explode("/",$endDate_gross);
	 
	 $end_year=$end_explide[0];
	 
	 $end_month=$end_explide[1];
	 
	 $end_day=$end_explide[2];
	 if($end_day<10 and $end_day>=1){
					 $end_day ="0".$end_day;
	 }
	$endDate=$end_year."-".$end_month."-".$end_day; */
	
		
    
		
	$endDate   = $_POST['eyear']."-".$_POST['emonth']."-".$_POST['eday'];
    $startDate = $_POST['year']."-".$_POST['month']."-".$_POST['day'];
     
    $transacttype=trim($_POST['treat']); 
	
	$counterCurrency=$_POST['counterCurrency'];




    $get_startDate=$_GET['startDate'];
	 
    $get_endDate=$_GET['endDate'];
	 
    $get_transactiontype=$_GET['transactiontype'];
	 
    $get_counterCurrency=$_GET['counterCurrency'];
	
     if(isset($get_startDate)){
		$startDate=$get_startDate; 
	 }
     if(isset($get_endDate)){
		$endDate=$get_endDate; 
	 }
     
	   if(isset($get_transactiontype)){
		$transacttype=$get_transactiontype; 
	 }
     
	   if(isset($get_counterCurrency)){
		$counterCurrency=$get_counterCurrency; 
	 }
     
	    
	  
	 
	$startDate ; 
	 
    if($transacttype=="1"){
	   $treatMent='رسیــدگیهــا';
	   if($counterCurrency!="all"){
		$mony_sql="SELECT   sum(amount) FROM `customerpayment` where remove='0' and  transacttype='$transacttype' and  transactCurrency='$counterCurrency' and (date >='$startDate' AND date <='$endDate') ";
	    $mony_query= $db ->query($mony_sql);
		$mony_row=$mony_query ->fetch_array();
		$mony=$mony_row['sum(amount)'];
	
	
	}

	} 
	
	
	if($transacttype=="2"){
	   $treatMent='بـردگیهــا';
	    if($counterCurrency!="all"){
		$mony_sql="SELECT   sum(amount) FROM `customerpayment` where remove='0' and  transacttype='$transacttype' and  transactCurrency='$counterCurrency' and (date >='$startDate' AND date <='$endDate') ";
	    $mony_query= $db ->query($mony_sql);
		$mony_row=$mony_query ->fetch_array();
		$mony=$mony_row['sum(amount)'];
	
	
	}
	 }
?>
<!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>
   <link rel="icon" href="../images/favicon.ico" type="image/png"/>  
   <link rel="stylesheet" href="table_style/table_style7.css">
   <link href="../css/pagenation.css" rel="stylesheet" type="text/css" /> 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../css/print.css" /> 
<!-- ===================ÇíÌÇÏ íÇã ÈÑÇí æíÑÇíÔ ÝÇíá====================================-->
<script type="text/javascript" src="../change/edite/revenue_edite.js"></script> 
<script type="text/javascript" src="../change/delete/revenue_delete.js"></script>
 
<!--======================= ÇíÇä  ============================================================-->
 <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)">
 <?php  //include("r_c_d_s_p/back_print_save_refresh.php"); ?>
<div id="wrap">
<table border="0" align="center"   width="930px" dir="rtl" class="font">
		<tr>
			<th style="width:166px;text-align:right">
			   
			</th>	 
			
			
			
			
			 
				 </th>
				 
				<th style="width:206px"><h3><?php include("../info/companyName.php"); ?></h3>بـرد و رسیـد مشتـریان&nbsp;<br><?php echo $treatMent; ?>
			    
				<br><span style='color:green'>از </span><?php echo $startDate ?><span style="color:green"> تا </span><?php echo $endDate ?><br><?php echo number_format($mony) ?></td>
				 
			  
			  
			
			<th style="width:186px;text-align:left;height: 40px" > </th>
			 
		</tr>
		</table> 

 <div id='content'>
 
  <?php
   //if($_POST['submit']){
     
	
	 
	
	 
	
	
    include("db.php");
	 
	  echo'
			<table id="box-table-a"   dir="rtl"  align="center" >
	        <thead> 
				<th scope="col">شماره</th>
				<th scope="col">مشتری</th>
				<th scope="col">تاریخ</th>
				<th scope="col">نوعیت پول</th>
				<th scope="col">مقدار</th>
				 
			</thead>
				 ';
    // Get page data
	 echo "<div id='content'>";
	  
			                include('db.php');
				            

						  
						 
					   if($counterCurrency=="all"){
						    $mony_sql="SELECT   *  FROM `customerpayment` where remove='0' and  transacttype='$transacttype'  and (date >='$startDate' AND date <='$endDate')  ";
						 }
						  if($counterCurrency!="all"){
						     $mony_sql="SELECT   *  FROM `customerpayment` where remove='0' and  transacttype='$transacttype' and  transactCurrency='$counterCurrency' and (date >='$startDate' AND date <='$endDate')  ";
						 }
						 $mony_query= $db ->query($mony_sql);
				  
						  
                          while($nrow=$mony_query ->fetch_array()){
						    $ii++;
							$id = $nrow['id'];
							 
							$date= $nrow['date'];
							$customerId= $nrow['customerId'];
							$transactCurrency= $nrow['transactCurrency'];
							$amount= $nrow['amount'];
						    $totalAmount+=$amount; 
							 
							 
							 
							//=============================================================
							 
							 
							//******************************Currency Name*******************************
							 $countercurrency_sql="select name from  `currencies` where id='$transactCurrency'";
							 $countercurrency_query=$db ->query($countercurrency_sql);
							 $countercurrency_row=$countercurrency_query ->fetch_array();
							 $countercurrency=$countercurrency_row['name'];	
							//=============================================================
							 //******************************customer Name*******************************
							 $customerName_sql="select name from  `customers` where id='$customerId'";
							 $customerName_query=$db ->query($customerName_sql);
							 $customerName_row=$customerName_query ->fetch_array();
							 $customerName=$customerName_row['name'];	
							//=============================================================
							 
							    
						    //**************************************************************************************************   
							 
							 
			echo "<tbody>
			<tr>
			<td>".$ii."</td>
			<td>".$customerName."</td>
			<td>".$date."</td>
			<td>".$countercurrency."</td> 
			<td>".number_format($amount)."</td> 
			 
			 </tr>";					  
				 	  }
          if($counterCurrency!="all"){					  
		      echo '<tr style="color: red"><td colspan="5" style="font-weight: bold">'.number_format($totalAmount,2).'</td></tr>';
		 
		 }
		 echo '</table>';
         	
	 

?>
<!--==========================================================================================-->  
<!--==========================================================================================-->  
<!--==========================================================================================-->  
	 
			
 </tbody></table>
</div>
</div>  
 </body>
 </form>
 </html>  
  
 
     