<?php
session_start();
    
   
   include("db.php");
   include("jdf.php");
	 $customerName_id=$_POST['customerName'];
	 $customerExplod=explode("-",$customerName_id);
	 $customerName_id=$customerExplod[0];
	 $customerName=$customerExplod[1];
	
	$startday=$_POST['day'];
	$startmonty=$_POST['month'];
	$startyear=$_POST['year'];
    $startDate=$startyear."-".$startmonty."-".$startday;
	$tarikhShoro= $startDate;
   echo "<br>"; 
	if($startday=="01"){$startday="1";}
	if($startday=="02"){$startday="2";}
	if($startday=="03"){$startday="3";}
	if($startday=="04"){$startday="4";}
	if($startday=="05"){$startday="5";}
	if($startday=="06"){$startday="6";}
	if($startday=="07"){$startday="7";}
	if($startday=="08"){$startday="8";}
	if($startday=="09"){$startday="9";}
	///===============================
	if($startmonty=="01"){$startmonty="1";}
	if($startmonty=="02"){$startmonty="2";}
	if($startmonty=="03"){$startmonty="3";}
	if($startmonty=="04"){$startmonty="4";}
	if($startmonty=="05"){$startmonty="5";}
	if($startmonty=="06"){$startmonty="6";}
	if($startmonty=="07"){$startmonty="7";}
	if($startmonty=="08"){$startmonty="8";}
	if($startmonty=="09"){$startmonty="9";}
	///===============================
	    $yserterDay_shamsi=$startyear."-".$startmonty."-".$startday;
         	 
	     $yserterDay_miladi=jalali_to_gregorian($startyear,$startmonty,$startday,'-');
		 
         $yserterDay_miladi=strtotime($yserterDay_miladi);
         $yserterDay_miladi=$yserterDay_miladi-86400;
		 
         $yserterDay_miladi=date('Y-m-d',$yserterDay_miladi );
		 $yesterday_explode=explode("-",$yserterDay_miladi);
		 
		 $yesterday_year=$yesterday_explode[0];
		 $yesterday_monht=$yesterday_explode[1];
		 $yesterday_day=$yesterday_explode[2];
		 //====
		 if($yesterday_day=="01"){$yesterday_day="1";}
		 if($yesterday_day=="02"){$yesterday_day="2";}
		 if($yesterday_day=="03"){$yesterday_day="3";}
		 if($yesterday_day=="04"){$yesterday_day="4";}
		 if($yesterday_day=="05"){$yesterday_day="5";}
		 if($yesterday_day=="06"){$yesterday_day="6";}
		 if($yesterday_day=="07"){$yesterday_day="7";}
		 if($yesterday_day=="08"){$yesterday_day="8";}
		 if($yesterday_day=="09"){$yesterday_day="9";}
		 
		 if($yesterday_monht=="01"){$yesterday_monht="1";}
		 if($yesterday_monht=="02"){$yesterday_monht="2";}
		 if($yesterday_monht=="03"){$yesterday_monht="3";}
		 if($yesterday_monht=="04"){$yesterday_monht="4";}
		 if($yesterday_monht=="05"){$yesterday_monht="5";}
		 if($yesterday_monht=="06"){$yesterday_monht="6";}
		 if($yesterday_monht=="07"){$yesterday_monht="7";}
		 if($yesterday_monht=="08"){$yesterday_monht="8";}
		 if($yesterday_monht=="09"){$yesterday_monht="9";}
		 
		 
		 
        $yesterday_pdate1=gregorian_to_jalali($yesterday_year,$yesterday_monht,$yesterday_day,'-');
        
		$yesterday_explode=explode("-",$yesterday_pdate1);
		$yesterday_year=$yesterday_explode[0];
		$yesterday_month=$yesterday_explode[1];
		$yesterday_day=$yesterday_explode[2];
		 
		if($yesterday_day=="1"){$yesterday_day="01";}
		if($yesterday_day=="2"){$yesterday_day="02";}
		if($yesterday_day=="3"){$yesterday_day="03";}
		if($yesterday_day=="4"){$yesterday_day="04";}
		if($yesterday_day=="5"){$yesterday_day="05";}
		if($yesterday_day=="6"){$yesterday_day="06";}
		if($yesterday_day=="7"){$yesterday_day="07";}
		if($yesterday_day=="8"){$yesterday_day="08";}
		if($yesterday_day=="9"){$yesterday_day="09";}
		 
		if($yesterday_month=="1"){$yesterday_month="01";}
		if($yesterday_month=="2"){$yesterday_month="02";}
		if($yesterday_month=="3"){$yesterday_month="03";}
		if($yesterday_month=="4"){$yesterday_month="04";}
		if($yesterday_month=="5"){$yesterday_month="05";}
		if($yesterday_month=="6"){$yesterday_month="06";}
		if($yesterday_month=="7"){$yesterday_month="07";}
		if($yesterday_month=="8"){$yesterday_month="08";}
		if($yesterday_month=="9"){$yesterday_month="09";}
		 
		 
	$yesterday_pdate1=$yesterday_year."-".$yesterday_month."-".$yesterday_day;
   
	$endday_main=$_POST['eday'];
	$endmonty_main=$_POST['emonth'];
	$endyear_main=$_POST['eyear'];
    $endDate_main=$endyear_main."-".$endmonty_main."-".$endday_main;
	$tarikhAkhar=$endDate_main;
    //include("yesterday_assets_date_plagin_jornal.php"); 
	//======================  
	//=====currencyName
	$currencyName_sql="select * from currencies where id='$money'";
	$currencyName_query= $db ->query($currencyName_sql);
	$currencyName_row=$currencyName_query ->fetch_array();
	$currencyName=$currencyName_row['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_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>
 
<!--======================= ÇíÇä  ============================================================-->
<link rel="stylesheet" href="css/internalReport_font.css" type="text/css" media="all" />
 <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" style="border: 0px solid red">
<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>راپور کلی محترم:<?php echo $customerName; ?></span><br>  از تاریخ &nbsp <?php echo  $startDate.' تا تاریخ'.$endDate_main; ?>
	     </th>
		</tr>
		</table> 

 <div id='content' style="border: 0px solid green;width:100%;margin: auto">
         <table border="1" style="margin:auto;text-align: center;width: 100%" dir="rtl" cellpadding="0" cellspacing="0" >
		 <tr>
		    <td style="height: 50px">شماره</td>
		    <td>تاریخ</td>
		    <td>توضیحات</td>
		    <td>نوعیت معامله</td>
		    <td>دالر</td>
		    <td>افغانی</td>
			<td>تومان</td>
		    <td>کالدار</td>
		   
		    <td>یورو</td>
		   
		 </tr>
		 
		 <?php
		             
		 
		  
		 
		    
			 
		    $sql="select * from customer_statement where (date between '$tarikhShoro' and '$tarikhAkhar')  and customerId='$customerName_id' order by date asc";
		    $query= $db ->query($sql);
			while($row=$query ->fetch_array()){
			 $i;
			 $transaction_id=$row['transaction_id'];
			 $date=$row['date'];
			 $currency_id=$row['currency_id'];
			 $amount=$row['amount']; 
			 $transaction_type=$row['transaction_type'];
			 $description=$row['description'];
			 $i++; 
		    echo "<td>$i</td>";
			echo "<td style='height: 30px'>$date</td>";
			echo "<td> $description</td>";
			echo "<td>";
			if($transaction_type==1){ echo "رسیدگی";}
			if($transaction_type==2){ echo "بردگی";}
			echo "</td>";
			 
			if($currency_id=="2"){
			 
			echo "<td style='text-align:right'>".number_format($amount,2)."</td>";
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'></td>";
			 
		    }
			if($currency_id=="1"){
			 
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'>".number_format($amount)."</td>";
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'></td>";
			 
		    }
			if($currency_id=="5"){
			 
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'>".number_format($amount)."</td>";
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'></td>";
			 
		    }
			
			if($currency_id=="4"){
			 
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'>".number_format($amount)."</td>";
			echo "<td style='text-align:right'></td>";
			 
		    }
			if($currency_id=="3"){
			 
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'>".number_format($amount,2)."</td>";
			 
		    }
			
			
			
			echo "</tr>";  
			 
			 
			} 
			 
		  
		 
		 ?>
		 
		 
		 </table>
	<table border="1" dir="rtl" style="width: 500px">
	<tr>
	   <td>کد</td>
	   <td>نام </td>
	   <td>رسید </td>
	   <td>برد</td>
	   <td>موجودی </td>
	</tr>
	<tr>
		<td>1</td>
		<td>دالر</td>
		<td>
		<?php
		  $sql="select sum(amount) as amount from customer_statement where (date between '$tarikhShoro' and '$tarikhAkhar')  and customerId='$customerName_id' and transaction_type=1 and currency_id=2  order by date asc";
		  $query= $db ->query($sql);
		  $row=$query ->fetch_array();
		  echo $dollar_cr=$row['amount'];
		?>
		</td>
		<td>
		<?php
		  $dr_sql="select sum(amount) as amount from customer_statement where (date between '$tarikhShoro' and '$tarikhAkhar')  and customerId='$customerName_id' and transaction_type=2 and currency_id=2  order by date asc";
		  $dr_query= $db ->query($dr_sql);
		  $dr_row=$dr_query ->fetch_array();
		 echo  $dollar_dr=$dr_row['amount'];
		?>
		</td>
		<td><?php $result=$dollar_cr-$dollar_dr; echo number_format($result,2); ?></td>
	</tr>
	<tr>
		<td>2</td>
		<td>افغانی</td>
		<td>
		<?php
		  $sql="select sum(amount) as amount from customer_statement where (date between '$tarikhShoro' and '$tarikhAkhar')  and customerId='$customerName_id' and transaction_type=1 and currency_id=1  order by date asc";
		  $query= $db ->query($sql);
		  $row=$query ->fetch_array();
		  echo $afn_cr=$row['amount'];
		?>
		</td>
		<td>
		<?php
		  $dr_sql="select sum(amount) as amount from customer_statement where (date between '$tarikhShoro' and '$tarikhAkhar')  and customerId='$customerName_id' and transaction_type=2 and currency_id=1  order by date asc";
		  $dr_query= $db ->query($dr_sql);
		  $dr_row=$dr_query ->fetch_array();
		 echo  $afn_dr=$dr_row['amount'];
		?>
		</td>
		<td><?php $result=$afn_cr-$afn_dr; echo number_format($result); ?></td>
	</tr>
	</tr>
	<tr>
		<td>3</td>
		<td>تومان</td>
		<td>
		<?php
		  $sql="select sum(amount) as amount from customer_statement where (date between '$tarikhShoro' and '$tarikhAkhar')  and customerId='$customerName_id' and transaction_type=1 and currency_id=5  order by date asc";
		  $query= $db ->query($sql);
		  $row=$query ->fetch_array();
		  $afn_cr=$row['amount'];
		  echo  number_format($row['amount']);
		?>
		</td>
		<td>
		<?php
		  $dr_sql="select sum(amount) as amount from customer_statement where (date between '$tarikhShoro' and '$tarikhAkhar')  and customerId='$customerName_id' and transaction_type=2 and currency_id=5  order by date asc";
		  $dr_query= $db ->query($dr_sql);
		  $dr_row=$dr_query ->fetch_array();
		   echo  number_format($row['amount']);
		   $afn_dr=$dr_row['amount'];
		?>
		</td>
		<td><?php $result=$afn_cr-$afn_dr; echo number_format($result); ?></td>
	</tr>
	<tr>
		<td>4</td>
		<td>کالدار</td>
		<td>
		<?php
		  $sql="select sum(amount) as amount from customer_statement where (date between '$tarikhShoro' and '$tarikhAkhar')  and customerId='$customerName_id' and transaction_type=1 and currency_id=4  order by date asc";
		  $query= $db ->query($sql);
		  $row=$query ->fetch_array();
		  $caldar_cr=$row['amount'];
		  echo  number_format($row['amount']);
		?>
		</td>
		<td>
		<?php
		  $dr_sql="select sum(amount) as amount from customer_statement where (date between '$tarikhShoro' and '$tarikhAkhar')  and customerId='$customerName_id' and transaction_type=2 and currency_id=4  order by date asc";
		  $dr_query= $db ->query($dr_sql);
		  $dr_row=$dr_query ->fetch_array();
		   echo  number_format($row['amount']);
		   $caldar_dr=$dr_row['amount'];
		?>
		</td>
		<td><?php $result=$caldar_cr-$caldar_dr; echo number_format($result); ?></td>
	</tr>
	<tr>
		<td>5</td>
		<td>یورو</td>
		<td>
		<?php
		  $sql="select sum(amount) as amount from customer_statement where (date between '$tarikhShoro' and '$tarikhAkhar')  and customerId='$customerName_id' and transaction_type=1 and currency_id=3  order by date asc";
		  $query= $db ->query($sql);
		  $row=$query ->fetch_array();
		  $euro_cr=$row['amount'];
		  echo  number_format($row['amount']);
		?>
		</td>
		<td>
		<?php
		  $dr_sql="select sum(amount) as amount from customer_statement where (date between '$tarikhShoro' and '$tarikhAkhar')  and customerId='$customerName_id' and transaction_type=2 and currency_id=3 order by date asc";
		  $dr_query= $db ->query($dr_sql);
		  $dr_row=$dr_query ->fetch_array();
		   echo  number_format($row['amount']);
		   $euro_dr=$dr_row['amount'];
		?>
		</td>
		<td><?php $result=$euro_cr-$euro_dr; echo number_format($result); ?></td>
	</tr>
	
	
	
	
	</table>
	
  </div>
 		
 </tbody>
 </table>
</div>
</div>  
 </body>
 </form>
 </html>  
  
 
     
					
					
			 