2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 11:29:03 +00:00
books/reports/ProfitAndLoss/ProfitAndLoss.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-04-18 09:02:05 +00:00
const frappe = require('frappejs');
const { unique } = require('frappejs/utils');
const { getData } = require('../FinancialStatements/FinancialStatements');
2018-04-18 09:02:05 +00:00
class ProfitAndLoss {
2018-04-19 14:31:35 +00:00
async run({ fromDate, toDate, periodicity }) {
2018-04-18 09:02:05 +00:00
let income = await getData({
rootType: 'Income',
2018-04-19 14:31:35 +00:00
balanceMustBe: 'Credit',
fromDate,
toDate,
periodicity
2018-04-18 09:02:05 +00:00
});
let expense = await getData({
rootType: 'Expense',
2018-04-19 14:31:35 +00:00
balanceMustBe: 'Debit',
fromDate,
toDate,
periodicity
2018-04-18 09:02:05 +00:00
});
const rows = [
...income.accounts, income.totalRow, [],
...expense.accounts, expense.totalRow, []
];
const columns = unique([...income.periodList, ...expense.periodList])
let profitRow = {
account: 'Total Profit'
}
for (let column of columns) {
profitRow[column] = (income.totalRow[column] || 0.0) - (expense.totalRow[column] || 0.0);
}
rows.push(profitRow);
return { rows, columns };
2018-04-18 09:02:05 +00:00
}
}
module.exports = ProfitAndLoss;