<style>
.paymentmodal {
    width: 75%;
    margin: 30px auto;
}
</style>
<script src="assets/js/king-table.js"></script>
<script src="assets/js/popper.min.js"></script>
<link href='https://fonts.googleapis.com/css?family=Charm' rel='stylesheet'>
<?php
$LoanTotalPaid=0;
foreach($data['LoanApplicantRecords'] as $LoanApplicantRec)
{
	$lacc_id = $LoanApplicantRec->lacc_id;
	$lacc_no = $LoanApplicantRec->lacc_no;
}
?>
<div class="printreport">
<!-- MAIN CONTENT WRAPPER -->
<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 Account detail</h3>

<div class='btn-toolbar pull-right'>
    <div class='btn-group'>
      <button type='button' class='btn btn-primary' id="idreload" onclick="reloadpage('<?php echo $lacc_id; ?>','<?php echo $lacc_no; ?>')" ><i class="fa fa-refresh" aria-hidden="true"></i></button>
    </div>
</div>
<script>
//#Reload Starts here
function reloadpage(lacc_id,lacc_no)
{
	document.getElementById("idreload").innerHTML = "<i class='fa fa-refresh fa-spin' aria-hidden='true'></i>";
	$.ajax({
		url: 'LoanAcPanel',
		type: 'get',
		data:'&lacc_id='+lacc_id+'&lacc_no='+lacc_no,
		success: function(data)
		{
			$('#sideMenu').html(data);
			document.getElementById("idreload").innerHTML = "<i class='fa fa-refresh' aria-hidden='true'></i>";
		}
	});
}
//#Reload ends here
</script>
			</div>
			<div class="widget-content">
			<form id="frmLoanApplication" name="frmLoanApplication" data-parsley-validate novalidate method="POST">
				<table  class="table table-striped table-bordered">
					<?php  $i=1;?>
					<?php $__currentLoopData = $data['LoanApplicantRecords']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $LoanApplicantRec): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
					<?php $lacc_id = $LoanApplicantRec->lacc_id; ?>
<input type="hidden" name="lacc_id" id="lacc_id" value="<?php echo e($LoanApplicantRec->lacc_id); ?>">
<input type="hidden" name="lacc_no" id="lacc_no" value="<?php echo e($LoanApplicantRec->lacc_no); ?>">
<input type="hidden" name="lacc_custname" id="lacc_custname" value="<?php echo e($LoanApplicantRec->lacc_custname); ?>">
						<tr>
							<th>Application No.</th><td><b><?php echo $loanacc = $LoanApplicantRec->lacc_no; ?></b></td>	
							<th>Loan amount</th><td><b> <?php echo e($LoanApplicantRec->lacc_loanamt); ?></b></td>								
						</tr>						
						<tr>
							<th>Name</th><td><b><?php echo e($LoanApplicantRec->lacc_custname); ?></b></td>	
							<th>Tenor</th><td><b><?php echo e($LoanApplicantRec->lacc_tenor); ?> months</b></td>								
						</tr>
						<tr>
							<th>Branch</th><td><b><?php echo e($LoanApplicantRec->br_name); ?></b></td>	
							<th>Interest</th><td><b><?php echo e($LoanApplicantRec->lacc_intrate); ?>% (per year)</b></td>
						</tr>
						<tr><?php /* $LoanApplicantRec->br_name */ ?>
							<th>Loan Account date</th><td><b><?php echo  date("d-m-Y",strtotime($LoanApplicantRec->lacc_opendt)); ?></b></td>	
							<th>Delay Payment interest</th>
							<td><b><?php echo $LoanApplicantRec->dpmt_charge; ?>%</b></td>
						</tr>						
					<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>	
				</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>Date</th>					
						<th>Principal</th>							
						<th>Interest(%)</th>
						<th>Interest</th>							
						<th>Delay Payment</th>					
						<th>Others</th>						
						<th>EMI</th>							
						<th>Paid</th>
						<th>Balance</th>
						<th>Dig</th>
						<td>Rex</td>
					</tr>
				</thead>
				<tbody>	
				<?php					
					$totinterestamt =0;
					$tototheramt = 0;
					$totemiamt = 0;
					$totpaidamt = 0;
					$totbalamt = 0;
					$btn=0;
					$paid_amt = 0;
					$bal_amt=0;
					$totdelaypayment=0;
					$totpaiddecreaseonloop = $data['LoanTotalPaid'];
				?>
						<?php $__currentLoopData = $data['LoanInstallmentRecords']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $LoanInstallmentRec): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
						<?php
						$lins_amt=$LoanInstallmentRec->lins_amt;						
						$lins_iamt=$LoanInstallmentRec->lins_iamt;						
						$othr_amt=$LoanInstallmentRec->penaltysum;
						$delayamt=$LoanInstallmentRec->delayamt;
						$totamt = $lins_amt+$lins_iamt+$othr_amt+$delayamt;
						//Sum Total
						$totinterestamt = $totinterestamt +  $lins_iamt;
						$tototheramt = $tototheramt + $othr_amt;
						$totemiamt = $totemiamt+ ($lins_amt+$lins_iamt+$othr_amt+$delayamt);
						$totdelaypayment = $totdelaypayment + $delayamt;
						if($totpaiddecreaseonloop > $totamt)
						{
							$paid_amt=$totamt;
							$totpaiddecreaseonloop = $totpaiddecreaseonloop - $totamt;
						}
						else
						{
							$paid_amt = $totpaiddecreaseonloop;
							$totpaiddecreaseonloop = 0;
						}
												
						$bal_amt=$totamt-$paid_amt;
						
						$totpaidamt = $totpaidamt + $paid_amt;
						
				//Coding to Calculate days difference between two days start here	
				$currentdt = strtotime(date("Y-m-d")); //Current day
				$installmentdt = strtotime($LoanInstallmentRec->lins_date); //Installment day
				$datediff = $currentdt - $installmentdt;				
				$daysdifference =  round($datediff / (60 * 60 * 24)) ;
				if($daysdifference >=0)
				{
					if($bal_amt > 0)
					{
						$daysdifference=$daysdifference;
					}
					else
					{
						$daysdifference=0;
					}
				}
				else
				{
					$daysdifference =0;
				}
				//Coding to Calculate days difference between two days ends here
						?>
						<tr  
						<?php
						if($bal_amt > 0)
						{
						echo 'style="color:red;"';
						}
						else
						{
						echo 'style="color:green;"';
						}
						?>
						>
							<td><?php echo e($LoanInstallmentRec->lins_no); ?></td><!-- SL No. -->
							<td><?php echo date("d-m-Y",strtotime($LoanInstallmentRec->lins_date)); ?></td><!-- Installment dt -->
							<td><?php echo e($LoanInstallmentRec->lins_amt); ?></td><!-- Principle Amt -->
							<td><?php echo e($LoanInstallmentRec->lins_iperc); ?>%</td>    <!-- Interest -->
							<td><?php echo e($LoanInstallmentRec->lins_iamt); ?></td>  <!-- Interest Amt -->
							<td>
