<style>
.paymentmodal {
    width: 75%;
    margin: 30px auto;
}
</style>
<script src="assets/js/king-table.js"></script>
<script src="assets/js/popper.min.js"></script>
<div class="loadreport">
<?php
$LoanTotalPaid=0;
?>
<!-- MAIN CONTENT WRAPPER -->
<div class="content">	
	<div class="main-content">
		<!-- DATA EXPORT -->
<div id="divprint">		
		<div class="widget widget-table">
			<div class="widget-content">
				<center><h3><img src="img/navachethana-logo.png" >Navachethana Finance Company (R)</h3><br>
				<p>"Beauty Plaza" Building, Ground Floor, Balmatta Road, mangalore-575001<br>
				<b>Phone : 0824 - 4255640 Mobile No. 7760833500</b>
				</p></center>
				<hr> 

				<table  class="table table-striped table-bordered" border="1">
					<?php  $i=1;?>
					@foreach($data['LoanApplicantRecords'] as $LoanApplicantRec)
					<?php $lacc_id = $LoanApplicantRec->lacc_id; ?>
					<input type="hidden" name="lacc_id" id="lacc_id" value="{{$LoanApplicantRec->lacc_id}}">
					<input type="hidden" name="lacc_no" id="lacc_no" value="{{$LoanApplicantRec->lacc_no}}">
						<tr>
							<th>Loan Account No.</th><td><b><?php echo $loanacc = $LoanApplicantRec->lacc_no; ?></b></td>	
							<th>Loan Account Date</th><td><b><?php echo  date("d-m-Y",strtotime($LoanApplicantRec->lacc_opendt)); ?></b></td>								
						</tr>						
						<tr>
							<th>Customer Name</th><td><b>{{$LoanApplicantRec->lacc_custname}}</b></td>	
					<th>EMI Start Date</th><td><b><?php 
echo $effectiveDate = date('d-M-Y', strtotime("+1 month", strtotime($LoanApplicantRec->lacc_opendt)));
					?></b></td>								
						</tr>
						<tr>
							<th rowspan="3">Customer Address</th><td rowspan="3"><b><?php 
							$addr=unserialize($LoanApplicantRec->lacc_resaddr); 
							//print_r($addr);
							echo $addr[0]."<br>";
							echo $addr[1]."<br>";
							echo $addr[2]."<br>";
							echo $addr[3]."," . $addr[4]."<br>";
							?></b></td>	
							<th>EMI Close Date</th><td><b> <?php 
