feat: general ledger and journal exporting

This commit is contained in:
Ahmed Bouhuolia
2024-01-07 18:48:14 +02:00
parent 7aee76e461
commit 5ef99f2cb3
10 changed files with 41 additions and 23 deletions

View File

@@ -87,7 +87,7 @@ export default class GeneralLedgerReportController extends BaseFinancialReportCo
return res.send(buffer);
// Retrieves the xlsx format.
} else if (ACCEPT_TYPE.APPLICATION_XLSX === acceptType) {
const buffer = this.generalLedgerApplication.xlsx(tenantId, filter);
const buffer = await this.generalLedgerApplication.xlsx(tenantId, filter);
res.setHeader('Content-Disposition', 'attachment; filename=output.xlsx');
res.setHeader(

View File

@@ -80,7 +80,7 @@ export default class JournalSheetController extends BaseFinancialReportControlle
return res.status(200).send(table);
// Retrieves the csv format.
} else if (ACCEPT_TYPE.APPLICATION_CSV === acceptType) {
const buffer = this.journalSheetApp.csv(tenantId, filter);
const buffer = await this.journalSheetApp.csv(tenantId, filter);
res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
res.setHeader('Content-Type', 'text/csv');

View File

@@ -82,6 +82,8 @@ export interface IGeneralLedgerMeta {
isCostComputeRunning: boolean,
organizationName: string,
baseCurrency: string,
fromDate: string;
toDate: string;
};
export interface IGeneralLedgerTableData extends IFinancialTable {

View File

@@ -89,9 +89,10 @@ export default class GeneralLedgerSheet extends FinancialSheet {
const newEntry = {
date: entry.date,
dateFormatted: moment(entry.date).format('YYYY/MM/DD'),
dateFormatted: moment(entry.date).format('YYYY MMM DD'),
entryId: entry.id,
transactionNumber: entry.transactionNumber,
referenceType: entry.referenceType,
referenceId: entry.referenceId,
referenceTypeFormatted: this.i18n.__(entry.referenceTypeFormatted),

View File

@@ -64,7 +64,7 @@ export class GeneralLedgerService {
* @param {number} tenantId -
* @returns {IGeneralLedgerMeta}
*/
reportMetadata(tenantId: number): IGeneralLedgerMeta {
reportMetadata(tenantId: number, filter): IGeneralLedgerMeta {
const settings = this.tenancy.settings(tenantId);
const isCostComputeRunning = this.inventoryService
@@ -78,11 +78,15 @@ export class GeneralLedgerService {
group: 'organization',
key: 'base_currency',
});
const fromDate = moment(filter.fromDate).format('YYYY MMM DD');
const toDate = moment(filter.toDate).format('YYYY MMM DD');
return {
isCostComputeRunning: parseBoolean(isCostComputeRunning, false),
organizationName,
baseCurrency
baseCurrency,
fromDate,
toDate
};
}
@@ -166,7 +170,7 @@ export class GeneralLedgerService {
return {
data: reportData,
query: filter,
meta: this.reportMetadata(tenantId),
meta: this.reportMetadata(tenantId, filter),
};
}
}

View File

@@ -1,6 +1,7 @@
import * as R from 'ramda';
import {
IColumnMapperMeta,
IGeneralLedgerMeta,
IGeneralLedgerSheetAccount,
IGeneralLedgerSheetAccountTransaction,
IGeneralLedgerSheetData,
@@ -21,17 +22,23 @@ export class GeneralLedgerTable extends R.compose(
)(FinancialSheet) {
private data: IGeneralLedgerSheetData;
private query: IGeneralLedgerSheetQuery;
private meta: IGeneralLedgerMeta;
/**
* Creates an instance of `GeneralLedgerTable`.
* @param {IGeneralLedgerSheetData} data
* @param {IGeneralLedgerSheetQuery} query
*/
constructor(data: IGeneralLedgerSheetData, query: IGeneralLedgerSheetQuery) {
constructor(
data: IGeneralLedgerSheetData,
query: IGeneralLedgerSheetQuery,
meta: IGeneralLedgerMeta
) {
super();
this.data = data;
this.query = query;
this.meta = meta;
}
/**
@@ -61,8 +68,8 @@ export class GeneralLedgerTable extends R.compose(
{ key: 'date', accessor: 'dateFormatted' },
{ key: 'account_name', accessor: 'account.name' },
{ key: 'reference_type', accessor: 'referenceTypeFormatted' },
{ key: 'reference_number', accessor: 'referenceNumber' },
{ key: 'description', accessor: 'description' },
{ key: 'reference_number', accessor: 'transactionNumber' },
{ key: 'description', accessor: 'note' },
{ key: 'credit', accessor: 'formattedCredit' },
{ key: 'debit', accessor: 'formattedDebit' },
{ key: 'amount', accessor: 'formattedAmount' },
@@ -76,7 +83,7 @@ export class GeneralLedgerTable extends R.compose(
*/
private openingBalanceColumnsAccessors(): IColumnMapperMeta[] {
return [
{ key: 'date', accessor: 'dateFormatted' },
{ key: 'date', value: this.meta.fromDate },
{ key: 'account_name', value: 'Opening Balance' },
{ key: 'reference_type', accessor: '_empty_' },
{ key: 'reference_number', accessor: '_empty_' },
@@ -84,7 +91,7 @@ export class GeneralLedgerTable extends R.compose(
{ key: 'credit', accessor: '_empty_' },
{ key: 'debit', accessor: '_empty_' },
{ key: 'amount', accessor: 'openingBalance.formattedAmount' },
{ key: 'running_balance', accessor: '_empty' },
{ key: 'running_balance', accessor: 'openingBalance.formattedAmount' },
];
}
@@ -94,7 +101,7 @@ export class GeneralLedgerTable extends R.compose(
*/
private closingBalanceColumnAccessors(): IColumnMapperMeta[] {
return [
{ key: 'date', accessor: 'dateFormatted' },
{ key: 'date', value: this.meta.toDate },
{ key: 'account_name', value: 'Closing Balance' },
{ key: 'reference_type', accessor: '_empty_' },
{ key: 'reference_number', accessor: '_empty_' },
@@ -102,7 +109,7 @@ export class GeneralLedgerTable extends R.compose(
{ key: 'credit', accessor: '_empty_' },
{ key: 'debit', accessor: '_empty_' },
{ key: 'amount', accessor: 'closingBalance.formattedAmount' },
{ key: 'running_balance', accessor: '_empty_' },
{ key: 'running_balance', accessor: 'closingBalance.formattedAmount' },
];
}
@@ -115,7 +122,7 @@ export class GeneralLedgerTable extends R.compose(
{ key: 'date', label: 'Date' },
{ key: 'account_name', label: 'Account Name' },
{ key: 'reference_type', label: 'Transaction Type' },
{ key: 'reference_number', label: 'Transaction Number' },
{ key: 'reference_number', label: 'Transaction #' },
{ key: 'description', label: 'Description' },
{ key: 'credit', label: 'Credit' },
{ key: 'debit', label: 'Debit' },
@@ -196,7 +203,10 @@ export class GeneralLedgerTable extends R.compose(
const transactions = this.transactionsMapper(account);
const closingBalance = this.closingBalanceMapper(account);
return [openingBalance, ...transactions, closingBalance];
return R.when(
R.always(R.not(R.isEmpty(transactions))),
R.prepend(openingBalance)
)([...transactions, closingBalance]) as ITableRow[];
};
/**

View File

@@ -31,7 +31,7 @@ export class GeneralLedgerTableInjectable {
meta: sheetMeta,
} = await this.GLSheet.generalLedger(tenantId, query);
const table = new GeneralLedgerTable(sheetData, sheetQuery);
const table = new GeneralLedgerTable(sheetData, sheetQuery, sheetMeta);
return {
table: {

View File

@@ -98,7 +98,7 @@ export default class JournalSheet extends FinancialSheet {
return {
date: groupEntry.date,
dateFormatted: moment(groupEntry.date).format('YYYY/MM/DD'),
dateFormatted: moment(groupEntry.date).format('YYYY MMM DD'),
referenceType: groupEntry.referenceType,
referenceId: groupEntry.referenceId,

View File

@@ -32,6 +32,7 @@ export class JournalSheetTable extends R.compose(
*/
constructor(data: IJournalTableData, query: IJournalReportQuery, i18n: any) {
super();
this.data = data;
this.query = query;
this.i18n = i18n;
@@ -43,10 +44,10 @@ export class JournalSheetTable extends R.compose(
*/
private groupColumnsAccessors = (): ITableColumnAccessor[] => {
return [
{ key: 'date', accessor: 'date' },
{ key: 'date', accessor: 'dateFormatted' },
{ key: 'transaction_type', accessor: 'referenceTypeFormatted' },
{ key: 'transaction_number', accessor: 'referenceNumber' },
{ key: 'description', accessor: 'entry.description' },
{ key: 'transaction_number', accessor: 'entry.transactionNumber' },
{ key: 'description', accessor: 'entry.note' },
{ key: 'account_code', accessor: 'entry.accountCode' },
{ key: 'account_name', accessor: 'entry.accountName' },
{ key: 'credit', accessor: 'entry.formattedCredit' },
@@ -62,8 +63,8 @@ export class JournalSheetTable extends R.compose(
return [
{ key: 'date', accessor: '_empty_' },
{ key: 'transaction_type', accessor: '_empty_' },
{ key: 'transaction_number', accessor: '_empty_' },
{ key: 'description', accessor: 'description' },
{ key: 'transaction_number', accessor: 'transactionNumber' },
{ key: 'description', accessor: 'note' },
{ key: 'account_code', accessor: 'accountCode' },
{ key: 'account_name', accessor: 'accountName' },
{ key: 'credit', accessor: 'formattedCredit' },

View File

@@ -70,7 +70,7 @@ const transactionTypeColumnAccessor = (column) => {
const transactionIdColumnAccessor = (column) => {
return {
...column,
width: 100,
width: 80,
};
};