<?php
require_once "../magic/session_config.php";
bdr_start_session();
// ob_start();
$branch_d = $_SESSION['branch'];
include "../actions/dbPDO.php";
$today = date("Y-m-d");
?>
<div  class="panel panel-primary" id="main_supp">
  <div class="panel-heading clearfix"style="font-size:1.2em;">
 <div class="row" style="padding:4px;margin-top:10px;">
     <div class="col-md-5"style="float:right;">
       <label class="control-label"style="float:right;font-size:16px;">سيارات تقسيط تشغيل</label>
     </div>
   </div>
    </div>
  <div class="panel-body"  style="background-color:#00324d;color:#cce5ff;">
  <br /><br />
  <div class="row">
            <div class="col-md-2" style="float:right;">
              <input type="datepicker" class="form-control" style="float:right;" id="myday" name="myday" value="<?php echo $today; ?>" readonly />
            </div>
    <div class="col-md-3" style="float: right;">
    <button class="btn btn-success" id="day_money">طباعة اليومية</button>
  </div>
  </div>
  <script>
              $(function() {
                var calendar = $.calendars.instance('');
                $('#myday').calendarsPicker({
                  calendar: calendar
                });
              });
            </script>
  <br /> 
    <div class="table-responsive">
         <table class="table table-bordered table-hover">
           <thead>
              <tr>
                   <th class="text-center" width="8%">حركة</th>
                   <th class="text-center" width="14%">طراز</th>
                   <th class="text-center" width="13%">لوحة</th>
                   <th class="text-center" width="7%">موديل</th>
                   <th class="text-center" width="10%">اللون</th>
                   <th class="text-center" width="12%">نهاية التأمين</th>
                   <th class="text-center" width="12%">نهاية الفحص</th>
                   <th class="text-center" width="10%">حالة السيارة</th>
                   <th class="text-center" width="14%">رخصةو صيانة</th>
              </tr>
            </thead>
              <tbody id="myData">
      <?php
          $output = '';
          $sql =$db->prepare("SELECT carid , kind , concat(letters,' ',numbers) as numm , status , model , color , carstatus ,lic_expire ,
          insurance_expire from cars , carstatus where cars.carstatus = carstatus.status_id and cars.branch = ? AND cars.car_job_id in(2,3) AND cars.carstatus in(1,3) order by carstatus ");
          $sql->bindParam(1,$branch_d);
            $sql->execute();
      if($sql->rowCount()>0)
        {
      while($row = $sql->fetch())
        {
         $carid = $row['carid'];
         $stat = $row['carstatus'] ;
if($stat == 1){
        $output .= '<tr><td>
            <a href="aksat/aksat_new.php?carid='.$carid.'"target="_blank"><button type="button" style="font-weight:bold;font-size:13px;color:black;" class="btn btn-success btn-block btn-xs ">فتح عقد</button></a>' ;
           }
           else if($stat > 2){
             $output .= '<tr><td>
             <a href="#"<button type="button" st="1"  mycar='. $carid .' class="btn btn-danger btn-block btn-xs car_ment " style="font-weight:bold;font-size:13px;color:black;">إستعداد</button></a>';
                }

            $output .= '
                  </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['insurance_expire'] . '</td>
                      <td class="text-center" >' . $row['lic_expire'] . '</td>
                      <td class="text-center" >'.$row['status'].'</td>
                      <td>
                        <a href="a/photo_print.php?carid='.$carid.'"target="_blank"><button type="button" style="font-weight:bold;font-size:13px;color:black;" class="btn btn-info btn-xs ">الرخصة</button></a>
                        <a href="a/ment_b_r.php?id='.$carid.'"target="_blank"><button type="button" style="font-weight:bold;font-size:13px;color:black;" class="btn btn-danger btn-xs ">صيانة</button></a>
                      </td>
                    </tr> '; }
                  }
                  else  {  $output .= '<tr><td colspan="9">لا يوجد سجلات ...</td></tr>'; }
                  echo $output;
                  ?>
              </tbody>
						<tfoot></tfoot>
          </table>
    </div>
</div>
</div>
<script>
$(document).ready(function(){

  $("#day_money").click(function(event) {
      event.preventDefault();
      var myday = $("#myday").val();
      window.open("aksat/day_money.php?day=" + myday, '_blank');
    });

  $(".car_ment").click(function(event){
      event.preventDefault();
      var st    = $(this).attr("st");
      var carid = $(this).attr("mycar");
        $.ajax({
            url     : "actions/day_action.php",
            method  : "POST",
            data    :{st:st,carid:carid},
            dataType:"json",
            success : function(data){
            $('#site').load("aksat/aksat_cars.php");
      },
        error   :function(result){
          alert(result.statusText);
          }
      });
    })//end of car monvement  ajax code
});

</script>
