<?php
 session_start();
    
   include("../pdate.php");
   include("db.php");
   
     
	$currencyId=$_GET['currency'];
	 
	 $startDate="1397-01-01";
   $endDate=pdate("Y-m-d"); 
	 
	 
	 
	 
	 
	  //============================currency Name======================
	   
	    $curencyName_sql="select name from  `currencies` where id='$currencyId'";
		$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:310px;text-align:right;">
			   
			</th>	 
			
			
			
			
			<?php 
				  echo '</th>
				<th style="width:310px"><h3>';
				include("../info/companyName.php");
				echo '</h3>لیســت تبـــدیلات از  &nbsp '.$currencyName;
			  ?>
				 
		 
		    <td style="width: 310px"></td>
		</tr>
		</table> 

 <div id='content'>
 
  <?php
   //if($_POST['submit']){
     
	
     
    include("db.php");
	$tableName="transaction";		
	$targetpage = "operation_karidPoli.php"; 	
	$limit = 13000; 
	 
	  
	  $sql="SELECT COUNT(*) as num FROM `$tableName` where baseCurrency='$currencyId' and (date between '$startDate' and '$endDate') and remove='0'  and extra='0' and treatment='1' ";
	  		 
	$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>
				<th scope="col">مقدار به ارز پایه</th>
			 
			</thead>
				 ';
    // Get page data
	 echo "<div id='content'>";
	  
			                include('db.php');
				            

						  
						 
					      
						 $mony_sql="select * from transaction where baseCurrency='$currencyId' and (date between '$startDate' and '$endDate') and remove='0'  and extra='0' and treatment='1' LIMIT $start, $limit";
						 $mony_query= $db ->query($mony_sql);
				  
						  
                          while($nrow=$mony_query ->fetch_array()){
						    $ii++;
							$id = $nrow['id'];
							 
							$date= $nrow['date'];
							$counterCurrency= $nrow['counterCurrency'];
							$counterAmount= $nrow['counterAmount'];
							$totalcounterAmount+=$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>".$rate*$unit."</td> 
			<td>".$basecurrency."</td>
			<td>".number_format($baseAmount) ."</td>
			 
			 </tr>";					  
				 	  } 
		 				  
		 echo '<tr style="color: red"><td colspan="7" style="font-weight: bold">'.number_format($totalBaseAmount).$currencyName." ".'</td></tr>';
		  
		 echo '</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 & startDate=$startDate & endDate=$endDate & baseCurrency_kind=$baseCurrency_kind '>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 & startDate=$startDate & endDate=$endDate & baseCurrency_kind=$baseCurrency_kind'>$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 & startDate=$startDate & endDate=$endDate & baseCurrency_kind=$baseCurrency_kind'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?page=$LastPagem1 & startDate=$startDate & endDate=$endDate & baseCurrency_kind=$baseCurrency_kind'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?page=$lastpage   & startDate=$startDate & endDate=$endDate & baseCurrency_kind=$baseCurrency_kind'>$lastpage</a>";		
			}
			// Middle hide some front and some back
			elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
			{
				$paginate.= "<a href='$targetpage?page=1 & startDate=$startDate & endDate=$endDate & baseCurrency_kind=$baseCurrency_kind'>1</a>";
				$paginate.= "<a href='$targetpage?page=2 & startDate=$startDate & endDate=$endDate & baseCurrency_kind=$baseCurrency_kind'>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 & startDate=$startDate & endDate=$endDate & baseCurrency_kind=$baseCurrency_kind'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?page=$LastPagem1 & startDate=$startDate & endDate=$endDate & baseCurrency_kind=$baseCurrency_kind'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?page=$lastpage & startDate=$startDate & endDate=$endDate & baseCurrency_kind=$baseCurrency_kind'>$lastpage</a>";		
			}
			// End only hide early pages
			else
			{
				$paginate.= "<a href='$targetpage?page=1 & startDate=$startDate & endDate=$endDate & baseCurrency_kind=$baseCurrency_kind'>1</a>";
				$paginate.= "<a href='$targetpage?page=2 & startDate=$startDate & endDate=$endDate & baseCurrency_kind=$baseCurrency_kind'>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 & startDate=$startDate & endDate=$endDate & baseCurrency_kind=$baseCurrency_kind'>$counter</a>";}					
				}
			}
		}
					
				// Next
		if ($page < $counter - 1){ 
			$paginate.= "<a href='$targetpage?page=$next & startDate=$startDate & endDate=$endDate & baseCurrency_kind=$baseCurrency_kind'>next</a>";
		}else{
			$paginate.= "<span class='disabled'>next</span>";
			}
			
		$paginate.= "</div>";		
	
	
}
 
 echo $paginate;
 die;
//}

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