<?php  
include("pdate.php");
    $date=pdate("Y-m-d");
 /* 
 //$date = "1998-08-14";
$newdate = strtotime ( '-1 day' , strtotime ( $date ) ) ;
$previousDate = pdate ( 'Y-m-d' , $newdate );
echo "<br>"; */
?>
<html>
<head>
<title>مفاد وضرر</title>
<link href="css/fontstyle.css" rel="stylesheet" type="text/css"/>	 
</head>
<body>
<div id="searcher">
<form method="post" action="">
  <table border="0" style="margin: auto">
  <tr>
	<td style="font-weight: bold">بـه تــاریــخ</td>
	<td><input type="text" name="startDate" value="<?php echo date("Y-m-d");  ?>"></td>
	 
	<td><input type="submit" name="submit" value="Search"></td>
  </tr>
  </table>

</div>
</form>
<?php
 if($_POST['submit']){
     $startDate_miladi=$_POST['startDate'];
	 $today=strtotime ( '0day' , strtotime ( $startDate_miladi ) ) ;
	 $startDate = pdate ( 'Y-m-d' , $today );
	 
     $newdate = strtotime ( '-1 day' , strtotime ( $startDate_miladi ) ) ;
     $previousDate = pdate ( 'Y-m-d' , $newdate );
	 
     echo "<table border='1' class='fotntitle' dir='rtl' cellpadding='0' cellspacing='0' style='margin: auto'>
	       
		   <tr>
			<td colspan='6' style='padding: 6px;text-align: center'>مفاد حاصل بر حسب دالر به تاریخ<br>".$startDate."</td>
		   </tr>
		   <tr>
				<th style='padding: 6px;background: #006699;color: #fff'>شماره</th>
				<th style='padding: 6px;background: #006699;color: #fff'>مجموع دارایی نقدی</th>
				<th style='padding: 6px;background: #006699;color: #fff'>خلص  موجودی مشتریان</th>
 				<th style='padding: 6px;background: #006699;color: #fff'>مجموع سرمایه خالص</th>
				<th style='padding: 6px;background: #006699;color: #fff'>تاریخ</th>
				</tr><tr>";
				 
  
  
include("db.php");

        
		   
		 
		/*جزئیات معاملات روز */
          $today_Details_Sql="select * from dailyprofit where date='$startDate'";
		  $today_Details_Query= $db ->query($today_Details_Sql);
		  $today_Details_Row=$today_Details_Query ->fetch_array();
		  $today_totalAsset=$today_Details_Row['totalAsset'];
		  $today_receivable=$today_Details_Row['dariyaft'];
		  $today_payable=$today_Details_Row['pardakht'];
		  $today_equity=$today_Details_Row['equity'];
		  $today_date=$today_Details_Row['date'];
		 echo "<td>1</td>";
		 $todayDayFinal=$today_totalAsset-$today_equity;
		 echo "<td>".number_format($today_totalAsset,2)."</td>";
		 echo "<td>".number_format($today_equity,2)."</td>";
		  
		 echo "<td style='background:#00cc00'>".number_format($todayDayFinal,2)."</td>";
		 echo "<td>".$today_date."</td>";
		  
		 echo "</tr><tr>";
		 /*جزئیات معاملات روز گذشته */
          $yesterday_Details_Sql="select * from dailyprofit where date='$previousDate'";
		  $yeserday_Details_Query= $db ->query($yesterday_Details_Sql);
		  $yesterday_Details_Row=$yeserday_Details_Query ->fetch_array();
		  $yesterday_totalAsset=$yesterday_Details_Row['totalAsset'];
		  $yesterday_receivable=$yesterday_Details_Row['dariyaft'];
		  $yesterday_payable=$yesterday_Details_Row['pardakht'];
		  $yesterday_equity=$yesterday_Details_Row['equity'];
		  $yesterday_date=$yesterday_Details_Row['date'];
		
		  if($yesterday_totalAsset==""){
			  
			  header("Location: assetRegistrationCheck.php");
			  die;
		  }
		  
		  
		  
		  $yesterDayFinal=$yesterday_totalAsset-$yesterday_equity;
		  
		  echo "<td>2</td>";
		  echo "<td>".number_format($yesterday_totalAsset,2)."</td>";
		  echo "<td>".number_format($yesterday_equity,2)."</td>";
		   
		  echo "<td style='background:#cc0000'>".number_format($yesterDayFinal,2)."</td>";
		  echo "<td>" .$yesterday_date."</td>";
		 
		/*  if($today_equity<0){
			 $today_equity=-$todayDayFinal; 
		  }
		  if($yesterday_equity<0){
			$yesterday_equity=-$yesterDayFinal;  
		  } */
		  $pourProfit=$todayDayFinal-$yesterDayFinal;
		  echo "</tr>
		        <tr>
					<th colspan='6' style='padding: 6px;text-align: center'>مفاد امروز:".number_format($pourProfit,2)." </th>
				</tr>
		  
		  </table>";
}

?>