Skip to content

Instantly share code, notes, and snippets.

@esmeromichael
Created March 2, 2017 03:14
Show Gist options
  • Save esmeromichael/056e89b9d3bf66c0f2fee7b43a6f38a8 to your computer and use it in GitHub Desktop.
Save esmeromichael/056e89b9d3bf66c0f2fee7b43a6f38a8 to your computer and use it in GitHub Desktop.
$('.finalize').on('click',function(){
var row = $('.receipts_app tr').filter(':has(:checkbox:checked)').length;
var total = parseFloat($('.grandtotal').val())
var type = $('.receipt_type option:selected').val();
var rowEwt = $('.ewt_app tr').filter(':has(:checkbox:checked)').length;
var totalEwt = parseFloat($('input.available').val());
if(type == "Payment"){
if(total < 0){
$('.flash-message').empty();
$('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Available is below zero.</p>');
return false;
}
else{
if(row > 0){
return true;
}
else{
$('.flash-message').empty();
$('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">No billing selected.</p>');
return false;
}
}
}
else{
if(totalEwt < 0){
$('.flash-message').empty();
$('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Available is below zero.</p>');
return false;
}
else{
if(rowEwt > 0){
return true;
}
else{
$('.flash-message').empty();
$('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">No billing selected.</p>');
return false;
}
}
}
});
$('.ewt_compute').on('change',function(e){
var type = e.target.value;
var ewttype = $('.ewt_compute option:selected').val();
$('table.secondtable thead.partner_label tr').each(function(){
$(this).closest('tr').find('.headcheck').prop('checked',false);
});
$('table.secondtable tbody.receipts_app tr').each(function(){
$(this).closest('tr').find('.app_amount').val('0.00');
$(this).closest('tr').find('.detailscheck').prop('checked',false);
$(this).closest('tr').find('.check_ewt').prop('checked',false);
$(this).closest('tr').find('.details_ewt').val('0.00');
$(this).closest('tr').find('.details_gross_val').val('0.00');
$(this).closest('tr').find('.details_billtotal_val').val('0.00');
$(this).closest('tr').find('.details_applied_val').val('0.00');
$(this).closest('tr').find('.details_balance_val').val('0.00');
if(type == "auto"){
$(this).closest('tr').find('.app_amount').prop('readonly',true);
$(this).closest('tr').find('.details_ewt').prop('readonly',true);
}
else{
$(this).closest('tr').find('.app_amount').prop('readonly',false);
$(this).closest('tr').find('.details_ewt').prop('readonly',false);
}
granddeducttotal();
});
});
$('table.secondtable thead.partner_label').on('click','.headcheck', function(){
var rec_total = $('.totalAmount').val();
//var rec_total = rec_tot.toFixed(2);
var total = 0;
var total2 = 0;
var partner_id = $(this).val();
var ewt_comp = $('.ewt_compute').val();
$('.flash-message').empty();
if(ewt_comp == "auto"){
if(rec_total > 0){
if($(this).is(':checked')){
var total = 0;
var total2 = 0;
var subtotal = 0;
var subtotal2 = 0;
var total_ewt = 0;
var balance = 0;
var sub_total = 0;
var tot = [];
$(this).closest('tr').parent().parent().find('td .detailscheck').each(function(){
var bal = parseFloat($(this).closest('tr').find(".balance").val());
var ewt = parseFloat($(this).closest('tr').find('.sub_ewt').val());
var amount = parseFloat(bal) - parseFloat(ewt);
$(this).closest('tr.'+partner_id+'').find(".app_amount2").val(amount.toFixed(2));
$(this).closest('tr.'+partner_id+'').find(".app_amount").val(amount.toFixed(2));
$(this).closest('tr').find('.details_ewt').val(ewt.toFixed(2));
granddeducttotal();
});
var avail = $('input.grandtotal').val();
total = parseFloat(avail).toFixed(2);
// if(total >= 0){
$(this).closest('tr').parent().parent().find('td .detailscheck').each(function(){
var bal = parseFloat($(this).closest('tr').find(".balance").val());
var gross = parseFloat($(this).closest('tr').find(".details_gross").text());
var billtotal = parseFloat($(this).closest('tr').find(".details_billtotal").text());
var applied = parseFloat($(this).closest('tr').find(".details_applied").text());
var that = this;
var bill_id = $(this).closest('tr').find('.bill_id').val();
var bill_type = $(this).closest('tr').find('.bill_type').val();
var ewt = parseFloat($(this).closest('tr').find('.sub_ewt').val());
$(this).closest('tr.'+partner_id+'').find(".detailscheck").prop('checked', true);
$(this).closest('tr.'+partner_id+'').find(".check_ewt").prop('checked', true);
$(this).closest('tr.'+partner_id+'').find(".details_gross_val").val(gross);
$(this).closest('tr.'+partner_id+'').find(".details_billtotal_val").val(billtotal);
$(this).closest('tr.'+partner_id+'').find(".details_applied_val").val(applied);
$(this).closest('tr.'+partner_id+'').find(".details_balance_val").val(bal);
$(this).closest('tr.'+partner_id+'').find('.details_vat').addClass('detailsvat');
$(this).closest('tr.'+partner_id+'').find('.detailscheck').attr('name','checks[]');
$(this).closest('tr.'+partner_id+'').find('.app_amount').attr('name','app_amount[]');
$(this).closest('tr.'+partner_id+'').find('.type').attr('name','type[]');
$(this).closest('tr.'+partner_id+'').find('.bill_id').attr('name','bill_id[]');
$(this).closest('tr.'+partner_id+'').find('.details_partner_id').attr('name','details_partner_id[]');
$(this).closest('tr.'+partner_id+'').find('.details_ewt').attr('name','details_ewt[]');
granddeducttotal();
});
// }
// else{
// $('.flash-message').empty();
// $('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Available is below zero.</p>');
// $(this).closest('tr').parent().parent().find('td .detailscheck').each(function(){
// $(this).closest('tr.'+partner_id+'').find('.check_ewt').prop('checked', false);
// $(this).closest('tr.'+partner_id+'').find(".detailscheck").prop('checked', false);
// $(this).closest('tr.'+partner_id+'').find('.detailscheck').removeAttr('name');
// $(this).closest('tr.'+partner_id+'').find('.app_amount').removeAttr('name');
// $(this).closest('tr.'+partner_id+'').find('.type').removeAttr('name');
// $(this).closest('tr.'+partner_id+'').find('.bill_id').removeAttr('name');
// $(this).closest('tr.'+partner_id+'').find('.details_vat').removeClass('detailsvat');
// $(this).closest('tr.'+partner_id+'').find('.details_partner_id').removeAttr('name');
// $(this).closest('tr.'+partner_id+'').find('.details_ewt').removeAttr('name');
// granddeducttotal();
// });
// }
}
else{
$(this).closest('tr').parent().parent().find('td .detailscheck').each(function(){
$(this).closest('tr.'+partner_id+'').find('.check_ewt').prop('checked', false);
$(this).closest('tr.'+partner_id+'').find(".details_ewt").val('0.00');
$(this).closest('tr.'+partner_id+'').find(".detailscheck").prop('checked', false);
$(this).closest('tr.'+partner_id+'').find(".app_amount").val("0.00");
$(this).closest('tr.'+partner_id+'').find(".app_amount2").val("0.00");
$(this).closest('tr.'+partner_id+'').find(".details_gross_val").val("0.00");
$(this).closest('tr.'+partner_id+'').find(".details_billtotal_val").val("0.00");
$(this).closest('tr.'+partner_id+'').find(".details_applied_val").val("0.00");
$(this).closest('tr.'+partner_id+'').find(".details_balance_val").val("0.00");
$(this).closest('tr.'+partner_id+'').find('.detailscheck').removeAttr('name');
$(this).closest('tr.'+partner_id+'').find('.app_amount').removeAttr('name');
$(this).closest('tr.'+partner_id+'').find('.type').removeAttr('name');
$(this).closest('tr.'+partner_id+'').find('.bill_id').removeAttr('name');
$(this).closest('tr.'+partner_id+'').find('.details_vat').removeClass('detailsvat');
$(this).closest('tr.'+partner_id+'').find('.details_partner_id').removeAttr('name');
$(this).closest('tr.'+partner_id+'').find('.details_ewt').removeAttr('name');
granddeducttotal();
});
}
}
else{
$('.flash-message').empty();
$('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Please add Amount.</p>');
}
}
else{
if(rec_total > 0){
if($(this).is(':checked')){
var total = 0;
var subtotal = 0;
$(this).closest('tr').parent().parent().find('td .detailscheck').each(function(){
var bal = $(this).closest('tr').find(".balance").val();
var gross = $(this).closest('tr').find(".details_gross").text();
var billtotal = $(this).closest('tr').find(".details_billtotal").text();
var applied = $(this).closest('tr').find(".details_applied").text();
var amount = $(this).closest('tr').find(".balance").val();
total += parseFloat(amount);
if(rec_total >= total){
$(this).closest('tr.'+partner_id+'').find(".detailscheck").prop('checked', true);
$(this).closest('tr.'+partner_id+'').find(".app_amount").val(parseFloat(bal).toFixed(2));
$(this).closest('tr.'+partner_id+'').find(".app_amount2").val(parseFloat(bal).toFixed(2));
$(this).closest('tr.'+partner_id+'').find(".details_gross_val").val(gross);
$(this).closest('tr.'+partner_id+'').find(".details_billtotal_val").val(billtotal);
$(this).closest('tr.'+partner_id+'').find(".details_applied_val").val(applied);
$(this).closest('tr.'+partner_id+'').find(".details_balance_val").val(bal);
$(this).closest('tr.'+partner_id+'').find('.check_ewt').prop('checked', false);
$(this).closest('tr.'+partner_id+'').find(".details_ewt").val('0.00');
$(this).closest('tr.'+partner_id+'').find(".details_vat").addClass('detailsvat');
granddeducttotal();
$(this).closest('tr.'+partner_id+'').find('.detailscheck').attr('name','checks[]');
$(this).closest('tr.'+partner_id+'').find('.app_amount').attr('name','app_amount[]');
$(this).closest('tr.'+partner_id+'').find('.type').attr('name','type[]');
$(this).closest('tr.'+partner_id+'').find('.bill_id').attr('name','bill_id[]');
$(this).closest('tr.'+partner_id+'').find('.details_partner_id').attr('name','details_partner_id[]');
$(this).closest('tr.'+partner_id+'').find('.details_ewt').attr('name','details_ewt[]');
}
else{
$(this).closest('tr').parent().parent().find('td .detailscheck:checked').each(function(){
var bals = $(this).closest('tr').find(".balance").val();
subtotal += parseFloat(bals)
});
if(subtotal <= rec_total){
$(this).closest('tr.'+partner_id+'').find(".detailscheck").prop('checked', true);
$(this).closest('tr.'+partner_id+'').find(".app_amount").val(parseFloat(bal).toFixed(2));
$(this).closest('tr.'+partner_id+'').find(".app_amount2").val(parseFloat(bal).toFixed(2));
$(this).closest('tr.'+partner_id+'').find(".details_gross_val").val(gross);
$(this).closest('tr.'+partner_id+'').find(".details_billtotal_val").val(billtotal);
$(this).closest('tr.'+partner_id+'').find(".details_applied_val").val(applied);
$(this).closest('tr.'+partner_id+'').find(".details_balance_val").val(bal);
$(this).closest('tr.'+partner_id+'').find('.check_ewt').prop('checked', false);
$(this).closest('tr.'+partner_id+'').find(".details_ewt").val('0.00');
$(this).closest('tr.'+partner_id+'').find(".details_vat").addClass('detailsvat');
granddeducttotal();
$(this).closest('tr.'+partner_id+'').find('.detailscheck').attr('name','checks[]');
$(this).closest('tr.'+partner_id+'').find('.app_amount').attr('name','app_amount[]');
$(this).closest('tr.'+partner_id+'').find('.type').attr('name','type[]');
$(this).closest('tr.'+partner_id+'').find('.bill_id').attr('name','bill_id[]');
$(this).closest('tr.'+partner_id+'').find('.details_partner_id').attr('name','details_partner_id[]');
$(this).closest('tr.'+partner_id+'').find('.details_ewt').attr('name','details_ewt[]');
}
else{
}
}
});
}
else{
$(this).closest('tr').parent().parent().find('td .detailscheck').each(function(){
$(this).closest('tr.'+partner_id+'').find('.check_ewt').prop('checked', false);
$(this).closest('tr.'+partner_id+'').find(".details_ewt").val('0.00');
$(this).closest('tr.'+partner_id+'').find(".detailscheck").prop('checked', false);
$(this).closest('tr.'+partner_id+'').find(".app_amount").val("0.00");
$(this).closest('tr.'+partner_id+'').find(".app_amount2").val("0.00");
$(this).closest('tr.'+partner_id+'').find(".details_grossoss_val").val("0.00");
$(this).closest('tr.'+partner_id+'').find(".details_billtotal_val").val("0.00");
$(this).closest('tr.'+partner_id+'').find(".details_applied_val").val("0.00");
$(this).closest('tr.'+partner_id+'').find(".details_balance_val").val("0.00");
$(this).closest('tr.'+partner_id+'').find('.detailscheck').removeAttr('name');
$(this).closest('tr.'+partner_id+'').find('.app_amount').removeAttr('name');
$(this).closest('tr.'+partner_id+'').find('.type').removeAttr('name');
$(this).closest('tr.'+partner_id+'').find('.bill_id').removeAttr('name');
$(this).closest('tr.'+partner_id+'').find(".details_vat").removeClass('detailsvat');
$(this).closest('tr.'+partner_id+'').find('.details_partner_id').removeAttr('name');
$(this).closest('tr.'+partner_id+'').find('.details_ewt').removeAttr('name');
granddeducttotal();
});
}
}
else{
$('.flash-message').empty();
$('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Please add Amount.</p>');
}
}
});
$('table.secondtable tbody.receipts_app').on('click','.detailscheck', function () {
var rec_total = parseFloat($('.totalAmount').val()).toFixed(2);
var total = 0;
var sub_total = 0;
var total_app = 0;
var total_app2 = 0;
var bal = parseFloat($(this).closest('tr').find(".balance").val()).toFixed(2);
var gross = parseFloat($(this).closest('tr').find(".details_gross").text()).toFixed(2);
var billtotal = parseFloat($(this).closest('tr').find(".details_billtotal").text()).toFixed(2);
var applied = parseFloat($(this).closest('tr').find(".details_applied").text()).toFixed(2);
var bill_id = $(this).closest('tr').find('.bill_id').val();
var bill_type = $(this).closest('tr').find('.bill_type').val();
var that = this;
var bals = parseFloat($(this).closest('tr').find(".balance").val());
var ewt = parseFloat($(this).closest('tr').find('.sub_ewt').val());
var amount = parseFloat(bals) - parseFloat(ewt);
$('.detailscheck:checked').each(function(){
var balance = $(this).closest('tr').find('.balance').val();
total += parseFloat(balance);
});
// for amount only
//
$('.flash-message').empty();
var ewt_type = $('.ewt_compute').val();
if(ewt_type == "auto"){
if(rec_total > 0){
if($(this).is(':checked')){
if(rec_total >= total){
$(this).prop('checked', true);
$(this).closest('tr').find(".app_amount2").val(parseFloat(bal).toFixed(2));
$(this).closest('tr').find(".details_gross_val").val(gross);
$(this).closest('tr').find(".details_billtotal_val").val(billtotal);
$(this).closest('tr').find(".details_applied_val").val(applied);
$(this).closest('tr').find(".details_balance_val").val(bal);
$(this).closest('tr').find(".details_vat").addClass('detailsvat');
// $.get('/dev/api/getEWT?bill_id=' +bill_id+'&bill_type='+bill_type, function(data){
// $(that).closest('tr').find('.app_amount').val(parseFloat(amount).toFixed(2));
// $(that).closest('tr').find('.details_ewt').val(parseFloat(ewt).toFixed(2));
// granddeducttotal();
// });
$(this).closest('tr').find('.app_amount').val(parseFloat(amount).toFixed(2));
$(this).closest('tr').find('.details_ewt').val(parseFloat(ewt).toFixed(2));
$(this).closest('tr').find('.check_ewt').prop('checked', true);
$(this).closest('tr').find('.detailscheck').attr('name','checks[]');
$(this).closest('tr').find('.app_amount').attr('name','app_amount[]');
$(this).closest('tr').find('.type').attr('name','type[]');
$(this).closest('tr').find('.bill_id').attr('name','bill_id[]');
$(this).closest('tr').find('.details_partner_id').attr('name','details_partner_id[]');
$(this).closest('tr').find('.details_ewt').attr('name','details_ewt[]');
}
else{
$('.detailscheck:checked').each(function(){
var app_amt = $(this).closest('tr').find('.app_amount').val();
total_app += parseFloat(app_amt);
total_app2 = total_app.toFixed(2);
});
var mike = rec_total - total_app2;
// if(parseFloat(bal) > parseFloat(mike).toFixed(2)){
// $('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Insufficient Amount.</p>');
// $(this).prop('checked', false);
// $(this).closest('tr').find(".app_amount").val("0.00");
// $(this).closest('tr').find(".app_amount2").val("0.00");
// $(this).closest('tr').find(".details_gross_val").val("0.00");
// $(this).closest('tr').find(".details_billtotal_val").val("0.00");
// $(this).closest('tr').find(".details_applied_val").val("0.00");
// $(this).closest('tr').find(".details_balance_val").val("0.00");
// $(this).closest('tr').find('.detailscheck').removeAttr('name');
// $(this).closest('tr').find('.app_amount').removeAttr('name');
// $(this).closest('tr').find('.type').removeAttr('name');
// $(this).closest('tr').find('.bill_id').removeAttr('name');
// $(this).closest('tr').find('.details_partner_id').removeAttr('name');
// $(this).closest('tr').find('.details_ewt').removeAttr('name');
// $(this).closest('tr').find(".details_vat").removeClass('detailsvat');
// $(this).closest('tr').find('.check_ewt').prop('checked', false);
// $(this).closest('tr').find('.details_ewt').val('0.00');
// granddeducttotal();
// }
// else{
$(this).prop('checked', true);
$(this).closest('tr').find(".app_amount").val(parseFloat(bal).toFixed(2));
$(this).closest('tr').find(".app_amount2").val(parseFloat(bal).toFixed(2));
$(this).closest('tr').find(".details_gross_val").val(gross);
$(this).closest('tr').find(".details_billtotal_val").val(billtotal);
$(this).closest('tr').find(".details_applied_val").val(applied);
$(this).closest('tr').find(".details_balance_val").val(bal);
$(this).closest('tr').find(".details_vat").addClass('detailsvat');
// $.get('/dev/api/getEWT?bill_id=' +bill_id+'&bill_type='+bill_type, function(data){
// $(that).closest('tr').find('.app_amount').val(parseFloat(bal - data).toFixed(2));
// $(that).closest('tr').find('.details_ewt').val(parseFloat(data).toFixed(2));
// granddeducttotal();
// });
$(this).closest('tr').find('.app_amount').val(parseFloat(amount).toFixed(2));
$(this).closest('tr').find('.details_ewt').val(parseFloat(ewt).toFixed(2));
$(this).closest('tr').find('.check_ewt').prop('checked', true);
$(this).closest('tr').find('.detailscheck').attr('name','checks[]');
$(this).closest('tr').find('.app_amount').attr('name','app_amount[]');
$(this).closest('tr').find('.type').attr('name','type[]');
$(this).closest('tr').find('.bill_id').attr('name','bill_id[]');
$(this).closest('tr').find('.details_partner_id').attr('name','details_partner_id[]');
$(this).closest('tr').find('.details_ewt').attr('name','details_ewt[]');
// }
}
granddeducttotal();
}
else{
$(this).prop('checked', false);
$(this).closest('tr').find(".app_amount").val("0.00");
$(this).closest('tr').find(".app_amount2").val("0.00");
$(this).closest('tr').find(".details_gross_val").val("0.00");
$(this).closest('tr').find(".details_billtotal_val").val("0.00");
$(this).closest('tr').find(".details_applied_val").val("0.00");
$(this).closest('tr').find(".details_balance_val").val("0.00");
$(this).closest('tr').find('.detailscheck').removeAttr('name');
$(this).closest('tr').find('.app_amount').removeAttr('name');
$(this).closest('tr').find('.type').removeAttr('name');
$(this).closest('tr').find('.bill_id').removeAttr('name');
$(this).closest('tr').find('.details_partner_id').removeAttr('name');
$(this).closest('tr').find(".details_vat").removeClass('detailsvat');
$(this).closest('tr').find('.details_ewt').removeAttr('name');
$(this).closest('tr').find('.check_ewt').prop('checked', false);
$(this).closest('tr').find('.details_ewt').val('0.00');
granddeducttotal();
}
}
else{
$(this).closest('tr').find('.detailscheck').prop('checked',false);
$('.flash-message').empty();
$('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Please add Amount.</p>');
}
}
else{
if(rec_total > 0){
if($(this).is(':checked')){
if(rec_total >= total){
$(this).prop('checked', true);
$(this).closest('tr').find(".app_amount").val(parseFloat(bal).toFixed(2));
$(this).closest('tr').find(".app_amount2").val(parseFloat(bal).toFixed(2));
$(this).closest('tr').find(".details_gross_val").val(gross);
$(this).closest('tr').find(".details_billtotal_val").val(billtotal);
$(this).closest('tr').find(".details_applied_val").val(applied);
$(this).closest('tr').find(".details_balance_val").val(bal);
$(this).closest('tr').find(".details_vat").addClass('detailsvat');
granddeducttotal();
$(this).closest('tr').find('.detailscheck').attr('name','checks[]');
$(this).closest('tr').find('.app_amount').attr('name','app_amount[]');
$(this).closest('tr').find('.type').attr('name','type[]');
$(this).closest('tr').find('.bill_id').attr('name','bill_id[]');
$(this).closest('tr').find('.details_partner_id').attr('name','details_partner_id[]');
$(this).closest('tr').find('.details_ewt').attr('name','details_ewt[]');
}
else{
$('.detailscheck:checked').each(function(){
var bala = $(this).closest('tr').find('.app_amount').val();
sub_total += parseFloat(bala);
});
if(parseFloat(sub_total).toFixed(2) == parseFloat(rec_total).toFixed(2)){
$('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Insufficient Amount.</p>');
$(this).prop('checked', false);
$(this).closest('tr').find(".app_amount").val("0.00");
$(this).closest('tr').find(".app_amount2").val("0.00");
$(this).closest('tr').find(".details_gross_val").val("0.00");
$(this).closest('tr').find(".details_billtotal_val").val("0.00");
$(this).closest('tr').find(".details_applied_val").val("0.00");
$(this).closest('tr').find(".details_balance_val").val("0.00");
$(this).closest('tr').find('.detailscheck').removeAttr('name');
$(this).closest('tr').find('.app_amount').removeAttr('name');
$(this).closest('tr').find('.type').removeAttr('name');
$(this).closest('tr').find('.bill_id').removeAttr('name');
$(this).closest('tr').find('.details_partner_id').removeAttr('name');
$(this).closest('tr').find('.details_ewt').removeAttr('name');
$(this).closest('tr').find('.check_ewt').prop('checked', false);
$(this).closest('tr').find('.details_ewt').val('0.00');
granddeducttotal();
}
else{
$(this).closest('tr').find(".app_amount").val(parseFloat(bal).toFixed(2));
$(this).closest('tr').find(".app_amount2").val(parseFloat(bal).toFixed(2));
$(this).closest('tr').find(".details_gross_val").val(gross);
$(this).closest('tr').find(".details_billtotal_val").val(billtotal);
$(this).closest('tr').find(".details_applied_val").val(applied);
$(this).closest('tr').find(".details_balance_val").val(bal);
granddeducttotal();
$(this).closest('tr').find('.detailscheck').attr('name','checks[]');
$(this).closest('tr').find('.app_amount').attr('name','app_amount[]');
$(this).closest('tr').find('.type').attr('name','type[]');
$(this).closest('tr').find('.bill_id').attr('name','bill_id[]');
$(this).closest('tr').find('.details_partner_id').attr('name','details_partner_id[]');
$(this).closest('tr').find('.details_ewt').attr('name','details_ewt[]');
}
}
}
else{
$(this).prop('checked', false);
$(this).prop('disabled', false);
$(this).closest('tr').find(".app_amount").val("0.00");
$(this).closest('tr').find(".app_amount2").val("0.00");
$(this).closest('tr').find(".details_gross_val").val("0.00");
$(this).closest('tr').find(".details_billtotal_val").val("0.00");
$(this).closest('tr').find(".details_applied_val").val("0.00");
$(this).closest('tr').find(".details_balance_val").val("0.00");
$(this).closest('tr').find('.detailscheck').removeAttr('name');
$(this).closest('tr').find('.app_amount').removeAttr('name');
$(this).closest('tr').find('.type').removeAttr('name');
$(this).closest('tr').find('.bill_id').removeAttr('name');
$(this).closest('tr').find('.details_partner_id').removeAttr('name');
$(this).closest('tr').find('.details_ewt').removeAttr('name');
$(this).closest('tr').find(".details_vat").removeClass('detailsvat');
$(this).closest('tr').find('.check_ewt').prop('checked', false);
$(this).closest('tr').find('.details_ewt').val('0.00');
granddeducttotal();
}
}
else{
$(this).closest('tr').find('.detailscheck').prop('checked',false);
$('.flash-message').empty();
$('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Please add Amount.</p>');
}
}
});
$('table.secondtable tbody.receipts_app').on('click','.check_ewt',function(e){
//var bill_id = e.target.value;
var that = this;
var amount = $(this).closest('tr').find('.app_amount').val();
var amount2 = $(this).closest('tr').find('.app_amount2').val();
var bill_total = $(this).closest('tr').find('.details_billtotal_val').val();
$('.flash-message').empty();
var total = 0;
var gross = $(this).closest('tr').find('.details_gross_val').val();
var bill_id = $(this).closest('tr').find('.bill_id').val();
var bill_type = $(this).closest('tr').find('.bill_type').val();
if(amount > 0){
if($(that).is(':checked')){
$.get('/dev/api/getEWT?bill_id='+bill_id+'&bill_type='+bill_type, function(data){
// var tax_rate = 1 + parseFloat(data[1] / 100);
// var whtaxrate = data[0]
// var wh = 0.00;
// var fwh = 0.00;
// if(bill_total == amount){
// wh = parseFloat(gross / parseFloat(tax_rate).toFixed(2));
// }
// else{
// wh = parseFloat(amount / parseFloat(tax_rate).toFixed(2));
// }
// //wh = parseFloat(gross / parseFloat(tax_rate).toFixed(2));
fwh = parseFloat(data);
$(that).closest('tr').find('.details_ewt').val(parseFloat(fwh).toFixed(2));
$(that).closest('tr').find('.app_amount').val(parseFloat(amount - fwh).toFixed(2));
granddeducttotal();
});
}
else{
$(this).closest('tr').find('.details_ewt').val('0.00');
//$(this).closest('tr').find('.details_ewt').removeAttr('name');
$(this).closest('tr').find('.app_amount').val(amount2);
granddeducttotal();
}
}
else{
granddeducttotal();
$(this).prop('checked',false);
$('.flash-message').empty();
$('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Please add Amount.</p>');
}
});
$('table.secondtable tbody.receipts_app').on('click','.details_ewt', function(e){
var bill_id = $(this).closest('tr').find('.bill_id').val();
var bill_type = $(this).closest('tr').find('.bill_type').val();
$('.ewtmodalheader').empty();
$('.flash-message').empty();
$('.ewtmodal').empty();
$('.ewtmodalheader').append('<button type="button" class="close" data-dismiss="modal">&times;</button>\
<h4><b> Bill No. '+pad(bill_id,8)+' </b></h4>');
if(bill_type == "Order"){
$.get('/dev/api/getDeliveryDetails?bill_id=' + bill_id, function(data){
$.each(data, function(index, del){
$('.ewtmodal').append('<div class="container" style="border:1px solid #8c8c8c;margin-bottom:15px;border-radius:3px;"><div class="form-horizontal" style="margin-bottom:10px;">\
<div class="form-group">\
\
<div class="col-sm-12">\
<table class="table table-hover" width="100%">\
<thead>\
<tr>\
<th>Delivery No.</th>\
<th>SO No.</th>\
<th>Vat Amount</th>\
<th>Vatable Sales</th>\
<th>Vat Exempt</th>\
<th>Zero Rated</th>\
<th>None</th>\
<tr>\
</thead>\
<tbody>\
<tr>\
<td>'+pad(del.dr_id,8)+'</td>\
<td>'+pad(del.header_id,8)+'</td>\
<td>'+parseFloat(del.vat_amount).toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2})+'</td>\
<td>'+parseFloat(del.vat_sales).toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2})+'</td>\
<td>'+parseFloat(del.vat_exempt).toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2})+'</td>\
<td>'+parseFloat(del.zero_rated).toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2})+'</td>\
<td>'+parseFloat(del.none).toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2})+'</td>\
</tr>\
</tbody>\
</table>\
</div>\
<label class="control-label col-sm-2"></label>\
<div class="col-sm-12" style="">\
<table class="table table-striped table-hover" width="100%">\
<thead style="">\
<tr>\
<th width="25%">Items</th>\
<th width="7%" style="text-align:center;">Qty.</th>\
<th width="10%" style="text-align:right;">Net Price</th>\
<th width="10%" style="text-align:center;">Tax Type</th>\
<th width="20%" style="text-align:center;">WthTax Type</th>\
<th width="15%" style="text-align:center;">WthTax Rate</th>\
<th width="12%" style="text-align:right;">Total</th>\
</tr>\
</thead>\
<tbody class="dtl_ewt'+del.header_id+'">\
</tbody>\
</table>\
</div>\
</div></div></div>');
});
});
setTimeout(function(){
$.get('/dev/api/getDeliverItemDetails?bill_id=' + bill_id, function(data2){
$.each(data2, function(index, delitems){
$('tbody.dtl_ewt'+delitems.head_ref_no+'').append('\
<tr>\
<td style="" class="cuts">'+delitems.item_name+'</td>\
<td style="text-align:center;">'+delitems.qty+'</td>\
<td style="text-align:right;">'+parseFloat(delitems.price).toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2})+'</td>\
<td style="text-align:center;">'+delitems.tax_type+'</td>\
<td style="text-align:center;" class="cuts">'+delitems.sales_acct+'</td>\
<td style="text-align:center;">'+parseFloat(delitems.rate).toFixed(2)+'</td>\
<td style="text-align:right;">'+parseFloat(delitems.total_amt).toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2})+'</td>\
</tr>');
});
});
}, 100);
}
else{
$.get('/dev/api/getDeliveryDetails?bill_id=' + bill_id, function(data){
if(!data || data == ""){
$.get('/dev/api/getProjectDetails?bill_id=' + bill_id, function(data2){
$.each(data2, function(index, dels){
$('.ewtmodal').append('<div class="container" style="border:1px solid #8c8c8c;margin-bottom:15px;border-radius:3px;"><div class="form-horizontal" style="margin-bottom:10px;">\
<div class="form-group" style="">\
\
<div class="col-sm-12">\
<table class="table table-hover" width="100%">\
<thead>\
<tr>\
<th>Project No.</th>\
<th>Vat Amount</th>\
<th>Vatable Sales</th>\
<th>Vat Exempt</th>\
<th>Zero Rated</th>\
<th>None</th>\
<tr>\
</thead>\
<tbody>\
<tr>\
<td>'+pad(dels.ref_no,8)+'</td>\
<td>'+dels.vat_amount+'</td>\
<td>'+dels.vat_sales+'</td>\
<td>'+dels.vat_exempt+'</td>\
<td>'+dels.zero_rated+'</td>\
<td>'+dels.none+'</td>\
</tr>\
</tbody>\
</table>\
</div>\
<label class="control-label col-sm-2"></label>\
<div class="col-sm-12" style="">\
<table class="table table-striped table-hover" width="100%">\
<thead>\
<tr>\
<th width="25%">Items</th>\
<th width="7%" style="text-align:center;">Qty.</th>\
<th width="10%" style="text-align:right;">Net Price</th>\
<th width="10%" style="text-align:center;">Tax Type</th>\
<th width="7%" style="text-align:center;">Tax Rate</th>\
<th width="20%" style="text-align:center;">WthTax Type</th>\
<th width="8%" style="text-align:center;">WthTax Rate</th>\
<th width="12%" style="text-align:right;">Total</th>\
</tr>\
</thead>\
<tbody class="dtl_ewt'+dels.ref_no+'">\
</tbody>\
</table>\
</div>\
</div>\
</div></div>');
});
});
setTimeout(function(){
$.get('/dev/api/getProjectItemDetails?bill_id=' + bill_id, function(data3){
$.each(data3, function(index, delitems){
$('tbody.dtl_ewt'+delitems.ref_no+'').append('\
<tr>\
<td style="" class="cuts">'+delitems.item_name+'</td>\
<td style="text-align:center;">'+delitems.qty+'</td>\
<td style="text-align:right;">'+parseFloat(delitems.price).toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2})+'</td>\
<td style="text-align:center;">'+delitems.tax_type+'</td>\
<td>'+delitems.vat_rate+'</td>\
<td style="text-align:center;" class="cuts">'+delitems.sales_acct+'</td>\
<td style="text-align:center;">'+parseFloat(delitems.rate).toFixed(2)+'</td>\
<td style="text-align:right;">'+parseFloat(delitems.total_amt).toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2})+'</td>\
</tr>');
});
});
}, 100);
}
else{
$.each(data, function(index, del){
$('.ewtmodal').append('<div class="container" style="border:1px solid #8c8c8c;margin-bottom:15px;border-radius:3px;"><div class="form-horizontal" style="margin-bottom:10px;">\
<div class="form-group" style="">\
\
<div class="col-sm-12">\
<table class="table table-hover" width="100%">\
<thead>\
<tr>\
<th>Delivery No.</th>\
<th>SO No.</th>\
<th>Vat Amount</th>\
<th>Vatable Sales</th>\
<th>Vat Exempt</th>\
<th>Zero Rated</th>\
<th>None</th>\
<tr>\
</thead>\
<tbody>\
<tr>\
<td>'+pad(del.dr_id,8)+'</td>\
<td>'+pad(del.header_id,8)+'</td>\
<td>'+del.vat_amount+'</td>\
<td>'+del.vat_sales+'</td>\
<td>'+del.vat_exempt+'</td>\
<td>'+del.zero_rated+'</td>\
<td>'+del.none+'</td>\
</tr>\
</tbody>\
</table>\
</div>\
<label class="control-label col-sm-2"></label>\
<div class="col-sm-12" style="">\
<table class="table table-striped table-hover" width="100%">\
<thead>\
<tr>\
<th width="25%">Items</th>\
<th width="7%" style="text-align:center;">Qty.</th>\
<th width="10%" style="text-align:right;">Net Price</th>\
<th width="10%" style="text-align:center;">Tax Type</th>\
<th width="20%" style="text-align:center;">WthTax Type</th>\
<th width="15%" style="text-align:center;">WthTax Rate</th>\
<th width="12%" style="text-align:right;">Total</th>\
</tr>\
</thead>\
<tbody class="dtl_ewt'+del.dr_id+'">\
</tbody>\
</table>\
</div>\
</div></div></div>');
});
setTimeout(function(){
$.get('/dev/api/getDeliverItemDetails?bill_id=' + bill_id, function(data2){
$.each(data2, function(index, delitems){
$('tbody.dtl_ewt'+delitems.dr_id+'').append('\
<tr>\
<td style="" class="cuts">'+delitems.item_name+'</td>\
<td style="text-align:center;">'+delitems.qty+'</td>\
<td style="text-align:right;">'+parseFloat(delitems.price).toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2})+'</td>\
<td style="text-align:center;">'+delitems.tax_type+'</td>\
<td style="text-align:center;" class="cuts">'+delitems.sales_acct+'</td>\
<td style="text-align:center;">'+parseFloat(delitems.rate).toFixed(2)+'</td>\
<td style="text-align:right;">'+parseFloat(delitems.total_amt).toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2})+'</td>\
</tr>');
});
});
}, 100);
}
});
}
});
$('table.secondtable tbody.receipts_app').on('change','.details_ewt',function(){
var ewt_type = $('.ewt_compute').val();
var balance = parseFloat($(this).closest('tr').find(".balance").val()).toFixed(2);
var amount = parseFloat($(this).closest('tr').find('.app_amount').val()).toFixed(2);
var dtl_ewt = parseFloat($(this).val()).toFixed(2);
var total_right = parseFloat(amount) + parseFloat(dtl_ewt);
var amount2 = balance - amount;
var amount3 = amount2.toFixed(2);
var rec_total = $('.totalAmount').val();
var grand_amount = $('.grand_amount').val();
var total = 0;
var sub_total = 0;
var total_ewt = 0;
var bal = $(this).closest('tr').find(".balance").val();
var gross = $(this).closest('tr').find(".details_gross").text();
var billtotal = $(this).closest('tr').find(".details_billtotal").text();
var applied = $(this).closest('tr').find(".details_applied").text();
$('.detailscheck:checked').each(function(){
var balance = $(this).closest('tr').find('.app_amount').val();
var ewt = $(this).closest('tr').find('.details_ewt').val();
total_ewt += parseFloat(ewt);
total += parseFloat(balance);
});
if(rec_total > 0){
var $this = $(this);
$this.val(parseFloat($this.val()).toFixed(2));
var amt_ewt = total_ewt + total;
if(amount > 0){
// if(amt_ewt < rec_total){
if(bal >= total_right){
$(this).closest('tr').find('.detailscheck').prop('checked',true);
$(this).closest('tr').find('.check_ewt').prop('checked',true);
$(this).closest('tr').find(".details_gross_val").val(gross);
$(this).closest('tr').find(".details_billtotal_val").val(billtotal);
$(this).closest('tr').find(".details_applied_val").val(applied);
$(this).closest('tr').find(".details_balance_val").val(bal);
$(this).closest('tr').find(".details_vat").addClass('detailsvat');
granddeducttotal();
$(this).closest('tr').find('.detailscheck').attr('name','checks[]');
$(this).closest('tr').find('.app_amount').attr('name','app_amount[]');
$(this).closest('tr').find('.type').attr('name','type[]');
$(this).closest('tr').find('.bill_id').attr('name','bill_id[]');
$(this).closest('tr').find('.details_partner_id').attr('name','details_partner_id[]');
$(this).closest('tr').find('.details_ewt').attr('name','details_ewt[]');
}
else{
$('.flash-message').empty();
$('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">This Amount and EWT is greater than Balance.</p>');
$(this).closest('tr').find('.detailscheck').prop('checked',false);
$(this).closest('tr').find('.check_ewt').prop('checked',false);
$(this).closest('tr').find(".details_gross_val").val("0.00");
$(this).closest('tr').find(".details_billtotal_val").val("0.00");
$(this).closest('tr').find(".details_applied_val").val("0.00");
$(this).closest('tr').find(".details_balance_val").val("0.00");
$(this).closest('tr').find('.detailscheck').removeAttr('name');
$(this).closest('tr').find('.app_amount').removeAttr('name');
$(this).closest('tr').find('.type').removeAttr('name');
$(this).closest('tr').find('.bill_id').removeAttr('name');
$(this).closest('tr').find('.details_partner_id').removeAttr('name');
$(this).closest('tr').find('.details_ewt').removeAttr('name');
$(this).closest('tr').find(".details_vat").removeClass('detailsvat');
granddeducttotal();
}
// }
// else{
// $('.flash-message').empty();
// $('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Insufficient Amount.</p>');
// $(this).closest('tr').find('.detailscheck').prop('checked',false);
// $(this).closest('tr').find('.check_ewt').prop('checked',false);
// // $(this).closest('tr').find(".app_amount").val("0.00");
// // $(this).closest('tr').find(".app_amount2").val("0.00");
// // $(this).closest('tr').find(".details_ewt").val("0.00");
// $(this).closest('tr').find(".details_gross_val").val("0.00");
// $(this).closest('tr').find(".details_billtotal_val").val("0.00");
// $(this).closest('tr').find(".details_applied_val").val("0.00");
// $(this).closest('tr').find(".details_balance_val").val("0.00");
// $(this).closest('tr').find('.detailscheck').removeAttr('name');
// $(this).closest('tr').find('.app_amount').removeAttr('name');
// $(this).closest('tr').find('.type').removeAttr('name');
// $(this).closest('tr').find('.bill_id').removeAttr('name');
// $(this).closest('tr').find('.details_ewt').removeAttr('name');
// $(this).closest('tr').find(".details_vat").removeClass('detailsvat');
// $(this).closest('tr').find('.details_partner_id').removeAttr('name');
// granddeducttotal();
// }
}
else{
$(this).closest('tr').find('.detailscheck').prop('checked',false);
$(this).closest('tr').find(".app_amount").val("0.00");
$(this).closest('tr').find(".app_amount2").val("0.00");
$(this).closest('tr').find(".details_gross_val").val("0.00");
$(this).closest('tr').find(".details_billtotal_val").val("0.00");
$(this).closest('tr').find(".details_applied_val").val("0.00");
$(this).closest('tr').find(".details_balance_val").val("0.00");
$(this).closest('tr').find('.detailscheck').removeAttr('name');
$(this).closest('tr').find('.app_amount').removeAttr('name');
$(this).closest('tr').find('.type').removeAttr('name');
$(this).closest('tr').find('.bill_id').removeAttr('name');
$(this).closest('tr').find(".details_vat").removeClass('detailsvat');
$(this).closest('tr').find('.details_partner_id').removeAttr('name');
$(this).closest('tr').find('.details_ewt').removeAttr('name');
granddeducttotal();
}
}
else{
$('.flash-message').empty();
$('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Please add Amount.</p>');
$(this).closest('tr').find('.detailscheck').prop('checked',false);
$(this).closest('tr').find(".app_amount").val("0.00");
$(this).closest('tr').find(".app_amount2").val("0.00");
$(this).closest('tr').find(".details_gross_val").val("0.00");
$(this).closest('tr').find(".details_billtotal_val").val("0.00");
$(this).closest('tr').find(".details_applied_val").val("0.00");
$(this).closest('tr').find(".details_balance_val").val("0.00");
$(this).closest('tr').find('.detailscheck').removeAttr('name');
$(this).closest('tr').find('.app_amount').removeAttr('name');
$(this).closest('tr').find('.type').removeAttr('name');
$(this).closest('tr').find('.bill_id').removeAttr('name');
$(this).closest('tr').find(".details_vat").removeClass('detailsvat');
$(this).closest('tr').find('.details_partner_id').removeAttr('name');
$(this).closest('tr').find('.details_ewt').removeAttr('name');
granddeducttotal();
}
});
$('table.secondtable tbody.receipts_app').on('change','.app_amount', function () {
var ewt_type = $('.ewt_compute').val();
var balance = parseFloat($(this).closest('tr').find(".balance").val()).toFixed(2);
var amount = parseFloat($(this).val()).toFixed(2);
var dtl_ewt = parseFloat($(this).closest('tr').find('.details_ewt').val()).toFixed(2);
var total_right = parseFloat(amount) + parseFloat(dtl_ewt);
var amount2 = balance - amount;
var amount3 = amount2.toFixed(2);
var rec_total = $('.totalAmount').val();
var grand_amount = $('.grand_amount').val();
var total = 0;
var sub_total = 0;
var total_ewt = 0;
var bal = $(this).closest('tr').find(".balance").val();
var gross = $(this).closest('tr').find(".details_gross").text();
var billtotal = $(this).closest('tr').find(".details_billtotal").text();
var applied = $(this).closest('tr').find(".details_applied").text();
if(ewt_type == "auto"){
$(this).closest('tr').find('.detailscheck').prop('checked',true);
}
// $('.detailscheck:checked').each(function(){
// var balance = $(this).closest('tr').find('.app_amount').val();
// var ewt = $(this).closest('tr').find('.details_ewt').val();
// total_ewt += parseFloat(ewt);
// total += parseFloat(balance);
// });
$('.flash-message').empty();
if(ewt_type == "auto"){
if(amount > 0){
if(rec_total >= total){
$(this).closest('tr').find('.detailscheck').prop('checked',true);
if(amount > balance){
$(this).closest('tr').find(".app_amount").val(parseFloat(bal).toFixed(2));
$(this).closest('tr').find(".app_amount2").val(parseFloat(bal).toFixed(2));
}
else{
$(this).closest('tr').find(".app_amount").val(parseFloat(amount).toFixed(2));
$(this).closest('tr').find(".app_amount2").val(parseFloat(amount).toFixed(2));
}
$(this).closest('tr').find(".details_gross_val").val(gross);
$(this).closest('tr').find(".details_billtotal_val").val(billtotal);
$(this).closest('tr').find(".details_applied_val").val(applied);
$(this).closest('tr').find(".details_balance_val").val(bal);
$(this).closest('tr').find(".details_vat").addClass('detailsvat');
granddeducttotal();
$(this).closest('tr').find('.detailscheck').attr('name','checks[]');
$(this).closest('tr').find('.app_amount').attr('name','app_amount[]');
$(this).closest('tr').find('.type').attr('name','type[]');
$(this).closest('tr').find('.bill_id').attr('name','bill_id[]');
$(this).closest('tr').find('.details_partner_id').attr('name','details_partner_id[]');
$(this).closest('tr').find('.details_ewt').attr('name','details_ewt[]');
}
else if(rec_total == total){
$(this).closest('tr').find('.app_amount').val('0.00');
}
else{
$(this).closest('tr').find('.detailscheck').prop('checked',false);
$('.detailscheck:checked').each(function(){
var bala = $(this).closest('tr').find('.app_amount').val();
sub_total += parseFloat(bala);
});
if(parseFloat(sub_total).toFixed(2) == parseFloat(rec_total).toFixed(2)){
$('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Insufficient Amount.</p>');
$(this).closest('tr').find('.detailscheck').prop('checked',false);
$(this).closest('tr').find(".app_amount").val("0.00");
$(this).closest('tr').find(".app_amount2").val("0.00");
$(this).closest('tr').find(".details_gross_val").val("0.00");
$(this).closest('tr').find(".details_billtotal_val").val("0.00");
$(this).closest('tr').find(".details_applied_val").val("0.00");
$(this).closest('tr').find(".details_balance_val").val("0.00");
$(this).closest('tr').find('.detailscheck').removeAttr('name');
$(this).closest('tr').find('.app_amount').removeAttr('name');
$(this).closest('tr').find('.type').removeAttr('name');
$(this).closest('tr').find('.bill_id').removeAttr('name');
$(this).closest('tr').find('.details_partner_id').removeAttr('name');
$(this).closest('tr').find('.details_ewt').removeAttr('name');
$(this).closest('tr').find(".details_vat").removeClass('detailsvat');
granddeducttotal();
}
else{
$(this).closest('tr').find('.detailscheck').prop('checked',true);
$(this).closest('tr').find(".app_amount").val(parseFloat(rec_total - sub_total).toFixed(2));
$(this).closest('tr').find(".app_amount2").val(parseFloat(rec_total - sub_total).toFixed(2));
$(this).closest('tr').find(".details_gross_val").val(gross);
$(this).closest('tr').find(".details_billtotal_val").val(billtotal);
$(this).closest('tr').find(".details_applied_val").val(applied);
$(this).closest('tr').find(".details_balance_val").val(bal);
$(this).closest('tr').find(".details_vat").removeClass('detailsvat');
granddeducttotal();
$(this).closest('tr').find('.detailscheck').attr('name','checks[]');
$(this).closest('tr').find('.app_amount').attr('name','app_amount[]');
$(this).closest('tr').find('.type').attr('name','type[]');
$(this).closest('tr').find('.bill_id').attr('name','bill_id[]');
$(this).closest('tr').find('.details_partner_id').attr('name','details_partner_id[]');
$(this).closest('tr').find('.details_ewt').attr('name','details_ewt[]');
}
}
}
else{
$('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Insufficient Amount.</p>');
$(this).closest('tr').find('.detailscheck').prop('checked',false);
$(this).closest('tr').find(".app_amount").val("0.00");
$(this).closest('tr').find(".app_amount2").val("0.00");
$(this).closest('tr').find(".details_gross_val").val("0.00");
$(this).closest('tr').find(".details_billtotal_val").val("0.00");
$(this).closest('tr').find(".details_applied_val").val("0.00");
$(this).closest('tr').find(".details_balance_val").val("0.00");
$(this).closest('tr').find('.detailscheck').removeAttr('name');
$(this).closest('tr').find('.app_amount').removeAttr('name');
$(this).closest('tr').find('.type').removeAttr('name');
$(this).closest('tr').find('.bill_id').removeAttr('name');
$(this).closest('tr').find('.details_partner_id').removeAttr('name');
$(this).closest('tr').find('.details_ewt').removeAttr('name');
$(this).closest('tr').find(".details_vat").removeClass('detailsvat');
granddeducttotal();
}
}
else{
$('.detailscheck:checked').each(function(){
var balance = $(this).closest('tr').find('.app_amount').val();
var ewt = $(this).closest('tr').find('.details_ewt').val();
total_ewt += parseFloat(ewt);
total += parseFloat(balance);
});
if(rec_total > 0){
var $this = $(this);
$this.val(parseFloat($this.val()).toFixed(2));
var amt_ewt = total_ewt + total;
if(amount > 0){
// alert(amt_ewt+ '<' +rec_total)
// if(amt_ewt < rec_total){
if(bal >= total_right){
$(this).closest('tr').find('.detailscheck').prop('checked',true);
$(this).closest('tr').find('.check_ewt').prop('checked',true);
$(this).closest('tr').find(".details_gross_val").val(gross);
$(this).closest('tr').find(".details_billtotal_val").val(billtotal);
$(this).closest('tr').find(".details_applied_val").val(applied);
$(this).closest('tr').find(".details_balance_val").val(bal);
$(this).closest('tr').find(".details_vat").addClass('detailsvat');
granddeducttotal();
$(this).closest('tr').find('.detailscheck').attr('name','checks[]');
$(this).closest('tr').find('.app_amount').attr('name','app_amount[]');
$(this).closest('tr').find('.type').attr('name','type[]');
$(this).closest('tr').find('.bill_id').attr('name','bill_id[]');
$(this).closest('tr').find('.details_partner_id').attr('name','details_partner_id[]');
$(this).closest('tr').find('.details_ewt').attr('name','details_ewt[]');
}
else{
$('.flash-message').empty();
$('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">This Amount and EWT is greater than Balance.</p>');
$(this).closest('tr').find('.detailscheck').prop('checked',false);
$(this).closest('tr').find('.check_ewt').prop('checked',false);
$(this).closest('tr').find(".details_gross_val").val("0.00");
$(this).closest('tr').find(".details_billtotal_val").val("0.00");
$(this).closest('tr').find(".details_applied_val").val("0.00");
$(this).closest('tr').find(".details_balance_val").val("0.00");
$(this).closest('tr').find('.detailscheck').removeAttr('name');
$(this).closest('tr').find('.app_amount').removeAttr('name');
$(this).closest('tr').find('.type').removeAttr('name');
$(this).closest('tr').find('.bill_id').removeAttr('name');
$(this).closest('tr').find('.details_partner_id').removeAttr('name');
$(this).closest('tr').find('.details_ewt').removeAttr('name');
$(this).closest('tr').find(".details_vat").removeClass('detailsvat');
granddeducttotal();
}
// }
// else{
// $('.flash-message').empty();
// $('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Insufficient Amount.</p>');
// $(this).closest('tr').find('.detailscheck').prop('checked',false);
// $(this).closest('tr').find('.check_ewt').prop('checked',false);
// $(this).closest('tr').find(".app_amount").val("0.00");
// $(this).closest('tr').find(".app_amount2").val("0.00");
// $(this).closest('tr').find(".details_ewt").val("0.00");
// $(this).closest('tr').find(".details_gross_val").val("0.00");
// $(this).closest('tr').find(".details_billtotal_val").val("0.00");
// $(this).closest('tr').find(".details_applied_val").val("0.00");
// $(this).closest('tr').find(".details_balance_val").val("0.00");
// $(this).closest('tr').find('.detailscheck').removeAttr('name');
// $(this).closest('tr').find('.app_amount').removeAttr('name');
// $(this).closest('tr').find('.type').removeAttr('name');
// $(this).closest('tr').find('.bill_id').removeAttr('name');
// $(this).closest('tr').find('.details_partner_id').removeAttr('name');
// $(this).closest('tr').find('.details_ewt').removeAttr('name');
// $(this).closest('tr').find(".details_vat").removeClass('detailsvat');
// granddeducttotal();
// }
}
else{
$(this).closest('tr').find('.detailscheck').prop('checked',false);
$(this).closest('tr').find(".app_amount").val("0.00");
$(this).closest('tr').find(".app_amount2").val("0.00");
$(this).closest('tr').find(".details_gross_val").val("0.00");
$(this).closest('tr').find(".details_billtotal_val").val("0.00");
$(this).closest('tr').find(".details_applied_val").val("0.00");
$(this).closest('tr').find(".details_balance_val").val("0.00");
$(this).closest('tr').find('.detailscheck').removeAttr('name');
$(this).closest('tr').find('.app_amount').removeAttr('name');
$(this).closest('tr').find('.type').removeAttr('name');
$(this).closest('tr').find('.bill_id').removeAttr('name');
$(this).closest('tr').find('.details_partner_id').removeAttr('name');
$(this).closest('tr').find('.details_ewt').removeAttr('name');
$(this).closest('tr').find(".details_vat").removeClass('detailsvat');
granddeducttotal();
}
}
else{
$('.flash-message').empty();
$('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Please add Amount.</p>');
$(this).closest('tr').find('.detailscheck').prop('checked',false);
$(this).closest('tr').find(".app_amount").val("0.00");
$(this).closest('tr').find(".app_amount2").val("0.00");
$(this).closest('tr').find(".details_gross_val").val("0.00");
$(this).closest('tr').find(".details_billtotal_val").val("0.00");
$(this).closest('tr').find(".details_applied_val").val("0.00");
$(this).closest('tr').find(".details_balance_val").val("0.00");
$(this).closest('tr').find('.detailscheck').removeAttr('name');
$(this).closest('tr').find('.app_amount').removeAttr('name');
$(this).closest('tr').find('.type').removeAttr('name');
$(this).closest('tr').find('.bill_id').removeAttr('name');
$(this).closest('tr').find('.details_partner_id').removeAttr('name');
$(this).closest('tr').find('.details_ewt').removeAttr('name');
$(this).closest('tr').find(".details_vat").removeClass('detailsvat');
granddeducttotal();
}
}
});
$('.receipt_type').on('change',function(e){
var type = e.target.value;
if(type == "Payment"){
$('.payment').show();
$('.taxcertificate').hide();
}
else{
$('.taxcertificate').show();
$('.payment').hide();
}
});
// $( "#datepicker" ).datepicker({
// dateFormat: "M-dd-yy",
// yearRange: "1950:2050",
// changeYear: true,
// changeMonth: true,
// });
function granddeducttotal(){
var total = 0;
var grandtotal = 0;
var grandtotal2 = 0;
$('.app_amount').each(function() {
var q = $(this).val();
total += parseFloat(q)
grandtotal = total.toFixed(2);
grandtotal2 = total.toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2});
});
$('.grandamount').val(grandtotal);
$('.grand_amount').text(grandtotal2);
$('.grand_amount').val(grandtotal);
grandgross();
grandbilltotal();
grandapplied();
grandbalance();
grandewt();
grandVAT();
var amount = $('.totalAmount').val();
var total_ewt = 0;
//for amount + ewt
// var grand_amt = parseFloat(parseFloat($('.grand_amount').val()) + parseFloat($('.grand_ewt').val())).toFixed(2);
// var total_ewt = parseFloat(amount - grand_amt).toFixed(2);
//end
//for only amount
var grand_amt = parseFloat($('.grand_amount').val()).toFixed(2);
var total_ewt = parseFloat(amount) - parseFloat(grand_amt);
$('label.grandtotal').text(parseFloat(total_ewt).toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2}));
$('input.grandtotal').val(parseFloat(total_ewt).toFixed(2));
}
function nullothers(){
$('.null').css('color', '#555');
$('.others').css('color', 'red');
}
function grandgross(){
var total = 0;
var grandtotal = 0;
var grandtotal2 = 0;
$('.details_gross_val').each(function(){
var q = $(this).val();
total += parseFloat(q)
grandtotal = total.toFixed(2);
grandtotal2 = total.toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2});
});
$('.grand_gross').text(grandtotal2);
}
function grandtotal(){
var total = 0;
var grandtotal = 0;
var grandtotal2 = 0;
$('.balance').each(function(){
var q = $(this).val();
total += parseFloat(q)
grandtotal = total.toFixed(2);
grandtotal2 = total.toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2});
});
$('.grandtotal').text(grandtotal2);
$('.grandtotal').val(grandtotal);
$('.grandbalance').val(grandtotal);
//return false;
}
function grandbilltotal(){
var total = 0;
var grandtotal = 0;
var grandtotal2 = 0;
$('.details_billtotal_val').each(function() {
var q = $(this).val();
total += parseFloat(q)
grandtotal = total.toFixed(2);
grandtotal2 = total.toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2});
});
$('.grand_billtotal').text(grandtotal2);
}
function grandapplied(){
var total = 0;
var grandtotal = 0;
var grandtotal2 = 0;
$('.details_applied_val').each(function(){
var q = $(this).val();
total += parseFloat(q)
grandtotal = total.toFixed(2);
grandtotal2 = total.toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2});
});
$('.grand_applied').text(grandtotal2);
}
function grandbalance(){
var total = 0;
var grandtotal = 0;
var grandtotal2 = 0;
$('.details_balance_val').each(function(){
var q = $(this).val();
total += parseFloat(q)
grandtotal = total.toFixed(2);
grandtotal2 = total.toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2});
});
$('.grand_balance').text(grandtotal2);
}
function grandewt(){
var total = 0;
var grandtotal = 0;
var grandtotal2 = 0;
$('.details_ewt').each(function() {
var q = $(this).val();
total += parseFloat(q)
grandtotal = total.toFixed(2);
grandtotal2 = total.toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2});
});
$('.grand_ewt').text(grandtotal2);
$('.grand_ewt').val(grandtotal);
}
function grandVAT(){
var vat = 0;
var grandvat = 0;
var grandvat2 = 0;
$('.detailsvat').each(function(){
var q = $(this).val();
vat += parseFloat(q);
grandvat = vat.toFixed(2);
grandvat2 = vat.toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2});
});
$('.grand_vat').text(grandvat2);
}
function isNumberKey(evt, element){
var charCode = (evt.which) ? evt.which : event.keyCode
if ((charCode != 46 || $(element).val().indexOf('.') != -1) && // “.” CHECK DOT, AND ONLY ONE.
(charCode < 48 || charCode > 57))
return false;
return true;
}
//**********************for EWT Certificate functions***************************
$('table.ewt_table thead.ewt_thead').on('click','.ewt_headcheck',function(){
if($(this).is(':checked')){
$(this).closest('tr').parent().parent().find('td .ewt_detailscheck').each(function(){
var bal = parseFloat($(this).closest('tr').find('.ewt_bal').val());
$(this).closest('tr').find('.bill_id').attr('name','bill_id[]');
$(this).closest('tr').find('.type').attr('name','type[]');
$(this).closest('tr').find('.ewt_amount').attr('name','ewt_amount[]');
$(this).closest('tr').find('.ewt_bill').addClass('ewt_bill_total');
$(this).closest('tr').find('.ewt_apply').addClass('ewt_applied');
$(this).closest('tr').find('.ewt_bal').addClass('ewt_balance');
$(this).closest('tr').find('.ewt_amount').val(bal.toFixed(2));
$(this).closest('tr').find('.ewt_detailscheck').prop('checked',true);
});
}
else{
$(this).closest('tr').parent().parent().find('td .ewt_detailscheck').each(function(){
$(this).closest('tr').find('.bill_id').removeAttr('name');
$(this).closest('tr').find('.type').removeAttr('name');
$(this).closest('tr').find('.ewt_amount').removeAttr('name');
$(this).closest('tr').find('.ewt_bill').removeClass('ewt_bill_total');
$(this).closest('tr').find('.ewt_apply').removeClass('ewt_applied');
$(this).closest('tr').find('.ewt_bal').removeClass('ewt_balance');
$(this).closest('tr').find('.ewt_amount').val('0.00');
$(this).closest('tr').find('.ewt_detailscheck').prop('checked',false);
});
}
ewt_bill();
ewt_applied();
ewt_balance();
ewt_total();
});
$('table.ewt_table tbody.ewt_app').on('click','.ewt_detailscheck',function(){
var bal = parseFloat($(this).closest('tr').find('.ewt_bal').val());
if($(this).is(':checked')){
$(this).closest('tr').find('.bill_id').attr('name','bill_id[]');
$(this).closest('tr').find('.type').attr('name','type[]');
$(this).closest('tr').find('.ewt_amount').attr('name','ewt_amount[]');
$(this).closest('tr').find('.ewt_bill').addClass('ewt_bill_total');
$(this).closest('tr').find('.ewt_apply').addClass('ewt_applied');
$(this).closest('tr').find('.ewt_bal').addClass('ewt_balance');
$(this).closest('tr').find('.ewt_amount').val(bal.toFixed(2));
}
else{
$(this).closest('tr').find('.bill_id').removeAttr('name');
$(this).closest('tr').find('.type').removeAttr('name');
$(this).closest('tr').find('.ewt_amount').removeAttr('name');
$(this).closest('tr').find('.ewt_bill').removeClass('ewt_bill_total');
$(this).closest('tr').find('.ewt_apply').removeClass('ewt_applied');
$(this).closest('tr').find('.ewt_bal').removeClass('ewt_balance');
$(this).closest('tr').find('.ewt_amount').val('0.00');
}
var rowCheck = $('.ewt_detailscheck:checked').length;
if(rowCheck == 0){
$('.ewt_headcheck').prop('checked',false);
}
else{
$('.ewt_headcheck').prop('checked',true);
}
ewt_bill();
ewt_applied();
ewt_balance();
ewt_total();
});
$('table.ewt_table tbody.ewt_app').on('change','.ewt_amount',function(){
var $this = $(this);
$this.val(parseFloat($this.val()).toFixed(2));
var bal = parseFloat($(this).closest('tr').find('.ewt_bal').val());
var amount = parseFloat($(this).val());
if(amount <= bal){
}
else{
$(this).val(bal.toFixed(2));
$('.flash-message').empty();
$('.flash-message').append('<p class="alert alert-danger" style="padding:3px;height:22px; width:140%; margin-right: -45px; margin-left: -70px;">Please check your balance.</p>');
}
ewt_total();
});
function ewt_bill(){
var vat = 0.00;
var grandvat = 0.00;
var grandvat2 = 0.00;
$('.ewt_bill_total').each(function(){
var q = $(this).val();
vat += parseFloat(q);
grandvat = vat.toFixed(2);
grandvat2 = vat.toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2});
});
$('.grand_ewt_billtotal').text(grandvat2);
}
function ewt_applied(){
var vat = 0.00;
var grandvat = 0.00;
var grandvat2 = 0.00;
$('.ewt_applied').each(function(){
var q = $(this).val();
vat += parseFloat(q);
grandvat = vat.toFixed(2);
grandvat2 = vat.toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2});
});
$('.grand_ewt_applied').text(grandvat2);
}
function ewt_balance(){
var vat = 0.00;
var grandvat = 0.00;
var grandvat2 = 0.00;
$('.ewt_balance').each(function(){
var q = $(this).val();
vat += parseFloat(q);
grandvat = vat.toFixed(2);
grandvat2 = vat.toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2});
});
$('.grand_ewt_balance').text(grandvat2);
}
function ewt_total(){
var vat = 0.00;
var grandvat = 0.00;
var grandvat2 = 0.00;
$('.ewt_amount').each(function(){
var q = $(this).val();
vat += parseFloat(q);
grandvat = vat.toFixed(2);
grandvat2 = vat.toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2});
});
$('.grand_ewt_amount').text(grandvat2);
var avail = parseFloat($('.totalAmount').val());
var huskar = 0.00;
huskar = parseFloat(avail) - parseFloat(grandvat);
$('label.available').text(huskar.toLocaleString(undefined, {minimumFractionDigits: 2,maximumFractionDigits: 2}));
$('input.available').val(huskar.toFixed(2));
}
$.getJSON('/dev/api/customer', function(data){
data = $.map(data, function(partner) {
return {id: partner.id, text: partner.name };
});
$(".otherPartner").select2({
minimumInputLength: 1,
multiple: false,
width: 294,
data: data
});
});
$('.otherP').on('click',function(){
// $('table.secondtable thead.partner_label tr').each(function(){
// var id2 = $(this).closest('tr').find('.headcheck').val();
// alert(id2)
// });
$('.aaaa').on('click', function(){
var id = $('.otherPartner option:selected').val();
var name = $('.otherPartner option:selected').text();
if(id == ""){
$('#addpartner .modal-footer').empty();
$('#addpartner .modal-footer').append('<p class="alert alert-danger" style="display:inline;padding:3px;height:30px; width:100%;">Please select partner name.</p>');
}
else{
$('.secondtable').append('\
<thead style="background-color:#F0F8FF;" class="partner_label">\
<tr>\
<th><input type="checkbox" class="headcheck" value="'+id+'"></th>\
<th colspan="9" class="here">\
<label class="here" style="font-weight:bold;">\
['+id+'] '+name+'\
</label>\
</th>\
</tr>\
</thead>\
<tbody class="receipts_app other'+id+'">\
</tbody>\
');
}
$('.otherPartner').select2('val', null);
});
$('.otherPartner').on('change',function(){
$('.flash-message').empty();
})
});
//**********************End Function********************************************
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment