<script src="assets/js/king-table.js"></script>
			<!-- main -->
			<div class="content">            
				<div class="main-content">
					<!-- DATA EXPORT -->
					<div class="widget widget-table">
						<div class="widget-header">
							<h3><i class="fa fa-user"></i> Customer</h3> <em> - Add Customer records</em>
									<div class="btn-group widget-header-toolbar">
										<a class="btn-borderless btn-focus clickme" href="WBcustomerView" title="Focus" ><i class="fa fa-eye"></i></a>
										<!--<a href="#" title="Expand/Collapse" class="btn-borderless btn-toggle-expand"><i class="fa fa-chevron-up"></i></a>
										<a href="#" title="Remove" class="btn-borderless btn-remove"><i class="fa fa-times"></i></a>-->
									</div>
						</div>
						<div class="widget-content">
                    <form id="frmmain" name="frmmain" data-parsley-validate novalidate>
					
<?php echo csrf_field(); ?>

<div class="alert  alert-info " >
    <ul><li class="fa fa-cog  fa-1x fa-fw"></li>Kindly enter Customer Details..</ul>
</div>						
<div class="alert alert-success print-success-msg" style="display:none">
    <ul></ul>
</div>	
<div class="alert alert-danger print-error-msg" style="display:none">
    <ul></ul>
</div>
<div class="col-md-6">
							<!-- ADVANCED VALIDATION -->
								<div class="widget-content"> 								
						<div class="form-group">
                            <label for="text-input1">Sequence Number*</label>
                            <input type="text" name="custcode" id="custcode" class="form-control" >
                            <small class="text-danger" id="errcustcode"></small>
                        </div>
                        <div class="form-group">
                            <label for="multiselect1">Tariff type*</label>
                            <br/>
                                <select name="tarifftype" id="tarifftype" class="form-control" required>
                                    <option value="">Select</option>
                                </select>
                            <small class="text-danger" id="errstatus"></small>
                        </div>
                        <div class="form-group">
                            <label for="text-input1">Customer name*</label>
                            <input type="text" name="customername" id="customername" class="form-control" >
                            <small class="text-danger" id="errcustomername"></small>
                        </div>
						<div class="form-group">
                            <label for="text-input1">House Name</label>
                            <input type="text" name="housename" id="housename" class="form-control" >
                            <small class="text-danger" id="errhousename"></small>
                        </div>
						<div class="form-group">
                            <label for="text-input1">Flat No.</label>
                            <input type="text" name="flatno" id="flatno" class="form-control" >
                            <small class="text-danger" id="errflatno"></small>
                        </div>
                        <div class="form-group">
                            <label>Address</label>
                            <textarea class="form-control" name="address" id="address" rows="5" cols="30" ></textarea>
                            <small class="text-danger" id="erraddress" ></small>
                        </div>	
                        <div class="form-group">
                            <label for="text-input1">Email ID*</label>
                            <input type="text" name="emailid" id="emailid" class="form-control" >
                            <small class="text-danger" id="erremailid"></small>
                        </div>                  	
                        <div class="form-group">
                            <label for="multiselect1">Block*</label>
                            <br/>
                                <select name="block" id="block" class="form-control" required>
                                    <option value="">Select</option>
                                </select>
                            <small class="text-danger" id="errstatus"></small>
                        </div>
                        <div class="form-group">
                            <label for="multiselect1">Ward*</label>
                            <br/>
                                <select name="ward" id="ward" class="form-control" required>
                                    <option value="">Select</option>
                                </select>
                            <small class="text-danger" id="errstatus"></small>
                        </div> 
                        <div class="form-group">
                            <label for="multiselect1">Area*</label>
                            <br/>
                                <select name="area" id="area" class="form-control" required>
                                    <option value="">Select</option>
                                </select>
                            <small class="text-danger" id="errstatus"></small>
                        </div>
								</div>
							<!-- END ADVANCED VALIDATION -->
