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

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

if (!isset($_SESSION)) {
}

if(isset($_REQUEST["id"]))
{
	$idd = $_REQUEST["id"] ;
	$output = "";
  $output2 = "";
	$sql = $db->prepare("SELECT car_ment_v.carid , car_ment_v.kind , car_ment_v.numbers , car_ment_v.model , 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 , supp_mat_v.store_name
     from supp_mat_v , car_ment_v
     where supp_mat_v.line_id = car_ment_v.line_in
     AND car_ment_v.req_id =?
");
	$sql->bindParam(1,$idd);
	$sql->execute();
	if($sql->rowCount()>0){
    $summ = 0;
	while($row = $sql->fetch())
	{
	 $output .= '<tr>
							   <td class="text-center">' . $row['tot_price'] .'</td>
							   <td class="text-center">' . $row['qty'] . '</td>
							   <td class="text-center">' . $row['item_name'] . '</td>
							   <td class="text-center">' . $row['date_out'] . '</td>
							   <td class="text-center">' . $row['technician'] . '</td>
							   <td class="text-center">' . $row['store_name'] . '</td>
                 <td class="text-center">' . $row['mat_name'] . '</td>
                 <td class="text-center">' . $row['invoice_no'] . '</td>
							   <td class="text-center">' . $row['mat_invoice_date'] . '</td>
					    </tr> ';
       $summ = $summ + $row['tot_price'] ;
       $kind = $row['kind'];
       $numm = $row['numbers'];
       $model = $row['model'];
       $req_id = $row['req_id'];
			}
$output .='<tr>
                    <td colspan="2">'.$summ.'</td>
                    <td> إجمالي التكلفة </td>
               </tr>';
$output2.=' <h6 class="text-center" style="font-weight:bold;font-size:14px;"> سيارة '.$kind.' لوحة '.$numm.' موديل '.$model.' طلب صيانة '.$req_id.'</h6>';

	}
	else
	{
	$output .= '<tr>
											<td colspan="9">لا يوجد سجلات ...</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="سامح دياب">
	<link rel="icon" href="../images/perfect.ico">
	<title>مصروفات طلب صيانة</title>
	<link rel="stylesheet" href="../dist/css/bootstrap.css"/>
	<link rel="stylesheet" href="../dist/css/day.css"/>
</head>
    <body onload ="javascript: window.print(); setTimeout(window.close, 2000);">
<br />
  <div class="form-row">
    <div class="col">
        <?php echo $output2 ; ?>
    </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="5%">الكمية</th>
                       <th class="text-center" width="25%">اسم الصنف</th>
											 <th class="text-center" width="10%">تاريخ الصرف</th>
											 <th class="text-center" width="15%">اسم الفني</th>
                       <th class="text-center" width="5%">المخزن</th>
                       <th class="text-center" width="15%">المورد</th>
                       <th class="text-center" width="5%">الفاتورة</th>
                       <th class="text-center" width="10%">تاريخ الفاتورة</th>
                    </tr>
                  </thead>
                  <tbody >
                        <?php echo $output ; ?>
                  </tbody>
          </table>
  </div>
</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>