<?php 
if($daysdifference>0)
{
?>							
	<button class="btn btn-warning btn-xs"  data-toggle="modal"  id="<?php echo e($LoanInstallmentRec->lins_id); ?>" data-target="#myDelayPayment"><?php echo e($LoanInstallmentRec->delayamt); ?></button>
<?php
}
else
{
?>
	<?php echo e($LoanInstallmentRec->delayamt); ?>

<?php
}
?>
[<?php echo $daysdifference; ?> Days]
							</td><!-- Delay Payment -->
							<td>
							<?php
							if($bal_amt > 0)
							{
							?>
							<button class="btn btn-danger btn-xs"  data-toggle="modal"  id="<?php echo e($LoanInstallmentRec->lins_id); ?>" data-target="#myotheramt"><?php echo " " . $LoanInstallmentRec->penaltysum; ?></button>
							<?php
							}
							else
							{
								echo " " . $LoanInstallmentRec->penaltysum;
							}							
							?>
							</td>  <!-- Others Amt -->
							<td> <?php echo $totamt; ?></td><!-- EMI Amt -->
							<td>							
							<?php
							if($bal_amt > 0)
							{
							?>
							<button class="btn btn-primary btn-xs"  data-toggle="modal"  id="<?php echo e($LoanInstallmentRec->lins_id); ?>" data-target="#mypayment" ><?php echo $paid_amt; ?></button>
							<?php
							}
							else
							{
							?>
							<?php echo $paid_amt; ?>
							<?php
							}
							?>
							</td><!-- Paid Amt -->
							<td><b> <?php echo $bal_amt; ?></b></td><!-- Balance Amt -->
							<td><button class="btn btn-info btn-xs"  data-toggle="modal"  id="<?php echo e($LoanInstallmentRec->lins_id); ?>" data-target="#viewreport" ><span class='fa fa-list'></span></button></td>
							<td><button class="btn btn-info btn-xs"  onclick="loadreport('<?php echo $LoanInstallmentRec->lins_id; ?>')" ><span class='fa fa-book'></span></button></td>
						</tr>
						<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
				</tbody>
				<tfoot>
						<th></th>
						<th></th>					
						<th><?php echo e($LoanApplicantRec->lacc_loanamt); ?></th>							
						<th></th>
						<th><?php echo $totinterestamt; ?></th>			
						<th><?php echo $totdelaypayment; ?></th>					
						<th><?php echo $tototheramt; ?></th>								
						<th><?php echo $totemiamt; ?></th>							
						<th><?php echo $data['LoanTotalPaid']; ?></th>		
						<th><?php echo $totemiamt-$data['LoanTotalPaid']; ?></th>
						<th></th>
						<th></th>
				</tfoot>
				</table>
			</div>
		</div>

		<!-- END DATA EXPORT -->

				<div class="widget">
					<div class="widget-header">
	<center>
		<button class="btn btn-info btn-default" onclick="loadcrdrreport('<?php echo $lacc_id; ?>')" ><span class="fa fa-area-chart"></span> CR-DR</button>
		
		<button class="btn btn-info btn-default" onclick="loadsinglecustreport('<?php echo $lacc_id; ?>')" ><span class="fa fa-folder-open-o"></span> Transaction Report</button>
		
		<button class="btn btn-info btn-default" onclick="funLoanPreClosure('<?php echo $lacc_id; ?>','<?php echo $loanacc; ?>')" ><span class="fa fa-pencil-square-o"></span> Update</button>
		
		<button class="btn btn-info btn-default" onclick="funSingleTransactionRPT('<?php echo $lacc_id; ?>','<?php echo $loanacc; ?>')" ><span class="fa fa-flag"></span> Logs</button>
	</center>
					</div>
				</div>
		</form>					
	</div>
