<?php

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

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

if(isset($_REQUEST["id"]))
{
	$idd = $_REQUEST["id"] ;
	$output = "";
	$sql = $db->prepare("SELECT car_ment_v.carid ,  car_ment_v.req_id ,
            car_ment_v.qty , car_ment_v.tot_price ,car_ment_v.technician , car_ment_v.date_out,
	          supp_mat_v.mat_name , supp_mat_v.invoice_no , supp_mat_v.mat_invoice_date , supp_mat_v.item_name
     from supp_mat_v , car_ment_v
     where supp_mat_v.line_id = car_ment_v.line_in
     AND car_ment_v.carid = ?  ORDER BY date_out");
	$sql->bindParam(1,$idd);
	$sql->execute();
	if($sql->rowCount()>0){
    $summ = 0; $nn = 0;
	while($row = $sql->fetch())
	{ $nn++;
$output .= '<tr>
              <td >' . $nn .'</td>
							<td >' . $row['tot_price'] .'</td>
							<td class="text-center">' . $row['qty'] . '</td>
							<td >' . $row['item_name'] . '</td>
							<td class="text-center">' . $row['date_out'] . '</td>
              <td >' . $row['mat_name'] . '</td>
              <td >' . $row['invoice_no'] . '</td>
							<td class="text-center">' . $row['mat_invoice_date'] .'</td>
							<td class="text-center">' . $row['req_id'] .'</td>
					</tr> ';
       $summ = $summ + $row['tot_price'] ;
			}
$output .='<tr><td colspan="2">'.$summ.'</td><td colspan="2"> إجمالي التكلفة </td></tr>';
	} else {
	      $output .= '<tr><td colspan="8">لا يوجد سجلات ...</td></tr>';
	      }}
?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="robots" content="index,follow">
	<meta name="author" content="سامح دياب">
	<title>مصروفات صيانة سيارة</title>
	<link rel="icon" href="../images/perfect.ico">
	<link rel="stylesheet" href="../dist/css/bootstrap.css"/>
	<link rel="stylesheet" href="../dist/css/day.css"/>
</head>
<!-- onLoad="javscript:window.close( window.print() )" -->
<body >
<br />
  <div class="form-row">
    <div class="col">
    <?php
          $sql = $db->prepare("SELECT carid , brand , letters , model , numbers , kind FROM cars WHERE carid = '$idd' LIMIT 1");
          $sql->execute();
          if($sql->rowCount()>0){$row = $sql->fetch(PDO::FETCH_ASSOC);
                $carid      = $row["carid"];
                $letters    = $row["letters"];
                $numbers    = $row["numbers"];
                $model      = $row["model"];
                $kind       = $row["kind"];
              }
    ?>
      <h6 class="text-center" style="font-weight:bold;font-size:12px;"> تقرير مصروفات سيارة <?php echo $kind; ?> لوحة رقم <?php echo $letters." ".$numbers ; ?> موديل <?php echo $model; ?></h6>
    </div>
  </div>
  <br />
  <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="8%">إجمالى</th>
                       <th class="text-center" width="6%">الكمية</th>
                       <th class="text-center" width="32%">اسم الصنف</th>
                       <th class="text-center" width="10%">تاريخ الصرف</th>
                       <th class="text-center" width="16%">المورد</th>
                       <th class="text-center" width="8%">الفاتورة</th>
                       <th class="text-center" width="10%">تاريخ الفاتورة</th>
											 <th class="text-center" width="5%">طلب</th>
                    </tr>
                  </thead>
                  <tbody >
                        <?php echo $output ; ?>
                  </tbody>
          </table>
  </div><!-- end of avilable invoice items -->
</div>
<script src="../js/jquery.js"></script>
<script src="../dist/js/umd/popper.min.js"></script>
<script src="../dist/js/bootstrap.js"></script>
</body>
</html>