</div>
<div class="col-md-6">
							<!-- ADVANCED VALIDATION -->
								<div class="widget-content">    
													
						<div class="form-group">
                            <label for="text-input1">Contact No. 1*</label>
                            <input type="text" name="contact1" id="contact1" class="form-control" >
                            <small class="text-danger" id="errcontact1"></small>
                        </div>
                        <div class="form-group">
                            <label for="text-input1">Contact No. 2</label>
                            <input type="text" name="contact2" id="contact2" class="form-control" >
                            <small class="text-danger" id="errcontact2"></small>
                        </div>
						<div class="form-group">
                            <label for="text-input1">Meter No.</label>
                            <input type="text" name="meterno" id="meterno" class="form-control" >
                            <small class="text-danger" id="errflatno"></small>
                        </div>						
                        <div class="form-group">
                            <label for="multiselect1">Meter Status</label>
                            <br/>
                                <select name="meterstatus" id="meterstatus" class="form-control" required>
                                    <option value="Working">Working</option>
                                    <option value="Not working">Not working</option>
                                    <option value="Not Visible">Not Visible</option>
                                    <option value="Door Locked">Door Locked</option>
                                </select>
                            <small class="text-danger" id="errmeterstatus"></small>
                        </div>				
						<div class="form-group">
                            <label for="text-input1">Connection date.</label>
                            <input type="date" name="connectiondt" id="connectiondt" class="form-control" >
                            <small class="text-danger" id="errconnectiondt"></small>
                        </div>						
                        <div class="form-group">
                            <label for="multiselect1">Connection Charge</label>
                            <br/>
                            <input type="text" name="connectioncharge" id="connectioncharge" class="form-control" >
                            <small class="text-danger" id="errmetersconnectioncharge"></small>
                        </div>						
                        <div class="form-group">
                            <label for="multiselect1">Advance Amount paid</label>
                            <br/>
                            <input type="text" name="advamt" id="advamt" class="form-control" >
                            <small class="text-danger" id="erradvamt"></small>
                        </div>
                        <div class="form-group">
                            <label>Note (Any note)</label>
                            <textarea class="form-control" name="description" id="description" rows="5" cols="30" ></textarea>
                            <small class="text-danger" id="errdescription" ></small>
                        </div>
                        <div class="form-group">
                            <label for="multiselect1">Status*</label>
                            <br/>
                                <select name="status" id="status" class="form-control" required>
                                    <option value="Active">Active</option>
                                    <option value="Inactive">Inactive</option>
                                </select>
                            <small class="text-danger" id="errstatus"></small>
                        </div>		
								</div>
							<!-- END ADVANCED VALIDATION -->
</div>
<div class="col-md-12">
			   <div class="form-group">
					<center><button type="submit" id="submit" name="submit" class="btn btn-primary">Submit</button></center>
				</div>
</div>                        
                    </form>
                    
						</div>
					</div>
					<!-- END DATA EXPORT -->

				</div>
			</div>
			<!-- /main -->
			
				
<script type="application/javascript">
	i=0;
