discount calculation and in print view
diff --git a/erpnext/public/js/controllers/accounts.js b/erpnext/public/js/controllers/accounts.js
index 652350a..21ad71f 100644
--- a/erpnext/public/js/controllers/accounts.js
+++ b/erpnext/public/js/controllers/accounts.js
@@ -93,11 +93,11 @@
cur_frm.pformat.taxes= function(doc){
//function to make row of table
- var make_row = function(title, val, bold){
+ var make_row = function(title, val, bold, is_negative) {
var bstart = '<b>'; var bend = '</b>';
return '<tr><td style="width:50%;">' + (bold?bstart:'') + title + (bold?bend:'') + '</td>'
- + '<td style="width:50%;text-align:right;">' + format_currency(val, doc.currency) + '</td>'
- + '</tr>';
+ + '<td style="width:50%;text-align:right;">' + (is_negative ? '- ' : '')
+ + format_currency(val, doc.currency) + '</td></tr>';
}
function convert_rate(val) {
@@ -125,6 +125,10 @@
out += make_row('Net Total', doc.print_total, 1);
}
+ // Discount Amount on net total
+ if(!print_hide('discount_amount') && doc.apply_discount_on == "Net Total" && doc.discount_amount)
+ out += make_row('Discount Amount', doc.discount_amount, 0, 1);
+
// add rows
if(cl.length){
for(var i=0;i<cl.length;i++) {
@@ -133,9 +137,9 @@
}
}
- // Discount Amount
- if(!print_hide('discount_amount') && doc.discount_amount)
- out += make_row('Discount Amount', doc.discount_amount, 0);
+ // Discount Amount on grand total
+ if(!print_hide('discount_amount') && doc.apply_discount_on == "Grand Total" && doc.discount_amount)
+ out += make_row('Discount Amount', doc.discount_amount, 0, 1);
// grand total
if(!print_hide('grand_total'))
diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js
index e30099c..603b147 100644
--- a/erpnext/public/js/controllers/taxes_and_totals.js
+++ b/erpnext/public/js/controllers/taxes_and_totals.js
@@ -88,8 +88,9 @@
"tax_amount_for_current_item", "grand_total_for_current_item",
"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]
- if (cstr(tax.charge_type) != "Actual" && !me.discount_amount_applied)
- tax_fields.push("tax_amount");
+ if (cstr(tax.charge_type) != "Actual" &&
+ !(me.discount_amount_applied && me.frm.doc.apply_discount_on=="Grand Total"))
+ tax_fields.push("tax_amount");
$.each(tax_fields, function(i, fieldname) { tax[fieldname] = 0.0 });
@@ -217,8 +218,9 @@
}
// accumulate tax amount into tax.tax_amount
- if (tax.charge_type != "Actual" && !me.discount_amount_applied)
- tax.tax_amount += current_tax_amount;
+ if (tax.charge_type != "Actual" &&
+ !(me.discount_amount_applied && me.frm.doc.apply_discount_on=="Grand Total"))
+ tax.tax_amount += current_tax_amount;
// store tax_amount for current item as it will be used for
// charge type = 'On Previous Row Amount'
@@ -254,7 +256,7 @@
me.round_off_totals(tax);
// adjust Discount Amount loss in last tax iteration
- if ((i == me.frm.doc["taxes"].length - 1) && me.discount_amount_applied)
+ if ((i == me.frm.doc["taxes"].length - 1) && me.discount_amount_applied && me.frm.doc.apply_discount_on == "Grand Total")
me.adjust_discount_amount_loss(tax);
}
});
@@ -428,8 +430,8 @@
get_total_for_discount_amount: function() {
var me = this;
- if(this.apply_discount_amount == "Print Total") {
- return this.net_total
+ if(this.frm.doc.apply_discount_on == "Net Total") {
+ return this.frm.doc.net_total
} else {
var total_actual_tax = 0.0;
var actual_taxes_dict = {};