feat: wip general ledger table

This commit is contained in:
Ahmed Bouhuolia
2024-01-04 21:43:57 +02:00
parent 60b1bc9ed7
commit c71836ec27
2 changed files with 99 additions and 16 deletions

View File

@@ -1,5 +1,6 @@
import * as R from 'ramda';
import {
IColumnMapperMeta,
IGeneralLedgerSheetAccount,
IGeneralLedgerSheetAccountTransaction,
IGeneralLedgerSheetData,
@@ -46,7 +47,7 @@ export class GeneralLedgerTable extends R.compose(
{ key: 'credit', accessor: '_empty_' },
{ key: 'debit', accessor: '_empty_' },
{ key: 'amount', accessor: 'amount.formattedAmount' },
{ key: 'running_balance', accessor: 'openingBalance.formattedAmount' },
{ key: 'running_balance', accessor: 'closingBalance.formattedAmount' },
];
}
@@ -56,14 +57,51 @@ export class GeneralLedgerTable extends R.compose(
*/
private transactionColumnAccessors(): ITableColumnAccessor[] {
return [
{ key: 'date', accessor: 'date' },
{ key: 'account_name', accessor: 'name' },
{ key: 'date', accessor: 'dateFormatted' },
{ key: 'account_name', accessor: 'account.name' },
{ key: 'reference_type', accessor: 'referenceTypeFormatted' },
{ key: 'reference_number', accessor: 'referenceNumber' },
{ key: 'currency_code', accessor: 'currencyCode' },
{ key: 'description', accessor: 'description' },
{ key: 'credit', accessor: 'formattedCredit' },
{ key: 'debit', accessor: 'formattedDebit' },
{ key: 'running_balance', accessor: 'runningBalance.formattedAmount' },
{ key: 'amount', accessor: 'formattedAmount' },
{ key: 'running_balance', accessor: 'formattedRunningBalance' },
];
}
/**
* Retrieves the opening row column accessors.
* @returns {ITableRowIColumnMapperMeta[]}
*/
private openingBalanceColumnsAccessors(): IColumnMapperMeta[] {
return [
{ key: 'date', accessor: 'dateFormatted' },
{ key: 'account_name', value: 'Opening Balance' },
{ key: 'reference_type', accessor: '_empty_' },
{ key: 'reference_number', accessor: '_empty_' },
{ key: 'description', accessor: 'description' },
{ key: 'credit', accessor: '_empty_' },
{ key: 'debit', accessor: '_empty_' },
{ key: 'amount', accessor: 'openingBalance.formattedAmount' },
{ key: 'running_balance', accessor: '_empty' },
];
}
/**
* Closing balance row column accessors.
* @returns {ITableColumnAccessor[]}
*/
private closingBalanceColumnAccessors(): IColumnMapperMeta[] {
return [
{ key: 'date', accessor: 'dateFormatted' },
{ key: 'account_name', value: 'Closing Balance' },
{ 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: 'closingBalance.formattedAmount' },
{ key: 'running_balance', accessor: '_empty_' },
];
}
@@ -90,13 +128,17 @@ export class GeneralLedgerTable extends R.compose(
* @param {IGeneralLedgerSheetAccountTransaction} transaction
* @returns {ITableRow}
*/
private transactionMapper = (
transaction: IGeneralLedgerSheetAccountTransaction
): ITableRow => {
const columns = this.transactionColumnAccessors();
private transactionMapper = R.curry(
(
account: IGeneralLedgerSheetAccount,
transaction: IGeneralLedgerSheetAccountTransaction
): ITableRow => {
const columns = this.transactionColumnAccessors();
const data = { ...transaction, account };
return tableRowMapper(transaction, columns, {});
};
return tableRowMapper(data, columns, {});
}
);
/**
* Maps the given transactions nodes to table rows.
@@ -104,9 +146,50 @@ export class GeneralLedgerTable extends R.compose(
* @returns {ITableRow[]}
*/
private transactionsMapper = (
transactions: IGeneralLedgerSheetAccountTransaction[]
account: IGeneralLedgerSheetAccount
): ITableRow[] => {
return R.map(this.transactionMapper)(transactions);
const transactionMapper = this.transactionMapper(account);
return R.map(transactionMapper)(account.transactions);
};
/**
* Maps the given account node to opening balance table row.
* @param {IGeneralLedgerSheetAccount} account
* @returns {ITableRow}
*/
private openingBalanceMapper = (
account: IGeneralLedgerSheetAccount
): ITableRow => {
const columns = this.openingBalanceColumnsAccessors();
return tableRowMapper(account, columns, {});
};
/**
* Maps the given account node to closing balance table row.
* @param {IGeneralLedgerSheetAccount} account
* @returns {ITableRow}
*/
private closingBalanceMapper = (account: IGeneralLedgerSheetAccount) => {
const columns = this.closingBalanceColumnAccessors();
return tableRowMapper(account, columns, {});
};
/**
* Maps the given account node to transactions table rows.
* @param {IGeneralLedgerSheetAccount} account
* @returns {ITableRow[]}
*/
private transactionsNode = (
account: IGeneralLedgerSheetAccount
): ITableRow[] => {
const openingBalance = this.openingBalanceMapper(account);
const transactions = this.transactionsMapper(account);
const closingBalance = this.closingBalanceMapper(account);
return [openingBalance, ...transactions, closingBalance];
};
/**
@@ -117,7 +200,7 @@ export class GeneralLedgerTable extends R.compose(
private accountMapper = (account: IGeneralLedgerSheetAccount): ITableRow => {
const columns = this.accountColumnsAccessors();
const row = tableRowMapper(account, columns, {});
const transactions = this.transactionsMapper(account.transactions);
const transactions = this.transactionsNode(account);
return R.assoc('children', transactions)(row);
};
@@ -130,7 +213,7 @@ export class GeneralLedgerTable extends R.compose(
private accountsMapper = (
accounts: IGeneralLedgerSheetAccount[]
): ITableRow[] => {
return this.mapNodesDeep(accounts, this.accountMapper)l
return this.mapNodesDeep(accounts, this.accountMapper);
};
/**