//echo  date("d-m-Y",strtotime($LoanApplicantRec->lacc_opendt));
echo $effectiveDate = date('d-M-Y', strtotime("+$LoanApplicantRec->lacc_tenor months", strtotime($LoanApplicantRec->lacc_opendt)));
					?></b></td>
						</tr>
						
						<tr>
							<th>Interest rate.</th><td><b><?php echo $loanacc = $LoanApplicantRec->lacc_intrate; ?>%</b></td>
						</tr>
						
						<tr>
							<th>Loan Tenure.</th><td><b>{{$LoanApplicantRec->lacc_tenor}} months</b></td>
						</tr>
						
						<tr>
							<th>Mobile No.</th><td><b><?php echo $addr[5]; ?></b></td>
							<th>Monthly EMI.</th><td><b><?php echo round($lins_amt + $lins_iamt); ?></b></td>
						</tr>
						<tr>
							<th>Tel.</th><td><b><?php echo $addr[6]; ?></b></td>
							<th>Outstanding Principal.</th><td><b><?php 
							echo round(($LoanApplicantRec->lacc_loanamt) - ($data['LoanTotalPaid'] - $data['LoanAllCharges'] ));
							?></b></td>
						</tr>
						<tr>
							<th>Branch</th><td><b><?php echo  $LoanApplicantRec->br_name; ?></b></td>	
							<th>No. of EMI Arrears</th>
							<td><b><?php echo $nopending; ?></b></td>
						</tr>
						
						<tr>
							<th>Loan Amount</th><td><b> {{$LoanApplicantRec->lacc_loanamt}}</b></td>	
							<th>Arrear EMI</th>
							<td><b><?php echo $totinsamt + $totinterestamt; ?></b></td>
						</tr>
						
						<tr>
							<th rowspan="3">Loan Paid details</th><td rowspan="3"><b>{{$LoanApplicantRec->lacc_remarks}}</b></td>	
							<th>Bank charges</th><td><b><?php echo $totchqbounce; ?></b></td>
						</tr>
						
						<tr>
							<th>Arrear Penalty.</th><td><b><?php echo $totdelaypayment; ?></b></td>
						</tr>
						
						<tr>
							<th>Legal/Other charges</th><td><b><?php echo $tototheramt; ?></b></td>
						</tr>
							
						<tr>
							<th>Chit Reference No.</th><td><b>{{$LoanApplicantRec->lacc_chitrefno}}</b></td>	
							<th>Total Arrear's.</th><td><b><?php echo round($data['PreviousPayableAmt']); ?></b></td>
						</tr>
							
						<tr>
							<th>Branch name.</th><td><b>{{$LoanApplicantRec->chitbr}}</b></td>	
							<th>Current installment</th><td><b><?php echo round($data['CurrentPayableAmt']); ?></b></td>
						</tr>	
						<tr>
							<th>Paid up amount.</th><td><b><?php
						if($LoanApplicantRec->lacc_paidupamt != "")
						{
						echo "". $LoanApplicantRec->lacc_paidupamt;
						}
						?></b></td>	
							<th>Total Amt pending</th>
							<td><b><?php 
							echo $LoanApplicantRec->lacc_loanamt-$data['LoanTotalPaid']; 
							?></b></td>
						</tr>
					@endforeach	
				</table>				
			</div>

		</div>
		<!-- END DATA EXPORT -->
		

		<!-- DATA EXPORT -->
		<div class="widget widget-table">
			<div class="widget-header">
				<h3><i class="fa fa-table"></i> Loan Installment detail </h3>
			</div>
			<div class="widget-content">
				<table  class="table table-striped table-bordered" id="tabloan">
				<thead>
					<tr>
						<th>SLNo.</th>
						<th>Receipt No.</th>					
						<th>Month</th>							
						<th>Date of <br>Repayment</th>
						<th>Principal</th>							
						<th>Interest</th>					
						<th>Bank charges</th>						
						<th>Late fee</th>							
						<th>Case/Other charges</th>
						<th>Mode of Payment</th>
						<th>Cheque No. & Bank</th>
					</tr>
				</thead>
				<tbody>	
	<?php
	$i=1;
	$linsamt= 0;
	$intamt = 0;
	$instno = 0;
	$principleamt = 0;	
	$Interestamt = 0;	
	$chqbounce = 0;
	$penaltyamt = 0;	
	$othercharges = 0;
	$totalinstallmentamount = 0;
	?>
					@foreach($data['LoanRpt'] as $LoanInstallmentRec)
		<?php
		$paidamt = $LoanPaymentRec->ltr_amt;
		$paidamtbal = $LoanPaymentRec->ltr_amt;
		if($LoanPaymentRec->lins_no  == $instno)
		{
		}
		else
		{
			$principleamt = $principleamt + $LoanPaymentRec->principleamt;	
			$Interestamt = $Interestamt  + $LoanPaymentRec->Interestamt;	
			$chqbounce = $chqbounce + $LoanPaymentRec->chqbounce;
			$penaltyamt = $penaltyamt + $LoanPaymentRec->penaltyamt;	
			$othercharges = $othercharges + $LoanPaymentRec->othercharges;
		}
		//###-Other charges starts here
		if($paidamtbal > $othercharges)
		{
			$othercharges = $othercharges;
			$paidamtbal = $paidamtbal - $othercharges;
		}
		else
		{
			$othercharges = $paidamtbal;
			$paidamtbal =0;
		}
		//###-Other charges ends here
		//###-Penalty charges starts here
		if($paidamtbal > $penaltyamt)
		{
			$penaltyamt = $penaltyamt;
			$paidamtbal = $paidamtbal - $penaltyamt;
		}
		else
		{
			$penaltyamt = $paidamtbal;
			$paidamtbal =0;
		}
		//###-Penalty charges ends here
		//###-Cheque Bounce charges starts here
		if($paidamtbal > $chqbounce)
		{
			$chqbounce = $chqbounce;
			$paidamtbal = $paidamtbal - $chqbounce;
		}
		else
		{
			$chqbounce = $paidamtbal;
			$paidamtbal =0;
		}
		//###-Cheque Bounce charges ends here
		//##Interest Amount starts here
		if($paidamtbal > $Interestamt)
		{
			$Interestamt = $Interestamt;
			$paidamtbal = $paidamtbal - $Interestamt;
		}
		else
		{
			$Interestamt = $paidamtbal;
			$paidamtbal =0;
		}
		//##Interest amount ends here
		//##Principal Amount starts here
		if($paidamtbal > $principleamt)
		{
			$principleamt = $principleamt;
			$paidamtbal = $paidamtbal - $principleamt;
		}
		else
		{
			$principleamt = $paidamtbal;
			$paidamtbal =0;
		}
		//##Principal Amount ends here
		?>
					<tr>
			<td><?php echo $LoanPaymentRec->lins_no; ?></td>
			<td><?php echo $LoanPaymentRec->ltr_billno; ?></td>
			<td><?php echo date("M",strtotime($LoanPaymentRec->ltr_transdt)); ?></td>
			<td><?php echo date("d-m-Y",strtotime($LoanPaymentRec->ltr_transdt)); ?></td>
			<td style="text-align: right;"><?php echo round($principleamt); ?></td>
			<td style="text-align: right;"><?php echo round($Interestamt); ?></td>
			<td style="text-align: right;"><?php echo round($chqbounce); ?></td>
			<td style="text-align: right;"><?php echo round($penaltyamt); ?></td>
			<td style="text-align: right;"><?php echo round($othercharges); ?></td>
			<td><?php echo $LoanPaymentRec->ltr_paymenttype; ?></td>
			<td><?php echo $LoanPaymentRec->ltr_chqno . " " . $LoanPaymentRec->ltr_bank; ?></td>
					</tr>
			<?php
			$linsamt = $linsamt + $LoanInstallmentRec->lins_amt;
			$intamt  = $intamt + $LoanInstallmentRec->lins_iamt;
			$totalinstallmentamount = $totalinstallmentamount + $paidamt;
			?>
					@endforeach
				</tbody>
				
	<tfoot>
		<tr>		
			<th colspan="11">Total Amount : <?php echo $totalinstallmentamount; ?></th>
		</tr>
	</tfoot>
				
				</table>
			</div>
		</div>
		
		<?php /* Cancelled Receipt transaction */ ?>
		<div class="widget widget-table">
			<div class="widget-header">
				<h3><i class="fa fa-table"></i> Cheque return / Cancelled Receipt Transactions </h3>
			</div>
			<div class="widget-content">
				<table  class="table table-striped table-bordered" >
					<thead>
						<tr>
							<th>Inst No.</th>
							<th>Cheque No. & Bank</th>
							<th>Receipt No.</th>								
							<th>Payment Date</th>				
							<th>Cheque Amount</th>	
							<th>Cheque return Date</th>				
							<th>Bank charges</th>
						</tr>
					</thead>
					<tbody>
					<?php
					$totcancellationcharge = 0;
					?>
						@foreach($data['LoanChqBounceRecords'] as $LoanChqBounceRecords)
						<tr>
							<td><?php echo $LoanChqBounceRecords->lins_no; ?></td>
							<td><?php echo $LoanChqBounceRecords->ltr_chqno; ?> <?php echo $LoanChqBounceRecords->ltr_bank; ?></td>
							<td><?php echo $LoanChqBounceRecords->ltr_billno; ?></td>
							<td><?php echo date("d-m-Y",strtotime($LoanChqBounceRecords->ltr_transdt)); ?></td>
							<td style="text-align: right;"><?php echo round($LoanChqBounceRecords->chequeamt); ?></td>
							<td><?php echo $LoanChqBounceRecords->cancellationdate; ?></td>
							<td style="text-align: right;"><?php echo round($LoanChqBounceRecords->cancellationcharge); ?></td>
						</tr>
						<?php
						$totcancellationcharge = $totcancellationcharge + $LoanChqBounceRecords->cancellationcharge;
						?>
						@endforeach
					</tbody>
	<tfoot>
		<tr>		
			<th colspan="6" style="text-align: right;">Total Amount</th>
			<th style="text-align: right;"><?php echo round($totcancellationcharge); ?></th>
		</tr>
	</tfoot>
			</div>
		</div>
		
		
				<?php /* Balance Amount */ ?>
		<div class="widget widget-table">
			<div class="widget-header">
				<h3><i class="fa fa-table"></i> Balance amount Details </h3>
			</div>
			<div class="widget-content">
				<table  class="table table-striped table-bordered" >
					<thead>
						<tr>
							<th>Installment No.</th>
							<th>Amount</th>					
							<th>Paid Date</th>					
							<th>Status</th>		
						</tr>
					</thead>
					<tbody>	
					<?php
					/*
						@foreach($data['LoanRpt'] as $LoanInstallmentRec)
						<tr>
							<td><?php echo $i; $i=$i+1; ?></td>
							<td><?php echo $LoanInstallmentRec->ltr_billno; ?></td>
							<td><?php echo date("M",strtotime($LoanInstallmentRec->ltr_transdt)); ?></td>
							<td><?php echo date("d-m-Y",strtotime($LoanInstallmentRec->lins_date)); ?></td>
							<td><?php echo $LoanInstallmentRec->lins_amt; ?></td>
							<td><?php echo $LoanInstallmentRec->lins_iamt; ?></td>
							<td><?php echo $LoanInstallmentRec->bankcharges; ?></td>
							<td><?php echo $LoanInstallmentRec->latefee; ?></td>
							<td><?php echo $LoanInstallmentRec->caseotherchrge; ?></td>
							<td><?php echo $LoanInstallmentRec->ltr_paymenttype; ?></td>
							<td><?php echo $LoanInstallmentRec->ltr_chqno; ?></td>
						</tr>
						@endforeach
					*/
					?>	
					</tbody>
				</table>
			</div>
		</div>
		
						<?php /* Balance Amount */ ?>
		<div class="widget widget-table">
			<div class="widget-header">
				<h3><i class="fa fa-table"></i> Expense Details </h3>
			</div>
			<div class="widget-content">
				<table  class="table table-striped table-bordered" >
					<thead>
						<tr>
							<th>Inst No.</th>
							<th>Reason</th>			
							<th>Expense Date</th>
							<th>Expense Amount</th>					
							<th>Note</th>		
						</tr>
					</thead>
					<tbody>
					<?php
					$totLoanExpenseRec = 0;
					?>
						@foreach($data['LoanExpenseRecords'] as $LoanExpenseRec)
						<tr>
							<td><?php echo $LoanExpenseRec->lins_no; ?></td>
							<td><?php echo $LoanExpenseRec->ltr_transtype; ?></td>
							<td><?php echo date("d-m-Y",strtotime($LoanExpenseRec->expensedate)); ?></td>
							<td style="text-align: right;"><?php echo round($LoanExpenseRec->expenseamt); ?></td>
							<td><?php echo $LoanExpenseRec->ltr_note ; ?></td>
						</tr>
						<?php
						$totLoanExpenseRec = $totLoanExpenseRec + $LoanExpenseRec->expenseamt;
						?>
						@endforeach
					</tbody>
					<tfoot>
						<tr>		
							<th colspan="3" style="text-align: right;">Total Amount</th>
							<th style="text-align: right;"><?php echo round($totLoanExpenseRec); ?></th>
							<th ></th>
						</tr>
					</tfoot>
				</table>
			</div>
		</div>
		
		<?php /* Balance Amount */ ?>
		<div class="widget widget-table">
			<div class="widget-header">
				<h3><i class="fa fa-table"></i> Security Entry </h3>
			</div>
			<div class="widget-content">
				<table  class="table table-striped table-bordered" >
					<thead>
						<tr>
							<td>{{$LoanApplicantRec->lacc_securityentry}}</td>		
						</tr>
					</thead>
				</table>
			</div>
		</div>

</div>
		<?php /* Print */ ?>
		<div class="widget widget-table">
			<div class="widget-header">
				<h3><i class="fa fa-table"></i> Print </h3>
			</div>
			<div class="widget-content">
				<table  class="table table-striped table-bordered" >
					<thead>
						<tr>
							<td>
							<center><button class="form-control" style="width: 250px;"  onclick="printDiv('divprint')">Print</button></center>
							</td>		
						</tr>
					</thead>
				</table>
			</div>
		</div>
<script>
function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;

     window.print();

     document.body.innerHTML = originalContents;
}
</script>