<!-- MAIN CONTENT WRAPPER -->
<script src="assets/js/king-table.js"></script>

			<div class="content">
				<div class="main-content">
					<div class="row">
                    	
                        <div class="col-md-4">
							<!-- ADVANCED VALIDATION -->
							<div class="widget">
								<div class="widget-header">
									<h3><i class="fa fa-check-circle"></i> Delay Payment Fee Settings</h3></div>
								<div class="widget-content">
                    <form id="frmmain" name="frmmain" data-parsley-validate novalidate>
                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
{!! csrf_field() !!}           
<div class="alert  alert-info " >
    <ul><li class="fa fa-cog  fa-1x fa-fw"></li>Kindly enter Delay Payment Fee Settings..</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="form-group">
 <input type="hidden" id="dpmt_id" name="dpmt_id" >
	<label for="text-input1">Delay payment charge*</label>
	<input type="text" name="dpmt_charge" id="dpmt_charge" class="form-control" >
	<small class="text-danger" id="errdpmt_charge"></small>
</div>
						         
<div class="form-group">
	<label for="multiselect1">Status*</label>
	<br/>
		<select name="dpmt_status" id="dpmt_status" class="form-control input-lg" required>
			<option value="Active">Active</option>
			<option value="Inactive">Inactive</option>
		</select>
	<small class="text-danger" id="errdpmt_status"></small>
</div>
                        <br/>
                        <button type="submit" id="submit" name="submit" class="btn btn-primary submit">Submit</button>
                    </form>
								</div>
							</div>
							<!-- END ADVANCED VALIDATION -->
						</div>
                    
						<div class="col-md-8">
							<!-- BASIC VALIDATION -->
								<div class="widget widget-table">
						<div class="widget-header">
							<h3><i class="fa fa-table"></i> View Delay Payment Fee Settings</h3> 
                        </div>
						<div class="widget-content">
							<table id="datatable-data-export" class="table table-sorting table-striped table-hover table-bordered datatable">
								<thead>
									<tr>
										<th>Delay Payment Charge</th>
										<th>Status</th>
										<th>Action</th>
									</tr>
								</thead>
								<tbody>
								@foreach($data['delaypayment'] as $delaypayment)
									<tr>
										<td>{{$delaypayment->dpmt_charge}} %</td>
										<td>{{$delaypayment->dpmt_status}}</td>
<?php 
	if($data['edit']=='1' || $data['delete']=='1'){ echo'<td>';}
?>
<?php 
	if($data['edit']=='1'){echo'<button class="btn btn-default btn-xs print" onclick="Edit('.$delaypayment->dpmt_id.')">Edit</button>'; } if($data['delete']=='1'){echo' <button class="btn btn-default btn-xs print" onclick="Delete('.$delaypayment->dpmt_id.')">Delete</button>';} echo '</td>';
?>
									</tr>
								@endforeach
								</tbody>
							</table>
							
						</div>
					</div>
							<!-- END BASIC VALIDATION -->
						</div>

					</div>
				</div>
			</div>
			<!-- /main -->

<script type="application/javascript">
i=0;
	//$(document).on('submit', '#frmmain', function()
	$('.submit').click(function()
	{
			$(".alert-info").find("ul").html('<li class="fa fa-cog fa-spin fa-1x fa-fw"></li>Processing...');
		   
			var _token = $("input[name='_token']").val();
			var dpmt_charge =  $("input[name='dpmt_charge']").val();
			var status = $("#dpmt_status").val();
			
			document.getElementById("errdpmt_charge").innerHTML = "";
			document.getElementById("errdpmt_status").innerHTML = "";
			
			if(dpmt_charge == "")
			{
				document.getElementById("errltyp_loantype").innerHTML = "Kindly enter Delay Payment Fee...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');				
			}
			else if(status == "")
			{
				document.getElementById("errltyp_status").innerHTML = "Status 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++;
			   //alert(i);
					$.ajax({
						url: "/delaypaymenttype",
						type:'POST',
						data: /* {_token:_token,branch:branch, usertype:usertype, description:description, status:status} */
						$('#frmmain').serialize(),
						success: function(data) {											
							if(data.status == 1)
							{
								printSuccessMsg(data.message);
								$('#sideMenu').load('delaypayment');
							}
							else
							{
								printErrorMsg(data.message)
							}
						}
					});					   
				}						
			}						

		return false;
	});    


	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);
	}
	
	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);
		//Code to redirect page
		//var url = "/dashboard";
		//$(location).attr('href',url);
	}
</script>	
<script>
	function Edit(id)
	{
		$.ajax({
			type: "GET",
			url:"/editdelaypaymenttype",
			dataType: "json",
			data: {
				'_token': $('input[name=_token]').val(),
				'id': id
			},
			success: function (data) {
				$.each(data,function(i,obj)
				{	
					$('#dpmt_id').val(obj.dpmt_id);
					$('#dpmt_charge').val(obj.dpmt_charge);
					$('#dpmt_status').val(obj.dpmt_status);
					// $('#btnadd').val("UPDATE"); 
				});  
			}
		});
	}
	function Delete(id)
	{
		//alert(id);
		if(confirm("Are you sure want to delete this record?") == true)
		{
			k = 0;
			if(k == 0)
			{
				k++;
				$.ajax({
					type: "GET",
					url:"/deldelaypaymenttype",
					dataType: "json",
					data: {
						'_token': $('input[name=_token]').val(),
						'id': id
					},
					success: function (sdata) {
						if(sdata.status == 1)
						{
							printSuccessMsg(sdata.message);
							$('#sideMenu').load('delaypayment');
						}
						else
						{
							printErrorMsg(sdata.message)
						}
					}
				});
			}
		}
	}
</script>				  