Added support for saving and showing 0% tax rates

This commit is contained in:
Hillel Coren 2015-01-25 08:48:40 +02:00
parent b362380615
commit fa371d2a77
7 changed files with 27 additions and 13 deletions

View File

@ -244,7 +244,7 @@ class InvoiceRepository
$invoice->po_number = trim($data['po_number']);
$invoice->invoice_design_id = $data['invoice_design_id'];
if (isset($data['tax_name']) && isset($data['tax_rate']) && Utils::parseFloat($data['tax_rate']) > 0) {
if (isset($data['tax_name']) && isset($data['tax_rate']) && $data['tax_name']) {
$invoice->tax_rate = Utils::parseFloat($data['tax_rate']);
$invoice->tax_name = trim($data['tax_name']);
} else {
@ -345,7 +345,7 @@ class InvoiceRepository
$invoiceItem->qty = Utils::parseFloat($item->qty);
$invoiceItem->tax_rate = 0;
if (isset($item->tax_rate) && Utils::parseFloat($item->tax_rate) > 0) {
if (isset($item->tax_rate) && isset($item->tax_name) && $item->tax_name) {
$invoiceItem->tax_rate = Utils::parseFloat($item->tax_rate);
$invoiceItem->tax_name = trim($item->tax_name);
}

View File

@ -14,7 +14,7 @@ class TaxRateRepository
continue;
}
if (!isset($record->name) || !Utils::parseFloat($record->rate) || !trim($record->name)) {
if (!isset($record->name) || !trim($record->name)) {
continue;
}

View File

@ -920,8 +920,10 @@
var taxRate = new TaxRateModel();
taxRate.name(name);
taxRate.rate(parseFloat(rate));
if (parseFloat(rate) > 0) taxRate.is_deleted(true);
if (name) {
taxRate.is_deleted(true);
self.tax_rates.push(taxRate);
}
return taxRate;
}

View File

@ -2906,3 +2906,6 @@ table.table thead .sorting_asc:after { content: '' !important }
table.table thead .sorting_desc:after { content: '' !important}
table.table thead .sorting_asc_disabled:after { content: '' !important }
table.table thead .sorting_desc_disabled:after { content: '' !important }
/* Prevent modal from shifting page a bit - https://github.com/twbs/bootstrap/issues/9886 */
body.modal-open { overflow:inherit; padding-right:inherit !important; }

View File

@ -32262,7 +32262,7 @@ function displaySubtotals(doc, layout, invoice, y, rightAlignTitleX)
data.push({'custom_invoice_label2': formatMoney(invoice.custom_value2, invoice.client.currency_id) })
}
data.push({'tax': invoice.tax_amount > 0 ? formatMoney(invoice.tax_amount, invoice.client.currency_id) : false});
data.push({'tax': (invoice.tax && invoice.tax.name) || invoice.tax_name ? formatMoney(invoice.tax_amount, invoice.client.currency_id) : false});
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 != '1') {
data.push({'custom_invoice_label1': formatMoney(invoice.custom_value1, invoice.client.currency_id) })
@ -32355,8 +32355,11 @@ function displayGrid(doc, invoice, data, x, y, layout, options) {
if (key.substring(0, 6) === 'custom') {
key = invoice.account[key];
} else if (key === 'tax' && invoice.tax_rate) {
key = invoiceLabels[key] + ' ' + (invoice.tax_rate*1).toString() + '%';
} else if (key === 'tax' && invoice.tax_name) {
key = invoice.tax_name + ' ' + (invoice.tax_rate*1).toString() + '%';
if (invoice.tax_name.toLowerCase().indexOf(invoiceLabels['tax'].toLowerCase()) == -1) {
key = invoiceLabels['tax'] + ': ' + key;
}
} else if (key === 'discount' && NINJA.parseFloat(invoice.discount) && !parseInt(invoice.is_amount_discount)) {
key = invoiceLabels[key] + ' ' + parseFloat(invoice.discount) + '%';
} else {
@ -32424,7 +32427,7 @@ function calculateAmounts(invoice) {
total += lineTotal;
}
if ((item.tax && item.tax.rate > 0) || (item.tax_rate && parseFloat(item.tax_rate) > 0)) {
if ((item.tax && item.tax.name) || item.tax_name) {
hasTaxes = true;
}
}

View File

@ -798,3 +798,6 @@ table.table thead .sorting_asc:after { content: '' !important }
table.table thead .sorting_desc:after { content: '' !important}
table.table thead .sorting_asc_disabled:after { content: '' !important }
table.table thead .sorting_desc_disabled:after { content: '' !important }
/* Prevent modal from shifting page a bit - https://github.com/twbs/bootstrap/issues/9886 */
body.modal-open { overflow:inherit; padding-right:inherit !important; }

View File

@ -739,7 +739,7 @@ function displaySubtotals(doc, layout, invoice, y, rightAlignTitleX)
data.push({'custom_invoice_label2': formatMoney(invoice.custom_value2, invoice.client.currency_id) })
}
data.push({'tax': invoice.tax_amount > 0 ? formatMoney(invoice.tax_amount, invoice.client.currency_id) : false});
data.push({'tax': (invoice.tax && invoice.tax.name) || invoice.tax_name ? formatMoney(invoice.tax_amount, invoice.client.currency_id) : false});
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 != '1') {
data.push({'custom_invoice_label1': formatMoney(invoice.custom_value1, invoice.client.currency_id) })
@ -832,8 +832,11 @@ function displayGrid(doc, invoice, data, x, y, layout, options) {
if (key.substring(0, 6) === 'custom') {
key = invoice.account[key];
} else if (key === 'tax' && invoice.tax_rate) {
key = invoiceLabels[key] + ' ' + (invoice.tax_rate*1).toString() + '%';
} else if (key === 'tax' && invoice.tax_name) {
key = invoice.tax_name + ' ' + (invoice.tax_rate*1).toString() + '%';
if (invoice.tax_name.toLowerCase().indexOf(invoiceLabels['tax'].toLowerCase()) == -1) {
key = invoiceLabels['tax'] + ': ' + key;
}
} else if (key === 'discount' && NINJA.parseFloat(invoice.discount) && !parseInt(invoice.is_amount_discount)) {
key = invoiceLabels[key] + ' ' + parseFloat(invoice.discount) + '%';
} else {
@ -901,7 +904,7 @@ function calculateAmounts(invoice) {
total += lineTotal;
}
if ((item.tax && item.tax.rate > 0) || (item.tax_rate && parseFloat(item.tax_rate) > 0)) {
if ((item.tax && item.tax.name) || item.tax_name) {
hasTaxes = true;
}
}