<?php
 session_start();
    
   include("../jdf.php");
   include("db.php");
   
  
      $startDate=$_REQUEST['startDate'];
      $endDate=$_REQUEST['endDate'];
	  
	  if(isset($_REQUEST['day'])){
		  
		  $endDate = $_REQUEST['eyear']."-".$_REQUEST['emonth']."-".$_REQUEST['eday'];
	      $startDate = $_REQUEST['year']."-".$_REQUEST['month']."-".$_REQUEST['day'];
		  
	  }
	 
?>
<!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_style_no_background.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><span>گزارش روزنامچه</span> از  &nbsp <?php echo  $startDate.'  تا  '.$endDate; ?>
			  
			<th style="width:186px;text-align:left;height: 40px" > </th>
			 
		</tr>
		</table> 

 <div id='content'>
 
  <?php
   //if($_POST['submit']){
     
	
     
	 
	  echo'
			<table id="box-table-a"   dir="rtl"  align="center"   >
	        <thead> 
				<th scope="col">شماره</th>
				 
				<th scope="col">صفحه</th>
				<th scope="col">اسم</th>
				 ';
				 
					  $selectCur = "select currencies.name from currencies where remove =0";
					  $selectCurQuery = $db->query($selectCur);
					   $count = mysqli_num_rows($selectCurQuery);
					  while($selectCurAll = $selectCurQuery->fetch_array()){
						 echo "<th>رسیدگی &nbsp;".$selectCurAll['name']."</th>";
					 }
				   $selectCur = "select currencies.name from currencies where remove =0";
					  $selectCurQuery = $db->query($selectCur);
					   $count = mysqli_num_rows($selectCurQuery);
					  while($selectCurAll = $selectCurQuery->fetch_array()){
						 echo "<th>بردگی &nbsp;".$selectCurAll['name']."</th>";
					 }
				
			echo '</thead>
				 ';
    // Get page data
	 echo "<div id='content'>";
	  
			            include('db.php');
						 $mony_sql="select journal.date,journal.reference_id,journal.amount,journal.reference,journal.name,currencies.name as c_name ,currencies.id as c_id  from journal,currencies where currencies.id = journal.currency and (date between '$startDate' and '$endDate') order by journal.id desc LIMIT $start, $limit";

						 $mony_query= $db ->query($mony_sql);
				  
						  
                          while($nrow=$mony_query ->fetch_array()){
						    $ii++;
							$id = $nrow['id'];
							$reference_id = $nrow['reference_id'];
							$c_id = $nrow['c_id'];    //currencyID
							 
							$date= $nrow['date'];
							$amount= $nrow['amount'];
							$reference = $nrow['reference'];
							$customerName = $nrow['name'];
							
							// select arz payaaa========================
								 
								 $selectArzpaya = "select * from transaction where id ='$reference_id'";
								 
								 $selectArzPayaQeury = $db->query($selectArzpaya);
								 $selecPayaAll = $selectArzPayaQeury->fetch_array();
								 $paya_id = $selecPayaAll['baseCurrency'];
								 $baseAmount = $selecPayaAll['baseAmount'];
								  
								 // find Base currency select 
								 $selectArzpaya1 = "select name from currencies where id ='$paya_id'"; 
								 $selectArzPayaQeury1 = $db->query($selectArzpaya1);
								 $selecPayaAll1 = $selectArzPayaQeury1->fetch_array();
								 $paya = $selecPayaAll1['name'];
								 if($paya==""){
									 $paya="-";
									 
								 }
							  
							   
							   if($reference!='مصرف' and $reference!='رسیدگی مشتری' and $reference!='عواید' and $reference!='بردگی مشتری'  ){  
							echo "<tbody>";
							 echo "<tr> <td>".$ii."</td>
										  
										 <td>".$reference."</td>
										 <td>".$customerName."</td>
										  ";
										 
                             //==========================================================================       
									if($reference=='خرید'){   // اگر خریداری بود	 
									$slectcc = "select * from currencies where remove =0";
									 
									$selectCCQeury = $db->query($slectcc);
									while($selectAll = $selectCCQeury->fetch_array()){
										 if($c_id==$selectAll['id']){
											echo "<td>".number_format($amount)."</td>";
										}else{
											echo "<td>0</td>";

										}  
										
									}//end of while
									
									$slectcc = "select * from currencies where remove =0";
									$selectCCQeury = $db->query($slectcc);
									while($selectAll = $selectCCQeury->fetch_array()){
										if($paya_id==$selectAll['id']){
											echo "<td>".number_format($baseAmount)."</td>";
										}else{
											echo "<td>0</td>";

										}
										
									}//end of while
									
									} //end of if condition
									//======================================================================
									if($reference=='فروش'){   // اگر فروش بود	 
									$slectcc = "select * from currencies where remove =0";
									 
									$selectCCQeury = $db->query($slectcc);
									while($selectAll = $selectCCQeury->fetch_array()){
										 if($paya_id==$selectAll['id']){
											echo "<td>".number_format($baseAmount)."</td>";
										}else{
											echo "<td>0</td>";

										}  
										
									}//end of while
									
									$slectcc = "select * from currencies where remove =0";
									$selectCCQeury = $db->query($slectcc);
									while($selectAll = $selectCCQeury->fetch_array()){
										if($c_id==$selectAll['id']){
											echo "<td>".number_format($amount)."</td>";
										}else{
											echo "<td>0</td>";

										}
										
									}//end of while
									
									} //end of if condition
									//======================================================================
									
									
								}	
									
		                 	///=======================================================================
                   if($reference=='مصرف' ){ 

                         
                         					
							echo "<tbody>";
							 echo "<tr> <td>".$ii."</td>
										  
										 <td>".$reference."</td>
										 <td>".$customerName."</td>
										  ";
										 
                                     
										 
									$slectcc = "select * from currencies where remove =0";
									$selectCCQeury = $db->query($slectcc);
									while($selectAll = $selectCCQeury->fetch_array()){
										if($c_id==$selectAll['id']){
											echo "<td>0</td>";
										}else{
											echo "<td>0</td>";

										}
										
									}
									
									$slectcc = "select * from currencies where remove =0";
									$selectCCQeury = $db->query($slectcc);
									while($selectAll = $selectCCQeury->fetch_array()){
										if($c_id==$selectAll['id']){
											echo "<td>".number_format($amount)."</td>";
										}else{
											echo "<td>0</td>";

										}
										
									}
									
									
								}	//end of Expenses
			//=========================================================================
					
		   ///=============================================other INcome==========================
                   if($reference=='عواید' ){ 

                         
                         					
							echo "<tbody>";
							 echo "<tr> <td>".$ii."</td>
										  
										 <td>".$reference."</td>
										 <td>".$customerName."</td>
										  ";
										 
                                     
										 
									$slectcc = "select * from currencies where remove =0";
									$selectCCQeury = $db->query($slectcc);
									while($selectAll = $selectCCQeury->fetch_array()){
										if($c_id==$selectAll['id']){
											echo "<td>".number_format($amount)."</td>";
										}else{
											echo "<td>0</td>";

										}
										
									}
									
									$slectcc = "select * from currencies where remove =0";
									$selectCCQeury = $db->query($slectcc);
									while($selectAll = $selectCCQeury->fetch_array()){
										if($c_id==$selectAll['id']){
											echo "<td>0</td>";
										}else{
											echo "<td>0</td>";

										}
										
									}
									
									
								}	//end of Income
			//=========================================================================
					
					
		///=============================================بردگی   ==========================
                   if($reference=='بردگی مشتری' ){ 
                        					
							echo "<tbody>";
							 echo "<tr> <td>".$ii."</td>
										  
										 <td>".$reference."</td>
										 <td>".$customerName."</td>
										  ";
										 
                                     
										 
									$slectcc = "select * from currencies where remove =0";
									$selectCCQeury = $db->query($slectcc);
									while($selectAll = $selectCCQeury->fetch_array()){
										if($c_id==$selectAll['id']){
											echo "<td>0</td>";
										}else{
											echo "<td>0</td>";

										}
										
									}
									
									$slectcc = "select * from currencies where remove =0";
									$selectCCQeury = $db->query($slectcc);
									while($selectAll = $selectCCQeury->fetch_array()){
										if($c_id==$selectAll['id']){
											echo "<td>".number_format($amount)."</td>";
										}else{
											echo "<td>0</td>";

										}
										
									}
									
									
								}	//end of Income
			//=========================================================================
			///=============================================بردگی   ==========================
                   if($reference=='رسیدگی مشتری' ){ 
                        					
							echo "<tbody>";
							 echo "<tr> <td>".$ii."</td>
										  
										 <td>".$reference."</td>
										 <td>".$customerName."</td>
										  ";
										 
                                     
										 
									$slectcc = "select * from currencies where remove =0";
									$selectCCQeury = $db->query($slectcc);
									while($selectAll = $selectCCQeury->fetch_array()){
										if($c_id==$selectAll['id']){
											echo "<td>".number_format($amount)."</td>";
										}else{
											echo "<td>0</td>";

										}
										
									}
									
									$slectcc = "select * from currencies where remove =0";
									$selectCCQeury = $db->query($slectcc);
									while($selectAll = $selectCCQeury->fetch_array()){
										if($c_id==$selectAll['id']){
											echo "<td>0</td>";
										}else{
											echo "<td>0</td>";

										}
										
									}
									
									
								}	//end of Income
			//=========================================================================
					
					
					
					
												
			echo "</tr>";
			//set dollar
							// if($nrow['c_name']=="دالر"){
								// $total_dollar+= $amount;
								// echo "<tr>
											// <td>".$ii."</td>
											// <td>".$date."</td>
											// <td>".$reference."</td>
											// <td>".$customerName."</td>
											// <td>".number_format($amount,2) ."</td>
											// <td>".number_format(0,2) ."</td>
											// <td>".number_format(0,2) ."</td>
											// <td>".number_format(0,2) ."</td>
											// <td>".number_format(0,2) ."</td>
											 // </tr>";
								
							// }
						
							// if($nrow['c_name']=="کلدار"){
								// $total_kaldar+= $amount;
								
								// echo "<tr>
											// <td>".$ii."</td>
											// <td>".$date."</td>
											// <td>".$reference."</td>
											// <td>".$customerName."</td>
											// <td>".number_format(0,2) ."</td>
											// <td>".number_format($amount,2) ."</td>
											// <td>".number_format(0,2) ."</td>
											// <td>".number_format(0,2) ."</td>
											// <td>".number_format(0,2) ."</td>
											 // </tr>";
								
							// }
							// if($nrow['c_name']=="تومان"){
								// $total_toman+= $amount;
								// echo "<tr>
											// <td>".$ii."</td>
											// <td>".$date."</td>
											// <td>".$reference."</td>
											// <td>".$customerName."</td>
											// <td>".number_format(0,2) ."</td>
											// <td>".number_format(0,2) ."</td>
											// <td>".number_format($amount,2) ."</td>
											// <td>".number_format(0,2) ."</td>
											// <td>".number_format(0,2) ."</td>
											 // </tr>";
								
							// }
							// if($nrow['c_name']=="یورو"){
								// $total_euro+= $amount;
								
								// echo "<tr>
											// <td>".$ii."</td>
											// <td>".$date."</td>
											// <td>".$reference."</td>
											// <td>".$customerName."</td>
											// <td>".number_format(0,2) ."</td>
											// <td>".number_format(0,2) ."</td>
											// <td>".number_format(0,2) ."</td>
											// <td>".number_format($amount,2) ."</td>
											// <td>".number_format(0,2) ."</td>
											 // </tr>";
								
							// }
							// if($nrow['c_name']=="افغانی"){
								// $total_Afghani+= $amount;
								// echo "<tr>
											// <td>".$ii."</td>
											// <td>".$date."</td>
											// <td>".$reference."</td>
											// <td>".$customerName."</td>
											// <td>".number_format(0,2) ."</td>
											// <td>".number_format(0,2) ."</td>
											// <td>".number_format(0,2) ."</td>
											// <td>".number_format(0,2) ."</td>
											// <td>".number_format($amount,2) ."</td>
											 // </tr>";
							// }
				 	  } 
		// if($baseCurrency_kind!="all"){					  
		      // echo '<tr style="color: #000;font-size: 15px"><td colspan="7" style="font-weight: bold">&nbsp;مجموع خریداریهای &nbsp;'.$currencyName.number_format($totalCounterAmount,2).'</td></tr>';
		      // echo '<tr style="color: #000;font-size: 15px"><td colspan="7" style="font-weight: bold">مجموع به پول پـایه&nbsp;'.number_format($totalBaseAmount,2).'</td></tr>';
		 
		 // }
		 echo '</table>';
              	
	  
?>
<!--==========================================================================================-->  
<!--==========================================================================================-->  
<!--==========================================================================================-->  
	 
			
 </tbody>
 </table>
</div>
</div>  
 </body>
 </form>
 </html>  
  
 
     
					
					
			 