</div>
<!-- /main -->

<!-- Modal starts here -->		
<div class="container">

  <!-- The Modal Other amount starts here-->
  <div class="modal" id="myotheramt">
    <div class="modal-dialog">
      <div class="modal-content">
      
        <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Other Charges</h4>
        </div>
        
        <!-- Modal body -->
        <div class="modal-body">
			<form id="frmothercharges" name="frmothercharges" data-parsley-validate novalidate>
					<input type="hidden" name="_token2" id="_token2" value="<?php echo e(csrf_token()); ?>">
					<input type="hidden" name="lacc_id2" id="lacc_id2">
					<input type="hidden" name="lins_id2" id="lins_id2">
				<div class="row">
					<div class="col-md-12">
						<div class="form-group">
							<label for="multiselect1">Select type*</label>
							<br/>
							<select name="penaltytype" id="penaltytype" class="form-control" required> 
								<option value=""> -- Select -- </option>
								<?php
								$arr = array("Cheque Bounce", "Case", "Others");
								foreach($arr as $val)
								{
									echo "<option value='$val'>$val</option>";
								}
								?>
							</select>
							<small class="text-danger" id="err_penaltytype"></small>
						</div>
						<div class="form-group">
							<label for="text-input1">Date</label>
							<input type="date" name="penaltydate" id="penaltydate" class="form-control" value="<?php echo date("Y-m-d"); ?>" >					
							<small class="text-danger" id="err_penaltydate"></small>
						</div>
						<div class="form-group">
							<label for="multiselect1">Amount.</label>
							<input type="text" name="penaltyamt" id="penaltyamt" class="form-control" >					
							<small class="text-danger" id="err_penaltyamt"></small>
						</div>
						<div class="form-group">
							<label for="text-input1">Any note</label>
							<input type="text" name="penaltynote" id="penaltynote" class="form-control" >					
							<small class="text-danger" id="err_penaltynote"></small>
						</div>
					</div>
				</div>
			</form>
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
		  <button type="button" class="btn btn-primary btnloanpenalty">Submit</button>
        </div>
        
      </div>
    </div>
  </div>
  <!-- The Modal Other amount ends here -->
  
<!-- The Modal Delay Payment starts here-->
  <div class="modal" id="myDelayPayment">
    <div class="modal-dialog">
      <div class="modal-content">
      
        <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Delay Payment</h4>
        </div>
        
        <!-- Modal body -->
        <div class="modal-body">
			<form id="frmothercharges" name="frmothercharges" data-parsley-validate novalidate>
					<input type="hidden" name="_token2" id="_token2" value="<?php echo e(csrf_token()); ?>">
					<input type="hidden" name="lacc_id3" id="lacc_id3">
					<input type="hidden" name="lins_id3" id="lins_id3">
				<div class="row">
					<div>
					
			<div class="form-group col-md-12">
				<label for="multiselect1">Total EMI Amount.</label>
				<input type="text" name="dpmtemiamt" id="dpmtemiamt" class="form-control"  onkeyup="updatedelaypayment()" onchange="updatedelaypayment()" >
				<small class="text-danger" id="err_dpmtemiamt"></small>
			</div>
			
			<div class="form-group col-md-4">
				<label for="text-input1">From Date</label>
				<input type="date" name="dpmtfdt" id="dpmtfdt" class="form-control"  onkeyup="updatedelaypayment()" onchange="updatedelaypayment()" >					
				<small class="text-danger" id="err_dpmtfdt"></small>
			</div>
			
			<div class="form-group col-md-4">
				<label for="text-input1">To Date </label>
				<input type="date" name="dpmttdt" id="dpmttdt" class="form-control" value="<?php echo date("Y-m-d"); ?>"  onkeyup="updatedelaypayment()" onchange="updatedelaypayment()">					
				<small class="text-danger" id="err_dpmttdt"></small>
			</div>
						
			<div class="form-group col-md-4">
				<label for="text-input1">No. of Days </label>
				<input type="number" name="dpmtnodays" id="dpmtnodays" class="form-control" readonly >					
				<small class="text-danger" id="err_dpmtnodays"></small>
			</div>

			<div class="form-group col-md-6">
				<label for="text-input1">Delay Payment interest(%)</label>
				<input type="text" name="dpmtdelayinterest" id="dpmtdelayinterest" class="form-control" value="0"  onkeyup="updatedelaypayment()" onchange="updatedelaypayment()">	<small class="text-danger" id="err_dpmtdelayinterest"></small>
			</div>
				
			<div class="form-group col-md-6">
				<label for="multiselect1">Total Penalty Amount.</label>
				<input type="text" name="dpmttotpenaltyamt" id="dpmttotpenaltyamt" class="form-control" value="0"   >
				<small class="text-danger" id="dpmt_totpenaltyamt"></small>
			</div>
						
					</div>
				</div>
			</form>
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
		  <button type="button" class="btn btn-primary btndpmttotpenaltyadd">Submit</button>
        </div>
        
      </div>
    </div>
  </div>
