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

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

$carid = $_REQUEST['id'];
?>
<!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="description" content="تأجير سيارات خصوصي ليموزين دباب ديانا تقسيط سيارات  بيع سيارات ورشة اصلاح متكاملة">
	<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="../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:#797953; padding-top: 130px;">
			<div class="navbar navbar-inverse navbar-fixed-top bg-faded">
			<div class="container-fluid">
				<br />
				<div class="row" style="background-color:transparent;">
					<input style="float:right; margin-right:30px;" type="submit" class="btn btn-danger" id="close2" value=" خروج "/>

					<h3 align='center' style="font-weight:bold; color:#EDDFDF;" id="title">عقد قديم</h3>
						</div>
					<?php
					$sql =$db->prepare("SELECT kind , numbers ,letters, color , model , carid from cars where carid = ? ") ;
					$sql->bindParam(1,$carid);
					$sql->execute();
					if($sql->rowCount()>0){
					while($row = $sql->fetch()){
?>
<div class="row" style="padding:5px; background-color:transparent;">
	<div class="col-xs-1 col-md-1"style="float:right;padding:2px;">
</div>
	<div class="col-xs-10 col-md-10"style="float:right;padding:2px;">
		<center class="control-label" style="font-size:1.3em; padding:0px; margin:0;font-weight:bold; color:#EDDFDF;">
			<?php  echo "سيارة ".$row['kind']." ".$row['letters']." ".$row['numbers']." موديل ". $row['model'] ;			 ?>
		</center>
	</div>
	<div class="col-xs-1 col-md-1"style="float:left;padding:2px;">
	<a href="../a/car_update.php?id=<?php echo $row['carid'] ; ?>" ><button type="button" class="btn btn-success btn-xs ">بيانات السيارة</button></a>
</div >
</div>
<?php		}} ?>
</div>
</div>
</div>
<p><br/></p>
<div class="container-fluid">
	<form id="koki" method="post" class="form-horizontal" >
	<div class="row" style="padding:2px;">
		<div class="col-xs-2 col-md-2"style="float:right;">
			<div class="row" style="padding:2px;">
				<div class="col-xs-10 col-md-10"style="float:right;">
				<input type="text" class="form-control" id="contract_id"  name="contract_id" placeholder="رقم العقد"/>
				<input type="text" id="carid"  name="carid" value="<?php echo $carid ; ?>"/>
				<input type="text" id="cust_id"  name="cust_id"/>
			</div>
		</div>
				<div class="row" style="padding:2px;">
			<div class="col-xs-10 col-md-10"style="float:right;">
				<select  class="form-control" id="branch" name="branch">
			 <!-- <option value= "" >الفرع</option> -->
		 <?php
		 $sql3 =$db->prepare("select branchID , b_name from branches where branchID > 1") ;
		 $sql3->execute();
			 if($sql3->rowCount()>0)
			{
				 while($row = $sql3->fetch()){
							 $id     = $row["branchID"];
							 $label  = $row["b_name"];
		 echo "<option value= $id >$label</option>";
					 }} ?>
</select>
			</div>
		</div>
			<div class="row" style="padding:2px;">
			<div class="col-xs-9 col-md-9"style="float:right;">
				<label for="used_area" class="control-label">منطقة الإستخدام</label>
			</div>
		</div>
		<div class="row" style="padding:2px;">
		<div class="col-xs-12 col-md-12"style="float:right;">
				<input type="text" class="form-control" id="used_area" name="used_area" style="float:right;" value="جدة و مكة"/>
				<div class="text-danger" style="font-size:12px;" id="used_area_msg"></div>
		</div>
	</div>
	<div class="row" style="padding:2px;">
		<div class="col-xs-12 col-md-12"style="float:right;">
			<input type="text" class="form-control" id="rent_days" name="rent_days" style="float:right;" value="اسبوع" placeholder="مدة الإيجار"/>
			<div class="text-danger" style="font-size:12px;" id="rent_days_msg"></div>
		</div>
	</div>
	<div class="row" style="padding:2px;">
		<div class="col-xs-11 col-md-11" style="float:right;">
			<button type="button" class="btn btn-warning btn-block" id="add_cust22" data-toggle="modal" style="float:left;font-weight:bold;" data-backdrop="static" data-keyboard="false" data-target="#customer2">إضافة مستأجر <span style="margin-right:10px;" class="glyphicon glyphicon-user" aria-hidden="true"></button>
	</div>
