<?php
require_once __DIR__ . '/../magic/auth.php';

$auth = bdr_require_privilege(30, '../logout.php');
$user = $auth['user_id'];
$father = $auth['user_id'];
$branch = $auth['branch'];
$conn = $auth['conn'];
$db = $auth['conn'];

if(isset($_REQUEST["dd"])){ $myday = $_REQUEST["dd"];	}
		else{$myday = date("Y-m-d"); }
			$first_day = date('Y-m-01', strtotime($myday));
			$last_day 	= date('Y-m-t', strtotime($myday));
			// $mms  = DateTime::createFromFormat( 'm-Y', $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.min.css"/>
      	 <link rel="stylesheet" href="../dist/css/day.css" />
	 </head>
    <body onload="javascript: window.print(); setTimeout(window.close, 1000);">
			<div class="container-fluid">
			<div class="row" style="padding:5 ;">
				<div class="col-9"style="float:right;">
					<h6 style="font-weight:bold;padding:3px;font-size:10pt;"> عقود شهر <?php echo $mms ; ?> </h6>
				</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="row">
		<div class="col">
				</div>
			 	</div>
			 		<table class="table table-bordered">
			 		<thead>
			 			<tr>
			 				<th class="align-middle text-center" width="5%">م</th>
			 				<th class="align-middle text-center" width="10%">رقم العقد</th>
			 				<th class="align-middle text-center" width="10%">المطلوب</th>
			 				<th class="align-middle text-center" width="8%">تاريخ الخروج</th>
			 				<th class="align-middle text-center" width="12%">تاريخ العودة</th>
			 				<th class="align-middle text-center" width="10%">وقت العودة</th>
							<th class="align-middle text-center" width="45%">ملاحظات</th>
			 			</tr>
			 		</thead>
			<tbody >
<?php
	$output = '';
	$sql =$db->prepare("SELECT contract_id , wanted,date_out,date_in , time_in FROM `contracts`
					WHERE date_in BETWEEN ? and ? ORDER BY date_in,time_in");
	$sql->bindParam(1,$first_day);
	$sql->bindParam(2,$last_day);
	$sql->execute();
 if($sql->rowCount()>0)
				{$money = 0 ; $no = 1;
					while($row = $sql->fetch())
							{
					$date_out = date_create($row['date_out']);
			         $date_out = date_format($date_out,"m/d");
					$output .= '<tr>
									<td>'.$no.'</td>
									<td>' . $row['contract_id'] . '</td>
									<td>' . $row['wanted'] . '</td>
									<td>' . $date_out . '</td>
									<td>' . $row['date_in'] . '</td>
									<td>'. $row['time_in'] .'</td>
									<td></td>
								</tr>  ';
			$money = $money + $row['wanted'] ;
			$no = $no +1 ;
		}
		$output .= '<tr><td>' . $money. '</td>	<td>إجمالي</td></tr>';
			} else {$output .= '<tr><td colspan="7">لا يوجد سجلات ...</td></tr>';}
		 echo $output; ?>
			</tbody>
		<tfoot></tfoot>
	</table>
</div>
<script src="../js/jquery.js"></script>
<script src="../dist/js/umd/popper.min.js"></script>
<script src="../dist/js/bootstrap.js"></script>
</body>
</html>