<?php
 session_start();
    
   include("../pdate.php");
   $todayDate= pdate("Y-m-d");
   $date = new DateTime('-30 day');

    
  $startDate=$date->format('Y-m-d'); 
  $startDate=pdate("Y-m-d"); 
  
  $customerName=$_SESSION['customerName'];
 // $customar_id=$_SESSION['customar_code'];
   $customerID=$_GET['customerID'];
   
if($customerID!=0){
	    $customer_id=$customerID ;
	    $customer_id=$_SESSION['customar_code']=$customer_id;
 }
if($customerID==0){
	$customer_id= $_SESSION['customar_code'];
	
 }
 
?>
<!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" /> 
<script>
function myconfirm()
{
    if(confirm('آیا مطمئن هستید می خواهید اطلاعات را به طور دایم حذف کنید'))
        return true;
    return false;
}
</script>
<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="950px" dir="rtl" class="font">
		<tr>
			<th style="width:166px;text-align:right">
			   <form method="post" action="">
				<table border='0' class="dontPrint">
				<tr>
					<td>تاریخ شروع</td>
					<td><input type="text" name="startDate" value="<?php  echo $startDate; ?>"></td>
				</tr>
				<tr>
					<td>تاریخ ختم</td>
					<td><input type="text" name="endDate" value="<?php  echo $todayDate; ?>"></td>
					
				</tr>
				<tr>
				<td>نوعیت پول</td>
				<td>
				    <select name="counterCurrency"  id='counterCurrency'  style="width:100%" onchange="changeCurrency();existingCustomerBalance();dollarsRate()" onclick="changeCurrency();existingCustomerBalance();dollarsRate()">
					<option value='all'>همه</option>
						<?php
							include("db.php");
							$sql="select * from currencies where remove =0";
						    $query=$db ->query($sql);
							while($row=$query ->fetch_array()){
							$id=$row['id'];
							$name=$row['name'];
							echo "<option value='$id'>$name</option>";	
							}
							echo "</select>";
														
						?>
				</td>
				<td><input type="submit" name="submit" value="جستجو" ></td>
				</tr>
				 
				</table>
			</form>
			
			
			
			
			<?php 
			      $startDate=$_POST['startDate'];
	          
	              $endDate=$_POST['endDate']; 
			  
			  if(isset( $startDate) and isset( $endDate)){
			  
			  
			  
				  echo '</th>
				<th style="width:206px"><h2>'?><?phpinclude("../info/companyName.php") ?> <?php echo '</h2>لیست رسیدگی&nbsp;'. ucfirst($customerName);
			    
				echo "<br><span style='color:green'>از </span>".$startDate.'<span style="color:green"> تا </span>'.$endDate.'</td>';
				}
			  
			  else{
			   
			     echo '</th>
			     <th style="width:206px"><h2>'?><?php include("../info/companyName.php")?><?php echo '</h2>لیست رسیدگی&nbsp;'.ucfirst($customerName);
			      echo '</br> '.pdate("Y-m-d" ).'</th>';
			  }
			  ?>
			
			<th style="width:186px;text-align:left" > </th>
			 
		</tr>
		</table> 

 <div id='content'>
 
  <?php
   if($_POST['submit']){
     
	$startDate=$_POST['startDate'];
	  
	$endDate=$_POST['endDate'];
	 
	$counterCurrency=$_POST['counterCurrency'];
     
    include("db.php");
	 
    //$customer_id = $_SESSION['customar_code'];
	 
    $currency_id=$_SESSION['currency_id'];
	
	 $customer_name =   $_SESSION['customer_name'];
	
	$tableName="customerpayment";		
	$targetpage = "customerPaymentReport.php"; 	
	$limit = 30; 
	if($counterCurrency=='all'){                                                                                                                      
	$sql="SELECT COUNT(*) as num FROM `$tableName` where  customerId='$customer_id' and transacttype='1' and  remove='0' and amount!='0' and (date >='$startDate' AND date <='$endDate')";
	}
	if($counterCurrency!='all'){
	$sql="SELECT COUNT(*) as num FROM `$tableName` where transactCurrency='$counterCurrency' and customerId='$customer_id' and remove='0' and amount!='0' 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>
				<th scope="col">توضیحات</th>
				 
				 
				<th scope="col"><span class="dontPrint">ویرایش</span></th>
				<th scope="col"><span class="dontPrint">پاک کردن</span></th>
			 
				<th scope="col" ><span class="dontPrint">سند پرداختی</span></th>
				<th scope="col" ><span class="dontPrint">سند انگلیسی</span></th>
				 
			</thead>
				 ';
    // Get page data
	 echo "<div id='content'>";
	  
			                include('db.php');
				            

						 $table_name="customerpayment";
						 
					     if($counterCurrency=='all'){
						   $mony_sql="SELECT   *  FROM `customerpayment` where  customerId='$customer_id' and transacttype='1' and  remove='0' and amount!='0' and (date >='$startDate' AND date <='$endDate')  ORDER BY `date`    LIMIT $start, $limit";
						 } 
						 if($counterCurrency!='all'){
						   $mony_sql="SELECT   *   FROM `customerpayment` where  transactCurrency='$counterCurrency' and customerId='$customer_id' and transacttype='1' and  remove='0' and amount!='0' and (date >='$startDate' AND date <='$endDate')  ORDER BY `date`    LIMIT $start, $limit";
						 }
						 $mony_query= $db ->query($mony_sql);
				  
						  
                          while($nrow=$mony_query ->fetch_array()){
						    $ii++;
							$id = $nrow['id'];
							$customerId = $nrow['customerId'];
							$date= $nrow['date'];
							$referenceNo= $nrow['referenceNo'];
							$transactCurrency= $nrow['transactCurrency'];
							$total+=$amount= $nrow['amount'];
							$description= $nrow['description'];
							$dollarRate= $nrow['dollarRate'];
							$dollarTotal= $nrow['dollarTotal'];
							$customersell_id= $nrow['customersell_id'];
							
							 
							 
							 
							//=============================================================
							 
							 
							//******************************Currency Name*******************************
							 $currency_sql="select name from  `currencies` where id='$transactCurrency'";
							 $currency_query=$db ->query($currency_sql);
							 $currency_row=$currency_query ->fetch_array();
							 $currency=$currency_row['name'];	
							//=============================================================
							//******************************Currency Name*******************************
							 $sumDollar_sql="select sum(dollarTotal) from  `customerpayment` where customerId='$customer_id' and transacttype='1' and  remove='0' and (date BETWEEN '$startDate' AND  '$endDate')";
							 $sumDollar_query=$db ->query($sumDollar_sql);
							 $sumDollar_row=$sumDollar_query ->fetch_array();
							 $sumDollar=$sumDollar_row['sum(dollarTotal)'];	
							//=============================================================
                             
							    
						    //**************************************************************************************************   
							 
							 
			echo "<tbody>
			<tr>
			<td>".$ii."</td>
			<td>".$date."</td>
			<td>".number_format($amount)."</td>
			<td>".$referenceNo."</td> 
			<td>".$currency."</td>  
			<td>".$description."</td>"; 
		     if($customersell_id==0){
			 
			echo "<td>
				  <a  href='../edit/edit_customerPayment.php?editID=".$id."  & table=".$table_name."'  ><img alt='Submit' src='img/edit.png' class='dontPrint'></a>
			</td>
			<td>
				  <a  href='../delete/delete_customerPayment.php?editID=".$id."  & table=".$table_name."' onclick='return myconfirm()'><img alt='Submit' src='img/delete.png' class='dontPrint'></a>
			</td>";
			 } if($customersell_id!=0){
			 
			echo "<td>
				   <img alt='Submit' src='img/edit_off.png' class='dontPrint'> 
			</td>
			<td>
				   <img alt='Submit' src='img/Delete_off.png' class='dontPrint'> 
			</td>";
			 }
			echo "<td>
				 <a  href='voucher.php?id=".$nrow['id']." ' ><img alt='Submit' src='img/voucher.png' class='dontPrint'></a>
			</td> 
			<td>
				 <a  href='en_voucher.php?id=".$nrow['id']." ' ><img alt='Submit' src='img/voucher.png' class='dontPrint'></a>
			</td> 
			 </tr>";					  
				 	  } 
		 echo '<tr style="color: red">
             <td colspan="13"  style="text-align: right;"><hr style="border:1px solid #000;"> 
			 
			   		 
			       <table border="0"  align="right"  width="600px"  >
				   <tr>
						<td style="border: hidden"><sapn style="color: #000;font-weight: bold;font-size: 16px">مجموع پرداختی: &nbsp;&nbsp;&nbsp;'.number_format($total,2).'&nbsp;'.$currency.'</span></td>
			             <td style="border: hidden">&nbsp;</td>
				   </tr> 
				    
				   
			       </table>
			 
			 
			 </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'>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;
}

?>
<!--==========================================================================================-->  
<!--==========================================================================================-->  
<!--==========================================================================================-->  
	<?php  
	    
   include("db.php");
	 
   //$customer_id = $_SESSION['customar_code'];
	 
    
	$tableName="customerpayment";		
	$targetpage = "customerPaymentReport.php"; 	
	$limit = 23; 
	
	 $sql="SELECT COUNT(*) as num FROM `$tableName` where customerId='$customer_id' and transacttype='1' and remove='0' and amount!='0'    ";
	
	$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" class="dontPrint"><span>ویرایش</span></th>
				<th scope="col" class="dontPrint"><span class="dontPrint">پاک کردن</span></th>
			 
				<th scope="col" class="dontPrint"><span class="dontPrint">سند پرداختی</span></th>
				<th scope="col" class="dontPrint"><span class="dontPrint">سند انگلیسی</span></th>
				 
			</thead>
				 ';
    // Get page data
	 echo "<div id='content'>";
	  
			                include('db.php');
				            

						 

							
						 $table_name="customerpayment";
						 
					 
						 $mony_sql="SELECT   *  FROM `customerpayment` where customerId='$customer_id' and transacttype='1' and  remove='0' and amount!='0'   ORDER BY `date`    LIMIT $start, $limit";
						 $mony_query= $db ->query($mony_sql);
				  
						  
                          while($nrow=$mony_query ->fetch_array()){
						    $ii++;
							$id = $nrow['id'];
							$customerId = $nrow['customerId'];
							$date= $nrow['date'];
							$referenceNo= $nrow['referenceNo'];
							$transactCurrency= $nrow['transactCurrency'];
							$amount= $nrow['amount'];
							$description= $nrow['description'];
							$dollarRate= $nrow['dollarRate'];
							$dollarTotal= $nrow['dollarTotal'];
							$customersell_id= $nrow['customersell_id'];
							
							 
							 
							 
							//=============================================================
							 
							 
							//******************************Currency Name*******************************
							 $currency_sql="select name from  `currencies` where id='$transactCurrency'";
							 $currency_query=$db ->query($currency_sql);
							 $currency_row=$currency_query ->fetch_array();
							 $currency=$currency_row['name'];	
							//=============================================================
							//******************************Currency Name*******************************
							 $sumDollar_sql="select sum(dollarTotal) from  `customerpayment` where customerId='$customer_id' and transacttype='1' and  remove='0'";
							 $sumDollar_query=$db ->query($sumDollar_sql);
							 $sumDollar_row=$sumDollar_query ->fetch_array();
							 $sumDollar=$sumDollar_row['sum(dollarTotal)'];	
							//=============================================================
                             
							    
						    //**************************************************************************************************   
							 
			                $checkEdit_sql="select * from customerpayment where customerId='$customer_id' and transacttype='1' and  remove='0' and customersell_id='0'";
			                $checkEdit_Query= $db ->query($checkEdit_sql);
							$checkEdit_Row=$checkEdit_Query->fetch_array();
							$checkEdit=$checkEdit_Row['customersell_id'];
			                
			echo "<tbody>
			<tr>
			<td>".$ii."</td>
			<td>".$date."</td>
			<td>".number_format($amount)."</td>
			<td>".$referenceNo."</td> 
			<td>".$currency."</td> 
			<td>".$description."</td>"; 
		     if($customersell_id==0){
			 
			echo "<td class='dontPrint'>
				  <a  href='../edit/edit_customerPayment.php?editID=".$id."  & table=".$table_name."'  ><img alt='Submit' src='img/edit.png' class='dontPrint'></a>
			</td>
			<td class='dontPrint'>
				  <a  href='../delete/delete_customerPayment.php?editID=".$id."  & table=".$table_name."' onclick='return myconfirm()'><img alt='Submit' src='img/delete.png' class='dontPrint'></a>
			</td>";
			 } if($customersell_id!=0){
			 
			echo "<td class='dontPrint'>
				   <img alt='Submit' src='img/edit_off.png' class='dontPrint'> 
			</td>
			<td class='dontPrint'>
				   <img alt='Submit' src='img/Delete_off.png' class='dontPrint'> 
			</td>";
			 }
			echo "<td class='dontPrint'>
				 <a  href='voucher.php?id=".$nrow['id']." ' ><img alt='Submit' src='img/voucher.png' class='dontPrint'></a>
			</td> 
			<td class='dontPrint'>
				 <a  href='en_voucher.php?id=".$nrow['id']." ' ><img alt='Submit' src='img/voucher.png' class='dontPrint'></a>
			</td> 
			
			
			 </tr>";					  
				 	  } 
		 echo '<tr style="color: red">
             <td colspan="13"  style="text-align: right;"><hr style="border:1px solid #000;"> 
			 
			   		 
			       <table border="0"  align="left" width="350px"  >
				    
				   <tr>
						<td style="border: hidden"><sapn style="color: #000;font-weight: bold;font-size: 16px">مجموع پرداختی به دلار: &nbsp;&nbsp;&nbsp;'.number_format($sumDollar,2).'</span></td>
			            <td style="border: hidden">&nbsp;</td>
				   </tr>
				   
			       </table>
			 
			 
			 </td>';
			 
		 
	 echo'    	</table>';
	 echo "<br></div>";
	 echo "<div class='dontPrint'>";
//====================================================================================================================
	// 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;
//===================================================================================================================================				 			
  ?> 
	
			
 </tbody></table>
</div>
</div>  
 </body>
 </form>
 </html>  
  
 
     