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

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

if (!isset($_SESSION)) {
}
$contt = $_REQUEST['contt'];
$sql = $db->prepare('SELECT * from aksatcontprint where contract_id = ? ');
$sql->bindParam(1, $contt);
$sql->execute();
if ($sql->rowCount() > 0) {
	$result = $sql->fetch(PDO::FETCH_ASSOC);
	$father = $result['father'];
	$branch = $result['branch'];
?>
	<!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/print2.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>
		<div class="row" style="padding:0 ;">
			<br style="line-height:115px;" />
		</div>
		<div class="col-md-12" style="float:right;">
			<div class="row " style="padding:0 ;">
				<input type="hidden" id="idxp_s" value="<?php echo $result['id_Expire']; ?>" />
				<input type="hidden" id="licxp_s" value="<?php echo $result['lic_expire']; ?>" />
				<input type="hidden" class="form-control" id="freekilo" name="freekilo" />
				<div class="col-xs-3" style="float:right;padding:2px;">
					<input type="text" class="form-control text-center" value="<?php echo $result['brand'];
																				echo " ";
																				echo $result['kind']; ?>" />
				</div>
				<div class="col-xs-4" style="padding:0;margin-right:-20px ;float:right;">
					<label class="label-control" style="font-size:10px;">الرقم الضريبي 300098532500003</label>
				</div>
				<div class="col-xs-2" style="padding:0; float:right;">
					<input type="text" class="form-control text-left" value="<?php echo $result['used_area']; ?>" />
				</div>
				<div class="col-xs-2" style="padding:2; float:left;">
					<input type="text" class="form-control text-left" value="<?php echo $result['rent_days']; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-2" style="float:right;">
					<input readonly type="text" class="form-control text-left" style="font-weight:bold;padding:0px;" value="<?php echo $result['plate']; ?>" />
				</div>
				<div class="col-xs-2" style="padding:0;float:right;">
					<input readonly type="text" style="font-weight:bold;padding:0px;" class="form-control text-left" value="<?php echo $result['contract_id']; ?>" />
				</div>
				<div class="col-xs-2" style="float:left;">
					<input readonly type="text" class="form-control text-left" style="padding:0px;font-size:9pt;" value="<?php echo $result['nation']; ?>" />
				</div>
				<div class="col-xs-5" style="padding:10; float:left;">
					<input readonly type="text" class="form-control text-right" style="margin-right:30px;" value="<?php echo $result['cust_name']; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-2" style="float:right;">
					<input readonly type="text" class="form-control text-left" value="<?php echo $result['model']; ?>" />
				</div>
				<div class="col-xs-2" style="padding:0; float:right;">
					<input readonly type="text" class="form-control text-left" value="<?php echo $result['color']; ?>" />
				</div>
				<div class="col-xs-2" style="padding:0; float:left;">
					<input readonly type="text" class="form-control text-left" value="<?php echo $result['phone2']; ?>" />
				</div>
				<div class="col-xs-4" style="float:left;">
					<input readonly type="text" class="form-control text-right" value="<?php echo $result['phone']; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-2" style="float:left;">
					<input readonly type="text" class="form-control text-left" value="<?php echo $result['w_phone']; ?>" />
				</div>
				<div class="col-xs-5" style="padding:2; float:left;">
					<input readonly type="text" class="form-control text-right" style="margin-right:20px;font-size:9pt;" value="<?php echo $result['working_woner']; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-6" style="float:left;">
					<input readonly type="text" class="form-control text-center" style="font-size:9pt;" value="<?php echo $result['address']; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-2" style="float:left;">
					<input readonly type="text" class="form-control text-left" value="<?php echo $result['w_phone']; ?>" />
				</div>
				<div class="col-xs-4" style="padding:0; float:left;">
					<input type="text" class="form-control text-right" value="<?php echo $result['working_lic']; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-2" style="float:left;padding:2px;">
					<input readonly type="text" class="form-control text-left" value="<?php echo $result['w_phone2']; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<br style="line-height:38px;" />
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-2" style="float:left;">
					<input readonly type="text" class="form-control text-left" value="<?php echo $result['id_From']; ?>" />
				</div>
				<div class="col-xs-2" style="float:left;padding:0px;">
					<input readonly type="text" id="idxp" class="form-control text-right" />
				</div>
				<div class="col-xs-3" style="padding:0; float:left;">
					<input readonly type="text" class="form-control text-center" style="font-weight: bold;font-size:11pt;" value="<?php echo $result['idSA']; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-5" style="float:right;padding:2px; font-size:10px;">
					<label class="control-label text-center">قيمة الإيجار غير شامل الضريبة المضافة</label>
				</div>
				<div class="col-xs-2" style="float:left;">
					<input readonly type="text" class="form-control text-left" value="<?php echo $result['lic_from']; ?>" />
				</div>
				<div class="col-xs-2" style="float:left;padding:0px;">
					<input readonly type="text" id="licxp" class="form-control text-right" />
				</div>
				<div class="col-xs-3" style="padding:0; float:left;">
					<input readonly type="text" class="form-control text-center" style="font-weight: bold;font-size:11pt;" value="<?php echo $result['license']; ?>" />
				</div>
			</div>
			<?php
			$phone9 			= "";
			$cust_name9		= "";
			$lic_from9		= "";
			$lic_expire9	= "";
			$license9			= "";
			$address9			= "";
			$cust_id2 = $result['cust_id2'];
			if ($cust_id2 > 0) {
				$dd2 = $db->prepare('select cust_name , phone ,license , lic_from ,lic_expire , address from customers where cust_id = ? ');
				$dd2->bindParam(1, $cust_id2);
				$dd2->execute();
				if ($dd2->rowCount() > 0) {
					$ddy = $dd2->fetch(PDO::FETCH_ASSOC);
					$phone9 			=  $ddy['phone'];
					$cust_name9		= $ddy['cust_name'];
					$lic_from9		= $ddy['lic_from'];
					$lic_expire9	= $ddy['lic_expire'];
					$license9			= $ddy['license'];
					$address9			= $ddy['address'];
				}
			}
			?>
			<div class="row" style="padding:0 ;">
				<br style="line-height:10px;" />
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-2" style="float:left;">
					<input readonly type="text" class="form-control text-left" value="<?php echo $phone9; ?>" />
				</div>
				<div class="col-xs-5" style="padding:2; float:left;">
					<input readonly type="text" class="form-control text-right" style="margin-right:30px;" value="<?php echo $cust_name9; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-2" style="float:left;">
					<input readonly type="text" class="form-control text-left" value="<?php echo $lic_from9; ?>" />
				</div>
				<input type="hidden" id="licxp_s2" value="<?php echo $lic_expire9; ?>" />
				<div class="col-xs-2" style="float:left;padding:0px;">
					<input readonly type="text" id="licxp2" class="form-control text-right" />
				</div>
				<div class="col-xs-3" style="padding:0; float:left;">
					<input readonly type="text" class="form-control text-center" style="font-size:11pt;" value="<?php echo $license9; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-6" style="float:left;">
					<input readonly type="text" class="form-control text-center" style="font-size:9pt;" value="<?php echo $address9; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<br style="line-height:5px;" />
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-3" style="padding:0;float:right;">
					<input readonly type="text" class="form-control text-right" style="font-weight:bold;margin-right:78px;" value="<?php echo date("Y-m-d"); ?>" />
				</div>
				<div class="col-xs-1" style="padding:0; float:right;">
					<input readonly type="text" class="form-control text-left" style="font-weight:bold;padding:0px;" value="<?php echo $result['km_out']; ?>" />
				</div>
				<div class="col-xs-3" style="padding-right:3; float:right;">
					<input readonly type="text" class="form-control text-right" style="font-weight:bold; margin-right:75px;" value="<?php echo date("h:i:sa"); ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<br style="line-height:29px;" />
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-2" style="float:right;padding:2px;">
					<input readonly type="text" class="form-control text-left" value="<?php echo $result['day_cost']; ?>" />
				</div>
				<div class="col-xs-2" style="padding:2; float:right;">
					<input readonly type="text" class="form-control text-left" style="padding:0px;" value="<?php echo $result['kilo_cost']; ?>" />
				</div>
				<div class="col-xs-2" style="padding:2; float:right;">
					<input readonly type="text" class="form-control text-left" style="margin-left:15px;font-weight: bold;" value="<?php echo round(($result['day_cost'] / 10), 2); ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<br style="line-height:58px;" />
			</div>
			<div class="row" style="padding:0px;">
				<div class="col-xs-4" style="padding:0; float:right;">
					<input readonly type="text" class="form-control text-left" value="<?php echo $result['free_kilo']; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<br style="line-height:16px;" />
			</div>
			<div class="row" style="padding:0 ;">
				<div class="col-xs-1" style="float:right;padding:0px;"></div>
				<div class="col-xs-4" style="float:right;padding:2px; font-size:10px;">
				</div>
			</div>
			<div class="row" style="padding:0 ;">
				<br style="line-height:20px;" />
			</div>
			<?php
			$ff = $db->prepare('SELECT realName , (SELECT b_name from branches WHERE branchID = ?) as branch FROM users WHERE user_Id = ?');
			$ff->bindParam(1, $branch);
			$ff->bindParam(2, $father);
			$ff->execute();
			if ($ff->rowCount() > 0) {
				$kk = $ff->fetch(PDO::FETCH_ASSOC);
				$bbr 		= $kk['branch'];
				$user = $kk['realName'];
			}
			?>
			<div class="row" style="padding:0px;">
				<div class="col-xs-2" style="padding:0; float:right;">
					<input readonly type="text" class="form-control text-center" value=" فرع <?php echo $bbr; ?>" />
				</div>
				<div class="col-xs-2" style="padding:0; float:right;">
					<input readonly type="text" class="form-control text-right" value="<?php echo $user; ?>" />
				</div>
			</div>
			<div class="row" style="padding:0px;">
				<div class="col-xs-4" style="padding:2; float:right;">
				</div>
				<?php
				$money			= "";
				$kok = $result['contract_id'];;
				$mm = $db->prepare('SELECT sum(money_in) as money from invoice where contract_id = ? AND sanad_date = ? ');
				$mm->bindParam(1, $kok);
				$mm->bindParam(2, $date_out);
				$mm->execute();
				if ($mm->rowCount() > 0) {
					$mony = $mm->fetch(PDO::FETCH_ASSOC);
					$money 			=  $mony['money'];
				} else {
					$money = 0;
				}
				?>
				<div class="col-xs-3" style="padding:2; float:right;">
					<input type="text" class="form-control text-center" style="margin-right:30px;font-weight: bold;" value="<?php echo $money ?>" />
				</div>
			</div>
		<?php
	}
		?>
		</div>
		<script>
			// $(document).ready(function(){

			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 tt = $('#idxp_s').val();
			if (tt.length != 0) {
				convertDates('gregorian', 'idxp_s', 'idxp');
			}
			var dd = $('#licxp_s').val();
			if (dd.length != 0) {
				convertDates('gregorian', 'licxp_s', 'licxp');
			}

			var ss = $("#licxp_s2").val();
			if (ss.length != 0) {
				convertDates('gregorian', 'licxp_s2', 'licxp2');
			}
			javascript: window.print();
			setTimeout(window.close, 1500);
		</script>
	</body>

	</html>