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

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

$cust 		= $_REQUEST['id'];

include "../op/wanted.php";

$myCust = $conn->prepare('SELECT * from customers where cust_id = ? ');
$myCust->bindParam(1, $cust);
$myCust->execute();
if ($myCust->rowCount() > 0) {
	$result = $myCust->fetch(PDO::FETCH_ASSOC);
}
?>
<!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="../css/bootstrap.css" />
	<link rel="stylesheet" href="../css/font-awesome.min.css">
	<link rel="stylesheet" href="../hj2/humanity.calendars.picker.css">
	<link rel="stylesheet" href="../css/myCar.css" />
	<script src="../js/jquery.js"></script>
	<script src="../js/bootstrap.js"></script>
	<script src="../dist/JIC.min.js" type="text/javascript"></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.picker.js"></script>
	<script src="../hj2/jquery.calendars.ummalqura.js"></script>
</head>

<body style="background-color:#a8a89f;">
	<div class="container">
		<br /><br />
		<input style="float:right ;" type="submit" class="btn btn-danger hidden-print" name="close" id="close" value=" خروج " />
		<br /><br />
		<h4 style="text-align:center"> تحديث بيانات السيد <?php echo $result['cust_name']; ?> الجنسية <?php echo $result['nation']; ?> جوال رقم <?php echo $result['phone']; ?></h4>
		<br /><br /><br />
		<!-- Nav tabs -->
		<ul class="nav nav-tabs navbar-right" role="tablist">
			<li role="presentation" class="active" style="float:right;"><a href="#tab_basic" aria-controls="home" role="tab" data-toggle="tab">بيانات اساسية</a></li>
			<li role="presentation" style="float:right;"><a href="#tab_photo" aria-controls="profile" role="tab" data-toggle="tab">صور الهوية و الرخصة</a></li>
			<li role="presentation" style="float:right;"><a href="#tab_tel" aria-controls="profile" role="tab" data-toggle="tab">سبل التواصل</a></li>
			<li role="presentation" style="float:right;"><a href="#tab_work" aria-controls="profile" role="tab" data-toggle="tab">جهة العمل</a></li>
			<li role="presentation" style="float:right;"><a href="#tab_contract" aria-controls="profile" role="tab" data-toggle="tab">عقود المستأجر</a></li>
			<!-- <li role="presentation" style="float:right;"><a href="#tab_deposit" aria-controls="profile" role="tab" data-toggle="tab">وديعة تأمين</a></li> -->
		</ul>
		<!-- Tab panes -->
		<div class="tab-content" style="width:100% ;">
			<div role="tabpanel" class="tab-pane fad active" id="tab_basic">
				<form class="form-horizontal" id="form_basic" method="POST" class="form-horizontal" style="float:center;"> <br /><br /><br />
					<input type="hidden" id="cust_basic" name="cust_basic" value="<?php echo $result['cust_id']; ?>" />
					<div id="form_basic_msg"></div>
					<div class="row" style="padding:2px;">
						<div class="col-xs-3 col-md-2" style="float:right;">
							<label for="cust_name" class="control-label" style="float:left;">اسم المستأجر</label>
						</div>
						<div class="col-xs-4 col-md-4" style="float:right;padding:2px;">
							<input type="text" class="form-control" style="float:right;" id="cust_name" name="cust_name" value="<?php echo $result['cust_name']; ?>" placeholder="اسم المستأجر" />
						</div>
						<div class="col-xs-3 col-md-2" style="float:right;padding:2px;">
							<input type="text" class="form-control" style="float:right;" id="nation" name="nation" value="<?php echo $result['nation']; ?>" placeholder="الجنسية" />
						</div>
						<div class="col-xs-1 col-md-2" style="float:right;">
							<label for="xn" class="control-label" style="float:left;">نسخة رقم</label>
						</div>
						<div class="col-xs-1 col-md-1" style="float:right;padding:2px;">
							<input type="text" class="form-control" style="float:right;" id="xn" name="xn" value="<?php echo $result['xn']; ?>" placeholder="نسخة" />
						</div>
					</div>
					<div class="row" style="padding:4px;">
						<div class="col-xs-3 col-md-2" style="float:right;">
							<label for="idSA" class="control-label" style="float:left;">رقم الهوية</label>
						</div>
						<div class="col-xs-3 col-md-2" style="float:right;padding:2px">
							<input type="text" class="form-control" style="float:right;" id="idSA" name="idSA" value="<?php echo $result['idSA']; ?>" placeholder="رقم الهوية" readonly />
						</div>
						<div class="col-xs-3 col-md-2" style="float:right;">
							<label for="id_From" class="control-label" style="float:left;">صادر من</label>
						</div>
						<div class="col-xs-3 col-md-2" style="float:right;padding:2px;">
							<input type="text" class="form-control" style="float:right;" id="id_From" name="id_From" value="<?php echo $result['id_From']; ?>" placeholder="مصدرها" />
						</div>
						<div class="col-xs-3 col-md-2" style="float:right;">
							<label for="id_Expire" class="control-label" style="float:left;">تنتهي</label>
						</div>
						<div class="col-xs-3 col-md-2" style="float:right;padding:2px;">
							<input type="text" style="float:right;" class="form-control" id="id_Expire" name="id_Expire" value="<?php echo $result['id_Expire']; ?>" readonly placeholder="نهاية الهوية">
							<script>
								$(function() {
									var calendar = $.calendars.instance('ummalqura');
									$('#id_Expire').calendarsPicker({
										calendar: calendar
									});
									// $('#birth_hijri').calendarsPicker({
									// 	calendar: calendar
									// });
								});
							</script>
						</div>
					</div>
					<div class="row" style="padding:2px;">
						<div class="col-xs-3 col-md-2" style="float:right;">
							<label for="license" class="control-label" style="float:left;">رقم الرخصة</label>
						</div>
						<div class="col-xs-3 col-md-2" style="float:right;padding:2px;">
							<input type="text" class="form-control" style="float:right;" id="license" name="license" value="<?php echo $result['license']; ?>" placeholder="رقم الرخصة" />
						</div>
						<div class="col-xs-3 col-md-2" style="float:right;">
							<label for="lic_from" class="control-label" style="float:left;">صادر من</label>
						</div>
						<div class="col-xs-3 col-md-2" style="float:right;padding:2px">
							<input type="text" class="form-control" style="float:right;" id="lic_from" name="lic_from" value="<?php echo $result['lic_from']; ?>" placeholder="مصدرها" />
						</div>
						<div class="col-xs-3 col-md-2" style="float:right;">
							<label for="lic_expire" class="control-label" style="float:left;">تنتهي</label>
						</div>
						<div class="col-xs-3 col-md-2" style="float:right;padding:2px;">
							<input type="text" style="float:right;" class="form-control" id="lic_expire" name="lic_expire" value="<?php echo $result['lic_expire']; ?>" readonly placeholder="نهاية الرخصة" />
							<script>
								$(function() {
									var calendar = $.calendars.instance('ummalqura');
									$('#lic_expire').calendarsPicker({
										calendar: calendar
									});
								});
							</script>
						</div>
					</div>
					<div class="row" style="padding:2px;">
						<div class="col-md-2" style="float:right;">
							<label for="birth_hijri" class="control-label" style="float:left;">تاريخ الميلاد</label>
						</div>
						<div class="col-md-1" style="float:right;padding:2px;">
							<input type="text" style="float:right;" class="form-control" onchange="max31('day')" id="day" name="day" placeholder="يوم">
						</div>
						<div class="col-md-1" style="float:right;padding:2px;">
							<input type="text" style="float:right;" class="form-control" onchange="max12('month')" id="month" name="month" placeholder="شهر">
						</div>
						<div class="col-md-1" style="float:right;padding:2px;">
							<input type="text" style="float:right;" class="form-control" onchange="max14('year')" id="year" name="year" placeholder="سنة">
						</div>
						<div class="col-md-1" style="float:right;padding:2px;">
						</div>
						<div class="col-md-2" style="float:right;padding:2px;">
							<input type="text" style="float:right;" class="form-control" id="birth_hijri" name="birth_hijri" value="<?php echo $result['birth_hijri']; ?>" placeholder="الميلاد بالهجري" readonly>
						</div>
						<div class="col-md-2" style="float:right;">
							<label for="birth" class="control-label" style="float:left;">تاريخ الميلاد ميلادي</label>
						</div>
						<div class="col-md-2" style="float:right;padding:2px;">
							<input type="text" style="float:right;" class="form-control" id="birth" name="birth" value="<?php echo $result['birth']; ?>" placeholder="<?php echo (date('Y-m-d', strtotime(' - 21 year')));  ?>"
								readonly>
							<script>
								function max12(field) {
									var data = parseInt($("#" + field).val());
									if (data > 12) {
										$("#" + field).val(12);
									} else if (data < 1) {
										$("#" + field).val(1);
									}
								}

								function max31(field) {
									var data = parseInt($("#" + field).val());
									if (data > 31) {
										$("#" + field).val(31);
									} else if (data < 1) {
										$("#" + field).val(1);
									}
								}

								function max14(field) {
									var data = parseInt($("#" + field).val());
									if (data > 2003) {
										$("#" + field).val(2002);
									} else if (data < 1373) {
										$("#" + field).val(1373);
									}
								}

								function getAge(year, month, day) {
									const birth = new Date(year, month - 1, day);
									const now = new Date();
									const diff = new Date(now.valueOf() - birth.valueOf());
									return Math.abs(diff.getFullYear() - 1970) + " سنة و " + Math.abs(diff.getMonth()) + "شهر";
								}

								function age() {
									var date = $('#birth').val().split('-');
									var year = parseInt(date[0], 10);
									var month = parseInt(date[1], 10);
									var day = parseInt(date[2], 10);
									var age = getAge(year, month, day);
									$("#age").val(age);
								}
							</script>
						</div>
					</div>
					<div class="row" style="padding:2px;">
						<div class="col-xs-3 col-md-2" style="float:right;">
							<label for="job" class="control-label" style="float:left;">المهنة</label>
						</div>
						<div class="col-xs-3 col-md-2" style="float:right;padding:2px">
							<input type="text" class="form-control" style="float:right;" id="job" name="job" value="<?php echo $result['job']; ?>" placeholder="المهنة" />
						</div>
						<div class="col-xs-3 col-md-2" style="float:right;">
							<label for="age" class="control-label" style="float:left;">العمر</label>
						</div>
						<div class="col-xs-3 col-md-2" style="float:right;padding:2px;">
							<input type="text" style="float:right;" class="form-control" id="age" name="age" value="" placeholder="العمر" />
						</div>
					</div>
					<br /><br />
					<div>
						<button type="submit" class="btn btn-success save" farm="form_basic" id="save_basic" data-loading-text="Loading..."> حفظ التحديث <i class="glyphicon glyphicon-ok-sign"></i></button>
					</div> <!-- /modal-footer -->
				</form> <!-- /.form -->
			</div><!-- /basic update -->

			<div role="tabpanel" class="tab-pane fad" id="tab_photo">
				<form method="POST" id="form_photo" class="form-horizontal" enctype="multipart/form-data">
					<br /><br /><br /><br /><br />
					<input type="hidden" id="cust_dd" class="hidden-print" name="cust_dd" value="<?php echo $result['cust_id']; ?>" />
					<input type="hidden" id="photo_idSA" name="photo_idSA" value="<?php echo $result['idSA']; ?>" placeholder="رقم الهوية" />

					<a href="cust_print.php?cust_id=<?php echo $result['cust_id']; ?>" target="_blank" class="hidden-print"><button type="button" class="btn btn-info btn-xs ">طباعة الرخصة و الهوية</button></a>

					<div class="row" style="padding:4px;">
						<img id="cust_preview" src="../photo/customers/<?php echo $result['cust_photo']; ?>" class="img-responsive img-rounded" width="100%" height="auto" style="" alt="صورة الرخصة غير متاحة" />
					</div>
					<div class="row" style="padding:4px;">
						<div class="col-md-6" style="float:right;">
							<input style="float:right ; font-weight:bold;" type="file" class="btn btn-primary hidden-print" name="cust_photo" id="cust_photo" />
						</div>
						<br /><br />
						<div id="uploaded_file"></div>
						<div class="col-xs-3 col-md-2" style="float:right;">
							<input style="float:right ; font-weight:bold;" type="submit" class="btn btn-primary hidden-print" id="photo_paly" farm="form_photo" value="حفظ تعديلات الرخصة" />
						</div>
						<div id="form_photo_msg"></div>
					</div>
				</form> <!-- /form -->
			</div><!-- car licens photo -->
			<div role="tabpanel" class="tab-pane" id="tab_tel">
				<form class="form-horizontal" id="form_tel" method="POST">
					<br /><br /><br />
					<input type="hidden" id="cust_tel" name="cust_tel" value="<?php echo $result['cust_id']; ?>" />
					<div id="form_tel_msg"></div>
					<div class="row" style="padding:4px;">
						<div class="col-md-2" style="float:right;">
							<label for="phone" class="control-label " style="float:left;">رقم الجوال</label>
						</div>
						<div class="col-md-2" style="float:right;padding:2px;">
							<input type="text" style="float:right;" class="form-control" id="phone" name="phone" value="<?php echo $result['phone']; ?>" placeholder="رقم الجوال" readonly />
						</div>
						<div class="col-md-2" style="float:right;">
							<label for="phone2" class="control-label " style="float:left;">جوال2</label>
						</div>
						<div class="col-md-2" style="float:right;padding:2px">
							<input type="text" style="float:right;" class="form-control" id="phone2" name="phone2" value="<?php echo $result['phone2']; ?>" placeholder="رقم جوال2">
						</div>
					</div>
					<!-- // -->
					<div class="row" style="padding:4px;">
						<div class="col-md-2" style="float:right;">
							<label for="CityName" class="control-label" style="float:left;">المدينة</label>
						</div>
						<div class="col-md-2" style="float:right; padding:2px;">
							<input type="text" style="float:right;" class="form-control" id="CityName" name="CityName" placeholder="المدينة" value="<?php echo $result['CityName']; ?>">
						</div>
						<div class="col-md-2" style="float:right; padding:2px;">
							<input type="text" style="float:right;" class="form-control" id="SubDivisionName" name="SubDivisionName" placeholder="الحي" value="<?php echo $result['SubDivisionName']; ?>" >
						</div>
						<div class="col-md-2" style="float:right;padding:2px; padding:2px;">
							<input type="text" style="float:right;" class="form-control" id="StreetName" name="StreetName" placeholder="شارع" value="<?php echo $result['StreetName']; ?>" >
						</div>
						<div class="col-md-1" style="float:right;padding:2px;">
							<input type="text" style="float:right;" class="form-control" id="BuildingNumber" name="BuildingNumber" placeholder="المبني" value="<?php echo $result['BuildingNumber']; ?>">
						</div>
						<div class="col-md-1" style="float:right;padding:2px;">
							<input type="text" style="float:right;" class="form-control" id="PlotIdentification" name="PlotIdentification" placeholder="وحدة" value="<?php echo $result['PlotIdentification']; ?>">
						</div>
						<div class="col-md-2" style="float:right;padding:2px;">
							<input type="text" style="float:right;" class="form-control" id="PostalNumber" name="PostalNumber" placeholder="الرقم البريدي" value="<?php echo $result['PostalNumber']; ?>" >
						</div>

					</div>
					<!-- // -->
					<div class="row" style="padding:4px;">
						<div class="col-md-2" style="float:right;">
							<label for="address" class="control-label" style="float:left;">العنوان</label>
						</div>
						<div class="col-md-7" style="float:right;padding:2px">
							<input type="text" class="form-control" style="float:right;" id="address" name="address" value="<?php echo $result['address']; ?>" placeholder="العنوان" />
						</div>
						<div class="col-md-1" style="float:right;padding:2px">
							<input type="text" style="float:right;" class="form-control" id="dgree" name="dgree" value="<?php echo $result['dgree']; ?>" placeholder="تقييم">
						</div>
					</div>
					<div class="row" style="padding:4px;">
						<div class="col-xs-3 col-md-2" style="float:right;">
							<label for="comm" class="control-label" style="float:left;">ملاحظات</label>
						</div>
						<div class="col-xs-9 col-md-10" style="float:right;padding:2px">
							<input type="text" class="form-control" style="float:right;" id="comm" name="comm" value="<?php echo $result['comm']; ?>" placeholder="ملاحظات ">
						</div>
					</div>
					<br /><br />
					<div>
						<button type="submit" class="btn btn-success save" farm="form_tel" id="save_tel" data-loading-text="Loading..."> <i class="glyphicon glyphicon-ok-sign"></i> حفظ التعديلات </button>
					</div> <!-- /modal-footer -->
				</form> <!-- /.form -->
			</div><!-- /tab telecomunication -->

			<div role="tabpanel" class="tab-pane" id="tab_work">
				<form class="form-horizontal" id="form_work" method="POST">
					<input type="hidden" id="cust_work" name="cust_work" value="<?php echo $result['cust_id']; ?>" />
					<br /><br /><br /><br />
					<div id="form_work_msg"></div>
					<div class="row" style="padding:4px;">
						<div class="col-xs-2 col-md-2" style="float:right;">
							<label for="working_lic" class="control-label" style="float:left;">رخصة العمل</label>
						</div>
						<div class="col-xs-4 col-md-2" style="float:right;padding:2px;">
							<input type="text" class="form-control" style="float:right;" id="working_lic" name="working_lic" value="<?php echo $result['working_lic']; ?>" placeholder="رقم رخصة العمل" />
						</div>
						<div class="col-xs-2 col-md-2" style="float:right;">
							<label for="working_woner" class="control-label " style="float:left;">صاحب العمل</label>
						</div>
						<div class="col-xs-6 col-md-5" style="float:right; padding:2px;">
							<input type="text" style="float:right;" class="form-control" id="working_woner" name="working_woner" value="<?php echo $result['working_woner']; ?>" placeholder="اسم جهة العمل">
						</div>
					</div>
					<div class="row" style="padding:4px;">
						<div class="col-md-2" style="float:right;">
							<label for="w_phone" class="control-label " style="float:left;">تليفون العمل</label>
						</div>
						<div class="col-md-2" style="float:right;padding:2px;">
							<input type="text" style="float:right;" class="form-control" id="w_phone" name="w_phone" value="<?php echo $result['w_phone']; ?>" placeholder="رقم الجوال" />
						</div>
						<div class="col-md-2" style="float:right;">
							<label for="w_phone2" class="control-label " style="float:left;">تليفون العمل2</label>
						</div>
						<div class="col-md-2" style="float:right;padding:2px">
							<input type="text" style="float:right;" class="form-control" id="w_phone2" name="w_phone2" value="<?php echo $result['w_phone2']; ?>" placeholder="رقم جوال2">
						</div>
					</div>
					<div class="row" style="padding:4px;">
						<div class="col-md-2" style="float:right;">
							<label for="working_address" class="control-label" style="float:left;">عنوان العمل</label>
						</div>
						<div class="col-md-10" style="float:right;padding:2px">
							<input type="text" class="form-control" style="float:right;" id="working_address" name="working_address" value="<?php echo $result['working_address']; ?>" placeholder="عنوان جهة العمل" />
						</div>
					</div>
					<div class="row" style="padding:4px;">
						<div class="col-md-2" style="float:right;">
							<label for="working_address" class="control-label" style="float:left;">الرقم الضريبي</label>
						</div>
						<div class="col-md-4" style="float:right;padding:2px">
							<input type="number" class="form-control" style="float:right;" id="cust_vat" name="cust_vat" onchange="fifteen('cust_vat')" value="<?php echo $result['cust_vat']; ?>" placeholder=" الرقم الضريبي " />
						</div>
					</div>
					<br /><br />
					<div>
						<button type="submit" class="btn btn-success save" farm="form_work" id="save_work" data-loading-text="Loading..."> <i class="glyphicon glyphicon-ok-sign"></i> حفظ التعديلات </button>
					</div> <!-- /modal-footer -->
				</form> <!-- /.form -->
			</div><!-- /tab work -->

			<div role="tabpanel" class="tab-pane fad" id="tab_contract">
				<br /><br /><br /><br /><br />
				<div class="table-responsive">
					<table class="table table-bordered table-hover">
						<thead>
							<tr>
								<th class="text-center" width="4%">م</th>
								<th class="text-center" width="7%">رقم العقد</th>
								<th class="text-center" width="7%">متأخرات</th>
								<th class="text-center" width="10%">إغلاق العقد</th>
								<th class="text-center" width="8%">طراز</th>
								<th class="text-center" width="6%">رقم</th>
								<th class="text-center" width="9%">موديل</th>
								<th class="text-center" width="5%">يومي</th>
								<th class="text-center" width="5%">أيام</th>
								<th class="text-center" width="6%">إضافي</th>
								<th class="text-center" width="30%">بيان الإضافي</th>
								<th class="text-center" width="7%">المدفوع</th>
							</tr>
						</thead>
						<tbody id="myData">
							<?php
							$output = '';
							$sql = $conn->prepare("SELECT contracts.contract_id ,contracts.date_in ,contracts.day_cost , contracts.addtion_desc, cars.kind , cars.numbers , cars.model , contracts.day_cost
				from  contracts , cars WHERE contracts.carid = cars.carid AND cont_status < 4
				AND (contracts.cust_id = ? OR contracts.cust_id2 = ? ) ORDER BY contracts.date_out DESC LIMIT 19");
							$sql->bindParam(1, $cust);
							$sql->bindParam(2, $cust);
							$sql->execute();
							if ($sql->rowCount() > 0) {
								$no = 1;
								while ($row = $sql->fetch()) {
									$output .= '<tr><td>' . $no . '</td>';
									$contract_id = $row['contract_id'];
									$wanted    = new  Wanted($conn, $contract_id);
									$pay       = $wanted->wanted();
									$ww        = $pay["wanted"];
									if ($ww > 0) {
										$output .= '<td>
			<a href="../rent/cont2debt.php?id=' . $contract_id . '"target="_blank"><button type="button" style="font-weight:bold ; font-size:14px; padding:2;" class="btn btn-danger btn-xs btn-block ">' . $contract_id . '</button></a></td>
			<td style="color:#DA2D07; background-color:#F0F7E4;font-weight:bold;">' . $ww . '</td>';
									} else {
										$output .= '<td><a href="../rent/cont2debt.php?id=' . $contract_id . '"target="_blank"><button type="button" style="font-weight:bold ; font-size:14px; padding:2;" class="btn btn-danger btn-xs btn-block ">' . $contract_id . '</button></a></td>
						 <td>' . $ww . '</td>';
									}
									$output .= '<td>' . $row['date_in'] . '</td>
					     <td class="text-center" >' . $row['kind'] . '</td>
						 <td class="text-center" >' . $row['numbers'] . '</td>
						 <td class="text-center" >' . $row['model'] . '</td>
						 <td class="text-center" >' . $row['day_cost'] . '</td>
						 <td class="text-center" >' . $pay["days_qty"] . '</td>
						 <td class="text-center" >' . $pay["tot_addtion"] . '</td>
						 <td class="text-center" >' . $row['addtion_desc'] . '</td>
						 <td class="text-center" >' . $pay["payed"] . '</td></tr>';
									$no = $no + 1;
								}
							} else {
								$output .= '<tr><td colspan="12">لا يوجد سجلات ...</td></tr>';
							}
							echo $output;
							?>
						</tbody>
						<tfoot></tfoot>
					</table>
				</div>
			</div>
			<!-- start deposit -->
			<!-- <div role="tabpanel" class="tab-pane fad" id="tab_deposit">
				<br /><br /><br />
				<div class="row" style="margin-top:3px;">
					<div class="col-sm-6" style="float:right;">
						<button type="button" class="btn btn-outline-primary btn-block" data-toggle="modal" style="float:left;font-weight:bold;" data-backdrop="static" data-keyboard="false" data-target="#deposit_in">سند قبض</button>
					</div>
				</div>
				<div class="form-row">
					<div class="col-sm-7" style="float:right;padding:2px;">
						<h6>سندات قبض</h6>
						<table class="table table-bordered table-hover">
							<thead>
								<tr>
									<th class="text-center" width="4%">م</th>
									<th class="text-center" width="9%">المبلغ</th>
									<th class="text-center" width="12%">التاريخ</th>
									<th class="text-center" width="8%">كود</th>
									<th class="text-center" width="15%">الفرع</th>
									<th class="text-center" width="15%">طريقة الدفع</th>
									<th class="text-center" width="12%">صرف</th>
								</tr>
							</thead>
							<tbody>
								<?php
				// 				$output = '';
				// 				$sql = $conn->prepare("SELECT in_id , money_in , sanad_date , realName , payMethod ,b_name  FROM sanad_in
				// WHERE contract_id = ? order by sanad_date DESC ");
				// 				$sql->bindParam(1, $contract_id);
				// 				$sql->execute();
				// 				if ($sql->rowCount() > 0) {
				// 					$ss = 1;
				// 					while ($row = $sql->fetch()) {
				// 						$in_id = $row['in_id'];
				// 						$bb = $row['payMethod'];
				// 						switch ($bb) {
				// 							case "1":
				// 								$pay =  "كاش";
				// 								$options = '<option selected value="1">كاش</option><option value="2" >تحويل الراجحي</option><option value="3" >نقاط بيع</option><option value="5" >تحويل الأهلي</option>';
				// 								break;
				// 							case "2":
				// 								$pay = "تحويل الراجحي";
				// 								$options = '<option value="1">كاش</option><option selected value="2" >تحويل الراجحي</option><option value="3" >نقاط بيع</option><option value="5" >تحويل الأهلي</option>';
				// 								break;
				// 							case "3":
				// 								$pay = "نقاط بيع";
				// 								$options = '<option value="1">كاش</option><option value="2" >تحويل الراجحي</option><option selected value="3" >نقاط بيع</option><option value="5" >تحويل الأهلي</option>';
				// 								break;
				// 							case "5":
				// 								$pay = "تحويل الأهلي";
				// 								$options = '<option value="1">كاش</option><option value="2" >تحويل الراجحي</option><option value="3" >نقاط بيع</option><option selected  value="5" >تحويل الأهلي</option>';
				// 								break;
				// 						}
				// 						$output .= '<tr>
				// 		<td style="padding:0px;margin:0px;"><button id="' . $in_id . '" style="font-weight:bold ;font-size:14px; padding:2;" class="btn btn-danger btn-ms btn-block in_edit ">' . $ss . '</button></td>
				// 			<td id="mon' . $in_id . '" contenteditable="true">' . $row['money_in'] . '</td>
				// 			<td>' . $row['sanad_date'] . '</td>
				// 			<td ><a  href="../rent/print/sanadin.php?sn=' . $row['in_id'] . '"target="_blank">' . $row['in_id'] . '</a></td>
				// 			<td>' . $row['realName'] . '</td>
				// 			<td>' . $row['b_name'] . '</td>
				// 			<td style="padding:0px;margin:0px;" contenteditable="true"><select id="pay' . $in_id . '" class="form-control payMM" style="background-color:transparent;padding:3px;margine:0px;" >
				// 			' . $options . '
				// 			</select></td>';
				// 						$ss = $ss + 1;
				// 					}
				// 				} else {
				// 					$output .= '<tr><td colspan="7">لا يوجد سجلات ...</td></tr>';
				// 				}
				// 				echo $output;
								// <td>' . $in_id . '</td>
								?>
							</tbody>
							<tfoot></tfoot>
						</table>
					</div>
					<div class="col-sm-5">
						<h6>مردود وديعة</h6>
						<table class="table table-bordered table-hover ">
							<thead>
								<tr>
									<th class="text-center" width="12%">المبلغ</th>
									<th class="text-center" width="10%">التاريخ</th>
									<th class="text-center" width="22%">نوع التحويل</th>
									<th class="text-center" width="26%">رقم العقد</th>
									<th class="text-center" width="15%">الفرع</th>
								</tr>
							</thead>
							<tbody id="tstandby">
								<?php
								// $output = '';
								// $sql = $conn->prepare("SELECT vat_id , after_vat , start , end, day_cost ,days_qty FROM vat WHERE contract_id = ? order by vat_id DESC  ");
								// $sql->bindParam(1, $contract_id);
								// $sql->execute();
								// if ($sql->rowCount() > 0) {
								// 	while ($row = $sql->fetch()) {
								// 		$vat_id = $row['vat_id'];
								// 		$output .= '<tr>
								// 					<td style="padding:0px;margin:0px;"><button id="' . $vat_id . '" style="font-weight:bold ;font-size:14px; padding:2;" class="btn btn-danger btn-ms btn-block vat_print">' . $vat_id . '</button></td>
								// 					<td >' . $row['after_vat'] . '</td>
								// 					<td>' . $row['start'] . '</td>
								// 					<td>' . $row['end'] . '</td>
								// 					<td>' . $row['day_cost'] . '</td>
								// 					<td>' . $row['days_qty'] . '</td>
								// 					</tr>  ';
								// 	}
								// } else {
								// 	$output .= '<tr><td colspan="6">لا يوجد سجلات ...</td></tr>';
								// }
								// echo $output;
								?>
							</tbody>
							<tfoot></tfoot>
						</table>
					</div><!-- end of out voice section -->
				<!-- </div> --> 
				<!-- end deposit -->
				<p><br /><br /><br /><br /><br /></p>
				</form>
			</div>
		</div>
		<!-- // moda -->
		<!-- deposit in modal -->
		<div class="modal fade" id="deposit_in" tabindex="-1" role="dialog" aria-labelledby="exLabel">

			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header" style="background-color:teal ;">
						<div class="col-md-1 text-right">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span style="color:red;font-size:18px;"><i class="fa fa-times" aria-hidden="true"></i></span></button>
						</div>
						<div class="col-md-11 text-right">
							<h6 class="modal-title" style="float:right;font-weight:bold;color:#FFFAF0; " id="exLabel">سند قبض وديعة تأمين</h6>
						</div>
					</div>
					<br />
					<div class="modal-body">
						<!-- start of deposit_in form -->
						<form method="post" action="../customers/deposit_actions.php" class="form-horizontal" id="modal_deposit">
							<div id="deposit_in_msg"></div>
							<div class="form">
								<input type="hidden" class="form-control" id="id2" name="id2" />
								<input type="hidden" id="id" name="id" />
								<div class="col-2" style="float:right;">
									<label for="money_in" class="control-label" style="float:left;color:black;">المبلغ <span class="text-danger">*</span></label>
								</div>
								<div class="col-md-3" style="float:right;">
									<input type="number" class="form-control" id="money_in" name="money_in" placeholder="بالريال" />
									<div id="money_in_msg" class="text-danger" style="font-size:12px;"></div>
								</div>
								<div class="col-md-3" style="float:right;">
									<!-- <input type="text" style="float:right;" class="form-control" id="printed_no" name="printed_no" placeholder="المطبوع" />
									<div id="printed_no_msg" class="text-danger" style="font-size:12px;"></div> -->
								</div>
								<div class="col-md-2" style="float:right;">
									<label for="payMethod" class="control-label " style="float:left;color:black;">طريقة الدفع</label>
								</div>
								<div class="col-md-2" style="float:right;">
									<select class="form-control" id="payMethod" name="payMethod" style="padding:3px;">
										<option selected value="1">كاش</option>
										<option value="2">تحويل الراجحي</option>
										<option value="3">نقاط بيع</option>
										<option value="5">تحويل الاهلي</option>
									</select>
								</div>
							</div>
							<div class="form" style="float:right;">
								<div class="col-md-2" style="float:right;">
									<label for="comm2" class="control-label" style="color:black;">ملاحظات</label>
								</div>
								<div class="col-md-10" style="float:right;">
									<input type="text" class="form-control" id="comm2" name="comm2" />
									<div id="comm2_msg" class="text-danger" style="font-size:12px;"></div>
								</div>
							</div>
						</form><!-- end of sanad_in form -->
					</div>
					<div class="modal-footer">
						<div class="col-md-1">
							<button type="button" class="btn btn-default" data-dismiss="modal">خروج</button>
						</div>
						<div class="col-md-10" style="float:right;">
							<button type="button" id="deposit_add" name="deposit_add" class="btn btn-primary">حفظ <i class="fa fa-cloud" aria-hidden="true"></i></button>
							<a id="deposite_print" href="" target="_blank" style="display: none;"><button type="button" class="btn btn-success">طباعة السند <i class="fa fa-print" aria-hidden="true"></i></button></a>
							<div>
							</div>
						</div>
					</div>
				</div>
			</div><!-- end of sanad_in modal -->
		</div> <!-- modal invoice end -->
		<script>
			$(document).ready(function() {
				age();
				$('#close').click(function() {
					close();
				});

				$(".save").click(function(event) {
					event.preventDefault();
					var farm = $(this).attr("farm");
					if (farm == "form_basic") {
						var tt = $('#id_Expire').val();
						if (tt.length != 0) {
							convertDates('ummalqura', 'id_Expire', 'id_Expire');
						}
						var dd = $('#lic_expire').val();
						if (dd.length != 0) {
							convertDates('ummalqura', 'lic_expire', 'lic_expire');
						}
						var day = $('#day').val() || 0;
						if (day.length > 0) {
							convertDate("year", "month", "day", 'birth_hijri', 'birth');
						}
					}
					$.ajax({
						url: "../rent/cust_update.php",
						method: "POST",
						data: $("#" + farm).serialize(),
						success: function(data) {
							$("#" + farm + "_msg").html(data);
						},
						error: function(result) {
							alert(result.statusText);
						}
					})
				});
				$('#form_photo').on('submit', function(event) {
					event.preventDefault();
					var cust_dd = $('#cust_dd').val();
					var extension = $('#cust_photo').val().split('.').pop().toLowerCase();

					if (extension != '') {
						if (jQuery.inArray(extension, ['png', 'jpg', 'jpeg']) == -1) {
							alert("صور jpg فقط");
							$('#cust_photo').val('');
							return false;
						}
						var oFReader = new FileReader();
						oFReader.readAsDataURL(document.getElementById("cust_photo").files[0]);
						var f = document.getElementById("cust_photo").files[0];
						var fsize = f.size || f.fileSize;
						// alert(f.size);
						if (fsize > 1600000) {
							alert("حجم الصورة كبير جدا ...");
							return false;
						}
						$.ajax({
							url: "../rent/cust_update.php",
							method: "POST",
							data: new FormData(this),
							contentType: false,
							processData: false,
							success: function(data) {
								$('#form_photo')[0].reset();
								$('#cust_preview').attr("src", "../photo/customers/" + data);
								$('#form_photo_msg').html(data);
							}
						});
					}
				}); //end of button add image

				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;
					}
				}

				function convertDate(year, month, day, hj, melady) {
					var name = 'gregorian';
					var year = parseInt($('#' + year).val());
					if (year > 1800) {
						name = 'gregorian';
					} else {
						name = 'ummalqura';
					}

					var month = parseInt($('#' + month).val());
					var day = parseInt($('#' + day).val());
					try {
						var jd = $.calendars.instance(name).newDate(year, month, day).toJD();
						if (jd < 1) {
							alert("يوجد خطأ في تاريخ الميلاد");
						}
					} catch (e) {
						alert(e);
						return;
					}
					showDate('gregorian', jd, melady);
					showDate('ummalqura', jd, hj);
				}

			});

			function ten(dd) {
				var a = $("#" + dd).val();
				if (a.length != 10) {
					$("#" + dd).css("background-color", "#FF6B46");
				} else {
					$("#" + dd).css("background-color", "");
				}
			};

			function fifteen(dd) {
				var a = $("#" + dd).val();
				if (a.length != 15) {
					$("#" + dd).css("background-color", "#FF6B46");
				} else {
					$("#" + dd).css("background-color", "");
				}
			};
		</script>
</body>

</html>
