<?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 = "";
	$sql = $db->prepare("SELECT items_line.unit_price, items.item_name,
		cars.kind , cars.numbers , cars.model, item_line_out.date_out
		FROM items, item_line_out, ment_request, cars ,items_line

		WHERE item_line_out.item_id = items.item_id 
		AND cars.carid = ment_request.car_id
		AND ment_request.req_id = item_line_out.req_id 
		AND items_line.line_id = item_line_out.line_in
		AND item_line_out.item_id =  ?");
	$sql->bindParam(1, $idd);
	$sql->execute();
	if ($sql->rowCount() > 0) {
		$nn = 1;
		while ($row = $sql->fetch()) {
			$price = $row['unit_price'];
			$output .= '<tr>
				<td >' . $nn . '</td>
				<td>' . $price . '</td>
				<td class="text-center">' . $row['item_name'] . '</td>
				<td >' . $row['kind'] . '</td>
				<td class="text-center">' . $row['numbers'] . '</td>
				<td class="text-center">' . $row['model'] . '</td>
				<td class="text-center">' . $row['date_out'] . '</td>
			</tr> ';
			$nn = $nn + 1;
		}
	} else {
		$output .= '<tr><td colspan="7">لا يوجد سجلات ...</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>

<body onload="javascript: window.print(); setTimeout(window.close, 1000);">
	<br />
	<div class="form-row">
		<div class="col">
			<h6 class="text-center" style="font-weight:bold;font-size:12px;"> تقرير اسعار </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="10%">سعر الوحدة</th>
						<th class="text-center" width="30%">اسم القطعة</th>
						<th class="text-center" width="15%">سيارة</th>
						<th class="text-center" width="15%">رقم</th>
						<th class="text-center" width="10%">موديل</th>
						<th class="text-center" width="15%">تاريخ</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>