Only show line item discounts if set

This commit is contained in:
Hillel Coren 2018-01-02 11:51:50 +02:00
parent b90d918925
commit 8c8ebf75c6
4 changed files with 43 additions and 28 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -519,6 +519,12 @@ NINJA.invoiceColumns = function(invoice, design, isTasks)
} else { } else {
continue; continue;
} }
} else if (field == 'product.discount') {
if (invoice.has_item_discounts) {
width = 15;
} else {
continue;
}
} else if (field == 'product.description') { } else if (field == 'product.description') {
width = 0; width = 0;
} else { } else {
@ -652,6 +658,8 @@ NINJA.invoiceLines = function(invoice, isSecondTable) {
} }
} else if (field == 'tax' && ! invoice.has_item_taxes) { } else if (field == 'tax' && ! invoice.has_item_taxes) {
continue; continue;
} else if (field == 'discount' && ! invoice.has_item_discounts) {
continue;
} else if (field == 'unit_cost' || field == 'rate' || field == 'hours') { } else if (field == 'unit_cost' || field == 'rate' || field == 'hours') {
headerStyles.push('cost'); headerStyles.push('cost');
} }
@ -753,6 +761,8 @@ NINJA.invoiceLines = function(invoice, isSecondTable) {
continue; continue;
} else if (field == 'tax' && ! invoice.has_item_taxes) { } else if (field == 'tax' && ! invoice.has_item_taxes) {
continue; continue;
} else if (field == 'discount' && ! invoice.has_item_discounts) {
continue;
} }
if (field == 'item' || field == 'service') { if (field == 'item' || field == 'service') {
@ -772,7 +782,9 @@ NINJA.invoiceLines = function(invoice, isSecondTable) {
if (parseInt(invoice.is_amount_discount)) { if (parseInt(invoice.is_amount_discount)) {
value = formatMoneyInvoice(discount, invoice); value = formatMoneyInvoice(discount, invoice);
} else { } else {
value = discount + '%'; if (discount) {
value = discount + '%';
}
} }
} else if (field == 'tax') { } else if (field == 'tax') {
value = ' '; value = ' ';

View File

@ -581,6 +581,7 @@ function calculateAmounts(invoice) {
var hasStandard = false; var hasStandard = false;
var hasTask = false; var hasTask = false;
var hasDiscount = false;
// sum line item // sum line item
for (var i=0; i<invoice.invoice_items.length; i++) { for (var i=0; i<invoice.invoice_items.length; i++) {
@ -647,6 +648,7 @@ function calculateAmounts(invoice) {
var lineTotal = roundSignificant(NINJA.parseFloat(item.cost)) * roundSignificant(NINJA.parseFloat(item.qty)); var lineTotal = roundSignificant(NINJA.parseFloat(item.cost)) * roundSignificant(NINJA.parseFloat(item.qty));
var discount = roundToTwo(NINJA.parseFloat(item.discount)); var discount = roundToTwo(NINJA.parseFloat(item.discount));
if (discount != 0) { if (discount != 0) {
hasDiscount = true;
if (parseInt(invoice.is_amount_discount)) { if (parseInt(invoice.is_amount_discount)) {
lineTotal -= discount; lineTotal -= discount;
} else { } else {
@ -696,6 +698,7 @@ function calculateAmounts(invoice) {
} }
invoice.has_item_taxes = hasTaxes; invoice.has_item_taxes = hasTaxes;
invoice.has_item_discounts = hasDiscount;
invoice.subtotal_amount = total; invoice.subtotal_amount = total;
var discount = 0; var discount = 0;