<?php
if(!isset($_SESSION)) {  session_start(); } 
ob_start();
if (!isset($_SESSION["user_id"])) {  header("location:../../logout.php"); }
$father = $_SESSION["user_id"];
	include "../actions/dbPDO.php";
	if(isset($_REQUEST["dd"])){ $myday = $_REQUEST["dd"];	}
				$first_day = date('Y-m-01', strtotime($myday));
				$last_day 	= date('Y-m-t', strtotime($myday));
	$mmm = new DateTime($myday);
	$mms =  $mmm->format("m Y");
						?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
      	<title>تحصيل الشئون القانونية</title>
         <link rel="stylesheet" href="../dist/css/bootstrap.css"/>
      	 <link rel="stylesheet" href="../css/day.css"media="print"/>
		 <script src="../js/jquery.js"></script>
		 <script src="../dist/js/umd/popper.min.js"></script>
		 <script src="../dist/js/bootstrap.js"></script>
	</head>
    <body onload="javascript: window.print(); setTimeout(window.close, 1000);" >
			<div class="container-fluid">
			<div class="row" style="padding:0 ;">
					<div class="col-9"style="float:right;">
					<p style="font-weight:bold;font-size:10pt;" > تحصيل الشئون القانونية خلال شهر <?php echo " خلال شهر ".$mms ;?></p>
					</div>
					<div class="col-3" style="float:left;">
						<p style="font-size:8pt;float:left;" ><?php echo date("Y-m-d"); ?></p>
					</div>
				</div>
				<div class="form-row">
					<div class="col">
	 					<table class="table table-bordered">
	 			<thead>
	 					<tr>
								<th class="text-center" width="6%">م</th>
	 							<th class="text-center" width="8%">المبلغ</th>
	 							<th class="text-center" width="30%">اسم العميل</th>
	 							<th class="text-center" width="8%">رقم العقد</th>
	 							<th class="text-center" width="36%">ملاحظات</th>
	 							<th class="text-center" width="12%">التاريخ</th>
	 					</tr>
	 				</thead>
	 			<tbody>
	<?php
	 	$output = '';
	 			$sql =$db->prepare("SELECT courts_in.sanad_id , courts_in.contract_id , courts_in.money_in , courts_in.sanad_date , courts_in.comm , courts_in.father , customers.cust_name
				 FROM courts_in,contracts,customers
				 WHERE courts_in.contract_id = contracts.contract_id
				 and contracts.cust_id = customers.cust_id
				 and sanad_date BETWEEN ? AND ?  ");
				 $sql->bindParam(1,$first_day);
		 		 $sql->bindParam(2,$last_day);
	 			$sql->execute();
	 		if($sql->rowCount()>0)
	 			{ $ss = 1 ;
	 		while($row = $sql->fetch())
	 			{
	 				$output .= '<tr>
									<td>' . $ss . '</td>
	 								<td>' . $row['money_in'] . '</td>
	 								<td>' . $row['cust_name'] . '</td>
	 								<td>' . $row['contract_id'] . '</td>
	 								<td>' . $row['comm'] . '</td>
									<td>' . $row['sanad_date'] . '</td>
								 </tr>  '; $ss = $ss + 1 ;
								//  <td class="text-center" >' . $row['model'] . '</td>
	 			}
	 		}
	 		else { $output .= '<tr><td colspan="7">لا يوجد سجلات ...</td></tr>';	}
	 	echo $output;
	 				 ?>
	 			</tbody>
	 		<tfoot></tfoot>
	 	</table>
	</div>
  </div> <!-- end of table row -->
  </div><!-- main fluied container -->
</body>
</html>