2018-04-18 09:02:05 +00:00
|
|
|
const frappe = require('frappejs');
|
2018-04-24 07:58:57 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2018-04-24 07:58:57 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-26 10:23:27 +00:00
|
|
|
module.exports = ProfitAndLoss;
|