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

$auth = bdr_require_privilege([20, 34], '../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="javscript:window.close( window.print() )" -->
    <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="text-center" width="4%">م</th>
                   <th class="text-center" width="7%">رقم العقد</th>
                   <th class="text-center" width="28%">الإسم</th>
                   <th class="text-center" width="8%">متأخرات</th>
                   <th class="text-center" width="10%">الجوال</th>
                   <th class="text-center" width="11%">إقفال</th>
                   <th class="text-center" width="8%">طراز</th>
                   <th class="text-center" width="7%">رقم</th>
                   <th class="text-center" width="9%">موديل</th>
                   <th class="text-center" width="8%">إضافي</th>
              </tr>
            </thead>
            <tbody id="myData">
                <?php
                  include "../op/wanted.php";
           $output = '';
           $sql =$db->prepare("SELECT customers.cust_name ,customers.phone , cars.kind , cars.numbers , cars.model ,
                     contracts.contract_id , contracts.date_in , contracts.days_qty , contracts.addtion_cost , contracts.violations , contracts.ins_claim
                      from customers , contracts , cars
                     WHERE contracts.cust_id = customers.cust_id AND contracts.carid = cars.carid
                      AND contracts.cont_status = 5  order by contracts.date_in  DESC, contracts.contract_id ");
            $sql->execute();
              if($sql->rowCount()>0)
                  { $nn = 1;
                while($row = $sql->fetch())
                     {
                       $ss        = $row['contract_id'];
                      $wanted = new  Wanted($db,$ss) ;
                      $pay    = $wanted->wanted() ;
                      $ww     = $pay["wanted"] ;

                       $tot_add   = $pay["tot_addtion"] ;
                    // if($ww < 200){ $output .='<tr class="bg-success" style="color:black;  border: 0.5px solid #000000;">'; } else { $output .= "<tr>" ;}
                          $output .= '<tr>
                                    <td>'.$nn.'</td>
                                    <td>' . $row['contract_id'] . '</td>
                                    <td>' . $row['cust_name'] . '</td>
                                    <td>' . $ww . '</td>
                                    <td>' . $row['phone'] . '</td>
                                    <td class = "table-info">' . $row['date_in'] . '</td>
                                    <td class="text-center" >' . $row['kind'] . '</td>
                                    <td class="text-center" >' . $row['numbers'] . '</td>
                                    <td class="text-center" >' . $row['model'] . '</td>
                                    <td class="text-center" >' . $tot_add . '</td>
                                 </tr>  ';
                                 $nn++ ;
                     }}
                  else
                  {    $output .= '<tr><td colspan="10">لا يوجد سجلات ...</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>