<?php
 session_start();
    
   include("../pdate.php");  
?>
<!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">
			   
				 
			
			
			
			
			<?php 
			       
			  
			 /*  if(isset( $startDate) and isset( $endDate)){
			  
			  
			  
				  echo '</th>
				<th style="width:206px"><h3>صرافی عبدالحکیم و برادران</h3>لیست پرداختی&nbsp;'. ucfirst($customerName);
			    
				echo "<br><span style='color:green'>از </span>".$startDate.'<span style="color:green"> TO </span>'.$endDate.'</td>';
				}
			  
			  else{
			   
			     echo '</th>
			     <th style="width:206px"><h2>صرافی عبدالحکیم و برادران</h2>لیست پرداختی&nbsp;'.ucfirst($customerName);
			      echo '</br> '.pdate("Y-m-d" ).'</th>';
			  } */
			  ?>
			
			<th style="width:186px;text-align:left" ><img src="img/tash.png" width="130" height="130"   ></th>
			 
		</tr>
		</table> 

 <div id='content'>
 
  <?php
    
	 $date=$_SESSION['date'];
    include("db.php");
	$tableName="transaction";		
	$targetpage = "detailsTreadReport.php"; 	
	$limit = 12; 
 
	$sql="SELECT COUNT(*) as num FROM `$tableName` where date='$date'";
	 
	$query= $db ->query($sql);
	$total_pages= $query ->fetch_array();
	
	 
	$total_pages = $total_pages[num];
	
	$stages = 3;
	$page = mysql_escape_string($_GET['page']);
	if($page){
		$start = ($page - 1) * $limit; 
	}else{
		$start = 0;	
		}	
	//================================================inter page cods HERE===============================================
    // Get page data
		
	  //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>
				 
			</thead>
				 ';
    // Get page data
	 echo "<div id='content'>";
	  
			                include('db.php');
				            

						  
						 
					   
						 $currencySql="select distinct baseCurrency,counterCurrency  from transaction where date='$date' LIMIT $start, $limit ";
					     $currencyQuery=$db ->query($currencySql);
					      $i=0;
						 while($currencyRow=$currencyQuery ->fetch_array()){
						
						  $baseCurrency=$currencyRow['baseCurrency'];    //واحد پولی پایه
						  $counterCurrency=$currencyRow['counterCurrency']; //واحد پولی ارز مورد معاوضه
						  
						  $baseNameSql="select name from currencies where id='$baseCurrency'";
						  $baseNameQuery =$db ->query($baseNameSql);
						  $baseNameRow=$baseNameQuery ->fetch_array();
						  $baseName=$baseNameRow ['name']; 
						  
						  $countNameSql="select name from currencies where id='$counterCurrency'";
						  $counterNameQuery =$db ->query($countNameSql);
						  $counterNameRow=$counterNameQuery ->fetch_array();
						  $counterName=$counterNameRow ['name'];
						  //=====================================================sum Buy==================
						   $totalBuySql="select sum(counterAmount) from transaction where baseCurrency='$baseCurrency' 
						   and counterCurrency='$counterCurrency'  and date='$date' and treatment='1'";
						   $totalBuyQuery= $db ->query($totalBuySql);
						   $totalBuyRow=$totalBuyQuery ->fetch_array();
						   $totalBuy=$totalBuyRow['sum(counterAmount)'];//مجموع خریداریها
					  
					  //=================================================End of sum Buy===============
					  //=====================================================sum sale==================
						   $totalSaleSql="select sum(counterAmount)  from transaction where baseCurrency='$baseCurrency' 
						   and counterCurrency='$counterCurrency'  and date='$date' and treatment='2'";
						   $totalSaleQuery= $db ->query($totalSaleSql);
						   $totalSaleRow=$totalSaleQuery ->fetch_array();
						   $totalSale=$totalSaleRow['sum(counterAmount)'];
							
						   $remain=$totalBuy-$totalSale;
					  //=================================================End of sum Buy===============
					   $i++;
						 echo "<tr><td style='text-align: center'>$i</td>
						       <td style='text-align: center'>$baseName</td>
							   <td style='text-align: center'>$counterName</td>
								
							   <td style='text-align: center'>".number_format($totalBuy,2)."</td>
							   <td style='text-align: center'>".number_format($totalSale,2)."</td>
							   <td style='text-align: center'>".number_format($remain,2).$counterName."</td> ";
							   
						
					 
					 }
						 echo "</tr></table>";
              	
	 echo "<br></div>";
//====================================================================================================================
	// Initial page num setup
	if ($page == 0){$page = 1;}
	$prev = $page - 1;	
	$next = $page + 1;							
	$lastpage = ceil($total_pages/$limit);		
	$LastPagem1 = $lastpage - 1;					
	
	
	$paginate = '';
	if($lastpage > 1)
	{	
	

	
	
		$paginate .= "<div class='paginate'>";
		// Previous
		if ($page > 1){
			$paginate.= "<a href='$targetpage?page=$prev'>previous</a>";
		}else{
			$paginate.= "<span class='disabled'>previous</span>";	}
			

		
		// Pages	
		if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up
		{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page){
					$paginate.= "<span class='current'>$counter</span>";
				}else{
					$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
			}
		}
		elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
		{
			// Beginning only hide later pages
			if($page < 1 + ($stages * 2))		
			{
				for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";		
			}
			// Middle hide some front and some back
			elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
			{
				$paginate.= "<a href='$targetpage?page=1'>1</a>";
				$paginate.= "<a href='$targetpage?page=2'>2</a>";
				$paginate.= "...";
				for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";		
			}
			// End only hide early pages
			else
			{
				$paginate.= "<a href='$targetpage?page=1'>1</a>";
				$paginate.= "<a href='$targetpage?page=2'>2</a>";
				$paginate.= "...";
				for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
				}
			}
		}
					
				// Next
		if ($page < $counter - 1){ 
			$paginate.= "<a href='$targetpage?page=$next'>next</a>";
		}else{
			$paginate.= "<span class='disabled'>next</span>";
			}
			
		$paginate.= "</div>";		
	
	
}
 
 echo $paginate;
 die;
 

?>
 
	
			
 </tbody></table>
</div>
</div>  
 </body>
 </form>
 </html>  
  
 
     