From 49e170153e404643fee17b1e88b952295ac4d104 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 16 Jul 2012 15:38:11 +0530 Subject: [PATCH] Include in print rate validation added --- .../doctype/sales_common/sales_common.js | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/erpnext/selling/doctype/sales_common/sales_common.js b/erpnext/selling/doctype/sales_common/sales_common.js index 952a55f610e..eda8d58b8cc 100644 --- a/erpnext/selling/doctype/sales_common/sales_common.js +++ b/erpnext/selling/doctype/sales_common/sales_common.js @@ -342,7 +342,7 @@ cur_frm.cscript.basic_rate = function(doc, cdt, cdn) { Please either
\ * Specify Basic Rate (i.e. Rate which will be displayed in print)
\ -- or --
\ - * Uncheck 'Included in Print Rate' in the tax entries of Taxes section."); + * Uncheck 'Is this Tax included in Basic Rate?' in the tax entries of Taxes section."); } } } @@ -655,27 +655,15 @@ cur_frm.cscript.included_in_print_rate = function(doc, cdt, cdn) { var tax = locals[cdt][cdn]; if(tax.included_in_print_rate==1) { if(!inList(['On Net Total', 'On Previous Row Total', 'On Previous Row Amount'], tax.charge_type)) { - msgprint("Included in Print Rate (i.e. Inclusive Price) is only valid for charges of type:
\ + msgprint("'Is this Tax included in Basic Rate?' (i.e. Inclusive Price) is only valid for charges of type:
\ * On Net Total
\ * On Previous Row Amount
\ * On Previous Row Total"); tax.included_in_print_rate = 0; refresh_field('included_in_print_rate', tax.name, cur_frm.cscript.other_fname); - } else if(inList(['On Previous Row Total', 'On Previous Row Amount'], tax.charge_type)){ - if(tax.row_id) { - var tax_list = getchildren('Sales Taxes and Charges', doc.name, cur_frm.cscript.other_fname, doc.doctype); - if(tax_list[tax.row_id-1].charge_type=='Actual') { - msgprint("Row of type 'Actual' cannot be depended on for type '" + tax.charge_type + "'\ - when using tax inclusive prices.
\ - This will lead to incorrect values.

\ - Please specify correct value in 'Enter Row' column of Row: " - + tax.idx + " in Taxes table"); - validated = false; - tax.included_in_print_rate = 0; - refresh_field('included_in_print_rate', tax.name, cur_frm.cscript.other_fname); - } - } - } + } + var tax_list = getchildren('Sales Taxes and Charges', doc.name, cur_frm.cscript.other_fname, doc.doctype); + cur_frm.cscript.validate_print_rate_option(doc, tax_list, tax.idx-1); } } @@ -757,6 +745,32 @@ cur_frm.cscript.recalculate_values = function(doc, cdt, cdn) { cur_frm.cscript.calculate_charges(doc,cdt,cdn); } +cur_frm.cscript.validate_print_rate_option = function(doc, taxes, i) { + if(in_list(['On Previous Row Amount','On Previous Row Total'], taxes[i].charge_type)) { + if(!taxes[i].row_id){ + alert("Please Enter Row on which amount needs to be calculated for row : "+taxes[i].idx); + validated = false; + } else if(taxes[i].included_in_print_rate && taxes[taxes[i].row_id-1].charge_type=='Actual') { + msgprint("Row of type 'Actual' cannot be depended on for type '" + taxes[i].charge_type + "'\ + when using tax inclusive prices.
\ + This will lead to incorrect values.

\ + Please specify correct value in 'Enter Row' column of Row: " + + taxes[i].idx + " in Taxes table"); + validated = false; + taxes[i].included_in_print_rate = 0; + refresh_field('included_in_print_rate', taxes[i].name, other_fname); + } else if ((taxes[i].included_in_print_rate && !taxes[taxes[i].row_id-1].included_in_print_rate) || + (!taxes[i].included_in_print_rate && taxes[taxes[i].row_id-1].included_in_print_rate)) { + msgprint("If any row in the tax table depends on 'Previous Row Amount/Total',
\ + 'Is this Tax included in Basic Rate?' column should be same for both row
\ + i.e for that row and the previous row.

\ + The same is violated for row #"+(i+1)+" and row #"+taxes[i].row_id + ); + validated = false; + } + } +} + cur_frm.cscript.calculate_charges = function(doc, cdt, cdn) { var other_fname = cur_frm.cscript.other_fname; @@ -766,21 +780,7 @@ cur_frm.cscript.calculate_charges = function(doc, cdt, cdn) { cl[i].total_amount = 0; cl[i].tax_amount = 0; // this is done to calculate other charges cl[i].total = 0; - if(in_list(['On Previous Row Amount','On Previous Row Total'], cl[i].charge_type)) { - if(!cl[i].row_id){ - alert("Please Enter Row on which amount needs to be calculated for row : "+cl[i].idx); - validated = false; - } else if(cl[i].included_in_print_rate && cl[cl[i].row_id-1].charge_type=='Actual') { - msgprint("Row of type 'Actual' cannot be depended on for type '" + cl[i].charge_type + "'\ - when using tax inclusive prices.
\ - This will lead to incorrect values.

\ - Please specify correct value in 'Enter Row' column of Row: " - + cl[i].idx + " in Taxes table"); - validated = false; - cl[i].included_in_print_rate = 0; - refresh_field('included_in_print_rate', cl[i].name, other_fname); - } - } + cur_frm.cscript.validate_print_rate_option(doc, cl, i); } cur_frm.cscript.recalc(doc, 1); }