File: /home/cafsindia/.trash/application.1/views/loan/installment.php
<?php
//Monthly Installment Details
$tr_line = "";
$not_paid_amt = 0;
$i = 1;
foreach($install_result as $loan){
$installment_id = $loan->prime_loan_installment_id;
$loan_id = $loan->loan_id;
$category = $loan->category;
$emp_code = $loan->emp_code;
$loan_type = $loan->loan_type;
$loan_date = $loan->loan_date;
$apply_year = $loan->apply_year;
$loan_amount = $loan->loan_amount;
$interest_rate = $loan->interest_rate;
$number_of_installment = $loan->number_of_installment;
$per_month = $loan->per_month;
$total_amount = $loan->total_amount;
$installment_count = $loan->installment_count;
$install_amount = $loan->install_amount;
$install_year = $loan->install_year;
$paid_status = $loan->paid_status;
$install_month = $loan->install_month;
$tot_installment +=$install_amount;
// echo ("$loan_amount::::$install_amount"); die;
$curr_year = $payroll_month;
// if ($curr_year === $install_year && (int)$paid_status !== 1) {
// $read = '';
// $btn = "<button class='btn btn-sm btn-info' onclick=update_data('$installment_id','$loan_id','$loan_amount','$per_month','$installment_count','$number_of_installment','$install_year','$loan_type')>update</button>";
// }else{
// $read = 'readonly';
// $btn = ' ';
// }
if((int)$paid_status === 1){
$paid_status = 'Paid';
$read = 'readonly';
}else
if((int)$paid_status === 2){
$paid_status = 'Foreclosed';
$read = 'readonly';
}else{
$paid_status = 'Not Paid';
$read = '';
if(is_int($not_paid_amt)){
$not_paid_amt += (int)$install_amount;
}
}
if(empty($not_paid_amt)){
$not_paid_amt ="Fully Paid";
}
// <td>$btn</td>
$tr_line .= "<tr id='install_row_$installment_id'><input type='hidden' name='hid_install_id[]' value='$installment_id'>
<td style = 'text-align:center;'>$installment_count<input type='hidden' name='hid_installment[]' value='$installment_count'></td>
<td>$install_year <input type='hidden' name='hid_install_year[]' value='$install_year'></td>
<td><input class='numbersOnly form-control' type='text' name='install_amount[]' id='install_amount_$installment_id' value='$install_amount' $read/></td>
<td>$paid_status</td>";
$i++;
}
$last_install_year = date("Y-m-d",strtotime("01-".$install_year));
$next_installment = date('m-Y', strtotime('+1 month', strtotime($last_install_year)));
$tr_line .= "<td><button Onclick=add_new_row($installment_count,$installment_id,'$next_installment','$total_amount') class='btn btn-xs btn-info'><i class='fa fa-plus' aria-hidden='true'></i>Add New</button></td></tr>";
echo "<div style='padding:15px;'>
<div style='background-color: #FFFFFF !important; box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.2); border-radius: 3px; margin: 8px; padding: 8px;overflow: auto;'>
<table style='width:100%;'>
<tr>
<td style='white-space:nowrap;padding-right:10px;font-weight:bold;text-align: center;'>
<span style='color:#00b0eb !important;font-size:12px;'>Employee Code</span><br/>
$emp_code
</td>
<td style='white-space:nowrap;padding-right:10px;font-weight:bold;text-align: center;'>
<span style='color:#00b0eb !important;font-size:12px;'>Apply Month Year</span><br/>
$apply_year
</td>
<td style='white-space:nowrap;padding-right:10px;font-weight:bold;text-align: center;'>
<span style='color:#00b0eb !important;font-size:12px;'>Loan Amount</span><br/>
$install_amount
</td>
<td style='white-space:nowrap;padding-right:10px;font-weight:bold;text-align: center;'>
<span style='color:#00b0eb !important;font-size:12px;'>Total Amount</span><br/>
$total_amount
</td>
<td style='white-space:nowrap;padding-right:10px;font-weight:bold;text-align: center;'>
<span style='color:#00b0eb !important;font-size:12px;'>Remaining Balance Amount</span><br/>
$not_paid_amt
</td>
</tr>
</table>
</div>
<div id='installment' style='max-height:450px !important;overflow:auto !important;'>
<table id='installment_data' class='table table-bordered col-style' style='padding:10px;'>
<thead>
<tr>
<th>Installment Count</th>
<th>Installment Month and Year</th>
<th>Monthly Amount Deduct</th>
<th>Paid Status</th>
<th>Option</th>
</tr>
</thead>
<tbody>$tr_line</tbody>
<tfoot><tr><td></td><td><h5 style='font-weight:bold; text-align:center;'>Total</h5></td><td><h5 id='footer' style='font-weight:bold;'>$tot_installment</h5></td><td></td><td><button id='installment_submit' onclick=update_data('$installment_id','$loan_id','$loan_amount','$per_month','$installment_count','$number_of_installment','$install_year','$loan_type','$emp_code','$category','$loan_date','$apply_year','$interest_rate','$total_amount') class='btn btn-sm btn-primary'>Submit</button><button type='button' class='btn btn-sm btn-primary' style='margin-left:10px;' data-dismiss='modal' aria-label='Close' onclick='close_formfun()'><span aria-hidden='true'>Close</span></button></td>
</tr></tfoot>
</table>
</div>
</div>";
?>
<script type="text/javascript">
$(document).ready(function(){
jQuery('.numbersOnly').keyup(function () {
this.value = this.value.replace(/[^0-9\.]/g,'');
});
$(document).on("input",'input[name="install_amount[]"]',function() {
this.value = this.value.replace(/[^0-9\.]/g,'');
var install_amt = $('input[name="install_amount[]"]').map(function(){return $(this).val();}).get();
var total = 0;
for (var i = 0; i < install_amt.length; i++) {
total += install_amt[i] << 0;
}
$('#installment_data #footer').html(total);
});
});
function add_new_row(row_count,installment_id,next_installment,total_amount){
var row_count = row_count+1;
var last_tr = $("#installment_data").find("tr").last();
count = $('#installment_data tr').length - 1;
var installment_id = "0";
var today = "01-"+next_installment;
var future_mnth = moment(today, 'DD-MM-YYYY').format('YYYY-MM');
var future = moment(future_mnth).add(1, 'M').format('MM-YYYY');
var install_amt = $('input[name="install_amount[]"]').map(function(){return $(this).val();}).get();
var total = 0;
for (var i = 0; i < install_amt.length; i++) {
total += install_amt[i] << 0;
}
total = parseInt(total);
if(total_amount <= total ){
toastr.error("Loan amount matched with install Amount. Could not able to create a new installment..");
return false;
}
$('tbody tr button').parent().remove();
var data;
data+="<tr><td style='text-align:center;'>" + (row_count) + "<input type='hidden' name='hid_install_id[]' value='0'><input type='hidden' name='hid_installment[]' value='"+ (row_count) +"'></td><td >"+next_installment+"<input type='hidden' name='hid_install_year[]' value='"+next_installment+"'></td><td><input type='text' name='install_amount[]' class='numbersOnly form-control'><input type='hidden' name='hid_install_amt[]' class='numbersOnly form-control'></td><td >Not Paid</td><td ><button Onclick=add_new_row("+row_count+","+installment_id+",'"+future+"','"+total_amount+"') class='btn btn-xs btn-info'><i class='fa fa-plus' aria-hidden='true'></i>Add New</button></td>";
$('#installment_data').append(data);
row_count +=1;
var today = "01-"+next_installment;
var future_mnth = moment(today, 'DD-MM-YYYY').format('YYYY-MM');
var future = moment(future_mnth).add(1, 'M').format('DD-MM-YYYY');
}
function update_data(installment_id,loan_id,loan_amount,per_month,installment_count,installments,install_year,loan_type,emp_code,category,loan_date,apply_year,interest_rate,total_amount){
// var install_amount = $('#install_amount_'+installment_id).val();
var installment_year = $('input[name="hid_install_year[]"]').map(function(){return $(this).val();}).get();
var install_amount = $('input[name="install_amount[]"]').map(function(){return $(this).val();}).get();
var install_id = $('input[name="hid_install_id[]"]').map(function(){return $(this).val();}).get();
var install_count = $('input[name="hid_installment[]"]').map(function(){return $(this).val();}).get();
if(installment_id){
$.ajax({
type: 'POST',
url: '<?php echo site_url("$this->control_name/update_data");?>',
data:{loan_id:loan_id,installment_id:install_id,install_amount:install_amount,loan_amount:loan_amount,per_month:per_month,installment_count:install_count,installments:installments,install_year:installment_year,loan_type:loan_type,emp_code:emp_code,category:category,loan_date:loan_date,apply_year:apply_year,interest_rate:interest_rate,total_amount:total_amount},
success: function(data){
var rslt = JSON.parse(data);
if(rslt.success){
toastr.success(rslt.message);
$('.modal').modal('toggle');
$('#notify_list_model').modal('hide');
}else{
toastr.error(rslt.message);
}
}
});
}
}
/*var install_amount = $('#install_amount_'+installment_id).val();
var total_amount = '<?php echo $total_amount; ?>';
var pay_amt = $("input[name^='install_amount']").map(function (idx, ele) {
return $(ele).val();
}).get();
var pay_total = 0;
for (var i = 0; i < pay_amt.length; i++) {
pay_total += pay_amt[i] << 0;
}
if (install_amount.length === 0) {
toastr.error("Please enter amount?");
return false;
}
//if(parseInt(pay_total) < parseInt(total_amount)){
$.ajax({
type: 'POST',
url: '<?php //echo site_url("$this->control_name/edit_data");?>',
data:{installment_id:installment_id,install_amount:install_amount},
success: function(data){
var rslt = JSON.parse(data);
if(rslt.success){
toastr.success(rslt.message);
$("input[name^='install_amount']").prop("readonly", true);
$(".check").attr("disabled", true);
$(".close").attr("disabled", true);
$("#close").attr("disabled", true);
}else{
toastr.error(rslt.message);
}
bal_amt_cal();
}
});
/*}else{
alert("Your enter amount is more than total loan amount?");
}
}*/
/*
function bal_amt_cal(){
var loan_id = '<?php echo $loan_id; ?>';
var total_amount = '<?php echo $total_amount; ?>';
var install_amount = '<?php echo $install_amount; ?>';
var installment_id = '<?php echo $installment_id; ?>';
var next_installment = '<?php echo $next_installment; ?>';
var pay_amt = $("input[name^='install_amount']").map(function (idx, ele) {
return $(ele).val();
}).get();
var pay_total = 0;
for (var i = 0; i < pay_amt.length; i++) {
pay_total += pay_amt[i] << 0;
}
rslt_amt = parseInt(total_amount) - parseInt(pay_total);
last_amt = parseInt(install_amount) + parseInt(rslt_amt);
if(rslt_amt > 0){
tr = "<tr><td>"+next_installment+"</td><td>"+rslt_amt+"</td><td ><button id='save' class='btn btn-xs btn-primary' onclick=add_install("+loan_id+",'"+next_installment+"',"+rslt_amt+");> <i class='fa fa-file-o' aria-hidden='true'></i> Save</button></td><td><button id='cancel' class='btn btn-xs btn-danger' onclick=add_prev("+installment_id+","+last_amt+");> <i class='fa fa-file-o' aria-hidden='true'></i> Cancel</button></td></tr>";
$("#installment_data").append(tr);
}
}
function add_install(loan_id,next_installment,rslt_amt){
if(loan_id){
$.ajax({
type: 'POST',
url: '<?php //echo site_url("$this->control_name/add_install");?>',
data:{loan_id:loan_id,next_installment:next_installment,rslt_amt:rslt_amt},
success: function(data){
var rslt = JSON.parse(data);
if(rslt.success){
toastr.success(rslt.message);
}else{
toastr.error(rslt.message);
}
$('.modal').modal('toggle');
}
});
}
}
function add_prev(installment_id,last_amt){
if(installment_id){
$.ajax({
type: 'POST',
url: '<?php echo site_url("$this->control_name/add_prev");?>',
data:{installment_id:installment_id,last_amt:last_amt},
success: function(data){
var rslt = JSON.parse(data);
if(rslt.success){
toastr.success(rslt.msg);
}else{
toastr.error(rslt.msg);
}
$('.modal').modal('toggle');
}
});
}
}*/
</script>