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

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

?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
        	<title>كشف حصر</title>
					<link rel="icon" href="../perfect.ico">
         <link rel="stylesheet" href="../dist/css/bootstrap.min.css"/>
      	 <link rel="stylesheet" href="../dist/css/day.css" />
	 </head>
	 <!-- onload="javascript: window.print(); setTimeout(window.close, 1000);" -->
    <body >
			<div class="container-fluid">
			<div class="row" style="padding:5 ;">
				<div class="col-xs-10"style="float:right;">
					<h6 style="font-weight:bold;padding:3px;">كشف حصر </h6>
				</div>
				<div class="col-xs-2"style="float:right;">
				</div>
			</div>
			<br />
			<div class="table-responsive">
				<table class="table table-bordered">
			<thead>
				<tr>
				  <th class="align-middle text-center" width="8%">م</th>
                   <th class="text-center" width="20%">طراز</th>
                   <th class="text-center" width="11%">لوحة</th>
                   <th class="text-center" width="19%">الفرع</th>
                   <th class="text-center" width="10%">الموديل</th>
                   <th class="text-center" width="13%">نهاية الرخصة</th>
                   <th class="text-center" width="13%">نهاية التأمين</th>
                </tr>
                
			</thead>
			<tbody >
			<?php
 if(isset($_REQUEST["b"])){
    $branch     = $_REQUEST["b"];
    $car_job_id = $_REQUEST["c"];
    $woner      = $_REQUEST["w"];
    $kind       = $_REQUEST["k"];
    $model      = $_REQUEST["m"];
    $sql = "";
      if($branch != "*"){ $sql = $sql." AND branch = ".$branch ;}
      if($car_job_id != "*"){ $sql = $sql." AND car_job_id = ".$car_job_id ;}
      if($woner != "*"){$sql = $sql." AND woner = ".$woner ;}
      if($kind != "*"){$sql = $sql." AND kind LIKE '$kind%'" ;}
      if($model != "*"){$sql = $sql." AND model = ".$model ;}
  $output = '';
  $sql2 =$db->prepare("SELECT carid,kind,concat(letters ,' ',numbers) as numbers,b_name,model,lic_expire,
  insurance_expire from cars , branches
  where cars.branch = branches.branchID $sql order by model DESC ");
  $sql2->execute();
   if($sql2->rowCount()>0)
  { $nn = 0 ;
     while($row = $sql2->fetch())
       { $nn++ ;
            $output .= '
                 <tr>
                      <td class="text-center">' . $nn . '</td>
                      <td class="text-center">' . $row['kind'] . '</td>
                      <td>' . $row['numbers'] . '</td>
                      <td>' . $row['b_name'] . '</td>
                      <td>' . $row['model'] . '</td>
                      <td class="text-center" >' . $row['lic_expire'] . '</td>
                      <td class="text-center" >' . $row['insurance_expire'] . '</td>
                   </tr> '; }
  }
  else
  { $output .= '<tr><td colspan="7">  لا توجد سيارات يا نجم..</td></tr>'; }
  echo $output;
  }
  ?>
			</tbody>
  </div>
</div>

  <script src="../js/jquery.js"></script>
	<script src="../dist/js/umd/popper.min.js"></script>
	<script src="../dist/js/bootstrap.min.js"></script>
    </body>
</html>
