2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 11:29:03 +00:00
books/reports/BalanceSheet/BalanceSheet.ts
18alantom 27aed52044 incr: type some files, frappe -> fyo
- get books to serve albiet broken
- one step at a time
2022-05-23 16:18:22 +05:30

60 lines
1.3 KiB
TypeScript

import { Fyo } from 'fyo';
import { unique } from 'fyo/utils';
import { FinancialStatements } from 'reports/FinancialStatements/financialStatements';
import { FinancialStatementOptions } from 'reports/types';
class BalanceSheet {
async run(options: FinancialStatementOptions, fyo: Fyo) {
const { fromDate, toDate, periodicity } = options;
const fs = new FinancialStatements(fyo);
const asset = await fs.getData({
rootType: 'Asset',
balanceMustBe: 'Debit',
fromDate,
toDate,
periodicity,
accumulateValues: true,
});
const liability = await fs.getData({
rootType: 'Liability',
balanceMustBe: 'Credit',
fromDate,
toDate,
periodicity,
accumulateValues: true,
});
const equity = await fs.getData({
rootType: 'Equity',
balanceMustBe: 'Credit',
fromDate,
toDate,
periodicity,
accumulateValues: true,
});
const rows = [
...asset.accounts,
asset.totalRow,
[],
...liability.accounts,
liability.totalRow,
[],
...equity.accounts,
equity.totalRow,
[],
];
const columns = unique([
...asset.periodList,
...liability.periodList,
...equity.periodList,
]);
return { rows, columns };
}
}
export default BalanceSheet;