</div>
			<div class="row" style="padding:2px;">
				<div class="col-xs-11 col-md-11"style="float:right;">
					<button type="button" class="btn btn-primary btn-block" data-toggle="modal" style="float:left;font-weight:bold;" data-backdrop="static" data-keyboard="false" data-target="#sanad_in">سند قبض</button>
				</div>
			</div>
				<div class="row" style="padding:2px;">
					<div class="col-xs-11 col-md-11" style="float:right;">
					<input style="float:right ;font-weight:bold;" type="button" id="contract_update" name="contract_update" class="btn btn-success btn-block" value="حفظ العقد"/>
				</div>
			</div>
	<div class="row" style="padding:2px;">
		<div class="col-xs-11 col-md-11" style="float:right;">
			<a id="print3" href="" target="_blank" ><button type="button" class="btn btn-success btn-block">طباعة العقد <span style="margin-right:20px;" class="glyphicon glyphicon-print" aria-hidden="true"></span></button></a>
	</div>
</div>
			<div class="row" style="padding:2px;">
				<div class="col-xs-11 col-md-11" style="float:right;">
					<input style="float:right ;font-weight:bold;" type="submit" class="btn btn-danger btn-block" id="close" value=" خروج "/>
				</div>
			</div>
		</div>
		<div class="col-xs-10 col-md-10"style="float:right;">
		<div id="koki_msg"></div>

		<input type="text" id="cust_id2"  name="cust_id2"/>
			<div class="row" style="padding:4px;">
					<div class="col-xs-2 col-md-2"style="float:right;">
					</div>
					<div class="col-xs-3 col-md-2"style="float:right;">
						<label for="date_in" class="control-label text-center">الخروج</label>
						</div>
					<div class="col-xs-3 col-md-2"style="float:right;">
						<label  class="control-label text-center">الدخول</label>
					</div>
					<div class="col-xs-1 col-md-1"style="float:right;">
						<label  class="control-label text-center">عدد</label>
					</div>
					<div class="col-xs-1 col-md-1"style="float:right;">
						<label  class="control-label text-center">سعر</label>
					</div>
					<div class="col-xs-3 col-md-2"style="float:right;">
						<label for="days_cost" class="control-label text-center">إجمالي</label>
					</div>
			</div>
			<div class="row" style="padding:2px;">
					<div class="col-xs-3 col-md-2"style="float:right;">
						<label for="date_in" class="control-label"style="float:left;">التاريخ</label>
					</div>
					<div class="col-xs-3 col-md-2"style="float:right;">
						<input type="text" class="form-control" style="float:right;" id="date_out" name="date_out" />
					</div>
					<div class="col-xs-3 col-md-2"style="float:right;">
						<input type="text" style="float:right;" class="form-control"  id="date_in" name="date_in" onchange="money()"/>
					</div>
					<script>
						$(function() {
							var calendar = $.calendars.instance('');
							$('#date_out').calendarsPicker({calendar: calendar});
							$('#date_in').calendarsPicker({calendar: calendar});
							});
					</script>
					<div class="col-xs-1 col-md-1"style="float:right;padding:2px;">
						<input type="number" style="float:right;padding:2px;" class="form-control" id="days_qty" name="days_qty" readonly/>
					</div>
					<div class="col-xs-1 col-md-1"style="float:right;padding:2px;">
						<input type="number" style="float:right; padding:2px;" onchange="money()" class="form-control" id="day_cost"  name="day_cost" value="90"/>
						<div class="text-danger" style="font-size:12px;" id="day_cost_msg"></div>
					</div>
					<div class="col-xs-3 col-md-2"style="float:right;">
						<input type="number" style="float:right;" class="form-control" id="days_cost" name="days_cost" readonly/>
					</div>
					<div class="col-xs-2 col-md-2"style="float:right;">
						<label for="free_kilo" class="control-label"style="float:right;">الكيلو المسموح</label>
					</div>
			</div>
			<div class="row" style="padding:2px;">
					<div class="col-xs-3 col-md-2"style="float:right;">
						<label for="km_in" class="control-label"style="float:left;">الكيلو</label>
					</div>
					<div class="col-xs-3 col-md-2"style="float:right;">
						<input type="number" class="form-control" style="float:right;" id="km_out" name="km_out"/>
						</div>
					<div class="col-xs-3 col-md-2"style="float:right;">
						<input type="number" style="float:right;" onchange="money()" class="form-control" id="km_in" name="km_in"/>
						<div class="text-danger" style="font-size:12px;" id="km_in_msg"></div>
					</div>
					<div class="col-xs-1 col-md-1"style="float:right;padding:1px;">
						<input type="number" style="float:right;padding:1px;" class="form-control" id="kilo_qty" name="kilo_qty" readonly/>
					</div>
					<div class="col-xs-1 col-md-1"style="float:right;padding:2px;">
						<input type="number" style="float:right;padding:2px;" onchange="money()" class="form-control" id="kilo_cost" name="kilo_cost" value="40"/>
						<div class="text-danger" style="font-size:12px;" id="kilo_cost_msg"></div>
					</div>
					<div class="col-xs-3 col-md-2"style="float:right;">
						<input type="number" style="float:right;" class="form-control" id="kilos_cost" name="kilos_cost" readonly />
					</div>
					<div class="col-xs-2 col-md-2"style="float:right;">
						<input type="number" style="float:right;" onchange="money()" class="form-control" id="free_kilo" name="free_kilo" value="200" />
						<div class="text-danger" style="font-size:12px;" id="free_kilo_msg"></div>
					</div>
			</div>
			<div class="row" style="padding:2px;">
					<div class="col-xs-3 col-md-2"style="float:right;">
						<label for="date_in" class="control-label"style="float:left;">الساعة</label>
					</div>
					<div class="col-xs-3 col-md-2"style="float:right;">
						<input type="text" class="form-control" style="float:right;" id="time_out" name="time_out" value="10:30"/>
					</div>
					<div class="col-xs-3 col-md-2"style="float:right;">
						<input type="text" style="float:right;" class="form-control" id="time_in" name="time_in" />
					</div>
					<div class="col-xs-1 col-md-1"style="float:right;padding:1px;">
						<input type="number" style="float:right;padding:2px;" class="form-control" id="hour_qty" name="hour_qty"/>
					</div>
					<div class="col-xs-1 col-md-1"style="float:right;padding:2px;">
						<input type="number" style="float:right;padding:2px;"  class="form-control" id="hour_cost" name="hour_cost"/>
					</div>
					<div class="col-xs-3 col-md-2"style="float:right;">
						<input type="number" style="float:right;" class="form-control" id="hours_cost" name="hours_cost" />
					</div>
					<div class="col-xs-2 col-md-2"style="float:right;">
						<input type="number" style="float:right;" class="form-control" id="used_kilo" name="used_kilo" disabled="disabled" readonly/>
					</div>
			</div>
		<div class="row" style="padding:2px;">
						<div class="col-xs-7 col-md-7"style="float:right;">
								<div class="row" style="padding:4px;">
									<div class="col-xs-3 col-md-3"style="float:right;">
										<label for="addtion_desc" class="control-label"style="float:left;">تعويضات</label>
									</div>
									<div class="col-xs-9 col-md-9"style="float:right;">
										<textarea class="form-control" rows="4" id="addtion_desc" name="addtion_desc"  placeholder="بيان الإضافي و التعويضات و المخالفات"    ></textarea>
										<div class="text-danger" style="font-size:12px;" id="addtion_desc_msg"></div>
										</div>
								</div>
								<div class="row" style="padding:4px;">
									<div class="col-xs-3 col-md-3"style="float:right;">
										<label for="dept_comm" class="control-label"style="float:left;">الإدارة</label>
									</div>
									<div class="col-xs-9 col-md-9"style="float:right;">
										<textarea class="form-control" rows="2" id="dept_comm" name="dept_comm"  placeholder="تعليمات الإدارة"    ></textarea>
										<div class="text-danger" style="font-size:12px;" id="dept_comm_msg"></div>
										</div>
								</div>
								<div class="row" style="padding:4px;">
									<div class="col-xs-3 col-md-3"style="float:right;">
										<label for="operating_comm" class="control-label"style="float:left;">التشغيل</label>
									</div>
									<div class="col-xs-9 col-md-9"style="float:right;">
										<textarea class="form-control" rows="3" id="operating_comm" name="operating_comm" disabled="disabled" readonly placeholder="تعليمات التشغيل"></textarea>
										<div class="text-danger" style="font-size:12px;" id="operating_comm_msg"></div>
										</div>
								</div>
								<div class="row" style="padding:4px;">
									<div class="col-xs-3 col-md-3"style="float:right;">
										<label for="open_comm" class="control-label"style="float:left;">ملاحظات</label>
									</div>
									<div class="col-xs-9 col-md-9"style="float:right;">
										<textarea class="form-control" rows="3" id="open_comm" name="open_comm" placeholder="عند فتح العقد"></textarea>
										<div class="text-danger" style="font-size:12px;" id="open_comm_msg"></div>
										</div>
								</div>
						</div>
						<div class="col-xs-5 col-md-5"style="float:right;">
								<div class="row" style="padding:2px;">
											<div class="col-xs-2 col-md-2"style="float:right;margin-right:20px;">
												<label for="addtion_cost" class="control-label"style="float:left;">تعويضات</label>
											</div>
											<div class="col-xs-4 col-md-4"style="float:right;">
												<input type="number" class="form-control" onchange="money()" style="float:right;" id="addtion_cost" name="addtion_cost" />
												<div class="text-danger" style="font-size:12px;" id="addtion_cost_msg"></div>
											</div>
									</div>
									<div class="row" style="padding:2px;">
												<div class="col-xs-2 col-md-2"style="float:right;margin-right:20px;">
													<label for="violations" class="control-label"style="float:left;">مخالفات</label>
												</div>
												<div class="col-xs-4 col-md-4"style="float:right;">
														<input type="number" class="form-control" onchange="money()" style="float:right;" id="violations" name="violations" />
														<div class="text-danger" style="font-size:12px;" id="violations_msg"></div>
												</div>
									</div>
									<div class="row" style="padding:2px;">
												<div class="col-xs-2 col-md-2"style="float:right;margin-right:20px;">
															<label for="ins_claim" class="control-label" style="float:left;">تأمينات</label>
												</div>
												<div class="col-xs-4 col-md-4"style="float:right;">
													<input type="number" class="form-control" onchange="money()" style="float:right;" id="ins_claim" name="ins_claim" />
													<div class="text-danger" style="font-size:12px;" id="ins_claim_msg"></div>
												</div>
									</div>
									<div class="row" style="padding:2px;">
												<div class="col-xs-2 col-md-2"style="float:right;margin-right:20px;">
													<label for="net_cost" class="control-label"style="float:left;color:blue;">إجمالي</label>
												</div>
												<div class="col-xs-5 col-md-4"style="float:right;">
														<input type="number" class="form-control" style="float:right;" id="net_cost" name="net_cost" disabled="disabled" readonly/>
												</div>
									</div>
									<div class="row" style="padding:2px;">
											<div class="col-xs-2 col-md-2"style="float:right;margin-right:20px;">
													<label for="payed" class="control-label"style="float:left;">المدفوع</label>
											</div>
											<div class="col-xs-4 col-md-4"style="float:right;">
														<input type="number" class="form-control" style="float:right;" id="payed" name="payed" disabled="disabled" readonly/>
											</div>
											<div class="col-xs-2 col-md-2"style="float:right;">
												<label for="total_in" class="control-label"style="float:right;">قبض</label>
											</div>
											<div class="col-xs-3 col-md-3"style="float:right;padding:0px;">
														<input type="number" class="form-control" style="float:right;" id="total_in" name="total_in" disabled="disabled" readonly/>
											</div>
									</div>
									<div class="row" style="padding:2px;">
												<div class="col-xs-2 col-md-2"style="float:right;margin-right:20px;">
														<label for="deduction" class="control-label"style="float:left;">الخصم</label>
												</div>
												<div class="col-xs-4 col-md-4"style="float:right;">
														<input type="number" class="form-control" style="float:right;" onchange="money()" id="deduction" name="deduction"/>
														<div class="text-danger" style="font-size:12px;" id="deduction_msg"></div>
												</div>
											<div class="col-xs-2 col-md-2"style="float:right;">
													<label for="total_out" class="control-label"style="float:right;">صرف</label>
										</div>
										<div class="col-xs-3 col-md-3"style="float:right;padding:0px;">
													<input type="number" class="form-control" style="float:right;" id="total_out" name="total_out" disabled="disabled" readonly/>
										</div>
								</div>
								<div class="row" style="padding:2px;">
											<div class="col-xs-2 col-md-2"style="float:right;margin-right:20px;">
													<label for="wanted" class="control-label"style="float:left;">المطلوب </label>
											</div>
											<div class="col-xs-4 col-md-4"style="float:right;">
													<input type="number" class="form-control wanted" style="float:right;" id="wanted" name="wanted" readonly/>
											</div>

							</div>
						</div>
			</div>
	<div class="row" style="padding:2px;">
					<div class="col-xs-2 col-md-1"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;">
					<input type="text" class="form-control" style="float:right;" id="comm" name="comm"/>
					<div class="text-danger" style="font-size:12px;" id="comm_msg"></div>
					</div>
		</div>
		<p><br/></p>
		<script>
		function money(){
			// alert(1323);
			var str2 = $("#date_in").val(); var str1 = $("#date_out").val();
			var b =  Math.floor(( Date.parse(str2) - Date.parse(str1) ) / 86400000);
			$("#days_qty").val(b) ;
			var a = parseInt($("#day_cost").val())|| 0;
			// var b = parseInt($("#days_qty").val())|| 0;
			$("#days_cost").val( a * b);
			var hq = parseInt($("#hour_qty").val())|| 0;
			var hcost = parseInt($("#hour_cost").val())|| 0;
			$("#hours_cost").val(hq * hcost);
			var h = parseInt($("#hours_cost").val())|| 0;
			var d = parseInt($("#addtion_cost").val())|| 0;
			var v = parseInt($("#violations").val())|| 0;
			var i = parseInt($("#ins_claim").val())|| 0;
			mykilo(h,a);
			var k = parseInt($("#kilos_cost").val())|| 0;
			$("#net_cost").val((a * b)+ h + d + v + i + k);
			var dd =  parseInt($("#deduction").val())|| 50 ;
			var nn = parseInt($("#net_cost").val())|| 0;
			var mm = parseInt($("#payed").val())|| 0;
			$(".wanted").val(nn-(dd + mm));
			var ww = parseInt($("#wanted").val())|| 0;
			if(ww > 200){ $(".wanted").css( "background-color", "#ffcccc");}
			else 	if(ww < 0){ $(".wanted").css( "background-color", "#ccffcc");}
			else { $(".wanted").css( "background-color", "");}

		 };
		function mykilo(hh,aa){
			var free = 0;
		 var a	= parseInt($("#km_out").val())|| 0; 			var b		= parseInt($("#km_in").val())|| 0;
		 if((b - a)> 0){$("#used_kilo").val(b - a);}else{$("#used_kilo").val(0);}
		 var s 	= parseInt($("#kilo_cost").val())|| 0;
		 var d 	= parseInt($("#days_qty").val())|| 0;
		 var f 	= myfree();
		 if(hh == aa){free = (1 + d )* f ; } else{ free = f * d ;}
		 if(free >( b - a )){$("#kilos_cost").val(0);
		 $("#kilo_qty").val(0);
	 }else {
		 var koky = ((b - ( a + free)) * s) / 100;
		 koky =  Math.trunc(koky);
		 $("#kilos_cost").val(koky);
		 $("#kilo_qty").val(b - ( a + free) );
	 }
	 } ;
	 function myfree(){
		 var a 	= parseInt($("#free_kilo").val())||200;
		 var b 	= 250;
		 if(a > b){
			 $("#free_kilo").val(b).css( "background-color", "#ffcccc");
			 return b;
		 }else if(a == b){
			 $("#free_kilo").css( "background-color", "#ffcccc");
			  return a ;
		}
		 else {
			 $("#free_kilo").css( "background-color", "");
			 return a ; }
	 }
		</script>

