<div  class="panel panel-primary" id="main_supp">
  <div class="panel-heading clearfix"style="font-size:1.2em;">
  <div class="row" style="padding:4px;">
      <div class="col-md-3"style="float:right;">
        <label class="control-label"style="float:right;font-size: 16px">بحث و تعديل بيانات السيارات</label>
      </div>
      <div class="col-md-1"style="float:left;">
      <a id="nn_sr" href=""target="_blank"><button type="button" style="float:right;  margin-right:8px; color: #000 ;" class="btn btn-success">تحديث</button></a>
    </div>
    <div class="col-md-2"style="float:left;">
    <input type="text" id="nn" name="nn" class="form-control" name="nn" style="float:left; margin-right:8px; color: #000 ;" placeholder="ابحث بالرقم">
  </div>
    </div>
    <br />
<form id="update7" method="post" class="form-horizontal" style="float:center;">
    <div class="row" style="padding:4px;">
        <div class="col-md-1"style="float:right;padding:2px;">
        </div>
        <div class="col-md-2"style="float:right;padding:2px;">
          <div class="input-group">
           <span class="input-group-addon" style="font-size:14px;font-weight:bold;background:transparent;color:black;" >فرع</span>
           <select  class="form-control" id="branch" name="branch">
           <option value= "*" >جميع الفروع </option>
           <?php
           include "../actions/dbPDO.php";
           $sql3 = $db->prepare("SELECT branchID , b_name from branches") ;
           $sql3->execute();
           if($sql3->rowCount()>0)
           {
            while($row = $sql3->fetch()){
                  $id     = $row["branchID"];
                  $label  = $row["b_name"];
           echo "<option value= $id >$label</option>";
              }} ?>
           </select>
         </div>
        </div>
        <div class="col-md-3"style="float:right;padding:2px;">
          <div class="input-group">
           <span class="input-group-addon" style="font-size: 14px;font-weight:bold;background:transparent;color:black;" >نوع التشغيل</span>
           <select  class="form-control" id="car_job_id" name="car_job_id">
           <option value= "*" >جميع السيارات</option>
           <?php
           $sql3 =$db->prepare("SELECT car_job_id , car_job_desc from car_job") ;
           $sql3->execute();
           if($sql3->rowCount()>0)
           {
            while($row = $sql3->fetch()){
                  $id     = $row["car_job_id"];
                  $label  = $row["car_job_desc"];
           echo "<option value= $id >$label</option>";
              }} ?>
           </select>
         </div>
        </div>
        <div class="col-md-3"style="float:right;padding:2px;">
          <div class="input-group">
           <span class="input-group-addon" style="font-size: 14px;font-weight:bold;background:transparent;color:black;" >موديل</span>
           <select  class="form-control" id="model" name="model">
           <option value= "*" >جميع الموديلات</option>
           <?php
           $sql3 =$db->prepare("SELECT DISTINCT model from cars where car_job_id < 6  ORDER BY model DESC") ;
           $sql3->execute();
           if($sql3->rowCount()>0)
           {
            while($row = $sql3->fetch()){
                  $id     = $row["model"];
                  $label  = $row["model"];
           echo "<option value= $id >$label</option>";
              }} ?>
           </select>
         </div>
        </div>
      </div>
      <div class="row" style="padding:4px;">
          <div class="col-md-5"style="float:right;padding:2px;margin-right:10px;">
            <div class="input-group">
             <span class="input-group-addon" style="font-size:14px;font-weight:bold;background:transparent;color:black;" >الشركات المالكة</span>
             <select  class="form-control" id="woner" name="woner">
             <option value= "*" >جميع الشركات</option>
             <?php
             $sql3 =$db->prepare("SELECT supp_id , supp_name from supplycomp ORDER BY supp_name") ;
             $sql3->execute();
             if($sql3->rowCount()>0)
             {
              while($row = $sql3->fetch()){
                    $id     = $row["supp_id"];
                    $label  = $row["supp_name"];
             echo "<option value= $id >$label</option>";
                }} ?>
             </select>
           </div>
          </div>
          <div class="col-md-3"style="float:right;padding:2px;">
            <div class="input-group">
             <span class="input-group-addon" style="font-size: 14px;font-weight:bold;background:transparent;color:black;" >نوع السيارة</span>
             <select  class="form-control" id="kind" name="kind" onchange="send()">
             <option value= "*" >جميع الأنواع</option>
             <?php
             $sql3 =$db->prepare("SELECT DISTINCT kind from cars where car_job_id < 6 ORDER BY kind") ;
             $sql3->execute();
             if($sql3->rowCount()>0)
             {
              while($row = $sql3->fetch()){
                    $id     = $row["kind"];
                    $label  = $row["kind"];
             echo "<option value='$id' >$label</option>";
                }} ?>
             </select>
           </div>
          </div>
          <div class="col-md-2"style="float:right;padding:2px;margin-right:20px;">
            <button class="btn btn-danger btn-block" id="search">بحث </button>
          </div>
          <div class="col-md-1"style="float:right;padding:2px;margin-right:20px;">
            <button class="btn btn-success btn-block" id="rep">تقرير</button>
          </div>
        </div>
