-
-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): general ledger exporting to csv/xlsx
- Loading branch information
Showing
9 changed files
with
376 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,45 @@ | ||
import { IJournalEntry } from './Journal'; | ||
import { IFinancialTable } from './Table'; | ||
|
||
export interface IJournalReportQuery { | ||
fromDate: Date | string, | ||
toDate: Date | string, | ||
fromDate: Date | string; | ||
toDate: Date | string; | ||
numberFormat: { | ||
noCents: boolean, | ||
divideOn1000: boolean, | ||
}, | ||
transactionType: string, | ||
transactionId: string, | ||
|
||
accountsIds: number | number[], | ||
fromRange: number, | ||
toRange: number, | ||
noCents: boolean; | ||
divideOn1000: boolean; | ||
}; | ||
transactionType: string; | ||
transactionId: string; | ||
|
||
accountsIds: number | number[]; | ||
fromRange: number; | ||
toRange: number; | ||
} | ||
|
||
export interface IJournalReportEntriesGroup { | ||
id: string, | ||
entries: IJournalEntry[], | ||
currencyCode: string, | ||
credit: number, | ||
debit: number, | ||
formattedCredit: string, | ||
formattedDebit: string, | ||
id: string; | ||
entries: IJournalEntry[]; | ||
currencyCode: string; | ||
credit: number; | ||
debit: number; | ||
formattedCredit: string; | ||
formattedDebit: string; | ||
} | ||
|
||
export interface IJournalReport { | ||
entries: IJournalReportEntriesGroup[], | ||
entries: IJournalReportEntriesGroup[]; | ||
} | ||
|
||
export interface IJournalSheetMeta { | ||
isCostComputeRunning: boolean, | ||
organizationName: string, | ||
baseCurrency: string, | ||
} | ||
isCostComputeRunning: boolean; | ||
organizationName: string; | ||
baseCurrency: string; | ||
} | ||
|
||
export interface IJournalTable extends IFinancialTable { | ||
query: IJournalReportQuery; | ||
meta: IJournalSheetMeta; | ||
} | ||
|
||
|
||
export type IJournalTableData = IJournalReportEntriesGroup[]; |
66 changes: 66 additions & 0 deletions
66
packages/server/src/services/FinancialStatements/GeneralLedger/GeneralLedgerApplication.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Inject } from 'typedi'; | ||
import { | ||
IGeneralLedgerSheetQuery, | ||
IGeneralLedgerTableData, | ||
} from '@/interfaces'; | ||
import { GeneralLedgerTableInjectable } from './GeneralLedgerTableInjectable'; | ||
import { GeneralLedgerExportInjectable } from './GeneralLedgerExport'; | ||
import { GeneralLedgerService } from './GeneralLedgerService'; | ||
|
||
export class GeneralLedgerApplication { | ||
@Inject() | ||
private GLTable: GeneralLedgerTableInjectable; | ||
|
||
@Inject() | ||
private GLExport: GeneralLedgerExportInjectable; | ||
|
||
@Inject() | ||
private GLSheet: GeneralLedgerService; | ||
|
||
/** | ||
* Retrieves the G/L sheet in json format. | ||
* @param {number} tenantId | ||
* @param {IGeneralLedgerSheetQuery} query | ||
*/ | ||
public sheet(tenantId: number, query: IGeneralLedgerSheetQuery) { | ||
return this.GLSheet.generalLedger(tenantId, query); | ||
} | ||
|
||
/** | ||
* Retrieves the G/L sheet in table format. | ||
* @param {number} tenantId | ||
* @param {IGeneralLedgerSheetQuery} query | ||
* @returns {Promise<IGeneralLedgerTableData>} | ||
*/ | ||
public table( | ||
tenantId: number, | ||
query: IGeneralLedgerSheetQuery | ||
): Promise<IGeneralLedgerTableData> { | ||
return this.GLTable.table(tenantId, query); | ||
} | ||
|
||
/** | ||
* Retrieves the G/L sheet in xlsx format. | ||
* @param {number} tenantId | ||
* @param {IGeneralLedgerSheetQuery} query | ||
* @returns {} | ||
*/ | ||
public xlsx( | ||
tenantId: number, | ||
query: IGeneralLedgerSheetQuery | ||
): Promise<Buffer> { | ||
return this.GLExport.xlsx(tenantId, query); | ||
} | ||
|
||
/** | ||
* Retrieves the G/L sheet in csv format. | ||
* @param {number} tenantId - | ||
* @param {IGeneralLedgerSheetQuery} query - | ||
*/ | ||
public csv( | ||
tenantId: number, | ||
query: IGeneralLedgerSheetQuery | ||
): Promise<string> { | ||
return this.GLExport.csv(tenantId, query); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/server/src/services/FinancialStatements/GeneralLedger/GeneralLedgerExport.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { IGeneralLedgerSheetQuery } from '@/interfaces'; | ||
import { TableSheet } from '@/lib/Xlsx/TableSheet'; | ||
import { Inject, Service } from 'typedi'; | ||
import { GeneralLedgerTableInjectable } from './GeneralLedgerTableInjectable'; | ||
|
||
@Service() | ||
export class GeneralLedgerExportInjectable { | ||
@Inject() | ||
private generalLedgerTable: GeneralLedgerTableInjectable; | ||
|
||
/** | ||
* Retrieves the general ledger sheet in XLSX format. | ||
* @param {number} tenantId | ||
* @param {IGeneralLedgerSheetQuery} query | ||
* @returns {Promise<Buffer>} | ||
*/ | ||
public async xlsx(tenantId: number, query: IGeneralLedgerSheetQuery) { | ||
const table = await this.generalLedgerTable.table(tenantId, query); | ||
|
||
const tableSheet = new TableSheet(table.table); | ||
const tableCsv = tableSheet.convertToXLSX(); | ||
|
||
return tableSheet.convertToBuffer(tableCsv, 'xlsx'); | ||
} | ||
|
||
/** | ||
* Retrieves the general ledger sheet in CSV format. | ||
* @param {number} tenantId | ||
* @param {IGeneralLedgerSheetQuery} query | ||
* @returns {Promise<Buffer>} | ||
*/ | ||
public async csv( | ||
tenantId: number, | ||
query: IGeneralLedgerSheetQuery | ||
): Promise<string> { | ||
const table = await this.generalLedgerTable.table(tenantId, query); | ||
|
||
const tableSheet = new TableSheet(table.table); | ||
const tableCsv = tableSheet.convertToCSV(); | ||
|
||
return tableCsv; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.