<div id="msg"></div>
	</div>
</div><!-- end of main row 2 and 10  -->
	</form>

	<!-- invoice modal -->
	<div class="modal fade" id="sanad_in" tabindex="-1" role="dialog" aria-labelledby="exLabel">
		<div class="modal-dialog modal-lg" role="document">
			<div class="modal-content">
				<div class="modal-header"style="background-color:teal ;">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" style="font-weight:bold;color:#FFFAF0; " id="exLabel">سند قبض</h4>
				</div>
				<div class="modal-body">
					<!-- start of sanad_in form -->
					<form method="post" class="form-horizontal" id="modal_sanad_in" style="float:center;">
						<div id="sanad_in_msg"></div>
							<div class="row" style="padding:4px;">
								<input type="hidden"  class="form-control" id="id2" name="id2" />
								<input type="hidden" id="in_id" name="in_id"/>
									<div class="col-xs-2 col-md-2"style="float:right;">
										<label for="money_in" class="control-label"style="float:left;">المبلغ <span class="text-danger">*</span></label>
									</div>
									<div class="col-xs-3 col-md-2"style="float:right;">
										<input type="number" class="form-control" style="float:right;" id="money_in" name="money_in" placeholder="بالريال"/>
										<div id="money_in_msg" class="text-danger" style="font-size:12px;"></div>
									</div>
										<div class="col-xs-2 col-md-2"style="float:right;">
											<label for="printed_no" class="control-label"style="float:left;">رقم السند</label>
										</div>
									<div class="col-xs-3 col-md-2"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-xs-2 col-md-2"style="float:right;">
											<label for="payMethod" class="control-label "style="float:left;">طريقة الدفع</label>
									</div>
									<div class="col-xs-2 col-md-2"style="float:right;">
											<select class="form-control" id="payMethod" name="payMethod"  >
													<option selected value="1">كاش</option>
													<option value="2" >تحويل بنكي</option>
													<option value="3" >نقاط بيع</option>
												</select>
									</div>
							</div>
							<div class="row" style="padding:4px;">
											<div class="col-xs-1 col-md-1"style="float:right;">
											<label for="comm2" class="control-label"style="float:right;">ملاحظات</label>
											</div>
											<div class="col-xs-7 col-md-7"style="float:right;">
											<input type="text" class="form-control" style="float:right;" id="comm2" name="comm2"/>
											<div id="comm2_msg" class="text-danger" style="font-size:12px;"></div>
											</div>
											<div class="col-xs-2 col-md-2"style="float:right;">
												<label for="current_km" class="control-label"style="float:left;">الكيلومتر</label>
											</div>
											<div class="col-xs-2 col-md-2"style="float:right;">
												<input type="number" style="float:right;" class="form-control" id="current_km" name="current_km" placeholder=" الحالي" />
												<div id="current_km_msg" class="text-danger" style="font-size:12px;"></div>
											</div>
								</div>
						</form><!-- end of sanad_in form -->
			</div>
				<div class="modal-footer form-group">
					<button type="button" class="btn btn-default" data-dismiss="modal">خروج</button>
					<input type="button" id="sanad_in_add" name="sanad_in_add" class="btn btn-primary" value="حفظ "/>
					<a id="sanad_in_print" href="" target="_blank" style="display: none;"><button type="button" class="btn btn-success">طباعة السند <span class="glyphicon glyphicon-print" aria-hidden="true"></span></button></a>
					</div>
			</div>
			</div><!-- end of sanad_in modal -->
	</div> <!-- modal invoice end -->

		<!-- start add customer2 -->
			<div class="modal fade" id="customer2" tabindex="-1" role="dialog" aria-labelledby="exLabel">
				<div class="modal-dialog modal-lg" role="document">
					<div class="modal-content">
						<div class="modal-header"style="background-color:blue ;">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
								<h4 class="modal-title" style="font-weight:bold;color:#F0FFFF; "id="exLabel">إضافة مستاجر</h4>
						</div>
						<div class="modal-body">
							<!-- start of add customer2 form -->
								<div class="row" style="padding-bottom:20px;">
									<input type="hidden"  class="form-control" id="cust_id3" name="cust_id3" />
									<div class="col-xs-4 col-md-4"style="float:right;">
											<label for="customer_sr" class="control-label"style="float:left;">رقم هوية المستاجر<span class="text-danger">*</span></label>
										</div>
										<div class="col-xs-5 col-md-5"style="float:right;">
											<input type="number" class="form-control" style="float:right;" id="customer_sr" name="customer_sr" placeholder=" رقم الهوية "/>
											<div class="text-danger" style="font-size:12px;" id="customer_sr_msg"></div>
										</div>
											<div class="col-xs-3 col-md-3"style="float:right;">
												<button type="button" id="cust_sr" class="btn btn-primary">بحث <span class="glyphicon glyphicon-search"></button>
											</div>
								</div>
									<div id="customer2_msg"></div>
				<form method="post" class="form-horizontal" id="modal_customer2" style="float:center;display:none;">
								<div class="row" style="padding:4px;">
									<div class="col-xs-8 col-md-8"style="float:right;">
										<div class="row" style="padding:2px;">
											<div class="col-xs-3" style="float:right ;">
												<label for="cust_name" class="control-label"style="float:left;">الاسم</label>
											</div>
											<div class="col-xs-6" style="float:right ;">
												<input type="text" class="form-control" style="float:right;" id="cust_name" name="cust_name" placeholder="بدون اسم"/>
											</div>
											<div class="col-xs-3" style="float:right ;">
												<input type="text" class="form-control" style="float:right;" id="nation" name="nation" placeholder="مجهول"/>
											</div>
										</div>
										<div class="row" style="padding:2px;">
											<div class="col-xs-3" style="float:right ;">
												<label for="idSA" class="control-label"style="float:left;">رقم الهوية</label>
											</div>
											<div class="col-xs-5" style="float:right ;">
												<input type="text" class="form-control" style="float:right;" id="idSA" name="idSA"/>
											</div>
											<div class="col-xs-4" style="float:right ;">
												<input type="text" class="form-control" style="float:right;" id="id_Expire" name="id_Expire" placeholder="بدون"/>
											</div>
										</div>
										<div class="row" style="padding:2px;">
											<div class="col-xs-3" style="float:right ;">
												<label for="license" class="control-label"style="float:left;">الرخصة</label>
											</div>
											<div class="col-xs-5" style="float:right ;">
												<input type="text" class="form-control" style="float:right;" id="license" name="license" placeholder="مجهول"/>
											</div>
											<div class="col-xs-4" style="float:right ;">
												<input type="text" class="form-control" style="float:right;" id="lic_expire" name="lic_expire" placeholder="مجهول"/>
											</div>
										</div>
										<div class="row" style="padding:2px;">
											<div class="col-xs-3" style="float:right ;">
												<label for="phone" class="control-label"style="float:left;">جوال</label>
											</div>
											<div class="col-xs-5" style="float:right ;">
												<input type="text" class="form-control" style="float:right;" id="phone" name="phone" placeholder="مجهول"/>
											</div>
											<div class="col-xs-4" style="float:right ;">
												<input type="text" class="form-control" style="float:right;" id="phone2" name="phone2" placeholder="مجهول"/>
											</div>
										</div>
										<div class="row" style="padding:2px;">
											<div class="col-xs-3" style="float:right ;">
												<label for="comm4" class="control-label"style="float:left;">ملاحظات</label>
											</div>
											<div class="col-xs-9" style="float:right ;">
												<input type="text" class="form-control" style="float:right;" id="comm4" name="comm4" placeholder="بدون"/>
											</div>
										</div>
									</div>
										<div class="col-xs-4 col-md-4"style="float:right;">
											<div class="row" style="padding:2px;">
												<div class="col-xs-8" style="float:right ;">
													<input type="text" class="form-control" style="float:right;" id="md" name="md" placeholder="بدون"/>
												</div>
												<div class="col-xs-4" style="float:right ;">
													<input type="text" class="form-control" style="float:right;" id="dgree" name="dgree" placeholder="بدون"/>
												</div>
											</div>
												<div class="row" style="padding:4px;">
												  <img id="cust_photo" src="" class="img-responsive img-rounded" width="90%" height="auto" style="float:left;" alt="صورة الرخصة غير متاحة" />
												</div>
										</div>
									</div>
								</form><!-- end of add customer2 form -->
								</div>
						<div class="modal-footer">
							<div class="row" style="padding:2px;">
								<div class="col-xs-2" style="float:right ;">
									<button type="button" class="btn btn-danger btn-block" data-dismiss="modal">خروج</button>
								</div>
								<div class="col-xs-2" style="float:right ;">
									<button id="cust_prim"  name="cust_prim" class="btn btn-success btn-block">مستأجر أساسي<span class="glyphicon glyphicon-user" aria-hidden="true"></butoon>
								</div>
								<div class="col-xs-2" style="float:right ;">
									<button id="cust_add" style="display: none;" name="cust_add" class="btn btn-primary btn-block">مستأجر إضافي<span class="glyphicon glyphicon-user" aria-hidden="true"></butoon>
								</div>
								<div class="col-xs-2" style="float:right ;">
										<a id="contt_open_print" href="" target="_blank" style="display: none;"><button type="button" class="btn btn-success"> طباعة فتح العقد <span class="glyphicon glyphicon-print" aria-hidden="true"></span></button></a>
								</div>
							</div>
							</div>
						</div>
					</div>
				</div><!-- end of add customer2 modal -->
