mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
feat: general ledger and journal exporting
This commit is contained in:
@@ -87,7 +87,7 @@ export default class GeneralLedgerReportController extends BaseFinancialReportCo
|
|||||||
return res.send(buffer);
|
return res.send(buffer);
|
||||||
// Retrieves the xlsx format.
|
// Retrieves the xlsx format.
|
||||||
} else if (ACCEPT_TYPE.APPLICATION_XLSX === acceptType) {
|
} 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('Content-Disposition', 'attachment; filename=output.xlsx');
|
||||||
res.setHeader(
|
res.setHeader(
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ export default class JournalSheetController extends BaseFinancialReportControlle
|
|||||||
return res.status(200).send(table);
|
return res.status(200).send(table);
|
||||||
// Retrieves the csv format.
|
// Retrieves the csv format.
|
||||||
} else if (ACCEPT_TYPE.APPLICATION_CSV === acceptType) {
|
} 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-Disposition', 'attachment; filename=output.csv');
|
||||||
res.setHeader('Content-Type', 'text/csv');
|
res.setHeader('Content-Type', 'text/csv');
|
||||||
|
|||||||
@@ -82,6 +82,8 @@ export interface IGeneralLedgerMeta {
|
|||||||
isCostComputeRunning: boolean,
|
isCostComputeRunning: boolean,
|
||||||
organizationName: string,
|
organizationName: string,
|
||||||
baseCurrency: string,
|
baseCurrency: string,
|
||||||
|
fromDate: string;
|
||||||
|
toDate: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface IGeneralLedgerTableData extends IFinancialTable {
|
export interface IGeneralLedgerTableData extends IFinancialTable {
|
||||||
|
|||||||
@@ -89,9 +89,10 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
|||||||
|
|
||||||
const newEntry = {
|
const newEntry = {
|
||||||
date: entry.date,
|
date: entry.date,
|
||||||
dateFormatted: moment(entry.date).format('YYYY/MM/DD'),
|
dateFormatted: moment(entry.date).format('YYYY MMM DD'),
|
||||||
entryId: entry.id,
|
entryId: entry.id,
|
||||||
|
|
||||||
|
transactionNumber: entry.transactionNumber,
|
||||||
referenceType: entry.referenceType,
|
referenceType: entry.referenceType,
|
||||||
referenceId: entry.referenceId,
|
referenceId: entry.referenceId,
|
||||||
referenceTypeFormatted: this.i18n.__(entry.referenceTypeFormatted),
|
referenceTypeFormatted: this.i18n.__(entry.referenceTypeFormatted),
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ export class GeneralLedgerService {
|
|||||||
* @param {number} tenantId -
|
* @param {number} tenantId -
|
||||||
* @returns {IGeneralLedgerMeta}
|
* @returns {IGeneralLedgerMeta}
|
||||||
*/
|
*/
|
||||||
reportMetadata(tenantId: number): IGeneralLedgerMeta {
|
reportMetadata(tenantId: number, filter): IGeneralLedgerMeta {
|
||||||
const settings = this.tenancy.settings(tenantId);
|
const settings = this.tenancy.settings(tenantId);
|
||||||
|
|
||||||
const isCostComputeRunning = this.inventoryService
|
const isCostComputeRunning = this.inventoryService
|
||||||
@@ -78,11 +78,15 @@ export class GeneralLedgerService {
|
|||||||
group: 'organization',
|
group: 'organization',
|
||||||
key: 'base_currency',
|
key: 'base_currency',
|
||||||
});
|
});
|
||||||
|
const fromDate = moment(filter.fromDate).format('YYYY MMM DD');
|
||||||
|
const toDate = moment(filter.toDate).format('YYYY MMM DD');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isCostComputeRunning: parseBoolean(isCostComputeRunning, false),
|
isCostComputeRunning: parseBoolean(isCostComputeRunning, false),
|
||||||
organizationName,
|
organizationName,
|
||||||
baseCurrency
|
baseCurrency,
|
||||||
|
fromDate,
|
||||||
|
toDate
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +170,7 @@ export class GeneralLedgerService {
|
|||||||
return {
|
return {
|
||||||
data: reportData,
|
data: reportData,
|
||||||
query: filter,
|
query: filter,
|
||||||
meta: this.reportMetadata(tenantId),
|
meta: this.reportMetadata(tenantId, filter),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import * as R from 'ramda';
|
import * as R from 'ramda';
|
||||||
import {
|
import {
|
||||||
IColumnMapperMeta,
|
IColumnMapperMeta,
|
||||||
|
IGeneralLedgerMeta,
|
||||||
IGeneralLedgerSheetAccount,
|
IGeneralLedgerSheetAccount,
|
||||||
IGeneralLedgerSheetAccountTransaction,
|
IGeneralLedgerSheetAccountTransaction,
|
||||||
IGeneralLedgerSheetData,
|
IGeneralLedgerSheetData,
|
||||||
@@ -21,17 +22,23 @@ export class GeneralLedgerTable extends R.compose(
|
|||||||
)(FinancialSheet) {
|
)(FinancialSheet) {
|
||||||
private data: IGeneralLedgerSheetData;
|
private data: IGeneralLedgerSheetData;
|
||||||
private query: IGeneralLedgerSheetQuery;
|
private query: IGeneralLedgerSheetQuery;
|
||||||
|
private meta: IGeneralLedgerMeta;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of `GeneralLedgerTable`.
|
* Creates an instance of `GeneralLedgerTable`.
|
||||||
* @param {IGeneralLedgerSheetData} data
|
* @param {IGeneralLedgerSheetData} data
|
||||||
* @param {IGeneralLedgerSheetQuery} query
|
* @param {IGeneralLedgerSheetQuery} query
|
||||||
*/
|
*/
|
||||||
constructor(data: IGeneralLedgerSheetData, query: IGeneralLedgerSheetQuery) {
|
constructor(
|
||||||
|
data: IGeneralLedgerSheetData,
|
||||||
|
query: IGeneralLedgerSheetQuery,
|
||||||
|
meta: IGeneralLedgerMeta
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
|
this.meta = meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,8 +68,8 @@ export class GeneralLedgerTable extends R.compose(
|
|||||||
{ key: 'date', accessor: 'dateFormatted' },
|
{ key: 'date', accessor: 'dateFormatted' },
|
||||||
{ key: 'account_name', accessor: 'account.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: 'transactionNumber' },
|
||||||
{ key: 'description', accessor: 'description' },
|
{ key: 'description', accessor: 'note' },
|
||||||
{ key: 'credit', accessor: 'formattedCredit' },
|
{ key: 'credit', accessor: 'formattedCredit' },
|
||||||
{ key: 'debit', accessor: 'formattedDebit' },
|
{ key: 'debit', accessor: 'formattedDebit' },
|
||||||
{ key: 'amount', accessor: 'formattedAmount' },
|
{ key: 'amount', accessor: 'formattedAmount' },
|
||||||
@@ -76,7 +83,7 @@ export class GeneralLedgerTable extends R.compose(
|
|||||||
*/
|
*/
|
||||||
private openingBalanceColumnsAccessors(): IColumnMapperMeta[] {
|
private openingBalanceColumnsAccessors(): IColumnMapperMeta[] {
|
||||||
return [
|
return [
|
||||||
{ key: 'date', accessor: 'dateFormatted' },
|
{ key: 'date', value: this.meta.fromDate },
|
||||||
{ key: 'account_name', value: 'Opening Balance' },
|
{ key: 'account_name', value: 'Opening Balance' },
|
||||||
{ key: 'reference_type', accessor: '_empty_' },
|
{ key: 'reference_type', accessor: '_empty_' },
|
||||||
{ key: 'reference_number', accessor: '_empty_' },
|
{ key: 'reference_number', accessor: '_empty_' },
|
||||||
@@ -84,7 +91,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: 'openingBalance.formattedAmount' },
|
{ 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[] {
|
private closingBalanceColumnAccessors(): IColumnMapperMeta[] {
|
||||||
return [
|
return [
|
||||||
{ key: 'date', accessor: 'dateFormatted' },
|
{ key: 'date', value: this.meta.toDate },
|
||||||
{ key: 'account_name', value: 'Closing Balance' },
|
{ key: 'account_name', value: 'Closing Balance' },
|
||||||
{ key: 'reference_type', accessor: '_empty_' },
|
{ key: 'reference_type', accessor: '_empty_' },
|
||||||
{ key: 'reference_number', accessor: '_empty_' },
|
{ key: 'reference_number', accessor: '_empty_' },
|
||||||
@@ -102,7 +109,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: 'closingBalance.formattedAmount' },
|
{ 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: 'date', label: 'Date' },
|
||||||
{ key: 'account_name', label: 'Account Name' },
|
{ key: 'account_name', label: 'Account Name' },
|
||||||
{ key: 'reference_type', label: 'Transaction Type' },
|
{ key: 'reference_type', label: 'Transaction Type' },
|
||||||
{ key: 'reference_number', label: 'Transaction Number' },
|
{ key: 'reference_number', label: 'Transaction #' },
|
||||||
{ key: 'description', label: 'Description' },
|
{ key: 'description', label: 'Description' },
|
||||||
{ key: 'credit', label: 'Credit' },
|
{ key: 'credit', label: 'Credit' },
|
||||||
{ key: 'debit', label: 'Debit' },
|
{ key: 'debit', label: 'Debit' },
|
||||||
@@ -196,7 +203,10 @@ export class GeneralLedgerTable extends R.compose(
|
|||||||
const transactions = this.transactionsMapper(account);
|
const transactions = this.transactionsMapper(account);
|
||||||
const closingBalance = this.closingBalanceMapper(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[];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export class GeneralLedgerTableInjectable {
|
|||||||
meta: sheetMeta,
|
meta: sheetMeta,
|
||||||
} = await this.GLSheet.generalLedger(tenantId, query);
|
} = await this.GLSheet.generalLedger(tenantId, query);
|
||||||
|
|
||||||
const table = new GeneralLedgerTable(sheetData, sheetQuery);
|
const table = new GeneralLedgerTable(sheetData, sheetQuery, sheetMeta);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
table: {
|
table: {
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ export default class JournalSheet extends FinancialSheet {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
date: groupEntry.date,
|
date: groupEntry.date,
|
||||||
dateFormatted: moment(groupEntry.date).format('YYYY/MM/DD'),
|
dateFormatted: moment(groupEntry.date).format('YYYY MMM DD'),
|
||||||
|
|
||||||
referenceType: groupEntry.referenceType,
|
referenceType: groupEntry.referenceType,
|
||||||
referenceId: groupEntry.referenceId,
|
referenceId: groupEntry.referenceId,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ export class JournalSheetTable extends R.compose(
|
|||||||
*/
|
*/
|
||||||
constructor(data: IJournalTableData, query: IJournalReportQuery, i18n: any) {
|
constructor(data: IJournalTableData, query: IJournalReportQuery, i18n: any) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.i18n = i18n;
|
this.i18n = i18n;
|
||||||
@@ -43,10 +44,10 @@ export class JournalSheetTable extends R.compose(
|
|||||||
*/
|
*/
|
||||||
private groupColumnsAccessors = (): ITableColumnAccessor[] => {
|
private groupColumnsAccessors = (): ITableColumnAccessor[] => {
|
||||||
return [
|
return [
|
||||||
{ key: 'date', accessor: 'date' },
|
{ key: 'date', accessor: 'dateFormatted' },
|
||||||
{ key: 'transaction_type', accessor: 'referenceTypeFormatted' },
|
{ key: 'transaction_type', accessor: 'referenceTypeFormatted' },
|
||||||
{ key: 'transaction_number', accessor: 'referenceNumber' },
|
{ key: 'transaction_number', accessor: 'entry.transactionNumber' },
|
||||||
{ key: 'description', accessor: 'entry.description' },
|
{ key: 'description', accessor: 'entry.note' },
|
||||||
{ key: 'account_code', accessor: 'entry.accountCode' },
|
{ key: 'account_code', accessor: 'entry.accountCode' },
|
||||||
{ key: 'account_name', accessor: 'entry.accountName' },
|
{ key: 'account_name', accessor: 'entry.accountName' },
|
||||||
{ key: 'credit', accessor: 'entry.formattedCredit' },
|
{ key: 'credit', accessor: 'entry.formattedCredit' },
|
||||||
@@ -62,8 +63,8 @@ export class JournalSheetTable extends R.compose(
|
|||||||
return [
|
return [
|
||||||
{ key: 'date', accessor: '_empty_' },
|
{ key: 'date', accessor: '_empty_' },
|
||||||
{ key: 'transaction_type', accessor: '_empty_' },
|
{ key: 'transaction_type', accessor: '_empty_' },
|
||||||
{ key: 'transaction_number', accessor: '_empty_' },
|
{ key: 'transaction_number', accessor: 'transactionNumber' },
|
||||||
{ key: 'description', accessor: 'description' },
|
{ key: 'description', accessor: 'note' },
|
||||||
{ key: 'account_code', accessor: 'accountCode' },
|
{ key: 'account_code', accessor: 'accountCode' },
|
||||||
{ key: 'account_name', accessor: 'accountName' },
|
{ key: 'account_name', accessor: 'accountName' },
|
||||||
{ key: 'credit', accessor: 'formattedCredit' },
|
{ key: 'credit', accessor: 'formattedCredit' },
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ const transactionTypeColumnAccessor = (column) => {
|
|||||||
const transactionIdColumnAccessor = (column) => {
|
const transactionIdColumnAccessor = (column) => {
|
||||||
return {
|
return {
|
||||||
...column,
|
...column,
|
||||||
width: 100,
|
width: 80,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user