<!-- The Modal Delay Payment ends here-->
  
  <!-- ###### The Modal payment amount starts here ###### -->
  <div class="modal" id="mypayment">
    <div class="modal-dialog paymentmodal">
      <div class="modal-content">
      
        <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Make Payment</h4>
        </div>
        
        <!-- Modal body -->
        <div class="modal-body">
			<form id="frmpayment" name="frmpayment" data-parsley-validate novalidate>
					<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
					<input type="hidden" name="lacc_id1" id="lacc_id1">
					<input type="hidden" name="lins_id1" id="lins_id1">
				<div class="row">
					<div class="col-md-4">
						<div class="form-group">
							<label for="text-input1">Current Balance</label>
							<input type="text" name="currentpayable" id="currentpayable" class="form-control" readonly >					
							<small class="text-danger" id="err_currentpayable"></small>
						</div>
						<div class="form-group">
							<label for="multiselect1">Previous Balance</label>
							<input type="text" name="previousbalance" id="previousbalance" class="form-control" readonly>					
							<small class="text-danger" id="err_previousbalance"></small>
						</div>
						<div class="form-group">
							<label for="multiselect1">Total payable</label>
							<input type="text" name="totalpayable" id="totalpayable" class="form-control" readonly >					
							<small class="text-danger" id="err_totalpayable"></small>
						</div>
					</div>
					<div class="col-md-4">
						<div class="form-group">
							<label for="text-input1">Transaction No.*</label>
							<input type="text" name="ltr_billno" id="ltr_billno" class="form-control" >					
							<small class="text-danger" id="err_ltr_billno"></small>
						</div>
						
						<div class="form-group">
							<label for="text-input1">Transaction Date.*</label>
							<input type="date" name="ltr_transdt" id="ltr_transdt" class="form-control" value="<?php echo  date("Y-m-d"); ?>" >					
							<small class="text-danger" id="err_ltr_transdt"></small>
						</div>
						<div class="form-group">
							<label for="multiselect1">Paid Amount.</label>
							<input type="text" name="ltr_amt" id="ltr_amt" class="form-control" onkeyup="calculatebal()" >					
							<small class="text-danger" id="err_ltr_amt"></small>
						</div>
						
						<div class="form-group">
							<label for="multiselect1">Balance Amount.</label>
							<input type="text" name="balanceamt" id="balanceamt" class="form-control" readonly>					
							<small class="text-danger" id="err_balanceamt"></small>
						</div>
						
					</div>
					<div class="col-md-4">
						<div class="form-group">
							<label for="multiselect1">Payment type*</label>
							<br/>
							<select name="ltr_paymenttype" id="ltr_paymenttype" class="form-control" required> 
								<option value=""> -- Select -- </option>
								<?php
								$arr = array("Cash", "Cheque", "NEFT", "Others");
								foreach($arr as $val)
								{
									echo "<option value='$val'>$val</option>";
								}
								?>
							</select>
							<small class="text-danger" id="err_ltr_paymenttype"></small>
						</div>
						<div class="form-group">
							<label for="multiselect1">Cheque No.</label>
							<input type="text" name="ltr_chqno" id="ltr_chqno" class="form-control" >					
							<small class="text-danger" id="err_ltr_chqno"></small>
						</div>
						<div class="form-group">
							<label for="text-input1">Bank Name</label>
							<input type="text" name="ltr_bank" id="ltr_bank" class="form-control" >					
							<small class="text-danger" id="err_ltr_bank"></small>
						</div>	
					</div>
				</div>
				<div class="row">
					<div class="col-md-12">
						<div class="form-group">
							<label for="text-input1">Any other note</label>
							<input type="text" name="ltr_note" id="ltr_note" class="form-control" >					
							<small class="text-danger" id="err_ltr_note"></small>
						</div>
					</div>
				</div>
			</form>
        </div>
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button> 
		  <button type="button" class="btn btn-primary btnloanpayment">Make Payment</button>
        </div>
        
      </div>
    </div>
  </div>
  <!-- ###### The Modal payment amount ends here ###### -->
  
  <!-- ###### The Modal payment amount starts here ###### -->
  <div class="modal" id="viewreport">
    <div class="modal-dialog paymentmodal">
      <div class="modal-content">
      
        <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">View Report</h4>
        </div>
        
        <!-- Modal body -->
        <div class="modal-body" id="rptsingle">
			
		</div>
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button> 
        </div>
        
      </div>
    </div>
  </div>
  <!-- ###### The Modal payment amount ends here ###### -->
  
<!-- ###### The Modal Payment Receipt starts here ###### -->
<div class="modal" id="modprintpaymentreceipt">
		<div class="modal-dialog paymentmodal">
		  <div class="modal-content">
		  
			<!-- Modal Header -->
			<div class="modal-header">
			  <h4 class="modal-title">Payment Receipt...</h4>
			</div>
			
			<!-- Modal body -->
			<div class="modal-body" id="divbillprint">
				<!-- PRINT RECEIPT START HERE -->
