2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 15:50:56 +00:00
books/reports/SalesRegister/SalesRegister.js
Faris Ansari 17e5187c51 Reports and Models
- Models
  - Bill
  - Quotation (extended from Invoice)
  - Journal Entry

- Reports
  - Sales Register
  - Purchase Register
2018-04-26 15:53:27 +05:30

44 lines
1.2 KiB
JavaScript

const frappe = require('frappejs');
class SalesRegister {
async run({ fromDate, toDate }) {
const invoices = await frappe.db.getAll({
doctype: 'Invoice',
fields: ['name', 'date', 'customer', 'account', 'netTotal', 'grandTotal'],
filters: {
date: ['>=', fromDate, '<=', toDate],
submitted: 1
},
orderBy: 'date',
order: 'desc'
});
const invoiceNames = invoices.map(d => d.name);
const taxes = await frappe.db.getAll({
doctype: 'TaxSummary',
fields: ['parent', 'amount'],
filters: {
parenttype: 'Invoice',
parent: ['in', invoiceNames]
},
orderBy: 'name'
});
for (let invoice of invoices) {
invoice.totalTax = taxes
.filter(tax => tax.parent === invoice.name)
.reduce((acc, tax) => {
if (tax.amount) {
acc = acc + tax.amount;
}
return acc;
}, 0);
}
return { rows: invoices };
}
}
module.exports = SalesRegister;