$(document).ready(function()
  {
   $(document).on('submit', '#frmmain', function()
   {
			$(".alert-info").find("ul").html('<li class="fa fa-cog fa-spin fa-1x fa-fw"></li>Inserting record...');			
			var _token = $("input[name='_token']").val();
			var custcode = $("input[name='custcode']").val();
			var customername = $("input[name='customername']").val();
			var housename = $("input[name='housename']").val();
			var flatno = $("input[name='flatno']").val();
			var address = $("#address").val();
			var block = $("#block").val();
			var ward = $("#ward").val();
			var area = $("#area").val();
			var tarifftype = $("#tarifftype").val();
			var meterno = $("input[name='meterno']").val();
			var meterstatus = $("input[name='meterstatus']").val();
			var contact1 = $("input[name='contact1']").val();
			var contact2 = $("input[name='contact2']").val();
			var emailid = $("input[name='emailid']").val();
			var note = $("#description").val();
			var status = $("#status").val();
			var connectiondate = $("input[name='connectiondt']").val();
			var connectioncharge = $("input[name='connectioncharge']").val();
			var advamt = $("input[name='advamt']").val();
	     
			document.getElementById("errcustomername").innerHTML = "";
			document.getElementById("errcontact1").innerHTML = "";

		   if(customername == "")
		   {
				document.getElementById("errcustomername").innerHTML = "Customer Name should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
		   }
		   else if(contact1 == "")
		   {
				document.getElementById("errcontact1").innerHTML = "Contact Number should not be empty...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
		   }
		   else
		   {
	   
							if(i==0)
							{
								i++;
				$.ajax({
					url: "/WBcustomer",
					type:'POST',
					data: {
					_token:_token,
					custcode:custcode,
					customername:customername,
					housename:housename,
					flatno:flatno,
					address:address,
					block:block,
					ward:ward,
					area:area,
					tarifftype:tarifftype,
					meterno:meterno,
					meterstatus:meterstatus,
					contact1:contact1,
					contact2:contact2,
					emailid:emailid,
					note:note,
					status:status,
					connectiondate:connectiondate,
					connectioncharge:connectioncharge,
					advamt:advamt
					},
					success: function(data) {
						if(data.status == 1)
						{
			/*
			$("#custcode").val('');
			$("#customername").val('');
			$("#housename").val('');
			$("#flatno").val('');
			$("#address").val('');
			$("#block").val('Select');
			$("#ward").val('Select');
			$("#area").val('Select');
			$("#tarifftype").val('Select');
			$("#meterno").val('');
			$("#meterstatus").val('');
			$("#contact1").val('');
			$("#contact2").val('');
			$("#emailid").val('');
			$("#description").val('');
			$("#status").val('Active');			
			$("#connectiondate").val('<?php echo date("Y-m-d"); ?>');
			$("#connectioncharge").val('');
			$("#advamt").val('');
			*/
							printSuccessMsg(data.message);
							
						//	$('#sideMenu').load('SellerView');
						}
						else
						{
							printErrorMsg(data.message);
						}
					}
				});
							}

		   }						

		return false;
   });
  });
			function printSuccessMsg (msg) {
				$(".alert-info").css('display','none');
				$(".print-error-msg").css('display','none');
				$(".print-success-msg").find("ul").html('');
				$(".print-success-msg").css('display','block');
				$(".print-success-msg").find("ul").append('<li class="fa fa-check  fa-1x fa-fw"></li>'+msg);
				$('#sideMenu').load('WBcustomerView');
			}
			function printErrorMsg (msg) {
				$(".alert-info").css('display','none');
				$(".print-success-msg").css('display','none');
				$(".print-error-msg").find("ul").html('');
				$(".print-error-msg").css('display','block');
				$(".print-error-msg").find("ul").append('<li class="fa fa-times-circle fa-1x fa-fw"></li>'+msg);
			}

</script>
<script>
	//Load block records
	$(document).ready(function(){
	 $.ajax({
            type: "GET",
            url:"/getblock",
            dataType: "json",
            success: function (data) {
                $.each(data,function(i,obj)
                {
				var div_data="<option value="+obj.blok_id+">"+obj.blok_name+ "</option>";	
                $(div_data).appendTo('#block'); 
                });
                }
          });
        });		
	//Load Ward records
	$(document).ready(function(){
	 $.ajax({
            type: "GET",
            url:"/getward",
            dataType: "json",
            success: function (data) {
                $.each(data,function(i,obj)
                {
				var div_data="<option value="+obj.ward_id+">"+obj.ward_name+ "</option>";	
                $(div_data).appendTo('#ward'); 
                });
                }
          });
        });	
	//Load Area records
	$(document).ready(function(){
	 $.ajax({
            type: "GET",
            url:"/getarea",
            dataType: "json",
            success: function (data) {
                $.each(data,function(i,obj)
                {
				var div_data="<option value="+obj.area_id+">"+obj.area_name+ "</option>";	
                $(div_data).appendTo('#area'); 
                });
                }
          });
        });	
	//Load Tariff type code
	$(document).ready(function(){
	 $.ajax({
            type: "GET",
            url:"/gettarifftype",
            dataType: "json",
            success: function (data) {
                $.each(data,function(i,obj)
                {
				var div_data="<option value="+obj.tarf_id+">"+obj.tarf_tarifftype+ "</option>";	
                $(div_data).appendTo('#tarifftype'); 
                });
                }
          });
        });		
</script>
<script>	
	$('.clickme').click(function(e)
	{
		e.preventDefault();
		$('#sideMenu').load($(this).attr('href'));
	});
</script>