<?php
 session_start();
    include("db.php");
        $endDate   = $_POST['eyear']."-".$_POST['emonth']."-".$_POST['eday'];
		 
        $startDate = $_POST['year']."-".$_POST['month']."-".$_POST['day'];
		 
        $counterCurrency_kind=$_POST['counterCurrency']; 
//==================================================
		
		
		 
		$get_startDate=$_GET['startDate'];
		$get_endDate=$_GET['endDate'];
		$get_counterCurrency_kind=trim($_GET['counterCurrency_kind']);
		
		 
		if(strlen($get_startDate)!=0){
			$startDate=$get_startDate;
		}
		if(strlen($get_endDate)!=0){
			$endDate=$get_endDate;
		}
		if(strlen($get_counterCurrency_kind)!=0){
			 
			$counterCurrency_kind=$get_counterCurrency_kind;
		}
		
		
     

	 //============================currency Name======================
	   
	   $curencyName_sql="select name from  `currencies` where id='$counterCurrency_kind'";
		$currencyName_query=$db ->query($curencyName_sql);
		$currencyName_row=$currencyName_query ->fetch_array();
		$currencyName=$currencyName_row['name'];	
	 						 
	 //============================currency Name======================
	 
	 
?>
<!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>فروشات روز</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 <?php echo $currencyName; ?>
			    
				<br><span style='color:green'>از </span><?php echo $startDate ?><span style="color:green"> تا </span> <?php echo $endDate ?></td>
				 
			  
			
			<th style="width:186px;text-align:left;height: 40px" > </th>
			 
		</tr>
		</table> 

 <div id='content'>
 
  <?php
    
	  //echo "<div id='content'>";
	
	  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>
				<th scope="col">ارز پایه</th>
				<th scope="col">مقدار به ارز پایه</th>
			 
			</thead>
				 ';
    // Get page data
	 echo "<div id='content'>";
	  
			                include('db.php');
				            

						  
						 
					    if(isset($startDate) and isset($endDate) and  $counterCurrency_kind!="all" ){
						     $mony_sql="SELECT   *  FROM `transaction` where counterCurrency='$counterCurrency_kind'  AND treatment='2'   and  (date >='$startDate' AND date <='$endDate')";
						 }
						 if(isset($startDate) and isset($endDate) and $counterCurrency_kind=="all"){
						  
						   $mony_sql="SELECT   *  FROM `transaction` where  treatment='2' 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'];
							$counterCurrency= $nrow['counterCurrency'];
							$totalDollar+=$counterAmount= $nrow['counterAmount'];
							$rate= $nrow['rate'];
						    $baseCurrency= $nrow['baseCurrency'];
							$baseAmount= $nrow['baseAmount'];
							$total+=$amount= $nrow['amount'];
							$totalBaseAmount+=$baseAmount;
							 
							 
							 
							//=============================================================
							 
							 
							//******************************Currency Name*******************************
							 $countercurrency_sql="select name from  `currencies` where id='$counterCurrency'";
							 $countercurrency_query=$db ->query($countercurrency_sql);
							 $countercurrency_row=$countercurrency_query ->fetch_array();
							 $countercurrency=$countercurrency_row['name'];	
							//=============================================================
							 //******************************Base Courrency*******************************
							 $basecurrency_sql="select name from  `currencies` where id='$baseCurrency'";
							 $basecurrency_query=$db ->query($basecurrency_sql);
							 $basecurrency_row=$basecurrency_query ->fetch_array();
							 $basecurrency=$basecurrency_row['name'];	
							//=============================================================
							  //=============finding Unit====================================
							 $unit_sql="select unit from crrencyrate where counterCurrency='$counterCurrency'";
							 $unit_query=$db ->query($unit_sql);
							 $unit_Row=$unit_query ->fetch_array();
							 $unit=$unit_Row['unit'];
							//=============end finding Unit====================================
							    
							    
						    //**************************************************************************************************   
							 
							 
			echo "<tbody>
			<tr>
			<td>".$ii."</td>
			<td>".$date."</td>
			<td>".$countercurrency."</td>
			<td>".number_format($counterAmount)."</td> 
			<td>".number_format($rate)."</td> 
			<td>".$basecurrency."</td>
			<td>".number_format($baseAmount) ."</td>
			 
			 </tr>";					  
				 	  } 
		 if($counterCurrency_kind!="all"){					  
		      echo '<tr style="color: red"><td colspan="7" style="font-weight: bold">فروش:'.number_format($totalDollar)."(".$currencyName.')</td></tr>';
		      echo '<tr style="color: red"><td colspan="7" style="font-weight: bold">رسیدگی:'.number_format($totalBaseAmount)."(".$basecurrency.')</td></tr>';
		 
		 }
		 echo '</table>';
		 
		 
              	
	 
?>
<!--==========================================================================================-->  
<!--==========================================================================================-->  
<!--==========================================================================================-->  
	 
			
 </tbody></table>
</div>
</div>  
 </body>
 </form>
 </html>  
  
 
     