<?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'];


require_once "../op/number_text.php";
$sql = $conn->prepare('SELECT aksat_in.ak_id ,aksat_in.ak_no , aksat_in.contract_id , aksat_in.payed , aksat_in.payMethod ,
					 aksat_in.comm , aksat_in.date_payed , aksat_in.start , aksat_in.endd , aksat_contract.start as cont_date ,aksat_contract.hj ,
					  cars.kind , concat(cars.letters ," ",cars.numbers) as PL, cars.model,customers.cust_name , users.realName
					 FROM aksat_in , aksat_contract , cars , customers , users
					 WHERE aksat_in.contract_id = aksat_contract.contract_id AND aksat_contract.cust_id = customers.cust_id
					 AND aksat_contract.carid = cars.carid AND aksat_in.father = users.user_Id AND aksat_in.ak_id = ?');
$sql->bindParam(1, $sanad);
$sql->execute();
if ($sql->rowCount() > 0) {
	$result = $sql->fetch(PDO::FETCH_ASSOC);
}
$payy =  $result['payMethod'];
$ak_no =  $result['ak_no'];
if ($ak_no == 0) {
	$ak_no = "دفعة أولي";
} else if ($ak_no == 10) {
	$ak_no = "عشرة";
}
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>
 <!--onload="javascript: window.print(); setTimeout(window.close, 1000);"-->
<body >
    <div class="row">
        <h1>_</h1>
    </div>
        <br /> <br/> <br/>
        <br /> <br/><br />
        <br />

	<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 ;">-->
	<!--	<br style="line-height:5000px;" />-->
	<!--</div>-->
			<div class="row" style="padding:0 ;">
				<div class="col-xs-3" style="float:right;">
					<input readonly type="text" class="form-control text-center" style="font-weight:bold;" value="<?php echo $result['ak_id']; ?>" />
					<input type="hidden" id="hj" class="form-control text-center" value="<?php echo $result['hj']; ?>" />
				</div>
				<div class="col-xs-6" style="padding:0;float:right;font-size:12px;">
					<input readonly type="text" style="font-weight:bold;" class="form-control text-center" value=" سند قبض <?php echo $ak_no; ?> " />
				</div>
				<div class="col-xs-3" style="float:left;">
					<input type="text" class="form-control text-left" style="font-weight:bold;" value="<?php echo $result['contract_id']; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-3" style="float:right;">
					<input readonly type="text" class="form-control text-center" style="font-weight:bold;" value="<?php echo $result['date_payed']; ?>" />
				</div>
				<div class="col-xs-2" style="padding:0; float:left;">
					<input readonly type="text" class="form-control text-left" style="font-weight:bold;" value="<?php echo $result['cont_date']; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-1" style="float:right;"></div>
				<div class="col-xs-2" style="float:right;">
					<input readonly type="text" class="form-control text-left" style="font-weight:bold;font-size:12pt;" value="<?php echo "# " . $result['payed'] . " #"; ?>" />
				</div>
				<div class="col-xs-7" style="padding:2; float:right;">
					<input readonly type="text" class="form-control text-right" style="margin-right:11px;font-size:10pt;" value=" <?php echo samTXT($result['payed']); ?> لا غير " />
				</div>
				<div class="col-xs-2" style="float:right;">
					<input readonly type="text" class="form-control text-right" style="font-size:9pt;" value="<?php echo $pay; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-6" style="float:right;font-size:12px;">
					<input readonly 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 readonly type="text" class="form-control text-right" value="<?php echo $result['comm']; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-3" 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 readonly type="text" id="start" style="font-weight:bold;font-size:11pt;" 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 readonly type="text" id="endd" style="float:right;font-weight:bold;font-size:11pt;" value="<?php echo $result['endd']; ?>" readonly />
				</div>
				<div class="col-xs-4" style="float:right;">
					<!-- <label class="control-label" style="float:left;font-size:11pt;font-weight:bold"><?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 readonly type="text" class="form-control text-left" value="<?php echo $result['realName']; ?>" />
				</div>
			</div>
		</form>
	</div>
	<script>
		function convertDates(name, ss, dest) {
			var date = $('#' + ss).val().split('-');
			var year = parseInt(date[0], 10);
			if (name == 'ummalqura') {
				if (year > 1800) {
					return false;
				}
			} else if (name == 'gregorian') {
				if (year < 1800) {
					return false;
				}
			}
			var month = parseInt(date[1], 10);

			var day = parseInt(date[2], 10);
			try {
				var jd = $.calendars.instance(name).newDate(year, month, day).toJD();
			} catch (e) {
				alert(e);
				return;
			}
			name == 'ummalqura' ? showDate('gregorian', jd, dest) : showDate('ummalqura', jd, dest);
		}

		function showDate(name, jd, dest) {
			try {
				$('#' + dest).val('');
				var date = $.calendars.instance(name).fromJD(jd);
				$('#' + dest).val(date.formatYear() + '/' + date.month() + '/' + date.day());
			} catch (e) {
				alert(e);
				return null;
			}
		}
		var ss = $("#hj").val();
		if (ss == 1) {
			convertDates("gregorian", "start", "start");
			convertDates("gregorian", "endd", "endd");
		}
	</script>
	<!--<script>-->
	<!--     onload="javascript: window.print(); setTimeout(window.close, 1000);"-->
	<!--</script>-->
</body>

</html>