</div><!-- end of fluid2  -->
	<script>
	$(document).ready(function(){
		  $('#close').click(function(){close();});
			 $('#close2').click(function(){close();});

		$("#sanad_in_add").click(function(event){
						event.preventDefault();
						$("#money_in_msg").html("");
						$("#printed_no_msg").html("");
						$("#comm2_msg").html("");
						$("#current_km_msg").html("");
				$.ajax({
				url     	: "sanad_in_action.php",
				method  	: "POST",
				data    	:	$("#modal_sanad_in").serialize(),
				dataType	:	"json",
				success 	: function(data){
					if(data.error){
				$("#money_in_msg").html(data.error.money_in);
				$("#printed_no_msg").html(data.error.printed_no);
				$("#comm2_msg").html(data.error.comm);
				$("#current_km_msg").html(data.error.current_km);
				}else{
			$('#sanad_in_add').attr("type","hidden");
			$('#sanad_in_print').css("display","block");
			$("#sanad_in_msg").html(data.msg);
			$("#in_id").val(data.in_id);
			$("#sanad_in_print").attr("href","../rent/sanad_in1.php?sanad="+ data.in_id);
			$("#total_in").val(data.total_in);
			$("#total_out").val(data.total_out);
			$("#payed").val(data.payed);
			money();
			$("#sanad_in_msg").delay(3000).slideUp(function(){  $("#sanad_in_msg").html(''); });
		}}
			});
		});

	$('#sanad_in').on('show.bs.modal', function (event) {
		 var recipient = $("#contract_id").val();
		 var modal = $(this);
		 modal.find('#id2').val(recipient);
	 });
	 	 $("#contract_update").click(function(event){
 					event.preventDefault();
	$.ajax({
 					url     	: "contract_update.php",
 					method  	: "POST",
 					data    	:	$("#koki").serialize(),
 					success 	: function(data){
 						$("#koki_msg").html(data);
 						$("#koki_msg").delay(3000).slideUp(function(){  $("#koki_msg").html(''); });
 	}
 		});
 	});


	$("#cust_sr").click(function(event){
					event.preventDefault();
	 var idSA  = $("#customer_sr").val();
					$("#customer_sr_msg").html("");
	$.ajax({
			url     	: "../actions/cust_single.php",
			method  	: "POST",
			data    	:	{idSA:idSA},
			dataType	:	"json",
			success 	: function(data){
				if(data.error){
			$("#customer_sr_msg").html(data.error.msg);
			}
else{
	$('#modal_customer2').css('display','block');
	$('#cust_add').css('display','block');
	$("#cust_id3").val(data.cust_id);
	$("#dgree").val(data.dgree);
	$("#cust_name").val(data.cust_name);
	$("#nation").val(data.nation);
	$("#idSA").val(data.idSA);
	$("#id_Expire").val(data.id_Expire);
	$("#license").val(data.license);
	$("#lic_expire").val(data.lic_expire);
	$("#phone").val(data.phone);
	$("#phone2").val(data.phone2);
	$("#comm4").val(data.comm);
	$('#cust_photo').attr("src","../photo/customers/"+(data.cust_photo));
	$("#customer2_msg").html(data.notfound);
		$("#customer2_msg").delay(4000).slideUp(function(){  $("#customer2_msg").html(''); });
	}}
		});
	});//end of customer2 search

$("#cust_prim").click(function(event){
				event.preventDefault();
 var cust_id  = $("#cust_id3").val();
 $("#cust_id").val(cust_id);
});//end of add customer1

	$("#cust_add").click(function(event){
					event.preventDefault();
	 var cust_id2  = $("#cust_id3").val();
	 $("#cust_id2").val(cust_id2);
	});//end of add customer2

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

	 });// end of script
	</script>

  </body>
</html>
