<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
	<title>Plot Booking | Admin Panel</title>

	<!-- Favicons -->
<link rel="shortcut icon" type="image/x-icon" href="../UserProfile/images/logo/logo.png">

	<!-- Bootstrap CSS -->
	<link rel="stylesheet" href="assets/plugins/bootstrap/css/bootstrap.min.css">

	<!-- Fontawesome CSS -->
	<link rel="stylesheet" href="assets/plugins/fontawesome/css/fontawesome.min.css">
	<link rel="stylesheet" href="assets/plugins/fontawesome/css/all.min.css">
	 
	<!-- Animate CSS -->
	<link rel="stylesheet" href="assets/css/animate.min.css">

	<!-- Main CSS -->
	<link rel="stylesheet" href="assets/css/admin.css">
		<!-- Datatables CSS -->
	<link rel="stylesheet" href="assets/plugins/datatables/datatables.min.css">

</head>

<body>
	<div class="main-wrapper">
	
		<!-- Header -->
	<?php include 'include/header.php'; ?>
		<!-- /Header -->
		
		<!-- Sidebar -->
		<?php include 'include/leftmenu.php'; ?>
		<!-- /Sidebar -->
		
		<div class="page-wrapper">
			<div class="content container-fluid">
			
				<!-- Page Header -->
				<div class="page-header">
					<div class="row">
						<div class="col">
							<h5 class="page-title text-white">Plot Booking</h5>
    					
						</div>
					
					</div>
				</div>
				
					<form action="Apk/PlotBooking" method="post" id="frmreg">
                	<div class="row">
						<div class="col-sm-12">
							<div class="card">
								<div class="card-header">
									<h6 class="card-title">Plot Booking Details </h6>
								<span style="color:red">	<?php echo $_REQUEST['msg']; ?></span>
								</div>
								<div class="card-body">

									<div class="table-responsive">
										<div class="card filter-card">
						<div class="card-body pb-0">
							<div class="row filter-row">
							    <div class="col-sm-6 col-md-4">
									<div class="form-group">
										<label>Booking Date</label>
										<input type="date" name="bookingDate" id="bookingDate" value="<?php echo date("Y-m-d"); ?>" class="form-control">
										</div>
								</div>
							   
								
								<div class="col-sm-6 col-md-3">
									<div class="form-group">
										<label>Customer Id</label>
								 <input type="text" class="form-control" id="member_user_id"  maxlength="10" minlength="10" style="text-transform:uppercase;background-color:#FFFFFF" placeholder="" name="member_user_id"  required onBlur="get_customer();" onkeyup="get_customer();">
									</div>
								</div>
									<div class="col-sm-6 col-md-5">
									<div class="form-group">
										<label>Customer Name</label>
									 <input type="text" class="form-control" id="member_name" placeholder="Customer Name" name="member_name" style="background-color:#FFFFFF"   readonly="true" required>
									</div>
								</div>
									<div class="col-sm-6 col-md-6">
									<div class="form-group">
										<label>Sponsor Id</label>
									  <input type="text" class="form-control" id="sponcer_id" placeholder="Sponcer Id" name="sponcer_id" readonly="true" style="background-color:#FFFFFF"  required>
									</div>
								</div>
							
									<div class="col-sm-6 col-md-6">
									<div class="form-group">
										<label>Sponsor Name</label>
										<input type="text" class="form-control" required="" readonly="" name="sponsor_name" id="sponsor_name"   placeholder=""  style="text-transform:uppercase;background-color:#fff" value="" >
									</div>
								</div>
							
							
								<div class="col-sm-6 col-md-6">
									<div class="form-group">
										<label>Promoter Id</label>
									<input type="text" class="form-control" readonly=""   placeholder="" name="promoter_id" id="promoter_id"  maxLength="10" style="text-transform:uppercase;background-color:#fff"  />
									</div>
								</div>
									<div class="col-sm-6 col-md-6">
									<div class="form-group">
										<label>Promoter Name</label>
										<input type="text" class="form-control" required="" readonly="" name="promoter_name" id="promoter_name"   placeholder=""   value="" style="text-transform:uppercase;background-color:#fff">
									</div>
								</div>
								 <div class="col-sm-6 col-md-4">
									<div class="form-group">
										<label>Select Project</label>
									<select id="project" name="project" class="form-control" required onChange="get_plot();" onClick="get_plot();">
									    <option value="" selected disabled value>Select Project</option>
									    <?php
									    $strP="Select * from tbl_prject_master order by project_name";
									    $resP=mysqli_query($connection,$strP);
									    while($row=mysqli_fetch_array($resP))
									    {
									        ?>
									        <option value="<?php echo $row['project_id']; ?>"><?php echo $row['project_name']; ?></option>
									        <?php
									    }
									    ?>
									</select>
									</div>
								</div>
								<div class="col-sm-6 col-md-2">
									<div class="form-group">
										<label>Business($)</label>
								    <input type="text" class="form-control" id="businessPer" name="businessPer">
									</div>
								</div>
								<div class="col-sm-6 col-md-3">
									<div class="form-group">
										<label>Plot Code</label>
								    <input type="text" class="form-control" id="plotCode" name="plotCode" onblur="checkPlotStatus()">
									</div>
								</div>
									<div class="col-sm-6 col-md-3">
									<div class="form-group">
								    <span id="plotMsg" style="color:red"></span>
									</div>
								</div>
								<div class="col-sm-6 col-md-4">
									<div class="form-group">
										<label>Plot Type</label>
								    <select name="cornorType" id="cornorType" class="form-control" required>
								        <option value="NC">NC</option>
								         <option value="C">C</option>
								    </select>
									</div>
								</div>
									<div class="col-sm-6 col-md-4">
									<div class="form-group">
										<label>Plot size</label>
										 <input type="text" class="form-control" id="plot_size" value="" name="plot_size" style="background-color:#FFFFFF; text-align:right;" required onkeydown="return ( event.ctrlKey || event.altKey || (47<event.keyCode &amp;&amp; event.keyCode<58 &amp;&amp; event.shiftKey==false) || (95<event.keyCode &amp;&amp; event.keyCode<106) || (event.keyCode==8) || (event.keyCode==9) || (event.keyCode>34 &amp;&amp; event.keyCode<40) || (event.keyCode==46) )">
									</div>
								</div>
								
								<div class="col-sm-6 col-md-3">
									<div class="form-group">
										<label>Plot Rate</label>
										 <input type="text" class="form-control" id="plot_rate"  name="plot_rate" required  style="background-color:#FFFFFF; text-align:right;" onkeydown="return ( event.ctrlKey || event.altKey || (47<event.keyCode &amp;&amp; event.keyCode<58 &amp;&amp; event.shiftKey==false) || (95<event.keyCode &amp;&amp; event.keyCode<106) || (event.keyCode==8) || (event.keyCode==9) || (event.keyCode>34 &amp;&amp; event.keyCode<40) || (event.keyCode==46) || (event.keyCode==190) )">
									</div>
								</div>
								
									<div class="col-sm-6 col-md-3">
									<div class="form-group">
										<label>Total Amount</label>
										 <input type="text" class="form-control" id="total_amount" value="" name="total_amount"  style="background-color:#FFFFFF; text-align:right;" required onkeydown="return ( event.ctrlKey || event.altKey || (47<event.keyCode &amp;&amp; event.keyCode<58 &amp;&amp; event.shiftKey==false) || (95<event.keyCode &amp;&amp; event.keyCode<106) || (event.keyCode==8) || (event.keyCode==9) || (event.keyCode>34 &amp;&amp; event.keyCode<40) || (event.keyCode==46) )">
									</div>
								</div>
								<div class="col-sm-6 col-md-3">
									<div class="form-group">
										<label>Corner Charge</label>
										 <input type="text" class="form-control" id="corner_charge" value="0" name="corner_charge"  style="background-color:#FFFFFF; text-align:right;" required onkeydown="return ( event.ctrlKey || event.altKey || (47<event.keyCode &amp;&amp; event.keyCode<58 &amp;&amp; event.shiftKey==false) || (95<event.keyCode &amp;&amp; event.keyCode<106) || (event.keyCode==8) || (event.keyCode==9) || (event.keyCode>34 &amp;&amp; event.keyCode<40) || (event.keyCode==46) )">
									</div>
								</div>
								
									<div class="col-sm-6 col-md-3">
									<div class="form-group">
										<label>Discount Amount</label>
										<input type="text" class="form-control" value="0" id="discount_amount" value="0" name="discount_amount"  style="background-color:#FFFFFF; text-align:right;" required onkeydown="return ( event.ctrlKey || event.altKey || (47<event.keyCode &amp;&amp; event.keyCode<58 &amp;&amp; event.shiftKey==false) || (95<event.keyCode &amp;&amp; event.keyCode<106) || (event.keyCode==8) || (event.keyCode==9) || (event.keyCode>34 &amp;&amp; event.keyCode<40) || (event.keyCode==46) )">
									</div>
								</div>
									<div class="col-sm-6 col-md-3">
									<div class="form-group">
										<label>Net Amount</label>
										<input type="text" class="form-control" id="net_amount" value="" name="net_amount"  style="background-color:#FFFFFF; text-align:right;" required>
									</div>
								</div>
							</div>	
							<div class="row filter-row">
								<div class="col-sm-4 col-md-3">
									<div class="form-group">
							      
										<button class="btn btn-primary btn-rounded" id="btnsubmit" type="button" onClick="SubmitForm()" style="width:150px;padding-top:10px">Submit</button>
									
									</div>
								
								</div>
							    	<div class="col-sm-6 col-md-6">
									<div class="form-group">
							      <span id="lblmsg" style="color:red; margin-left:10px"></span>
									</div>
									
								</div>

							</div>
						</div>
					</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				    </form>
	<!-- jQuery -->
	<script src="assets/js/jquery-3.5.0.min.js"></script>

	<!-- Bootstrap Core JS -->
	<script src="assets/js/popper.min.js"></script>
	<script src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>

	<!-- Slimscroll JS -->
	<script src="assets/plugins/slimscroll/jquery.slimscroll.min.js"></script>
		<script src="assets/plugins/datatables/jquery.dataTables.min.js"></script>
	<script src="assets/plugins/datatables/datatables.min.js"></script> 

	<!-- Custom JS -->
	<script src="assets/js/admin.js"></script>
	<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script>