<div class="widget widget-table">
	<div class="widget-content">

		<div class="col-md-12">
			<center><h3><img src="img/navachethana-logo.png" >Navachethana Finance Company (Regd.)</h3><br>
				<p>"Beauty Plaza" Building, Ground Floor, Balmatta Road, mangalore-575001<br>
				<b>Phone : 0824 - 4255640 Mobile No. 7760833500</b></p></center>
			<hr>
		</div>

		<div class="col-md-3"><h3 style="font-size: 22px;"><b>No.</b><label id="receiptbillno"></label></h3></div>
		<div class="col-md-3"><center><h3 style="font-size: 22px;"><b><ul>RECEIPT</ul></b></h3></center></div>
		<div class="col-md-3 text-right"><br><b style="font-size: 22px;">Date:</b><label id="receiptdate" style="font-size: 20px;">00-00-0000</label></div>

		<div class="col-md-12"></div>

		<div class="col-md-12"><h3 style="font-family: 'Charm';font-size: 22px;">Received with thanks from  <label id="receiptname" style="text-decoration: underline;" >Loading</label> </h3></div>

		<div class="col-md-12"></div>

		<div class="col-md-12"><h3 style="font-family: 'Charm';font-size: 22px;">the sum of Rupees <label id="textsum" style="text-decoration: underline;" ></label></h3> </div>

		<div class="col-md-12"></div>

		<div class="col-md-12"><h1 style="font-family: 'Charm';font-size: 22px;">towards Loan A/C No. <label id="receiptlacc_no" style="text-decoration: underline;" ></label></h1> </div>

		<div class="col-md-12"></div>

		<div class="col-md-8"><h1 style="font-family: 'Charm';font-size: 22px;">by <label id="receiptpaytype" style="text-decoration: underline;" ></label></h1></div><div class="col-md-4"><h1 style="font-family: 'Charm';font-size: 22px;">Dated <label id="receiptdate1" style="text-decoration: underline;" >00-00-0000</label></h1></div>

		<div class="col-md-12"></div>

		<div class="col-md-12"><h1 style="font-family: 'Charm';font-size: 22px;">towards <label id="receipttowards" style="text-decoration: underline;" ></label></h1> </div>

		<div class="col-md-12">&nbsp;<br>&nbsp;</div>

		<div class="col-md-6"><h1 style="border:1px solid #cecece;">Rs. <label id="receiptamt"  ></label>*</h2>Subject to realisation</div><div class="col-md-6 text-right">For <b>NAVACHETHANA FINANCE COMPANY (REGD.)</b> <br><br><br><br>
		Authorised Signatury
		</div>
	</div>
</div>
<!-- PRINT RECEIPT ENDS HERE -->
			</div>
			<!-- Modal footer -->
			<div class="modal-footer">			
				<button type="button" class="btn btn-primary"  onclick="printDiv('divbillprint')">Print</button>
				<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button> 
			</div>
			
		  </div>
		</div>
</div>
<!-- ###### The Modal Payment Receipt ends here ###### -->
  
  <!-- ###### The Modal Cancellation starts here ###### -->
  <div class="modal" id="modcancellation">
    <div class="modal-dialog paymentmodal">
      <div class="modal-content">
      
        <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Cancellation card</h4>
        </div>
        
        <!-- Modal body -->
        <div class="modal-body">
			<form id="frmcancellation" name="frmcancellation" data-parsley-validate novalidate>
			<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
			<div id="rptCancellation"></div>
				<div class="row">
					<div class="col-md-12">
						<div class="form-group">
							<label for="text-input1">Title</label>
							<input type="text" name="ltr_cancellationtype" id="ltr_cancellationtype" class="form-control" >					
							<small class="text-danger" id="err_ltr_cancellationtype"></small>
						</div>
						<div class="form-group">
							<label for="ltr_cancellationreason">Note</label>
							<textarea  name="ltr_cancellationreason" id="ltr_cancellationreason" class="form-control" ></textarea>
							<small class="text-danger" id="err_ltr_cancellationreason"></small>
						</div>
					</div>
				</div>
			</form>
		</div>
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
		  <button type="button" class="btn btn-primary btncancel">Confirm Cancellation</button>		  
        </div>
        
      </div>
    </div>
  </div>
  <!-- ###### The Modal Cancellation amount ends here ###### -->
  
