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

@@ -89,7 +89,7 @@ export default class GeneralLedgerSheet extends FinancialSheet {
const newEntry = { const newEntry = {
date: entry.date, date: entry.date,
dateFromatted: moment(entry.date).format('YYYY/MM/DD'), dateFormatted: moment(entry.date).format('YYYY/MM/DD'),
entryId: entry.id, entryId: entry.id,
referenceType: entry.referenceType, referenceType: entry.referenceType,

View File

@@ -1,5 +1,6 @@
import * as R from 'ramda'; import * as R from 'ramda';
import { import {
IColumnMapperMeta,
IGeneralLedgerSheetAccount, IGeneralLedgerSheetAccount,
IGeneralLedgerSheetAccountTransaction, IGeneralLedgerSheetAccountTransaction,
IGeneralLedgerSheetData, IGeneralLedgerSheetData,
@@ -46,7 +47,7 @@ export class GeneralLedgerTable extends R.compose(
{ key: 'credit', accessor: '_empty_' }, { key: 'credit', accessor: '_empty_' },
{ key: 'debit', accessor: '_empty_' }, { key: 'debit', accessor: '_empty_' },
{ key: 'amount', accessor: 'amount.formattedAmount' }, { 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[] { private transactionColumnAccessors(): ITableColumnAccessor[] {
return [ return [
{ key: 'date', accessor: 'date' }, { key: 'date', accessor: 'dateFormatted' },
{ key: 'account_name', accessor: 'name' }, { key: 'account_name', accessor: 'account.name' },
{ key: 'reference_type', accessor: 'referenceTypeFormatted' }, { key: 'reference_type', accessor: 'referenceTypeFormatted' },
{ key: 'reference_number', accessor: 'referenceNumber' }, { key: 'reference_number', accessor: 'referenceNumber' },
{ key: 'currency_code', accessor: 'currencyCode' }, { key: 'description', accessor: 'description' },
{ key: 'credit', accessor: 'formattedCredit' }, { key: 'credit', accessor: 'formattedCredit' },
{ key: 'debit', accessor: 'formattedDebit' }, { 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 * @param {IGeneralLedgerSheetAccountTransaction} transaction
* @returns {ITableRow} * @returns {ITableRow}
*/ */
private transactionMapper = ( private transactionMapper = R.curry(
transaction: IGeneralLedgerSheetAccountTransaction (
): ITableRow => { account: IGeneralLedgerSheetAccount,
const columns = this.transactionColumnAccessors(); 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. * Maps the given transactions nodes to table rows.
@@ -104,9 +146,50 @@ export class GeneralLedgerTable extends R.compose(
* @returns {ITableRow[]} * @returns {ITableRow[]}
*/ */
private transactionsMapper = ( private transactionsMapper = (
transactions: IGeneralLedgerSheetAccountTransaction[] account: IGeneralLedgerSheetAccount
): ITableRow[] => { ): 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 => { private accountMapper = (account: IGeneralLedgerSheetAccount): ITableRow => {
const columns = this.accountColumnsAccessors(); const columns = this.accountColumnsAccessors();
const row = tableRowMapper(account, columns, {}); const row = tableRowMapper(account, columns, {});
const transactions = this.transactionsMapper(account.transactions); const transactions = this.transactionsNode(account);
return R.assoc('children', transactions)(row); return R.assoc('children', transactions)(row);
}; };
@@ -130,7 +213,7 @@ export class GeneralLedgerTable extends R.compose(
private accountsMapper = ( private accountsMapper = (
accounts: IGeneralLedgerSheetAccount[] accounts: IGeneralLedgerSheetAccount[]
): ITableRow[] => { ): ITableRow[] => {
return this.mapNodesDeep(accounts, this.accountMapper)l return this.mapNodesDeep(accounts, this.accountMapper);
}; };
/** /**