Merge pull request #25831 from deepeshgarg007/tds_advance_payment_v13

feat: Tax deduction against advance payments
This commit is contained in:
Nabin Hait
2021-06-10 20:25:30 +05:30
committed by GitHub
26 changed files with 2243 additions and 582 deletions

View File

@@ -156,31 +156,31 @@ cur_frm.cscript.validate_taxes_and_charges = function(cdt, cdn) {
var d = locals[cdt][cdn];
var msg = "";
if(d.account_head && !d.description) {
if (d.account_head && !d.description) {
// set description from account head
d.description = d.account_head.split(' - ').slice(0, -1).join(' - ');
}
if(!d.charge_type && (d.row_id || d.rate || d.tax_amount)) {
if (!d.charge_type && (d.row_id || d.rate || d.tax_amount)) {
msg = __("Please select Charge Type first");
d.row_id = "";
d.rate = d.tax_amount = 0.0;
} else if((d.charge_type == 'Actual' || d.charge_type == 'On Net Total') && d.row_id) {
} else if ((d.charge_type == 'Actual' || d.charge_type == 'On Net Total' || d.charge_type == 'On Paid Amount') && d.row_id) {
msg = __("Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'");
d.row_id = "";
} else if((d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total') && d.row_id) {
} else if ((d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total') && d.row_id) {
if (d.idx == 1) {
msg = __("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row");
d.charge_type = '';
} else if (!d.row_id) {
msg = __("Please specify a valid Row ID for row {0} in table {1}", [d.idx, __(d.doctype)]);
d.row_id = "";
} else if(d.row_id && d.row_id >= d.idx) {
} else if (d.row_id && d.row_id >= d.idx) {
msg = __("Cannot refer row number greater than or equal to current row number for this Charge type");
d.row_id = "";
}
}
if(msg) {
if (msg) {
frappe.validated = false;
refresh_field("taxes");
frappe.throw(msg);

View File

@@ -531,7 +531,7 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
},
calculate_totals: function() {
// Changing sequence can cause rounding_adjustmentng issue and on-screen discrepency
// Changing sequence can because of rounding adjustment issue and on-screen discrepancy
var me = this;
var tax_count = this.frm.doc["taxes"] ? this.frm.doc["taxes"].length : 0;
this.frm.doc.grand_total = flt(tax_count

View File

@@ -8,24 +8,23 @@ erpnext.payments = erpnext.stock.StockController.extend({
this.dialog = new frappe.ui.Dialog({
title: 'Payment'
});
this.dialog.show();
this.$body = this.dialog.body;
this.set_payment_primary_action();
this.make_keyboard();
this.select_text()
this.select_text();
},
select_text: function(){
var me = this;
$(this.$body).find('.form-control').click(function(){
select_text() {
$(this.$body).find('.form-control').click(function() {
$(this).select();
})
});
},
set_payment_primary_action: function(){
set_payment_primary_action: function() {
var me = this;
this.dialog.set_primary_action(__("Submit"), function() {
// Allow no ZERO payment
$.each(me.frm.doc.payments, function (index, data) {
@@ -38,20 +37,20 @@ erpnext.payments = erpnext.stock.StockController.extend({
})
},
make_keyboard: function(){
make_keyboard: function() {
var me = this;
$(this.$body).empty();
$(this.$body).html(frappe.render_template('pos_payment', this.frm.doc))
this.show_payment_details();
this.bind_keyboard_event()
this.clear_amount()
this.bind_keyboard_event();
this.clear_amount();
},
make_multimode_payment: function(){
make_multimode_payment: function() {
var me = this;
if(this.frm.doc.change_amount > 0){
me.payment_val = me.doc.outstanding_amount
if (this.frm.doc.change_amount > 0) {
me.payment_val = me.doc.outstanding_amount;
}
this.payments = frappe.model.add_child(this.frm.doc, 'Multi Mode Payment', "payments");
@@ -59,11 +58,11 @@ erpnext.payments = erpnext.stock.StockController.extend({
this.payments.amount = flt(this.payment_val);
},
show_payment_details: function(){
show_payment_details: function() {
var me = this;
var multimode_payments = $(this.$body).find('.multimode-payments').empty();
if(this.frm.doc.payments.length){
$.each(this.frm.doc.payments, function(index, data){
if (this.frm.doc.payments.length) {
$.each(this.frm.doc.payments, function(index, data) {
$(frappe.render_template('payment_details', {
mode_of_payment: data.mode_of_payment,
amount: data.amount,
@@ -84,92 +83,90 @@ erpnext.payments = erpnext.stock.StockController.extend({
}
},
set_outstanding_amount: function(){
set_outstanding_amount: function() {
this.selected_mode = $(this.$body).find(repl("input[idx='%(idx)s']",{'idx': this.idx}));
this.highlight_selected_row()
this.payment_val = 0.0
if(this.frm.doc.outstanding_amount > 0 && flt(this.selected_mode.val()) == 0.0){
this.highlight_selected_row();
this.payment_val = 0.0;
if (this.frm.doc.outstanding_amount > 0 && flt(this.selected_mode.val()) == 0.0) {
//When user first time click on row
this.payment_val = flt(this.frm.doc.outstanding_amount / this.frm.doc.conversion_rate, precision("outstanding_amount"))
this.selected_mode.val(format_currency(this.payment_val, this.frm.doc.currency));
this.update_payment_amount()
}else if(flt(this.selected_mode.val()) > 0){
this.update_payment_amount();
} else if (flt(this.selected_mode.val()) > 0) {
//If user click on existing row which has value
this.payment_val = flt(this.selected_mode.val());
}
this.selected_mode.select()
this.bind_amount_change_event();
},
bind_keyboard_event: function(){
var me = this;
bind_keyboard_event() {
this.payment_val = '';
this.bind_form_control_event();
this.bind_numeric_keys_event();
},
bind_form_control_event: function(){
bind_form_control_event: function() {
var me = this;
$(this.$body).find('.pos-payment-row').click(function(){
$(this.$body).find('.pos-payment-row').click(function() {
me.idx = $(this).attr("idx");
me.set_outstanding_amount()
})
$(this.$body).find('.form-control').click(function(){
me.set_outstanding_amount();
});
$(this.$body).find('.form-control').click(function() {
me.idx = $(this).attr("idx");
me.set_outstanding_amount();
me.update_paid_amount(true);
})
$(this.$body).find('.write_off_amount').change(function(){
});
$(this.$body).find('.write_off_amount').change(function() {
me.write_off_amount(flt($(this).val()), precision("write_off_amount"));
})
$(this.$body).find('.change_amount').change(function(){
});
$(this.$body).find('.change_amount').change(function() {
me.change_amount(flt($(this).val()), precision("change_amount"));
})
});
},
highlight_selected_row: function(){
var me = this;
var selected_row = $(this.$body).find(repl(".pos-payment-row[idx='%(idx)s']",{'idx': this.idx}));
$(this.$body).find('.pos-payment-row').removeClass('selected-payment-mode')
selected_row.addClass('selected-payment-mode')
highlight_selected_row() {
var selected_row = $(this.$body).find(repl(".pos-payment-row[idx='%(idx)s']", {'idx': this.idx}));
$(this.$body).find('.pos-payment-row').removeClass('selected-payment-mode');
selected_row.addClass('selected-payment-mode');
$(this.$body).find('.amount').attr('disabled', true);
this.selected_mode.attr('disabled', false);
},
bind_numeric_keys_event: function(){
bind_numeric_keys_event: function() {
var me = this;
$(this.$body).find('.pos-keyboard-key').click(function(){
me.payment_val += $(this).text();
me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency))
me.idx = me.selected_mode.attr("idx")
me.update_paid_amount()
})
$(this.$body).find('.delete-btn').click(function(){
me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency));
me.idx = me.selected_mode.attr("idx");
me.update_paid_amount();
});
$(this.$body).find('.delete-btn').click(function() {
me.payment_val = cstr(flt(me.selected_mode.val())).slice(0, -1);
me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency));
me.idx = me.selected_mode.attr("idx")
me.idx = me.selected_mode.attr("idx");
me.update_paid_amount();
})
},
bind_amount_change_event: function(){
bind_amount_change_event() {
var me = this;
this.selected_mode.change(function(){
this.selected_mode.change(function() {
me.payment_val = flt($(this).val()) || 0.0;
me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency))
me.idx = me.selected_mode.attr("idx")
me.update_payment_amount()
})
me.selected_mode.val(format_currency(me.payment_val, me.frm.doc.currency));
me.idx = me.selected_mode.attr("idx");
me.update_payment_amount();
});
},
clear_amount: function() {
var me = this;
$(this.$body).find('.clr').click(function(e){
$(this.$body).find('.clr').click(function(e) {
e.stopPropagation();
me.idx = $(this).attr("idx");
me.selected_mode = $(me.$body).find(repl("input[idx='%(idx)s']",{'idx': me.idx}));
@@ -177,50 +174,48 @@ erpnext.payments = erpnext.stock.StockController.extend({
me.selected_mode.val(0.0);
me.highlight_selected_row();
me.update_payment_amount();
})
});
},
write_off_amount: function(write_off_amount) {
var me = this;
write_off_amount(write_off_amount) {
this.frm.doc.write_off_amount = flt(write_off_amount, precision("write_off_amount"));
this.frm.doc.base_write_off_amount = flt(this.frm.doc.write_off_amount * this.frm.doc.conversion_rate,
precision("base_write_off_amount"));
this.calculate_outstanding_amount(false)
this.show_amounts()
this.calculate_outstanding_amount(false);
this.show_amounts();
},
change_amount: function(change_amount) {
var me = this;
this.frm.doc.change_amount = flt(change_amount, precision("change_amount"));
this.calculate_write_off_amount()
this.show_amounts()
this.calculate_write_off_amount();
this.show_amounts();
},
update_paid_amount: function(update_write_off) {
var me = this;
if(in_list(['change_amount', 'write_off_amount'], this.idx)){
if (in_list(['change_amount', 'write_off_amount'], this.idx)) {
var value = me.selected_mode.val();
if(me.idx == 'change_amount'){
me.change_amount(value)
} else{
if (me.idx == 'change_amount') {
me.change_amount(value);
} else {
if(flt(value) == 0 && update_write_off && me.frm.doc.outstanding_amount > 0) {
value = flt(me.frm.doc.outstanding_amount / me.frm.doc.conversion_rate, precision(me.idx));
}
me.write_off_amount(value)
me.write_off_amount(value);
}
}else{
this.update_payment_amount()
} else {
this.update_payment_amount();
}
},
update_payment_amount: function(){
update_payment_amount: function() {
var me = this;
$.each(this.frm.doc.payments, function(index, data){
if(cint(me.idx) == cint(data.idx)){
data.amount = flt(me.selected_mode.val(), 2)
$.each(this.frm.doc.payments, function(index, data) {
if (cint(me.idx) == cint(data.idx)) {
data.amount = flt(me.selected_mode.val(), 2);
}
})
@@ -228,12 +223,12 @@ erpnext.payments = erpnext.stock.StockController.extend({
this.show_amounts();
},
show_amounts: function(){
show_amounts: function() {
var me = this;
$(this.$body).find(".write_off_amount").val(format_currency(this.frm.doc.write_off_amount, this.frm.doc.currency));
$(this.$body).find('.paid_amount').text(format_currency(this.frm.doc.paid_amount, this.frm.doc.currency));
$(this.$body).find('.change_amount').val(format_currency(this.frm.doc.change_amount, this.frm.doc.currency))
$(this.$body).find('.outstanding_amount').text(format_currency(this.frm.doc.outstanding_amount, frappe.get_doc(":Company", this.frm.doc.company).default_currency))
$(this.$body).find('.change_amount').val(format_currency(this.frm.doc.change_amount, this.frm.doc.currency));
$(this.$body).find('.outstanding_amount').text(format_currency(this.frm.doc.outstanding_amount, frappe.get_doc(":Company", this.frm.doc.company).default_currency));
this.update_invoice();
}
})