</form>
    </div>
  <div class="panel-body"  style="background-color:#00324d;color:#cce5ff;">
    <div class="table-responsive">
         <table class="table table-bordered table-hover">
           <thead>
              <tr>
                   <th class="text-center" width="5%">م</th>
                   <th class="text-center" width="22%">حركة</th>
                   <th class="text-center" width="14%">طراز</th>
                   <th class="text-center" width="10%">لوحة</th>
                   <th class="text-center" width="12%">الفرع</th>
                   <th class="text-center" width="8%">الموديل</th>
                   <th class="text-center" width="13%">نهاية الرخصة</th>
                   <th class="text-center" width="13%">نهاية التأمين</th>
              </tr>
        </thead>
        <tbody id="myData">
                <?php
                  $output = '';
                  $sql =$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 AND cars.branch != 1 AND cars.insurance_expire < SYSDATE()  order by model DESC ");
                  $sql->execute();
                   if($sql->rowCount()>0)
                  { $nn = 0 ;
                     while($row = $sql->fetch())
                       { $nn++ ;
            $output .= '<tr> <td>' . $nn . '</td>
                            <td>
                            <a href="a/car_update.php?id=' . $row['carid'] . '"target="_blank"><button type="button" class="btn btn-success btn-xs ">تحديث</button></a>
                            <a href="naql/lic_print.php?J=' . $row['carid'] . '"target="_blank"><button type="button" class="btn btn-info btn-xs ">الرخصة</button></a>
                            <a href="acc/car_contracts.php?dd=' . $row['carid'] . '"target="_blank"><button type="button" class="btn btn-danger btn-xs ">عقود السيارة</button></a>
                            </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>
						<tfoot></tfoot>
          </table>
    </div>
</div>
</div>
<!-- panel body style -->
<?php
$outcar = array();
    $cars_sr = $db->prepare("SELECT carid , concat(letters,' ', numbers) as plate FROM cars ORDER by numbers ");
    $cars_sr->execute();
    $i=0;
    if($cars_sr->rowCount()>0)
      {
         while($row = $cars_sr->fetch())
         { $outcar[$i] = array(
                           "value" => $row["plate"],
                           "data" => $row["carid"]
                           );$i++ ;
           }  }
    else {  $outcar[0]= 'لا يوجد '; }
?>
<script>
$(document).ready(function(){
  $("#search").click(function(event){
          event.preventDefault();
        // var formdata = 	$("#update7").serialize();
        // alert (formdata);
      $.ajax({
      url       :"actions/cars12Update.php",
      method  	: "POST",
      data    	:	$("#update7").serialize(),
      success 	: function(data){
       $('#myData').html(data);
     }});
});
$("#rep").click(function(event){
          event.preventDefault();
    var b = $("#branch").val();
    var c = $("#car_job_id").val();
    var m = $("#model").val();
    var w = $("#woner").val();
    var k = $("#kind").val();
  window.open("acc/cars_rep.php?b="+b+"&c="+c+"&m="+m+"&w="+w+"&k="+k   , '_blank');
    });
$("#all").click(function(event){
  event.preventDefault();
  // var col   = $(".action").attr("id");
  // var val   = $(".action").val();
    window.open("acc/all_cars.php", '_blank');
});

var arr=  JSON.parse('<?php echo json_encode($outcar) ; ?>');
$('#nn').autocomplete({
 lookup: arr,
 maxHeight : 200,
 onSelect: function(suggestion) {
  $('#nn_sr').attr("href","a/car_update.php?id="+suggestion.data);
      //  one_invoice(suggestion.data);
       },
  })

});

</script>