function get_plot()
{
	var project_id=$("#project").val();
    var dataString = 'project_id='+ project_id;
	//alert(dataString);
		$.ajax
		({
			type: "POST",
			url: "getPlot.php",
			data: dataString,
			cache: false,
			success: function(data)
			{
			    
				$("#businessPer").val(data);
			} 
		});
}

function checkPlotStatus()
{
	var project_id=$("#project").val();
	var plotCode=$.trim($("#plotCode").val());
    var dataString = 'project_id='+ project_id+'&plotCode='+plotCode;
	//alert(dataString);
		$.ajax
		({
			type: "POST",
			url: "getPlotStatus.php",
			data: dataString,
			cache: false,
			success: function(data)
			{
				$("#plotMsg").html(data);
			} 
		});
}
function get_customer()
{
	var member_id=$("#member_user_id").val();
	var dataString = 'member_id='+ member_id;
	//alert(dataString);
		$.ajax
		({
			type: "POST",
			url: "getCustomerDetails.php",
			data: dataString,
			cache: false,
			success: function(data)
			{
				//alert(data);
				var ArrayName=data.split("%");
				$("#member_name").val(ArrayName[0]);
				$("#sponcer_id").val(ArrayName[1]);
				$("#sponsor_name").val(ArrayName[2]);
				$("#promoter_id").val(ArrayName[3]);
				$("#promoter_name").val(ArrayName[4]);
				
			} 
		});
}




