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

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

if (!isset($_SESSION)) {
}
$sanad = $_REQUEST['sanad'];
include "../op/number_text.php";
$sql = $db->prepare('SELECT tash_in.tash_id , tash_in.contract_id , tash_in.payed , tash_in.payMethod ,
					 tash_in.comm , tash_in.date_payed , tash_in.start , tash_in.endd , aksat_contract.start as cont_date ,
					  cars.kind , concat(cars.letters ," ",cars.numbers) as PL, cars.model,customers.cust_name , users.realName
					 FROM tash_in , aksat_contract , cars , customers , users
					 WHERE tash_in.contract_id = aksat_contract.contract_id AND aksat_contract.cust_id = customers.cust_id
					 AND aksat_contract.carid = cars.carid AND tash_in.father = users.user_Id AND tash_in.tash_id = ?');
$sql->bindParam(1, $sanad);
$sql->execute();
if ($sql->rowCount() > 0) {
	$result = $sql->fetch(PDO::FETCH_ASSOC);
}
$payy =  $result['payMethod'];
switch ($payy) {
	case "1":
		$pay =  "كاش";
		break;
	case "2":
		$pay =  "تحويل الراجحي";
		break;
	case "3":
		$pay =  "نقاط بيع";
		break;
	case "4":
		$pay = "فواتير";
		break;
	case "5":
			$pay = "تحويل الأهلي";
			break;
}
$start = $result['start'];
$endd = $result['endd'];
$start = new DateTime($start);
$start =  $start->format("d-m-Y");
$endd = new DateTime($endd);
$endd =  $endd->format("d-m-Y");
?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">

<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>طباعة سند تشغيل</title>
	<link rel="stylesheet" href="../css/bootstrap.css" />
	<link rel="stylesheet" href="../css/sanad.css" />
	<script src="../js/jquery.js"></script>
	<script src="../js/bootstrap.js"></script>
	<script src="../hj2/jquery.plugin.js"></script>
	<script src="../hj2/jquery.calendars.js"></script>
	<script src="../hj2/jquery.calendars.plus.js"></script>
	<script src="../hj2/jquery.calendars.ummalqura.js"></script>
</head>

<body onload="javascript: window.print(); setTimeout(window.close, 1000);">
	<div class="row" style="padding:0 ;">
		<br style="line-height:180px;" />
	</div>
	<div class="col-xs-12" style="float:right;">
		<form method="post" class="form-horizontal " style="float:center;" id="new_sanad">
			<div class="row" style="padding:0 ;">
				<div class="col-xs-3" style="float:right;">
					<input type="text" class="form-control text-center" value="<?php echo $result['tash_id']; ?>" />
				</div>
				<div class="col-xs-6" style="padding:0;float:right;">
					<input type="text" style="font-weight:bold;" class="form-control text-center" value="قبض تشغيل سيارة" />
				</div>
				<div class="col-xs-3" style="float:left;">
					<input type="text" class="form-control text-left" value="<?php echo $result['contract_id']; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-3" style="float:right;">
					<input type="text" class="form-control text-center" value="<?php echo $result['date_payed']; ?>" />
				</div>
				<div class="col-xs-2" style="padding:0; float:left;">
					<input type="text" class="form-control text-left" value="<?php echo $result['cont_date']; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-2" style="float:right;">
					<input type="text" class="form-control text-left" style="font-weight:bold;" value="<?php echo $result['payed']; ?>" />
				</div>
				<div class="col-xs-8" style="padding:2; float:right;">
					<input type="text" class="form-control text-right" style="margin-right:10px;font-size:10pt;" value=" <?php echo samTXT($result['payed']); ?> لا غير " />
				</div>
				<div class="col-xs-2" style="float:right;">
					<input type="text" class="form-control text-left" style="font-weight:bold;" value="<?php echo $pay; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-6" style="float:right;">
					<input type="text" class="form-control text-left" value="<?php echo $result['cust_name']; ?>" />
				</div>
				<div class="col-xs-5" style="padding:0; float:left;">
					<input type="text" class="form-control text-right" value="<?php echo $result['comm']; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-2" style="float:right;">
					<label class="control-label" style="float:left;font-size:11px;">سداد تشغيل من</label>
				</div>
				<div class="col-xs-1" style="float:right;padding:0px;">
					<input type="text" id="start" value="<?php echo $result['start']; ?>" readonly />
				</div>
				<div class="col-xs-1" style="float:right;">
					<label class="control-label" style="float:left;font-size:11px;"> إلي </label>
				</div>
				<div class="col-xs-1" style="float:right;padding:0px;">
					<input type="text" id="endd" style="float:right;" value="<?php echo $result['endd']; ?>" readonly />
				</div>
				<div class="col-xs-4" style="float:right;">
					<label class="control-label" style="float:left;font-size:11px;"><?php echo $result['kind'] . "  " . $result['PL'] . " موديل " . $result['model']; ?></label>
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-3" style="float:left;">
					<input type="text" class="form-control text-left" value="<?php echo $result['realName']; ?>" />
				</div>
			</div>
		</form>
	</div>
</body>

</html>