</div>
<!-- Modal ends here -->
</div>
<script>
	$('.createMod').click(function(e)
	{
		e.preventDefault();
		$('#sideMenu').load($(this).attr('href'));
	});
	
	$('.edit').click(function(e)
	{
		e.preventDefault();
		$('#sideMenu').load($(this).attr('href')); 
	});
	
	$('#mypayment').on('show.bs.modal', function(e) {
        var $modal = $(this),
            lins_id = e.relatedTarget.id;
        $.ajax({
            cache: false,
            type: 'GET',
            url: 'loanpaymentcalculation',
            data: 'lins_id=' + lins_id,
            success: function(data) {
				var Obj=JSON.parse(data);	
				$('#lacc_id1').val($("input[name='lacc_id']").val());
				$('#lins_id1').val(lins_id);
				var CurrentPayableAmt =Obj.CurrentPayableAmt;
				var PreviousPayableAmt =Obj.PreviousPayableAmt;
				var TotalPayableAmt =Obj.TotalPayableAmt;
				$('#currentpayable').val(CurrentPayableAmt);
				$('#previousbalance').val(PreviousPayableAmt);
				$('#totalpayable').val(TotalPayableAmt);
            }
        });
    })
	
	$('#myotheramt').on('show.bs.modal', function(e) {
        var $modal = $(this),
            lins_id = e.relatedTarget.id;
        $.ajax({
            cache: false,
            type: 'GET',
            url: 'loanpaymentcalculation',
            data: 'lins_id=' + lins_id,
            success: function(data) {
				var Obj=JSON.parse(data);	
				$('#lacc_id2').val($("input[name='lacc_id']").val());
				$('#lins_id2').val(lins_id);
            }
        });
    })
	
	
	$('#myDelayPayment').on('show.bs.modal', function(e) {
        var $modal = $(this),
            lacc_id = $("input[name='lacc_id']").val();
            lins_id = e.relatedTarget.id;
        $.ajax({
            cache: false,
            type: 'GET',
            url: 'loandelaypaymentcalculation',
            data: 'lacc_id=' + lacc_id + '&lins_id=' + lins_id,
            success: function(data) {
				var Obj=JSON.parse(data);	
				$('#lacc_id3').val($("input[name='lacc_id']").val());
				$('#lins_id3').val(lins_id);
				$('#dpmtemiamt').val(Obj.CurrentPayableAmt);
				$('#dpmtdelayinterest').val(Obj.delaypmt_charge);
				$('#dpmtfdt').val(Obj.lins_date);
				$('#dpmtnodays').val(Obj.nodays);
				$('#dpmttotpenaltyamt').val(Obj.totaldelaysum);
            }
        });
    })
	
	//updatedelaypayment() lacc_id3 lins_id3 dpmtemiamt dpmtfdt dpmtnodays  dpmttdt dpmtdelayinterest
	function updatedelaypayment() 
	{
        var $modal = $(this),
            lacc_id = $("input[name='lacc_id3']").val();
            lins_id = $("input[name='lins_id3']").val();
            dpmtemiamt = $("input[name='dpmtemiamt']").val();
            dpmtfdt = $("input[name='dpmtfdt']").val();
            dpmtnodays = $("input[name='dpmtnodays']").val();
            dpmttdt = $("input[name='dpmttdt']").val();
            dpmtdelayinterest = $("input[name='dpmtdelayinterest']").val();
        $.ajax({
            cache: false,
            type: 'GET',
            url: 'loandelaypaymentrecalculation',
            data: 'lacc_id=' + lacc_id + '&lins_id=' + lins_id + '&dpmtemiamt=' + dpmtemiamt + '&dpmtfdt=' + dpmtfdt + '&dpmtnodays=' + dpmtnodays + '&dpmttdt=' + dpmttdt + '&dpmtdelayinterest=' + dpmtdelayinterest,
            success: function(data) {
				var Obj=JSON.parse(data);
				$('#dpmtnodays').val(Obj.nodays);
				$('#dpmttotpenaltyamt').val(Obj.totaldelaysum);
            }
        });
	}
	
	//### Payment submission entry code starts here
	flag=0;
	$('.btnloanpayment').click(function(e)
	{
		e.preventDefault();
		_token = $("input[name='_token']").val();		           
		var lacc_id1 = $("input[name='lacc_id1']").val();
		var lins_id1 = $("input[name='lins_id1']").val();
		var ltr_transdt = $("input[name='ltr_transdt']").val();
		var currentpayable = $("input[name='currentpayable']").val();
		var previousbalance = $("input[name='previousbalance']").val();
		var totalpayable = $("input[name='totalpayable']").val();
		var ltr_amt = $("input[name='ltr_amt']").val();
		var balanceamt = $("input[name='balanceamt']").val();
		var ltr_billno = $("input[name='ltr_billno']").val();
		var ltr_chqno = $("input[name='ltr_chqno']").val();
		var ltr_paymenttype = $('#ltr_paymenttype').val();
		var ltr_bank = $("input[name='ltr_bank']").val();
		var ltr_note = $("input[name='ltr_note']").val();
		if(ltr_billno == "" )
		{
			alert("Transaction No. Should not be empty...");
		}
		else if(ltr_transdt == "" )
		{
			alert("Transaction Date Should not be empty...");
		}
		else if(ltr_amt == "" )
		{
			alert("Paid Amount. Should not be empty...");
		}
		else if(parseFloat(ltr_amt) < parseFloat(previousbalance) )
		{
			alert("Paid amount should be greater than Previous balance...");
		}
		else if(ltr_paymenttype == "" )
		{
			alert("Payment type should not be empty...");
		}
		else
		{
			$.ajax({
				url: "loaninstallmentpayment",
				type:'POST',
				dataType: 'json',
				//cache : false,
				//processData: false,
				data: {_token:_token,lacc_id:lacc_id1, lins_id:lins_id1, ltr_transdt:ltr_transdt, ltr_transtype:"Payment", ltr_billno:ltr_billno, ltr_amt:ltr_amt, ltr_paymenttype:ltr_paymenttype, ltr_chqno:ltr_chqno, ltr_bank:ltr_bank, ltr_note:ltr_note, ltr_status:"Active"},
				success: function(data)
				{
					if(data.status == "Success")
					{
						alert("Loan payment done successfully..");
						//$('#sideMenu').load('viewloanaccount');
						LoadLoanApplication(lacc_id1,lins_id1);
						$('#mypayment').modal('toggle');
					}
					else
					{
						alert("Failed to Generate Purchase Bill..");
						//printErrorMsg(data.message)
					}
				}
			});
		}
	});
	//### Payment submission entry code ends here
	
	function LoadLoanApplication(b,acno)
	{
		$.ajax({
			url: 'LoanAcPanel',
			type: 'GET',
			data:'&lacc_id='+b+'&acno='+acno,
			success: function(data)
			{
				$('#sideMenu').html(data);
			}
		});
	}
	
	//### Penalty submission entry code starts here
	$('.btnloanpenalty').click(function(e)
	{
		//_token2 lacc_id2 lins_id2 penaltydate penaltytype  penaltyamt penaltynote
		e.preventDefault();
		_token = $("input[name='_token2']").val();		           
		var lacc_id1 = $("input[name='lacc_id2']").val();
		var lins_id1 = $("input[name='lins_id2']").val();
		var ltr_transdt = $("input[name='penaltydate']").val();
		var penaltytype = $('#penaltytype').val();
		var currentpayable = 0;
		var previousbalance = 0;
		var totalpayable = 0;
		var ltr_amt = $("input[name='penaltyamt']").val();
		var balanceamt = 0;
		var ltr_billno = 0;
		var ltr_chqno = '';
		var ltr_paymenttype = '';
		var ltr_bank = '';
		var ltr_note = $("input[name='penaltynote']").val();
		if(penaltytype == "" )
		{
			alert("Type Should not be empty...");
		}
		else if(ltr_transdt == "" )
		{
			alert("Date Should not be empty...");
		}
		else if(ltr_amt == "" )
		{
			alert("Amount should not be empty...");
		}
		else
		{
			$.ajax({
				url: "loaninstallmentpayment",
				type:'POST',
				dataType: 'json',
				//cache : false,
				//processData: false,
				data: {_token:_token,lacc_id:lacc_id1, lins_id:lins_id1, ltr_transdt:ltr_transdt, ltr_transtype:penaltytype, ltr_billno:ltr_billno, ltr_amt:ltr_amt, ltr_paymenttype:ltr_paymenttype, ltr_chqno:ltr_chqno, ltr_bank:ltr_bank, ltr_note:ltr_note, ltr_status:"Active"},
				success: function(data)
				{
					if(data.status == "Success")
					{
						alert("Other charges added successfully..");
						LoadLoanApplication(lacc_id1,lins_id1);
						$('#myotheramt').modal('toggle');
					}
					else
					{
						alert("Failed to Generate Purchase Bill..");
					}
				}
			});
		}
	});
	//### Penalty submission entry code ends here
	
	//Preclosure starts here
	function funLoanPreClosure(lacc_id,lacc_no)
	{
		$.ajax({
			url: 'loanAccountPreclosure',
			type: 'GET',
			data:'&lacc_id='+lacc_id+'&lacc_no='+lacc_no,
			success: function(data)
			{
				$('#sideMenu').html(data);
			}
		});
	}
	//Preclosure ends here
	
	//View Report starts here
	$('#viewreport').on('show.bs.modal', function(e) {
        var $modal = $(this),
            lins_id = e.relatedTarget.id;
        $.ajax({
            cache: false,
            type: 'GET',
            url: 'loanrptsingle',
            data: 'lins_id=' + lins_id,
            success: function(data) {
				$('#rptsingle').html(data);
            }
        });
    })
	//View Report ends here
	
	//Load Loan Cancellation Starts here
	$('#modcancellation').on('show.bs.modal', function(e) {
        var $modal = $(this),
            ltr_id = e.relatedTarget.id;
        $.ajax({
            cache: false,
            type: 'GET',
            url: 'loanCancellationLoad',
            data: 'ltr_id=' + ltr_id,
            success: function(data) {
				$('#rptCancellation').html(data);
            }
        });
    })
	//Load Loan Cancellation Ends here
	
	//loanCancellation insert
	flag=0;
	$('.btncancel').click(function(e)
	{
		e.preventDefault();
		_token = $("input[name='_token']").val();	           
		var ltr_id = $("input[name='ltr_id']").val();
		var lacc_id = $("input[name='lacc_id']").val();
		var lins_id = $("input[name='lins_id']").val();
		var ltr_cancellationtype = $("input[name='ltr_cancellationtype']").val();
		var ltr_cancellationreason = $('#ltr_cancellationreason').val();
		if(ltr_cancellationtype == "" )
		{
			alert("Cancellation type Should not be empty...");
		}
		else
		{
			$.ajax({
				url: "loaninstallmentcancellationins",
				type:'POST',
				dataType: 'json',
				//cache : false,
				//processData: false,
				data: {_token:_token,ltr_id:ltr_id, lacc_id:lacc_id, lins_id:lins_id, ltr_cancellationtype:ltr_cancellationtype, ltr_cancellationreason:ltr_cancellationreason},
				success: function(data)
				{
					if(data.status == "Success")
					{
						alert("Loan Cancellation done successfully..");
						$('#modcancellation').modal('toggle');
						//############
						reloadcancelmodal(lins_id,lacc_id);
						//############
					}
					else
					{
						alert("Failed to Generate Purchase Bill..");
						//printErrorMsg(data.message)
					}
				}
			});
		}
	});
	
