<!-- 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> Loan types</h3></div>
								<div class="widget-content">
                    <form id="frmmain" name="frmmain" data-parsley-validate novalidate>
                    <input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
<?php echo csrf_field(); ?>           
<div class="alert  alert-info " >
    <ul><li class="fa fa-cog  fa-1x fa-fw"></li>Kindly enter Loan types..</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="ltyp_id" name="ltyp_id" >
	<label for="text-input1">Loan type*</label>
	<input type="text" name="ltyp_loantype" id="ltyp_loantype" class="form-control" >
		<small class="text-danger" id="errltyp_loantype"></small>
</div>
						
<div class="form-group">
	<label for="text-input1">Maximum Month*</label>
	<input type="text" name="ltyp_maxmonth" id="ltyp_maxmonth" class="form-control" >
	<small class="text-danger" id="errltyp_maxmonth"></small>
</div>
                        
<div class="form-group">
	<label>Interest (in %)</label>
	<input type="text" name="ltyp_interestperc" id="ltyp_interestperc" class="form-control" >
	<small class="text-danger" id="errltyp_interestperc" ></small>
</div>
                
<div class="form-group">
	<label for="multiselect1">Status*</label>
	<br/>
		<select name="ltyp_status" id="ltyp_status" class="form-control input-lg" required>
			<option value="Active">Active</option>
			<option value="Inactive">Inactive</option>
		</select>
	<small class="text-danger" id="errltyp_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 Loan types</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>Loan type</th>
										<th>Maximum month</th>
										<th>Interest(in %)</th>
										<th>Status</th>
										<th>Action</th>
									</tr>
								</thead>
								<tbody>
								<?php $__currentLoopData = $data['LoanTypeRecords']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $LoanType): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
									<tr>
										<td><?php echo e($LoanType->ltyp_loantype); ?></td>
										<td><?php echo e($LoanType->ltyp_maxmonth); ?></td>
										<td><?php echo e($LoanType->ltyp_interestperc); ?></td>
										<td><?php echo e($LoanType->ltyp_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('.$LoanType->ltyp_id.')">Edit</button>'; } if($data['delete']=='1'){echo' <button class="btn btn-default btn-xs print" onclick="Delete('.$LoanType->ltyp_id.')">Delete</button>';} echo '</td>';
?>
									</tr>
								<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
								</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 ltyp_loantype =  $("input[name='ltyp_loantype']").val();
			var ltyp_maxmonth = $("input[name='ltyp_maxmonth']").val();
			var ltyp_interestperc = $("#ltyp_interestperc").val();
			var status = $("#ltyp_status").val();
			
			document.getElementById("errltyp_loantype").innerHTML = "";
			document.getElementById("errltyp_maxmonth").innerHTML = "";
			document.getElementById("errltyp_interestperc").innerHTML = "";
			document.getElementById("errltyp_status").innerHTML = "";
			
			if(ltyp_loantype == "")
			{
				document.getElementById("errltyp_loantype").innerHTML = "Kindly enter Loan type...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');				
			}
			else if(ltyp_maxmonth == "")
			{
				document.getElementById("errltyp_maxmonth").innerHTML = "Kindly enter maximum month...";
				$(".alert-info").find("ul").html('<li class="fa fa-cog fa-1x fa-fw"></li>Kindly check the error...');
			}
			else if(ltyp_interestperc == "")
			{
				document.getElementById("errltyp_interestperc").innerHTML = "Kindly enter interest percentage...";
				$(".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: "/ltype",
						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('loantype');
							}
							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:"/editLoantype",
			dataType: "json",
			data: {
				'_token': $('input[name=_token]').val(),
				'id': id
			},
			success: function (data) {
				$.each(data,function(i,obj)
				{	
					$('#ltyp_id').val(obj.ltyp_id);
					$('#ltyp_loantype').val(obj.ltyp_loantype);
					$('#ltyp_maxmonth').val(obj.ltyp_maxmonth);
					$('#ltyp_interestperc').val(obj.ltyp_interestperc);
					$('#ltyp_status').val(obj.ltyp_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:"/delLoantype",
					dataType: "json",
					data: {
						'_token': $('input[name=_token]').val(),
						'id': id
					},
					success: function (sdata) {
						if(sdata.status == 1)
						{
							printSuccessMsg(sdata.message);
							alert('test');
							$('#sideMenu').load('loantype');
						}
						else
						{
							printErrorMsg(sdata.message)
						}
					}
				});
			}
		}
	}
</script>				  