Skip to content

Commit

Permalink
feat: wip journal and general ledger dyanmic columns
Browse files Browse the repository at this point in the history
  • Loading branch information
abouolia committed Jan 6, 2024
1 parent c71836e commit 79f3f1b
Show file tree
Hide file tree
Showing 15 changed files with 615 additions and 214 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as R from 'ramda';
import { first } from 'lodash';
import {
IColumnMapperMeta,
IJournalEntry,
IJournalReport,
IJournalReportEntriesGroup,
IJournalReportQuery,
IJournalTableData,
Expand All @@ -13,7 +14,7 @@ import { tableRowMapper } from '@/utils';
import { FinancialTable } from '../FinancialTable';
import { FinancialSheetStructure } from '../FinancialSheetStructure';
import FinancialSheet from '../FinancialSheet';
import { first } from 'lodash';
import { ROW_TYPE } from './types';

export class JournalSheetTable extends R.compose(
FinancialTable,
Expand Down Expand Up @@ -70,6 +71,10 @@ export class JournalSheetTable extends R.compose(
];
};

/**
* Retrieves the total entry column accessors.
* @returns {ITableColumnAccessor[]}
*/
private totalEntryColumnAccessors = (): ITableColumnAccessor[] => {
return [
{ key: 'date', accessor: '_empty_' },
Expand All @@ -83,6 +88,23 @@ export class JournalSheetTable extends R.compose(
];
};

/**
* Retrieves the total entry column accessors.
* @returns {IColumnMapperMeta[]}
*/
private blankEnrtyColumnAccessors = (): IColumnMapperMeta[] => {
return [
{ key: 'date', value: '' },
{ key: 'transaction_type', value: '' },
{ key: 'transaction_number', value: '' },
{ key: 'description', value: '' },
{ key: 'account_code', value: '' },
{ key: 'account_name', value: '' },
{ key: 'credit', value: '' },
{ key: 'debit', value: '' },
];
};

/**
* Retrieves the common columns.
* @returns {ITableColumn[]}
Expand Down Expand Up @@ -113,6 +135,7 @@ export class JournalSheetTable extends R.compose(
};
const computedGroup = { ...group, entry: first(group.entries) };
const columns = this.groupColumnsAccessors();

return tableRowMapper(computedGroup, columns, meta);
};

Expand Down Expand Up @@ -153,6 +176,16 @@ export class JournalSheetTable extends R.compose(
return tableRowMapper(group, total, meta);
};

/**
* Retrieves the blank entry row.
* @returns {ITableRow}
*/
private blankEntryMapper = (): ITableRow => {
const columns = this.blankEnrtyColumnAccessors();
const meta = {};
return tableRowMapper({} as IJournalEntry, columns, meta);
};

/**
* Maps the entry group to table rows.
* @param {IJournalReportEntriesGroup} group -
Expand All @@ -162,8 +195,9 @@ export class JournalSheetTable extends R.compose(
const firstRow = this.firstEntryGroupMapper(group);
const lastRows = this.entriesMapper(group);
const totalRow = this.totalEntryMapper(group);
const blankRow = this.blankEntryMapper();

return [firstRow, ...lastRows, totalRow];
return [firstRow, ...lastRows, totalRow, blankRow];
};

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@


enum ROW_TYPE {
export enum ROW_TYPE {
ENTRY = 'ENTRY',
TOTAL = 'TOTAL'
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import classNames from 'classnames';

import { DashboardActionsBar, FormattedMessage as T, Icon } from '@/components';
import { GeneralLedgerSheetExportMenu } from './components';
import { useGeneralLedgerContext } from './GeneralLedgerProvider';
import { compose } from '@/utils';

Expand Down Expand Up @@ -84,11 +85,18 @@ function GeneralLedgerActionsBar({
icon={<Icon icon="print-16" iconSize={16} />}
text={<T id={'print'} />}
/>
<Button
className={Classes.MINIMAL}
icon={<Icon icon="file-export-16" iconSize={16} />}
text={<T id={'export'} />}
/>
<Popover
content={<GeneralLedgerSheetExportMenu />}
interactionKind={PopoverInteractionKind.CLICK}
placement="bottom-start"
minimal
>
<Button
className={Classes.MINIMAL}
icon={<Icon icon="file-export-16" iconSize={16} />}
text={<T id={'export'} />}
/>
</Popover>
</NavbarGroup>
</DashboardActionsBar>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const GeneralLedgerHeaderDimensionsPanelContext = React.createContext();

/**
* General Ledger Header Dimensions Panel provider.
* @returns
* @returns {JSX.Element}
*/
function GeneralLedgerHeaderDimensionsPanelProvider({ query, ...props }) {
// Features guard.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function GeneralLedgerProvider({ query, ...props }) {
sheetRefresh: refetch,
isFetching,
isLoading,
httpRequest: requestQuery
};
return (
<FinancialReportPage name={'general-ledger-sheet'}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import {
} from '@/components';

import { useGeneralLedgerContext } from './GeneralLedgerProvider';
import { useGeneralLedgerTableColumns } from './components';
import { useGeneralLedgerTableColumns } from './dynamicColumns';

/**
* General ledger table.
*/
export default function GeneralLedgerTable({ companyName }) {
// General ledger context.
const {
generalLedger: { tableRows, query },
generalLedger: { query, table },
isLoading,
} = useGeneralLedgerContext();

Expand All @@ -30,8 +30,8 @@ export default function GeneralLedgerTable({ companyName }) {

// Default expanded rows of general ledger table.
const expandedRows = useMemo(
() => defaultExpanderReducer(tableRows, 1),
[tableRows],
() => defaultExpanderReducer(table.rows, 1),
[table.rows],
);

return (
Expand All @@ -48,7 +48,7 @@ export default function GeneralLedgerTable({ companyName }) {
'this_report_does_not_contain_any_data_between_date_period',
)}
columns={columns}
data={tableRows}
data={table.rows}
rowClassNames={tableRowTypesToClassnames}
expanded={expandedRows}
virtualizedRows={true}
Expand Down
Loading

0 comments on commit 79f3f1b

Please sign in to comment.