//Coding to manually add penaltyamt starts here 
	$('.btndpmttotpenaltyadd').click(function(e)
	{
		e.preventDefault();
		_token = $("input[name='_token']").val();	  
		var lacc_id = $("input[name='lacc_id3']").val();
		var lins_id = $("input[name='lins_id3']").val();
		var dpmtemiamt = $("input[name='dpmtemiamt']").val();
		var dpmtfdt = $("input[name='dpmtfdt']").val();
		var dpmttdt = $("input[name='dpmttdt']").val();
		var dpmtnodays = $("input[name='dpmtnodays']").val();
		var dpmtdelayinterest = $("input[name='dpmtdelayinterest']").val();
		var dpmttotpenaltyamt = $("input[name='dpmttotpenaltyamt']").val();
		if(dpmttotpenaltyamt <= 0)
		{
			alert("Penalty amount not valid...");
		}
		else
		{
			$.ajax({
				url: "AddManualPenalty",
				type:'POST',
				dataType: 'json',
				//cache : false,
				//processData: false,
				data: {_token:_token,lacc_id:lacc_id, lins_id:lins_id, dpmtemiamt:dpmtemiamt, dpmtfdt:dpmtfdt, dpmttdt:dpmttdt, dpmtnodays:dpmtnodays, dpmtdelayinterest:dpmtdelayinterest, dpmttotpenaltyamt:dpmttotpenaltyamt},
				success: function(data)
				{
					if(data.status == "Success")
					{
						alert("Loan Cancellation done successfully..");
						$('#myDelayPayment').modal('toggle');
						LoadLoanApplication(lacc_id,lins_id);
					}
					else
					{
						alert("Failed to Generate Purchase Bill..");
						//printErrorMsg(data.message)
					}
				}
			});
		}
	});
	
	function reloadcancelmodal(lins_id,lacc_id)
	{
		var $modal = $(this),
            lins_id = lins_id;
        $.ajax({
            cache: false,
            type: 'GET',
            url: 'loanrptsingle',
            data: 'lins_id=' + lins_id,
            success: function(data) {
				$('#rptsingle').html(data);
            }
        });		
	}
	
	$('#viewreport').on('hidden.bs.modal', function () {	           
		var lacc_id = $("input[name='lacc_id']").val();
		var lacc_no = $("input[name='lacc_no']").val();		 
			LoadLoanApplication(lacc_id,lacc_no);
	})
	
	function funSingleTransactionRPT(lacc_id,acno)
	{
		$.ajax({
			url: 'RPTSingleTrans',
			type: 'GET',
			data:'&lacc_id='+lacc_id+'&acno='+acno,
			success: function(data)
			{
				$('#sideMenu').html(data);
			}
		});
	}
	
	function loadreport(lins_id)
	{
		$.ajax({
			url: 'LoanEMIreport',
			type: 'GET',
			data:'&lins_id='+lins_id,
			success: function(data)
			{
				$('.printreport').html(data);
			}
		});
	}
	
	function loadsinglecustreport(lacc_id)
	{
		$.ajax({
			url: 'LoanSingleCustomerReport',
			type: 'GET',
			data:'&lacc_id='+lacc_id,
			success: function(data)
			{
				$('.printreport').html(data);
			}
		});
	}
	
	//Credit Debit Report starts here
	function loadcrdrreport(lacc_id)
	{
		$.ajax({
			url: 'rptCreditDebit',
			type: 'GET',
			data:'&lacc_id='+lacc_id,
			success: function(data)
			{
				$('#sideMenu').html(data);
			}
		});
	}
	//Credit Debit Report ends here
	
	//Make payment - Show Balance amount starts here
	function calculatebal()
	{
		document.getElementById("balanceamt").value= parseFloat(document.getElementById("totalpayable").value) - parseFloat(document.getElementById("ltr_amt").value);
	}
	//Make payment - Show Balance amount ends here
	
	//Payment Receipt starts here
	function funPaymentReceipt(billno,dt,amt,textamt,paytype,lins_no,towards)
	{
		document.getElementById("receiptbillno").innerHTML=billno;
		document.getElementById("receiptdate").innerHTML=dt;
		document.getElementById("receiptdate1").innerHTML=dt;
		document.getElementById("textsum").innerHTML=textamt;
		document.getElementById("receiptpaytype").innerHTML=paytype;
		document.getElementById("receiptname").innerHTML=document.getElementById("lacc_custname").value;
		document.getElementById("receiptlacc_no").innerHTML=document.getElementById("lacc_no").value;
		document.getElementById("receipttowards").innerHTML=towards;
		document.getElementById("receiptamt").innerHTML=amt;
		$('#modprintpaymentreceipt').modal({show:true});		 
	}
	//Payment Receipt ends here

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>
	
</script>