mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
feat: general ledger sub-accounts
This commit is contained in:
@@ -113,6 +113,27 @@ export class GeneralLedgerTable extends R.compose(
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Closing balance row column accessors.
|
||||
* @returns {ITableColumnAccessor[]}
|
||||
*/
|
||||
private closingBalanceWithSubaccountsColumnAccessors(): IColumnMapperMeta[] {
|
||||
return [
|
||||
{ key: 'date', value: this.meta.toDate },
|
||||
{ key: 'account_name', value: 'Closing Balance with sub-accounts' },
|
||||
{ key: 'reference_type', accessor: '_empty_' },
|
||||
{ key: 'reference_number', accessor: '_empty_' },
|
||||
{ key: 'description', accessor: '_empty_' },
|
||||
{ key: 'credit', accessor: '_empty_' },
|
||||
{ key: 'debit', accessor: '_empty_' },
|
||||
{ key: 'amount', accessor: 'closingBalanceSubaccounts.formattedAmount' },
|
||||
{
|
||||
key: 'running_balance',
|
||||
accessor: 'closingBalanceSubaccounts.formattedAmount',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the common table columns.
|
||||
* @returns {ITableColumn[]}
|
||||
@@ -191,6 +212,21 @@ export class GeneralLedgerTable extends R.compose(
|
||||
return tableRowMapper(account, columns, meta);
|
||||
};
|
||||
|
||||
/**
|
||||
* Maps the given account node to opening balance table row.
|
||||
* @param {IGeneralLedgerSheetAccount} account
|
||||
* @returns {ITableRow}
|
||||
*/
|
||||
private closingBalanceWithSubaccountsMapper = (
|
||||
account: IGeneralLedgerSheetAccount
|
||||
): ITableRow => {
|
||||
const columns = this.closingBalanceWithSubaccountsColumnAccessors();
|
||||
const meta = {
|
||||
rowTypes: [ROW_TYPE.CLOSING_BALANCE],
|
||||
};
|
||||
return tableRowMapper(account, columns, meta);
|
||||
};
|
||||
|
||||
/**
|
||||
* Maps the given account node to transactions table rows.
|
||||
* @param {IGeneralLedgerSheetAccount} account
|
||||
@@ -221,8 +257,23 @@ export class GeneralLedgerTable extends R.compose(
|
||||
rowTypes: [ROW_TYPE.ACCOUNT],
|
||||
};
|
||||
const row = tableRowMapper(account, columns, meta);
|
||||
const closingBalanceWithSubaccounts =
|
||||
this.closingBalanceWithSubaccountsMapper(account);
|
||||
|
||||
return R.assoc('children', transactions)(row);
|
||||
const children = R.compose(
|
||||
// Appends the closing balance with sub-accounts row if the account has children accounts.
|
||||
R.when(
|
||||
() => account.children?.length > 0,
|
||||
R.append(closingBalanceWithSubaccounts)
|
||||
),
|
||||
R.concat(R.defaultTo([], transactions)),
|
||||
R.when(
|
||||
() => account?.children?.length > 0,
|
||||
R.concat(R.defaultTo([], account.children))
|
||||
)
|
||||
)([]);
|
||||
|
||||
return R.assoc('children', children)(row);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -233,7 +284,7 @@ export class GeneralLedgerTable extends R.compose(
|
||||
private accountsMapper = (
|
||||
accounts: IGeneralLedgerSheetAccount[]
|
||||
): ITableRow[] => {
|
||||
return this.mapNodesDeep(accounts, this.accountMapper);
|
||||
return this.mapNodesDeepReverse(accounts, this.accountMapper);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -250,7 +301,6 @@ export class GeneralLedgerTable extends R.compose(
|
||||
*/
|
||||
public tableColumns(): ITableColumn[] {
|
||||
const columns = this.commonColumns();
|
||||
|
||||
return R.compose(this.tableColumnsCellIndexing)(columns);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user