mirror of
https://github.com/frappe/books.git
synced 2024-12-24 11:55:46 +00:00
17e5187c51
- Models - Bill - Quotation (extended from Invoice) - Journal Entry - Reports - Sales Register - Purchase Register
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
const frappe = require('frappejs');
|
|
const { unique } = require('frappejs/utils');
|
|
const { getData } = require('../FinancialStatements/FinancialStatements');
|
|
|
|
class ProfitAndLoss {
|
|
async run({ fromDate, toDate, periodicity }) {
|
|
|
|
let income = await getData({
|
|
rootType: 'Income',
|
|
balanceMustBe: 'Credit',
|
|
fromDate,
|
|
toDate,
|
|
periodicity
|
|
});
|
|
|
|
let expense = await getData({
|
|
rootType: 'Expense',
|
|
balanceMustBe: 'Debit',
|
|
fromDate,
|
|
toDate,
|
|
periodicity
|
|
});
|
|
|
|
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 };
|
|
}
|
|
}
|
|
|
|
module.exports = ProfitAndLoss;
|