Skip to content

Commit

Permalink
feat: show totals in closing column for Trial Balance
Browse files Browse the repository at this point in the history
  • Loading branch information
mildred committed Nov 21, 2024
1 parent 586d0f3 commit f4c3adb
Showing 1 changed file with 49 additions and 6 deletions.
55 changes: 49 additions & 6 deletions reports/TrialBalance/TrialBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class TrialBalance extends AccountReport {
toDate?: string;
showOnlyBalance = false;
hideGroupAmounts = false;
showTotal = false;
loading = false;

_rawData: LedgerEntry[] = [];
Expand Down Expand Up @@ -149,11 +150,13 @@ export class TrialBalance extends AccountReport {
toDate: fromDate,
},
{ fromDate, toDate },
{
fromDate: toDate,
toDate: DateTime.fromISO('9999-12-31'),
},
];
this.showTotal
? null
: {
fromDate: toDate,
toDate: DateTime.fromISO('9999-12-31'),
},
].filter((x) => x);
}

getRowFromAccountListNode(al: AccountListNode) {
Expand All @@ -166,9 +169,15 @@ export class TrialBalance extends AccountReport {
indent: al.level ?? 0,
} as ReportCell;

let totalDebit = 0,
totalCredit = 0;
const hide = this.hideGroupAmounts && al.isGroup;

const balanceCells = this._dateRanges!.map((k) => {
const map = al.valueMap?.get(k);
const hide = this.hideGroupAmounts && al.isGroup;

totalDebit += map?.debit ?? 0;
totalCredit += map?.credit ?? 0;

if (this.showOnlyBalance) {
const balance = (map?.debit ?? 0) - (map?.credit ?? 0);
Expand Down Expand Up @@ -198,6 +207,35 @@ export class TrialBalance extends AccountReport {
}
});

if (this.showTotal) {
if (this.showOnlyBalance) {
const balance = totalDebit - totalCredit;
balanceCells.push([
{
rawValue: balance,
value: hide ? '' : this.fyo.format(balance, 'Currency'),
align: 'right',
width: ACC_BAL_WIDTH,
} as ReportCell,
]);
} else {
balanceCells.push([
{
rawValue: totalDebit,
value: hide ? '' : this.fyo.format(totalDebit, 'Currency'),
align: 'right',
width: ACC_BAL_WIDTH,
},
{
rawValue: totalCredit,
value: hide ? '' : this.fyo.format(totalCredit, 'Currency'),
align: 'right',
width: ACC_BAL_WIDTH,
} as ReportCell,
]);
}
}

return {
cells: [nameCell, balanceCells].flat(2),
level: al.level,
Expand Down Expand Up @@ -249,6 +287,11 @@ export class TrialBalance extends AccountReport {
label: t`Hide Group Amounts`,
fieldname: 'hideGroupAmounts',
},
{
fieldtype: 'Check',
label: t`Show totals`,
fieldname: 'showTotal',
},
{
fieldtype: 'Check',
label: t`Show Balance`,
Expand Down

0 comments on commit f4c3adb

Please sign in to comment.