<script src="assets/js/king-table.js"></script>
<div class="content">	
	<div class="main-content">
		<!-- DATA EXPORT -->
		<div class="widget widget-table">
			<div class="widget-header">
				<h3><i class="fa fa-table"></i> View Loan Applicantions</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>#</th>
							<th>Account No.</th>
							<th>Name</th>
							<th>Date</th>
							<th>Loan amt</th>
							<th>Tenor</th>	
							<th>Total</th>		
							<th>Paid</th>	
							<th>Balance</th>			
							<th>Action</th>					
						</tr>
					</thead>
					<tbody>
	<?php  $i=1;?>
	@foreach($data['LoanApplicantRecords'] as $LoanApplicantRec)
	<tr>
		<td><?php echo $i++;?></td>
		<td><b><font color="green">{{$LoanApplicantRec->lacc_no}}</font></b><br>({{$LoanApplicantRec->br_name }})</td>
		<td>{{$LoanApplicantRec->lacc_custname}}<br><b>Mob - </b><?php $resaddr = unserialize($LoanApplicantRec->lacc_resaddr); echo $resaddr[5]; ?></td>
		<td><?php echo date("d-m-Y",strtotime($LoanApplicantRec->lacc_opendt)); ?></td>  
		<td style="text-align: right;"><?php echo round($LoanApplicantRec->lacc_loanamt); ?></td> 
		<td style="text-align: center;">{{$LoanApplicantRec->lacc_tenor }}</td> 
		<td style="text-align: right;"><?php echo round($LoanApplicantRec->totalamt); ?></td>
		<td style="text-align: right;"><font color="green">{{$LoanApplicantRec->paidamt }}</font></td>
		<td style="text-align: right;"><?php $bal =  $LoanApplicantRec->totalamt - $LoanApplicantRec->paidamt; echo round($bal); ?></td>
		<td>
	<?php
	if(round($bal) > 0)
	{
	?>
		<button class="btn btn-info btn-xs" onclick="LoadLoanApplication({{$LoanApplicantRec->lacc_id}},'{{$LoanApplicantRec->lacc_no}}')" title="Loan Panel" ><span class="fa fa-eye"></span></button>
		<button class="btn btn-warning btn-xs" onclick="EditloanApp({{$LoanApplicantRec->lacc_id}},'{{$LoanApplicantRec->lacc_no}}')" title="Edit" ><span class="fa fa-edit"></span></button> 
		<?php
		if($LoanApplicantRec->paidamt == 0)
		{
		?>
		<button class="btn btn-success btn-xs" onclick="LoadWelcomeMail({{$LoanApplicantRec->lacc_id}},'{{$LoanApplicantRec->lacc_no}}')" title="Welcome Mail" ><span class="fa fa-envelope"></span></button>
		<?php
		}
		?>
	<?php
	}
	else
	{
	?>
		<button class="btn btn-success btn-xs" onclick="LoadLoanApplication({{$LoanApplicantRec->lacc_id}},'{{$LoanApplicantRec->lacc_no}}')"  title="Loan Panel" ><span class="fa fa-eye"></span> </button>
		<button class="btn btn-success btn-xs" onclick="EditloanApp({{$LoanApplicantRec->lacc_id}},'{{$LoanApplicantRec->lacc_no}}')" data-toggle="tooltip"  title="Edit"><span class="fa fa-edit"></span></button> 
		<?php
		if($LoanApplicantRec->paidamt == 0)
		{
		?>
		<button class="btn btn-success btn-xs" onclick="LoadWelcomeMail({{$LoanApplicantRec->lacc_id}},'{{$LoanApplicantRec->lacc_no}}')"  title="Welcome Mail"><span class="fa fa-envelope"></span></button>
		<?php
		}
		?>
	<?php
	}
	?>
							</td>  
						</tr>
						@endforeach	
					</tbody>
				</table>
			</div>
		</div>
		<!-- END DATA EXPORT -->
		
	</div>
</div>
<!-- /main -->
<script>
	$('.createMod').click(function(e)
	{   
		e.preventDefault();
		$('#sideMenu').load($(this).attr('href'));
	});
	function loadloanrecord(id)
	{
		$.ajax({
			url: 'loadcreateloanapplication',
			type: 'GET',
			data:'&lacc_id='+id,
			success: function(data)
			{
				$('.content').html(data);
				//$('.loadcreateloanapplication').html(data);
				//$('#sideMenu').load('loadcreateloanapplication');
			}
		});
	}
	$('.edit').click(function(e)
	{
		e.preventDefault();
		$('#sideMenu').load($(this).attr('href')); 
	});
	function DeleteloanApp(a)
	{
		$.confirm({
			title: 'Confirm!',
			content: 'Are you confirm Delete!',
			buttons: {
				confirm: function () {
					sureDeleteloanApp(a);
				},
				cancel: function () {
					$.alert('Canceled!');
				}
				
			}
		});
	}
	function sureDeleteloanApp(a)
	{
		$.ajax({
			url: 'sureDeleteloanApp',
			type: 'GET',
			data:'&lacc_id='+a,
			success: function(data)
			{
				$.toast({
					heading: 'Delete!',
					text: 'Sucessfully Deleted.',
					showHideTransition: 'slide',
					icon: 'success',
					loaderBg: '#d9534f'
				});
				$('#sideMenu').load('/LoadViewLoanApplicantion');
			}
		});
	}
	
	function LoadLoanApplication(b,acno)
	{
		$.ajax({
			url: 'LoanAcPanel',
			type: 'GET',
			data:'&lacc_id='+b+'&acno='+acno,
			success: function(data)
			{
				$('#sideMenu').html(data);
			}
		});
	}
	function LoadWelcomeMail(b,acno)
	{
		$.ajax({
			url: 'welcomekit',
			type: 'GET',
			data:'&lacc_id='+b+'&acno='+acno,
			success: function(data)
			{
				$('#sideMenu').html(data);
			}
		});
	}
</script>
