<?php

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

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

// include "../op/car_history.php";
require_once "../op/CarHistory.php";
$carHistory = new CarHistory($conn);

if (isset($_REQUEST["dd"])) {
	$myday = $_REQUEST["dd"];
} else {
	$myday = date("Y-m-d");
}
if (empty($_REQUEST["br"])) {
} else {
	$branch = $_REQUEST["br"];
}
?>
<!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>
<!-- onload="javascript: window.print(); setTimeout(window.close, 1000);" -->

<body onload="javascript: window.print(); setTimeout(window.close, 1500);">
	<div class="container-fluid">
		<div class="form-row">
			<div class="col-10">
				<div class="form-row">
					<div class="col">
						<h6 style="font-weight:bold;font-size:10pt;"><?php echo $myday; ?> يومية فرع <?php
																										$bb = $conn->prepare('SELECT b_name from branches where branchID = ' . $branch . '  LIMIT 1');
																										$bb->execute();
																										if ($bb->rowCount() > 0) {
																											$row = $bb->fetch();
																											echo $row["b_name"];
																										}
																										?> </h6>
						<h6 style="font-weight:bold;font-size:9pt;">سندات القبض</h6>
						<?php
						$first_day  = date('Y-m-01', strtotime($myday));
						$last_day 	= date('Y-m-t', strtotime($myday));
						?>
					</div>
				</div>
				<div class="form-row">
					<div class="col">
						<table class="table table-bordered table-striped ">
							<thead>
								<tr>
									<th class="text-center" width="5%">م</th>
									<th class="text-center" width="12%">المبلغ</th>
									<th class="text-center" width="8%">دفع</th>
									<th class="text-center" width="10%">ID</th>
									<th class="text-center" width="11%">طراز</th>
									<th class="text-center" width="15%">لوحة رقم</th>
									<th class="text-center" width="11%">عقد رقم</th>
									<th class="text-center" width="18%">الحالة</th>
									<th class="text-center" width="10%">موظف</th>
								</tr>
							</thead>
							<tbody>
								<?php
								$output = '';
								$sql = $conn->prepare("SELECT money_in , in_id , kind , concat(letters,' ',numbers) as mmh,
							contract_id , date_out , cont_status , sanad_date , father ,payMethod
							FROM sanad_in WHERE branchID = ? AND sanad_date=?  order by in_id ");
								$sql->bindParam(1, $branch);
								$sql->bindParam(2, $myday);
								$sql->execute();
								if ($sql->rowCount() > 0) {
									$qq = 1;
									while ($row = $sql->fetch()) {
										$cont 			= $row['cont_status'];
										$contract_id 	= $row['contract_id'];
										$sanad_date 	= $row['sanad_date'];
										$sad = $conn->prepare("SELECT date_in , date_out from contracts where contract_id = ?");
										$sad->bindParam(1, $contract_id);
										$sad->execute();
										if ($sad->rowCount() > 0) {
											$do = $sad->fetch();
											$date_in = $do["date_in"];
											$date_out = $do["date_out"];
										}
										switch ($cont) {
											case "1":
												if ($date_out == $sanad_date) {
													$contt = "فتح عقد";
												} else {
													$contt = "دفعة تجديد";
												}
												break;
											case "2":
												if ($date_in < $sanad_date) {
													$contt = "سداد مديونية";
												} else {
													if ($date_in == $sanad_date) {
														$contt = "إغلاق عقد";
													} else {
														$contt = "مغلق";
													}
												}
												break;
											case "3":
												if ($date_in < $sanad_date) {
													$contt = "جزء من المديونية";
												} else {
													$contt = "إغلاق مديون";
												}
												break;
										}
										$method = $row['payMethod'];
										switch ($method) {
											case '1':
												$paym = "كاش";
												break;
											case '2':
												$paym = "راجحي";
												break;
											case '3':
												$paym = "نقاط";
												break;
											case '5':
												$paym = "أهلي";
												break;
										}
										$output .= '<tr>
								 <td>' . $qq . '</td>
								 <td>' . $row['money_in'] . '</td>
								 <td>' . $paym . '</td>
								 <td>' . $row['in_id'] . '</td>
								 <td>' . $row['kind'] . '</td>
								 <td>' . $row['mmh'] . '</td>
								 <td>' . $contract_id . '</td>
								 <td>' . $contt . '</td>
								 <td>' . $row['father'] . '</td>
							</tr>  ';
										$qq = $qq + 1;
									}
								} else {
									$output .= '<tr><td colspan="9">لا يوجد سندات ...</td></tr>';
								}
								echo $output;
								?>
							</tbody>
							<tfoot></tfoot>
						</table>
					</div>
				</div>
				<!-- home sanad in row -->
				<div class="form-row">
					<div class="col">
						<table class="table table-bordered ">
							<thead>
								<tr>
									<th class="text-center" width="5%">م</th>
									<th class="text-center" width="11%">الصرف</th>
									<th class="text-center" width="8%">مردود</th>
									<th class="text-center" width="9%">ID</th>
									<th class="text-center" width="15%">طراز</th>
									<th class="text-center" width="15%">رقم</th>
									<th class="text-center" width="12%">رقم العقد</th>
									<th class="text-center" width="12%">الحالة</th>
									<th class="text-center" width="6%">موظف</th>
								</tr>
							</thead>
							<tbody>
								<?php
								$output = '';
								$sql = $conn->prepare("SELECT money_out ,out_id , kind , concat(letters,' ',numbers) as mmh ,contract_id ,
			cont_status , father ,payOutMethod FROM sanad_out WHERE branch = ? AND sanad_out = ? order by out_id ");
								$sql->bindParam(1, $branch);
								$sql->bindParam(2, $myday);
								$sql->execute();
								if ($sql->rowCount() > 0) {
									$qq = 1;
									while ($row = $sql->fetch()) {
										$cont = $row['cont_status'];
										switch ($cont) {
											case "1":
												$contt =  "ساري";
												break;
											case "2":
												$contt = "مغلق";
												break;
											case "3":
												$contt = "مديون";
												break;
										}
										$method = $row['payOutMethod'];
										switch ($method) {
											case '1':
												$paym = "كاش";
												break;
											case '2':
												$paym = "بنكي";
												break;
										}
										$output .= '<tr>
							 <td>' . $qq . '</td>
							 <td>' . $row['money_out'] . '</td>
							 <td>' . $paym . '</td>
							 <td>' . $row['out_id'] . '</td>
							 <td>' . $row['kind'] . '</td>
							 <td>' . $row['mmh'] . '</td>
							 <td>' . $row['contract_id'] . '</td>
							 <td>' . $contt . '</td>
							 <td>' . $row['father'] . '</td>
						</tr>  ';
										$qq = $qq + 1;
									}
								} else {
									$output .= '<tr><td colspan="9">لا يوجد سندات ...</td> </tr>';
								}
								echo $output;
								?>
							</tbody>
							<tfoot></tfoot>
						</table>
					</div>
				</div>
				<!-- standby -->
				<div class="form-row">
					<div class="col-4">
						<div class="form-row">
							<div class="col">
								<table class="table table-bordered ">
									<thead>
										<tr>
											<th class="text-center" width="50%">البيان</th>
											<th class="text-center" width="50%">المبلغ</th>
										</tr>
									</thead>
									<tbody>
										<?php
										// round($row['mm'] ?? 0, 2)
										$bb = $conn->prepare('SELECT sum(money_in) as mm from invoice 
	 					where payMethod = 1 AND branch = ? AND sanad_date = ?');
										$bb->bindParam(1, $branch);
										$bb->bindParam(2, $myday);
										$bb->execute();
										if ($bb->rowCount() > 0) {
											$row = $bb->fetch();
											echo '<tr><td class="text-center">كاش</td>
											
							<td>' . round(($row['mm'] ?? 0), 2) . '</td>
						</tr>  ';
										} else {
											echo '<tr><td class="text-center">كاش</td><td>بدون سندات</td></tr>  ';
										}

										$bb = $conn->prepare('SELECT sum(money_in) as mm from invoice where payMethod = 3 AND branch = ? AND sanad_date = ?'); //
										$bb->bindParam(1, $branch);
										$bb->bindParam(2, $myday);
										$bb->execute();
										if ($bb->rowCount() > 0) {
											$row = $bb->fetch();
											echo '<tr>
							<td class="text-center">نقاط بيع</td>
							<td>' . round(($row['mm'] ?? 0), 2) . '</td>
						    </tr>  ';
										} else {
											echo '<tr><td class="text-center">كاش</td><td>بدون سندات</td>	</tr>  ';
										}

										$bb = $conn->prepare('SELECT sum(money_in) as mm from invoice where payMethod = 2 AND branch = ? AND sanad_date = ?'); //
										$bb->bindParam(1, $branch);
										$bb->bindParam(2, $myday);
										$bb->execute();
										if ($bb->rowCount() > 0) {
											$row = $bb->fetch();
											echo '<tr><td class="text-center">تحويل الراجحي</td><td>' . round(($row['mm'] ?? 0), 2) . '</td></tr>  ';
										} else {
											echo '<tr><td class="text-center">كاش</td><td>بدون سندات</td></tr>  ';
										}
										$bb = $conn->prepare('SELECT sum(money_in) as mm from invoice where payMethod = 5 AND branch = ? AND sanad_date = ?'); //
										$bb->bindParam(1, $branch);
										$bb->bindParam(2, $myday);
										$bb->execute();
										if ($bb->rowCount() > 0) {
											$row = $bb->fetch();
											echo '<tr><td class="text-center">تحويل الأهلي</td><td>' . round(($row['mm'] ?? 0), 2) . '</td></tr>  ';
										} else {
											echo '<tr><td class="text-center">كاش</td><td>بدون سندات</td></tr>  ';
										}
										echo '<tr><td colspan="2" class="text-center"></td></tr>';
										$bb = $conn->prepare('SELECT sum(money_in) as mm from invoice where branch = ? AND sanad_date = ?'); //
										$bb->bindParam(1, $branch);
										$bb->bindParam(2, $myday);
										$bb->execute();
										if ($bb->rowCount() > 0) {
											$row = $bb->fetch();
											echo '<tr><td class="text-center">وارد</td><td>' . round(($row['mm'] ?? 0), 2) . '</td></tr>';
											$inn = $row["mm"];
										} else {
											echo '<tr><td class="text-center">كاش</td><td>0</td></tr>  ';
											$inn = 0;
										}
										$bb = $conn->prepare('SELECT sum(money_out) as mm from outvoice where payOutMethod = 1 AND branch = ? AND sanad_out = ?'); //
										$bb->bindParam(1, $branch);
										$bb->bindParam(2, $myday);
										$bb->execute();
										if ($bb->rowCount() > 0) {
											$row = $bb->fetch();
											echo '<tr><td class="text-center">مردود كاش</td><td>' . round(($row['mm'] ?? 0), 2) . '</td></tr>';
											$outt1 = $row["mm"];
										} else {
											echo '<tr><td class="text-center">مردود كاش<</td><td>0</td></tr>';
											$outt1 = 0;
										}
										$bb = $conn->prepare('SELECT sum(money_out) as mm2 from outvoice where payOutMethod = 2 AND branch = ? AND sanad_out = ?'); //
										$bb->bindParam(1, $branch);
										$bb->bindParam(2, $myday);
										$bb->execute();
										if ($bb->rowCount() > 0) {
											$row = $bb->fetch();
											echo '<tr><td class="text-center">مردود بنكي</td><td>' . round(($row['mm2'] ?? 0), 2) . '</td></tr>';
											$outt2 = $row["mm2"];
										} else {
											echo '<tr><td class="text-center">مردود بنكي<</td><td>0</td></tr>';
											$outt2 = 0;
										}
										$nett = round(($inn - ($outt1 + $outt2)), 2);
										echo '<tr><td class="text-center">صافي</td><td>' . $nett . '</td></tr>  ';

										$bb = $conn->prepare('SELECT sum(money_out) as mm from outvoice 
							where branch = ? AND payOutMethod = 1 AND sanad_out  between ? and ?');
										$bb->bindParam(1, $branch);
										$bb->bindParam(2, $first_day);
										$bb->bindParam(3, $last_day);
										$bb->execute();
										if ($bb->rowCount() > 0) {
											$row = $bb->fetch();
											$month_out = round(($row["mm"] ?? 0), 2);
											if (empty($month_out)) {
												$month_out = 0;
											}
										}
										$bb = $conn->prepare('SELECT sum(money_in) as mm from invoice 
												where branch = ? AND payMethod = 1 AND sanad_date between ? and ? ');
										$bb->bindParam(1, $branch);
										$bb->bindParam(2, $first_day);
										$bb->bindParam(3, $last_day);
										$bb->execute();
										if ($bb->rowCount() > 0) {
											$row = $bb->fetch();
											$month_inn = $row["mm"];
											if (empty($month_inn)) {
												$month_inn = 0;
											}
										}

										$bb = $conn->prepare('SELECT sum(money_box) as mm from boxmoney where branch = ? AND month_date between ? and ? ');
										$bb->bindParam(1, $branch);
										$bb->bindParam(2, $first_day);
										$bb->bindParam(3, $last_day);
										$bb->execute();
										if ($bb->rowCount() > 0) {
											$row = $bb->fetch();
											$month_box = round(($row["mm"] ?? 0), 2);
											if (empty($month_box)) {
												$month_box = 0;
											}
										}

										$bb = $conn->prepare('SELECT count(DISTINCT carid) as mm from active where cont_status = 1 and branch = ? ');
										$bb->bindParam(1, $branch);
										$bb->execute();
										if ($bb->rowCount() > 0) {
											$row = $bb->fetch();
											echo '<tr><td class="text-center">سيارات مؤجرة</td>
							<td class="text-center">' . $row["mm"] . '</td>
						</tr>  ';
										}
										// COUNT ( DISTINCT cust_code )
										$bb = $conn->prepare('SELECT count(carid) as mm from cars where branch = ? ');
										$bb->bindParam(1, $branch);
										$bb->execute();
										if ($bb->rowCount() > 0) {
											$row = $bb->fetch();
											echo '<tr><td class="text-center">قوة الفرع</td>
					      <td class="text-center">' . $row["mm"] . '</td></tr>  ';
										}
										// boxmoney for current day
										$bb = $conn->prepare('SELECT sum(money_box) as mm from boxmoney 
						where branch = ? AND pay_method = 1 AND month_date = ? ');
										$bb->bindParam(1, $branch);
										$bb->bindParam(2, $myday);
										$bb->execute();
										if ($bb->rowCount() > 0) {
											$row = $bb->fetch();
											$bax_cash = round(($row["mm"] ?? 0), 2);
											if (empty($bax_cash)) {
												$bax_cash = 0;
											}
											echo '<tr><td class="text-center"> توريد كاش</td>
			<td class="text-center">' . $bax_cash . '</td></tr>  ';
										}
										$bb = $conn->prepare('SELECT sum(money_box) as mm from boxmoney 
						where branch = ? AND pay_method = 4 AND month_date = ? ');
										$bb->bindParam(1, $branch);
										$bb->bindParam(2, $myday);
										$bb->execute();
										if ($bb->rowCount() > 0) {
											$row = $bb->fetch();
											$bax_fatora = round(($row["mm"] ?? 0), 2);
											if (empty($bax_fatora)) {
												$bax_fatora = 0;
											}
											echo '<tr><td class="text-center">فواتير اليوم</td>
			<td class="text-center">' . $bax_fatora . '</td></tr>  ';
										}
										$fact = round(($month_inn - ($month_out + $month_box) ?? 0), 2);
										echo '<tr><td colspan="2" class="text-center">صافي الصندوق</td></tr>
								  <tr><td class="text-center" colspan="2">' . $fact . '</td></tr>';
										?>
									</tbody>
									<tfoot></tfoot>
								</table>
							</div>
						</div>
						<br>
						<h5>عقود جديدة</h5>
						<div class="form-row">
							<div class="col">
								<table class="table table-bordered ">
									<thead>
										<tr>
											<th width="5%">م</th>
											<th class="text-center" width="45%">رقم العقد</th>
											<th class="text-center" width="50%">المقدم</th>
										</tr>
									</thead>
									<tbody>
										<?php
										$body = "<tr>";
										$bb = $conn->prepare("SELECT contract_id 	from contracts 
											where  branch = ? AND date_out = ?"); //
										$bb->bindParam(1, $branch);
										$bb->bindParam(2, $myday);
										$bb->execute();
										if ($bb->rowCount() > 0) {
											$nn = 1;
											while ($kok = $bb->fetch()) {
												$contract_id = $kok['contract_id'];
												$body .= "<td>  $nn </td>";
												$body .= "<td>  $contract_id </td>";
												$mon = $conn->prepare("SELECT sum(money_in) as mm 
								from invoice where  contract_id = ? AND sanad_date = ?");
												$mon->bindParam(1, $contract_id);
												$mon->bindParam(2, $myday);
												$mon->execute();
												if ($mon->rowCount() > 0) {
													$monn = $mon->fetch();
													$body .= '<td>' . round(($monn['mm'] ?? 0), 2) . '</td>';
												} else {
													$body .= '<td> 0 </td>';
												}
												$body .= "</tr><tr>";
												$nn++;
											}
										} else {
											$body .= '<td class="text-center" colspan="2">لا يوجد عقود جديدة</td>';
										}
										$body .= "</tr>";
										echo $body;
										?>
									</tbody>
									<tfoot></tfoot>
								</table>
							</div>
						</div>
					</div>
					<div class="col-8">
						<!-- side mageor data -->
						<div class="form-row">
							<div class="col">
								<table class="table table-bordered ">
									<thead>
										<tr>
											<th class="text-center" width="5%">م</th>
											<th class="text-center" width="15%">وقوف</th>
											<th class="text-center" width="14%">لوحة</th>
											<th class="text-center" width="6%">موديل</th>
											<th class="text-center" width="15%">اللون</th>
											<th class="text-center" width="10%">عدد ايام</th>
										</tr>
									</thead>
									<tbody>
										<?php
										$output = '';
										$sql = $conn->prepare("SELECT carid,kind,concat(letters,' ',numbers) as numm, model,color
						from cars  where carstatus = 1 and cars.branch = ? order by kind , model DESC ");
										$sql->bindParam(1, $branch);
										$sql->execute();
										if ($sql->rowCount() > 0) {
											$ss = 1;
											while ($row = $sql->fetch()) {
												$mycar = $row['carid'];
												$qty = $carHistory->car_state($mycar);
												$output .= '<tr>
								<td>' . $ss . '</td>
								<td class="text-center">' . $row['kind'] . '</td>
								<td>' . $row['numm'] . '</td>
								<td>' . $row['model'] . '</td>
								<td>' . $row['color'] . '</td>
								<td class="text-center" >' . $qty . '</td>
							</tr>';
												$ss++;
											}
										} else {
											$output .= '<tr><td colspan="6">لا يوجد سجلات ...</td></tr>';
										}
										echo $output;
										?>
									</tbody>
									<tfoot></tfoot>
								</table>
							</div>
						</div><!-- end of stand by -->
						<div class="form-row">
							<div class="col">
								<table class="table table-bordered ">
									<thead>
										<tr>
											<th class="text-center" width="5%">م</th>
											<th class="text-center" width="15%">تلقاني</th>
											<th class="text-center" width="12%">لوحة</th>
											<th class="text-center" width="5%">موديل</th>
											<th class="text-center" width="11%">اللون</th>
											<th class="text-center" width="14%">الفرع</th>
										</tr>
									</thead>
									<tbody>
										<?php
										$output = '';
										$sql = $conn->prepare("SELECT cars.carid,cars.kind,concat(cars.letters,cars.numbers) as numm, cars.model,cars.color,
											branches.b_name 	 from cars , branches 	
											where cars.branch = branches.branchID AND cars.branch != ? AND 
											 carstatus = 1 and cars.area = ? order by kind , model DESC ");
										$sql->bindParam(1, $branch);
										$sql->bindParam(2, $branch);
										$sql->execute();
										if ($sql->rowCount() > 0) {
											$ss = 1;
											while ($row = $sql->fetch()) {
												$mycar = $row['carid'];
												$output .= '<tr>
					   <td>' . $ss . '</td>
						<td class="text-center">' . $row['kind'] . '</td>
						<td>' . $row['numm'] . '</td>
						<td>' . $row['model'] . '</td>
						<td>' . $row['color'] . '</td>
						<td class="text-center" >' . $row['b_name'] . '</td>
					</tr>  ';
												$ss++;
											}
										} else {
											$output .= '<tr><td colspan="6">لا يوجد سجلات ...</td></tr>';
										}
										echo $output;
										?>
									</tbody>
									<tfoot></tfoot>
								</table>
							</div>
						</div>
						<div class="form-row">
							<div class="col">
								<table class="table table-bordered ">
									<thead>
										<tr>
											<th class="text-center" width="5%">م</th>
											<th class="text-center" width="15%">صيانة</th>
											<th class="text-center" width="14%">لوحة</th>
											<th class="text-center" width="6%">موديل</th>
											<th class="text-center" width="15%">اللون</th>
											<th class="text-center" width="10%">عدد ايام</th>
										</tr>
									</thead>
									<tbody>
										<?php
										$output = '';
										$sql = $conn->prepare("SELECT carid,kind,concat(letters,' ',numbers) as numm, model,color
						from cars  where carstatus = 3 and cars.branch = ? order by kind , model DESC");
										$sql->bindParam(1, $branch);
										$sql->execute();
										if ($sql->rowCount() > 0) {
											$ss = 1;
											while ($row = $sql->fetch()) {
												$mycar = $row['carid'];
												$qty = $carHistory->car_state($mycar);
												$output .= '<tr>
					<td>' . $ss . '</td>
					<td class="text-center">' . $row['kind'] . '</td>
					<td>' . $row['numm'] . '</td>
					<td>' . $row['model'] . '</td>
					<td>' . $row['color'] . '</td>
					<td class="text-center" >' . $qty . '</td>
				  </tr>  ';
												$ss++;
											}
										} else {
											$output .= '<tr><td colspan="6">لا يوجد سجلات ...</td></tr>';
										}
										echo $output;
										?>
									</tbody>
									<tfoot></tfoot>
								</table>
							</div>
						</div><!-- end of workshope -->
						<h5>عقود مغلقة</h5>
						<div class="form-row">
							<div class="col">
								<table class="table table-bordered ">
									<thead>
										<tr>
											<th width="4%">م</th>
											<th class="text-center" width="14%">رقم العقد</th>
											<th class="text-center" width="14%">المديونية</th>
											<th class="text-center" width="68%">ملاحظات</th>
										</tr>
									</thead>
									<tbody>
										<?php
										$body = "<tr>";
										$bb = $conn->prepare("SELECT contract_id,wanted,addtion_desc 	from contracts 
											where  branch = ? AND date_in = ?"); //
										$bb->bindParam(1, $branch);
										$bb->bindParam(2, $myday);
										$bb->execute();
										if ($bb->rowCount() > 0) {
											$nn = 1;
											while ($kok = $bb->fetch()) {
												$body .= "<td>$nn</td>";
												$body .= "<td>" .  $kok['contract_id'] . "</td>";
												$body .= "<td>" .  $kok['wanted'] . "</td>";
												$body .= "<td>" .  $kok['addtion_desc'] . "</td>";
												$body .= "</tr><tr>";
												$nn++;
											}
										} else {
											$body .= '<td class="text-center" colspan="4">لا يوجد عقود مغلقة</td>';
										}
										$body .= "</tr>";
										echo $body;
										?>
									</tbody>
									<tfoot></tfoot>
								</table>
							</div>
						</div>
					</div><!-- end 8 -->
					<!-- </div>car statuse group -->
				</div>
				<!-- //end of main body area -->
			</div>
			<div class="col-2">
				<div class="form-row">
					<div class="col">
						<table class="table table-bordered ">
							<thead>
								<tr>
									<th class="text-center" width="60%">سيارات</th>
									<th class="text-center" width="40%">مؤجرة</th>
								</tr>
							</thead>
							<tbody id="tstandby">
								<?php
								$output = '';
								$sql = $conn->prepare("SELECT DISTINCT contracts.carid, cars.kind , cars.numbers from contracts , cars
				 where contracts.carid = cars.carid AND contracts.cont_status = 1 and contracts.branch = ? order by kind , numbers ");
								$sql->bindParam(1, $branch);
								$sql->execute();
								if ($sql->rowCount() > 0) {
									while ($row = $sql->fetch()) {
										$output .= '<tr>
							<td class="text-center">' . $row['kind'] . '</td>
							<td>' . $row['numbers'] . '</td>
						 </tr>';
									}
								} else {
									$output .= '<tr><td colspan="2">لا يوجد سجلات ...</td></tr>';
								}
								echo $output;
								?>
							</tbody>
							<tfoot></tfoot>
						</table>
					</div>
				</div>
			</div><!-- side cars in rent -->
		</div><!-- end of main row -->
	</div>
</body>

</html>