From 4d3122b569d4b458be8e6b15cf604e860cdc6644 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Mon, 19 Mar 2018 20:38:10 +0530 Subject: [PATCH 1/2] Fix Invoice --- models/doctype/Invoice/InvoiceDocument.js | 72 +++++++++++++++++++++++ models/doctype/Invoice/InvoiceList.js | 13 ++++ 2 files changed, 85 insertions(+) create mode 100644 models/doctype/Invoice/InvoiceDocument.js create mode 100644 models/doctype/Invoice/InvoiceList.js diff --git a/models/doctype/Invoice/InvoiceDocument.js b/models/doctype/Invoice/InvoiceDocument.js new file mode 100644 index 00000000..70933a9d --- /dev/null +++ b/models/doctype/Invoice/InvoiceDocument.js @@ -0,0 +1,72 @@ +const BaseDocument = require('frappejs/model/document'); +const frappe = require('frappejs'); + +module.exports = class Invoice extends BaseDocument { + async getRowTax(row) { + if (row.tax) { + let tax = await this.getTax(row.tax); + let taxAmount = []; + for (let d of (tax.details || [])) { + taxAmount.push({account: d.account, rate: d.rate, amount: row.amount * d.rate / 100}); + } + return JSON.stringify(taxAmount); + } else { + return ''; + } + } + + async getTax(tax) { + if (!this._taxes) this._taxes = {}; + if (!this._taxes[tax]) this._taxes[tax] = await frappe.getDoc('Tax', tax); + return this._taxes[tax]; + } + + makeTaxSummary() { + if (!this.taxes) this.taxes = []; + + // reset tax amount + this.taxes.map(d => { d.amount = 0; d.rate = 0; }); + + // calculate taxes + for (let row of this.items) { + if (row.taxAmount) { + let taxAmount = JSON.parse(row.taxAmount); + for (let rowTaxDetail of taxAmount) { + let found = false; + + // check if added in summary + for (let taxDetail of this.taxes) { + if (taxDetail.account === rowTaxDetail.account) { + taxDetail.rate = rowTaxDetail.rate; + taxDetail.amount += rowTaxDetail.amount; + found = true; + } + } + + // add new row + if (!found) { + this.taxes.push({ + account: rowTaxDetail.account, + rate: rowTaxDetail.rate, + amount: rowTaxDetail.amount + }); + } + } + } + } + + // clear no taxes + this.taxes = this.taxes.filter(d => d.amount); + } + + getGrandTotal() { + this.makeTaxSummary(); + let grandTotal = this.netTotal; + if (this.taxes) { + for (let row of this.taxes) { + grandTotal += row.amount; + } + } + return grandTotal; + } +} \ No newline at end of file diff --git a/models/doctype/Invoice/InvoiceList.js b/models/doctype/Invoice/InvoiceList.js new file mode 100644 index 00000000..7068852e --- /dev/null +++ b/models/doctype/Invoice/InvoiceList.js @@ -0,0 +1,13 @@ +const BaseList = require('frappejs/client/view/list'); +const frappe = require('frappejs'); + +module.exports = class InvoiceList extends BaseList { + getFields() { + return ['name', 'customer', 'grandTotal', 'submitted']; + } + getRowHTML(data) { + return `
${this.getNameHTML(data)}
+
${data.customer}
+
${frappe.format(data.grandTotal, "Currency")}
`; + } +} \ No newline at end of file From 69281812203b4dc3d72c99490a6506fb266d3a37 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Mon, 19 Mar 2018 20:44:00 +0530 Subject: [PATCH 2/2] Fix Invoice: delete unused files --- models/doctype/Invoice/invoiceDocument.js | 72 ----------------------- models/doctype/Invoice/invoiceList.js | 13 ---- 2 files changed, 85 deletions(-) delete mode 100644 models/doctype/Invoice/invoiceDocument.js delete mode 100644 models/doctype/Invoice/invoiceList.js diff --git a/models/doctype/Invoice/invoiceDocument.js b/models/doctype/Invoice/invoiceDocument.js deleted file mode 100644 index 70933a9d..00000000 --- a/models/doctype/Invoice/invoiceDocument.js +++ /dev/null @@ -1,72 +0,0 @@ -const BaseDocument = require('frappejs/model/document'); -const frappe = require('frappejs'); - -module.exports = class Invoice extends BaseDocument { - async getRowTax(row) { - if (row.tax) { - let tax = await this.getTax(row.tax); - let taxAmount = []; - for (let d of (tax.details || [])) { - taxAmount.push({account: d.account, rate: d.rate, amount: row.amount * d.rate / 100}); - } - return JSON.stringify(taxAmount); - } else { - return ''; - } - } - - async getTax(tax) { - if (!this._taxes) this._taxes = {}; - if (!this._taxes[tax]) this._taxes[tax] = await frappe.getDoc('Tax', tax); - return this._taxes[tax]; - } - - makeTaxSummary() { - if (!this.taxes) this.taxes = []; - - // reset tax amount - this.taxes.map(d => { d.amount = 0; d.rate = 0; }); - - // calculate taxes - for (let row of this.items) { - if (row.taxAmount) { - let taxAmount = JSON.parse(row.taxAmount); - for (let rowTaxDetail of taxAmount) { - let found = false; - - // check if added in summary - for (let taxDetail of this.taxes) { - if (taxDetail.account === rowTaxDetail.account) { - taxDetail.rate = rowTaxDetail.rate; - taxDetail.amount += rowTaxDetail.amount; - found = true; - } - } - - // add new row - if (!found) { - this.taxes.push({ - account: rowTaxDetail.account, - rate: rowTaxDetail.rate, - amount: rowTaxDetail.amount - }); - } - } - } - } - - // clear no taxes - this.taxes = this.taxes.filter(d => d.amount); - } - - getGrandTotal() { - this.makeTaxSummary(); - let grandTotal = this.netTotal; - if (this.taxes) { - for (let row of this.taxes) { - grandTotal += row.amount; - } - } - return grandTotal; - } -} \ No newline at end of file diff --git a/models/doctype/Invoice/invoiceList.js b/models/doctype/Invoice/invoiceList.js deleted file mode 100644 index 7068852e..00000000 --- a/models/doctype/Invoice/invoiceList.js +++ /dev/null @@ -1,13 +0,0 @@ -const BaseList = require('frappejs/client/view/list'); -const frappe = require('frappejs'); - -module.exports = class InvoiceList extends BaseList { - getFields() { - return ['name', 'customer', 'grandTotal', 'submitted']; - } - getRowHTML(data) { - return `
${this.getNameHTML(data)}
-
${data.customer}
-
${frappe.format(data.grandTotal, "Currency")}
`; - } -} \ No newline at end of file