<?php
session_start();
    
   
    include("db.php");
    include("jdf.php");
     $money=$_POST['money'];
	
	 $startday=$_POST['day'];
	$startmonty=$_POST['month'];
	$startyear=$_POST['year'];
    $startDate=$startyear."-".$startmonty."-".$startday;
	$tarikhShoro= $startDate;
	
	 
	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>گزارش روزنامچه</span> از  &nbsp <?php echo  $startDate.'  تا  '.$endDate; ?>
			  
			<th style="width:186px;text-align:left;height: 40px" > </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>
		    <td>بردگی</td>
		    <?php if($money!="all") {echo "<td>موجودی دخل </td>";} ?>
		    <td>توضیحات</td>
		 </tr>
		 
		 <?php
		             
		  if($yesterday_finalAccount>0){
			  $beforDebit=$yesterday_finalAccount;
			  $beforCredit=0;
			  $remian=$beforDebit;
			  $befor=$remian;
		  }
		  if($yesterday_finalAccount<0){
			 $beforCredit=-$yesterday_finalAccount;
			 $beforDebit=0;
			 $remian=-$beforCredit;
			 $befor=$remian;
		  }
		if($money!="all") { 
		  echo "<td>".$ii."</td>
			<td>".$yesterday_pdate1."</td>
			<td>دخل روز گذشته</td>
			<td>مجموع از حسابات قبلی</td>
			<td></td>
			<td></td>
			<td></td>
			<td>$currencyName</td>
			
			
		   <td> </td> 
		   <td> </td> 
		   <td style='text-align: center' dir='ltr'>".$befor_bank."</td>
		   <td style='text-align: center' dir='ltr'></td>
		   
		   </tr><tr>";
		    }
		    if($money!="all"){
		       $sql="select * from journal where (date between '$tarikhShoro' and '$tarikhAkhar') and currency='$money' and amount!=0 order by date asc";
			}
			if($money=="all"){
		       $sql="select * from journal where (date between '$tarikhShoro' and '$tarikhAkhar')  and amount!=0 order by date asc";
			}
			
		    $query= $db ->query($sql);
			while($row=$query ->fetch_array()){
			 $i;
			 $reference_id=$row['reference_id'];
			 $date=$row['date'];
			 $name=$row['name'];
			 $currency_id=$row['currency']; 
			 $reference=$row['reference'];
			 $amount=$row['amount'];
			 $threadment=$row['threadment'];
			 $des=$row['description'];
			 $dr_cr=$row['dr_cr'];
			 $transacttype=$dr_cr;
			 
			 //currencyName
			 $currencyName_sql="select * from currencies where id='$currency_id'";
			 $currencyName_query= $db ->query($currencyName_sql);
			 $currencyName_row=$currencyName_query ->fetch_array();
			 $currencyName=$currencyName_row['name'];
			 //currencyName
			 //bordo resid
			  if($threadment=='رسیدگی مشتری' or  $threadment=='بردگی مشتری'){
			   $customerInfo_sql="select * from customerpayment where  id='$reference_id'";
			   $customerInfo_query= $db ->query($customerInfo_sql);
			   $customerInfo_row=$customerInfo_query ->fetch_array();
			   $customerId=$customerInfo_row['customerId'];
			   $transacttype=$customerInfo_row['transacttype'];
			   $transactCurrency=$customerInfo_row['transactCurrency'];
			   
			   $customerName_info_sql="select * from customers where id='$customerId'";
			   $customerName_info_query= $db ->query($customerName_info_sql);
			   $customerName_info_row=$customerName_info_query ->fetch_array();
			   $customerName=$customerName_info_row['name'];
			   
			   $tran_currency_sql="select * from currencies where id='$transactCurrency'";
			   $tran_currency_query= $db ->query($tran_currency_sql);
			   $tran_currency_row=$tran_currency_query ->fetch_array();
			   $tran_currency=$tran_currency_row['name'];
			   
			   if($transacttype==1){$transactType="رسیدگی";}
			   if($transacttype==2){$transactType="بردگی";}
			   
			  $info_transact=$customerName."(".$transactType."&nbsp;".$tran_currency.")";
			  
			  }
			  //End of Bordo Resid
			 //خریداری
			 if($threadment=='خرید'){
			   $kahrid_sql="select * from transaction where id='$reference_id'";
			   $kahrid_query= $db ->query($kahrid_sql);
			   $kahrid_row= $kahrid_query ->fetch_array();
			   $counterCurrency=$kahrid_row['counterCurrency'];
			   $counterAmount  =number_format($kahrid_row['counterAmount']);
			   $baseCurrency   =$kahrid_row['baseCurrency'];
			   $baseAmount     =number_format($kahrid_row['baseAmount']);
			   $treatment      =$kahrid_row['treatment'];
			   if($treatment==1){
			   $treatment=$counterCurrency;
			    
			    $counterCurrencyName_sql="select * from currencies where id='$treatment'";
			    $counterCurrencyName_query= $db ->query($counterCurrencyName_sql);
			    $counterCurrencyName_row=$counterCurrencyName_query ->fetch_array();
			    $counterCurrencyName=$counterCurrencyName_row['name'];
				
				$baseCurrencyName_sql="select * from currencies where id='$baseCurrency'";
			    $baseCurrencyName_query= $db ->query($baseCurrencyName_sql);
			    $baseCurrencyName_row=$baseCurrencyName_query ->fetch_array();
			    $baseCurrencyName=$baseCurrencyName_row['name'];
				
				
			    $treatment=$counterCurrencyName.$counterAmount."فروش ".$baseCurrencyName.$baseAmount;
			   }
			   if($treatment==2){$treatment=$baseCurrency;}
			 
			 
			 }//انتهای خریداری
			//expenses Name
			 if( $threadment=="مصرف"){
			   $expensesName_id_sql="select * from others where typeOthers='1' and id='$reference_id'";
			   $expensesName_id_query= $db ->query($expensesName_id_sql);
			   $expensesName_id_row=$expensesName_id_query ->fetch_array();
			   $expensesName_id=$expensesName_id_row['expensesId'];
			   //Exspenses Name
			   $expensesName_sql="select * from expensesname where id='$expensesName_id'";
			   $expensesName_query= $db ->query($expensesName_sql);
			   $expensesName_row=$expensesName_query ->fetch_array();
			   $expensesName=$expensesName_row['name'];
			 
			 
			 }
			//expenses Name
            if( $threadment=="عواید"){
			   $incomeName_id_sql="select * from others where typeOthers='2' and id='$reference_id'";
			   $incomeName_id_query= $db ->query($incomeName_id_sql);
			   $incomeName_id_row=$incomeName_id_query ->fetch_array();
			   $incomeName_id=$incomeName_id_row['expensesId'];
			   //Exspenses Name
			   $incomeName_sql="select * from incomename where id='$incomeName_id'";
			   $incomeName_query= $db ->query($incomeName_sql);
			   $incomeName_row=$incomeName_query ->fetch_array();
			   $incomeName=$incomeName_row['incomeName'];
			 
			 
			 }
			//expenses Name

			
             if($threadment=='رسیدگی مشتری'){$href="edit/edit_customerPayment.php";$table='customerpayment';}			
             if($threadment=='بردگی مشتری'){$href="edit/edit_customerPayment.php";$table='customerpayment';}			
             if($threadment=='خرید'){$href="edit/edit_registerBuy.php";$table='transaction';}		
             if($threadment=='فروش'){$href="edit/edit_registerSell.php";$table='transaction';}					
			 if($threadment=='مصرف' ) {$dr_cr=2;$transacttype=2;$name="مصرف" ;$href="edit/edit_defineExpenses.php";$table='others';}
			 if($threadment=='عواید') {$dr_cr=1;$name="عواید";$transacttype=1;$href="edit/edite_defineIncome.php";$table='others';}
			  
			if($transacttype==1){   ///رسیدگی
				$debit=$amount;
				$credit=0;
				$balance_debit+=$debit;
								 
		  }
			if($transacttype==2){  //بردگی
								 
				$credit_king=$amount;  
				$debit=0;
				if($credit_king<0){ $credit=-$amount;}
				if($credit_king>0){ $credit=$amount; }
				$balance_credit+=$credit;
			}
			
			 $remian = ($balance_debit-$balance_credit)+$befor_bank;
			 $i++;
			echo "<td>$i</td>";
			echo "<td style='height: 30px'>$date</td>";
			echo "<td><a target='_blank' href='$href?editID=$reference_id&table=$table'>$reference</a></td>";
			if($threadment=="خرید" or $threadment=="فروش"){
			echo "<td>0</td>";
			echo "<td style='text-align:right'>$name ($treatment)</td>";
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'></td>";
			 
		    }
			 
			if($threadment=="رسیدگی مشتری" or $threadment=="بردگی مشتری"){
			echo "<td style='text-align:right'>$name</td>";
			echo "<td style='text-align:right'>$info_transact</td>";
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'></td>";
		    }
			if($threadment=="عواید"){
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'>$name</td>";
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'>$incomeName</td>";
		    }
			
			 
			if($threadment=="مصرف"){
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'>$name</td>";
			echo "<td style='text-align:right'>$expensesName</td>";
			echo "<td></td>";
		    }
			if($threadment=="کمیشن حواله"){
			echo "<td style='text-align:right'></td>";
			echo "<td style='text-align:right'>$name</td>";
			echo "<td style='text-align:right'>$expensesName</td>";
			echo "<td></td>";
		    }
			 
			echo "<td>$currencyName</td>";
			
			echo "<td style='text-align: center' dir='ltr'>";
			if($dr_cr==1){ echo $amount; $totalResidegi+=$amount;}
			echo "</td>";
			echo "<td style='text-align: center' dir='ltr'>";
			if($dr_cr==2){ echo $amount; $totalBordegi+=$amount;}
			echo "</td>";
			if($money!="all"){
			echo "<td style='text-align: center' dir='ltr'>".round($remian)."</td>";
			}
			echo "<td style='text-align: right'>$des</td></tr>";
			}
		   echo "<tr>";
		          if($money!="all"){
				      
		             echo "<td colspan='8'>مجموع</td>
		              <td style='background: green'>".number_format($totalResidegi)."</td>
		              <td style='background: red'>".number_format($totalBordegi)."</td>";
		            }
		    
		 
		 
		 
		 ?>
		   <?php if($money!="all") {echo "<td>$remian</td>";} ?>
		   <td></td>
		   </tr>
		 <table border="0" width="100%">
		 <tr>
		   <td>
			   <input name='submit' src='img/prent.png' type='image' border='0'  style='width:40px; height:40px'  title='Print'     class='dontPrint' onclick='window.print();return false;'/> 
		   </td>
		 </tr>
		 </table>
  </div>
 		
 </tbody>
 </table>
</div>
</div>  
 </body>
 </form>
 </html>  
  
 
     
					
					
			 