<?php
 session_start();
    
   include("../pdate.php");
   include("db.php");
   
   $pdate1=trim($_GET['date']);
   $transactCurrency=$_GET['currency'];
   //===================currency Name====================
   $currencyName_sql="select * from currencies where id='$transactCurrency'";
   $currencyName_query= $db ->query($currencyName_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>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( <?php echo $currencyName ?>) 
			   <br><span style='color:green'></span><?php echo $pdate1 ?></td>
				 
			 
			<th style="width:186px;text-align:left;height: 40px" > </th>
			 
		</tr>
		</table> 

 <div id='content'>
 
  <?php
 
    include("db.php");
	$tableName="customerpayment";		
	$targetpage = "customerTransaction.php"; 	
	$limit = 30; 
	 
	 
	$sql="SELECT COUNT(*) as num FROM `$tableName` where remove='0' and transacttype='$transacttype' and  transactCurrency='$counterCurrency' and  (date >='$startDate' AND date <='$endDate')   ";
	 
	$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>
				 
			</thead>
				 ';
    // Get page data
	 echo "<div id='content'>";
	  
			                include('db.php');
				            

						  
						 
			 //dollar payment
		        $dollar_payment_sql="SELECT sum(amount) FROM `customerpayment` where remove='0' and  transacttype='2'  and transactCurrency='$transactCurrency' and date='$pdate1'"; 
                $dollar_payment_query= $db ->query($dollar_payment_sql);
				$dollar_payment_row=$dollar_payment_query ->fetch_array();
				$dollar_payment=$dollar_payment_row['sum(amount)'];
			//خریداری از دلار وکم شدن از دلار
				$dollar_Sales_sql="select sum(baseAmount) from transaction where baseCurrency='$transactCurrency' and date='$pdate1' and remove='0'  and extra='0' and treatment='1' ";
				$dollar_Sales_query=$db ->query($dollar_Sales_sql);
				$dollar_Sales_row=$dollar_Sales_query ->fetch_array();
				$dollar_Sales=$dollar_Sales_row['sum(baseAmount)'];
             //فروش دلار				
 			    $frosh_dollar_sql="select sum(counterAmount) from transaction where counterCurrency='$transactCurrency' and date='$pdate1' and remove='0' and treatment='2' and extra='0'  ";
				$frosh_dollar_query=$db ->query($frosh_dollar_sql);
				$frosh_dollar_row=$frosh_dollar_query ->fetch_array();
				$frosh_dollar=$frosh_dollar_row['sum(counterAmount)'];
 				
                //پرداخت مصارف از دالر
				$totalExpenses_dollar_sql="select sum(amount) from others where currencyId='$transactCurrency' and  typeOthers='1' and date='$pdate1' and remover='0'    ";
				$totalExpenses_dollar_query=$db ->query($totalExpenses_dollar_sql);
				$totalExpenses_dollar_row=$totalExpenses_dollar_query ->fetch_array();
				$totalExpenses_dollar=$totalExpenses_dollar_row['sum(amount)'];	 
				$bordegi_dollar=($dollar_payment+$dollar_Sales+$frosh_dollar+$totalExpenses_dollar); 
			echo "<tbody>
			<tr>
			<td>1</td>
			<td><a href='bordegi_customer.php?date=$pdate1 & currency=$transactCurrency' target='_blank'>".number_format($dollar_payment)."</a></td>
			<td><a href='bordegi_baraye_karid.php?date=$pdate1 & currency=$transactCurrency' target='_blank'>".number_format($dollar_Sales)."</a></td>
			<td><a href='forosh_pool.php?date=$pdate1 & currency=$transactCurrency' target='_blank'>".number_format($frosh_dollar)."</a></td> 
			<td><a href='masarefe_khareji.php?date=$pdate1 & currency=$transactCurrency' target='_blank'>".number_format($totalExpenses_dollar)."</a></td> 
			 
			 </tr><tr>";
			 echo '   
		       
						<td colspan="6"  style="text-align: left;"><hr style="border:1px solid #000;"><sapn style="color: #000;font-weight: bold;font-size: 16px">مجموع: &nbsp;&nbsp;&nbsp;'.number_format($bordegi_dollar).'&nbsp'.$currencyName.'   </span></td>';
			
		 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 & transactiontype=$transacttype & counterCurrency=$counterCurrency'>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 & transactiontype=$transacttype & counterCurrency=$counterCurrency'>$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 & transactiontype=$transacttype & counterCurrency=$counterCurrency'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?page=$LastPagem1 &  startDate=$startDate & endDate=$endDate & transactiontype=$transacttype & counterCurrency=$counterCurrency'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?page=$lastpage  & startDate=$startDate & endDate=$endDate & transactiontype=$transacttype & counterCurrency=$counterCurrency'>$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 & transactiontype=$transacttype & counterCurrency=$counterCurrency'>1</a>";
				$paginate.= "<a href='$targetpage?page=2 & startDate=$startDate & endDate=$endDate & transactiontype=$transacttype & counterCurrency=$counterCurrency'>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 & transactiontype=$transacttype & counterCurrency=$counterCurrency'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?page=$LastPagem1 & startDate=$startDate & endDate=$endDate & transactiontype=$transacttype & counterCurrency=$counterCurrency'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?page=$lastpage   & startDate=$startDate & endDate=$endDate & transactiontype=$transacttype & counterCurrency=$counterCurrency'>$lastpage</a>";		
			}
			// End only hide early pages
			else
			{
				$paginate.= "<a href='$targetpage?page=1  & startDate=$startDate & endDate=$endDate & transactiontype=$transacttype & counterCurrency=$counterCurrency'>1</a>";
				$paginate.= "<a href='$targetpage?page=2 & startDate=$startDate & endDate=$endDate & transactiontype=$transacttype  & counterCurrency=$counterCurrency'>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 & transactiontype=$transacttype & counterCurrency=$counterCurrency'>$counter</a>";}					
				}
			}
		}
					
				// Next
		if ($page < $counter - 1){ 
			$paginate.= "<a href='$targetpage?page=$next & startDate=$startDate & endDate=$endDate & transactiontype=$transacttype & counterCurrency=$counterCurrency'>next</a>";
		}else{
			$paginate.= "<span class='disabled'>next</span>";
			}
			
		$paginate.= "</div>";		
	
	
}
 
 echo $paginate;
 die;
//}

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