$(document).ready(function(){

	$("#plot_size").keyup(function()
	{ // Keyup function for check the user action in input
		 var plot_size=$.trim($("#plot_size").val());
		 if(plot_size.length==0)
		 {
			$("#plot_size").val(0);
			$("#plot_size").select();
		 }
		 cal_net_amt();
	});
	$("#plot_rate").keyup(function()
	{ // Keyup function for check the user action in input
		 var plot_rate=$.trim($("#plot_rate").val());
		 if(plot_rate.length==0)
		 {
		 $("#plot_rate").val(0);
		 $("#plot_rate").select();
		 }
		 cal_net_amt();
	});
	$("#corner_charge").keyup(function()
	{ // Keyup function for check the user action in input
		 var corner_charge=$.trim($("#corner_charge").val());
		 if(corner_charge.length==0)
		 {
		 $("#corner_charge").val(0);
		 $("#corner_charge").select();
		 }
	    cal_net_amt();
	});


	$("#discount_amount").keyup(function()
	{ // Keyup function for check the user action in input
		 var discount_amount=$.trim($("#discount_amount").val());
		 if(discount_amount.length==0)
		 {
		 $("#total_amount").val(0);
		 $("#total_amount").select();
		 }
 		cal_net_amt();
		
	});


function cal_net_amt()
{
    var corner_charge=$.trim($("#corner_charge").val());
	var discount_amount=$.trim($("#discount_amount").val());
	var plot_size=$.trim($("#plot_size").val());
	var plot_rate=$.trim($("#plot_rate").val());
	var total_amt=0;var netAmt=0;
	var Balacne=0;
	if(parseInt(plot_size)>0)
 	{
    	plot_size=parseInt(plot_size);
 	}
	if(parseFloat(plot_rate)>0)
 	{
    	plot_rate=parseFloat(plot_rate);
 	}
    
 	if(parseInt(corner_charge)>0)
 	{
 	corner_charge=parseInt(corner_charge);
 	}
	if(parseInt(discount_amount)>0)
 	{
 	discount_amount=parseInt(discount_amount);
 	}
 	
	total_amt=plot_size*plot_rate;
	netAmt=parseFloat(total_amt)+parseFloat(corner_charge)-parseFloat(discount_amount);
	console.log("netAmt",netAmt);
	$("#total_amount").val(total_amt.toFixed(0));
	$("#net_amount").val(netAmt);
    
}


		
});


function SubmitForm()
{
   
	var booking_date=$.trim($("#bookingDate").val());
    var project_id=$.trim($("#project").val());
	var plotCode=$.trim($("#plotCode").val());
	var plot_size=$.trim($("#plot_size").val());
	var plot_rate=$.trim($("#plot_rate").val());
	var member_user_id=$.trim($("#member_user_id").val());
	var member_name=$.trim($("#member_name").val());
	var sponcer_id=$.trim($("#sponcer_id").val());
	var sponcer_name=$.trim($("#sponsor_name").val());
	var pramoter_id=$.trim($("#promoter_id").val());
	var pramoter_name=$.trim($("#promoter_name").val());
	var total_amount=$.trim($("#total_amount").val());
// 	var corner_charge=$.trim($("#corner_charge").val());
	// alert("aa");
    if(booking_date.length==0)
	{
		//alert("fsadfs");
    	swal("Fill Booking Date...");
    	return ;
	}

	else if(project_id.length==0)
	{
		swal("Please Select Project...");
    	return ;
	}

	else if(plotCode.length==0)
	{
		swal("Please Fill Plot No...");
    	return ;
	}
	else if(plot_size.length==0)
	{
		$("#lblmsg").html("Please Fill Plot Area....");
		$("#plot_Length").focus();$("#plot_size").select();return;
	}
	else if(parseInt(plot_size)==0)
	{
		swal("Fill Plot Size...");
    	return ;
	}
	else if(plot_rate.length==0)
	{
		swal("Fill Plot Rate...");
    	return ;
	}
	else if(parseInt(plot_rate)==0)
	{
		swal("Fill Plot Rate...");
    	return ;
	}
	else if(member_user_id.length!=10)
	{
		swal("Fill Valid Customer Id...");
    	return ;
	}
	else if(member_name.length==0)
	{
		swal("Fill Valid Customer Id...");
    	return ;
	}
	else if(sponcer_id.length==0)
	{
		swal("Fill Valid Customer Id...");
    	return ;
	}
	else if(pramoter_id.length==0)
	{
		swal("Fill Valid Customer Id...");
    	return ;
	}
	else
	{
		$("#btnsubmit").attr("disabled", true);
		$("#frmreg").submit();
	}
}

</script>
</body>

</html>
