-
-
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: inventory valuation csv and xlsx export (#308)
* feat: inventory valuation csv and xlsx export * feat(server): inventory valuation sheet exporting * feat(webapp): inventory valuation sheet dyanmic columns * feat: inventory valuation dynamic columns * feat: inventory valuation TS types
- Loading branch information
Showing
15 changed files
with
622 additions
and
65 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
76 changes: 76 additions & 0 deletions
76
...ervices/FinancialStatements/InventoryValuationSheet/InventoryValuationSheetApplication.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,76 @@ | ||
import { | ||
IInventoryValuationReportQuery, | ||
IInventoryValuationSheet, | ||
IInventoryValuationTable, | ||
} from '@/interfaces'; | ||
import { Inject, Service } from 'typedi'; | ||
import { InventoryValuationSheetService } from './InventoryValuationSheetService'; | ||
import { InventoryValuationSheetTableInjectable } from './InventoryValuationSheetTableInjectable'; | ||
import { InventoryValuationSheetExportable } from './InventoryValuationSheetExportable'; | ||
|
||
@Service() | ||
export class InventoryValuationSheetApplication { | ||
@Inject() | ||
private inventoryValuationSheet: InventoryValuationSheetService; | ||
|
||
@Inject() | ||
private inventoryValuationTable: InventoryValuationSheetTableInjectable; | ||
|
||
@Inject() | ||
private inventoryValuationExport: InventoryValuationSheetExportable; | ||
|
||
/** | ||
* Retrieves the inventory valuation json format. | ||
* @param {number} tenantId | ||
* @param {IInventoryValuationReportQuery} query | ||
* @returns | ||
*/ | ||
public sheet( | ||
tenantId: number, | ||
query: IInventoryValuationReportQuery | ||
): Promise<IInventoryValuationSheet> { | ||
return this.inventoryValuationSheet.inventoryValuationSheet( | ||
tenantId, | ||
query | ||
); | ||
} | ||
|
||
/** | ||
* Retrieves the inventory valuation json table format. | ||
* @param {number} tenantId | ||
* @param {IInventoryValuationReportQuery} query | ||
* @returns {Promise<IInventoryValuationTable>} | ||
*/ | ||
public table( | ||
tenantId: number, | ||
query: IInventoryValuationReportQuery | ||
): Promise<IInventoryValuationTable> { | ||
return this.inventoryValuationTable.table(tenantId, query); | ||
} | ||
|
||
/** | ||
* Retrieves the inventory valuation xlsx format. | ||
* @param {number} tenantId | ||
* @param {IInventoryValuationReportQuery} query | ||
* @returns | ||
*/ | ||
public xlsx( | ||
tenantId: number, | ||
query: IInventoryValuationReportQuery | ||
): Promise<Buffer> { | ||
return this.inventoryValuationExport.xlsx(tenantId, query); | ||
} | ||
|
||
/** | ||
* Retrieves the inventory valuation csv format. | ||
* @param {number} tenantId | ||
* @param {IInventoryValuationReportQuery} query | ||
* @returns | ||
*/ | ||
public csv( | ||
tenantId: number, | ||
query: IInventoryValuationReportQuery | ||
): Promise<string> { | ||
return this.inventoryValuationExport.csv(tenantId, query); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...services/FinancialStatements/InventoryValuationSheet/InventoryValuationSheetExportable.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,46 @@ | ||
import { Inject, Service } from 'typedi'; | ||
import { IInventoryValuationReportQuery } from '@/interfaces'; | ||
import { InventoryValuationSheetTableInjectable } from './InventoryValuationSheetTableInjectable'; | ||
import { TableSheet } from '@/lib/Xlsx/TableSheet'; | ||
|
||
@Service() | ||
export class InventoryValuationSheetExportable { | ||
@Inject() | ||
private inventoryValuationTable: InventoryValuationSheetTableInjectable; | ||
|
||
/** | ||
* Retrieves the trial balance sheet in XLSX format. | ||
* @param {number} tenantId | ||
* @param {IInventoryValuationReportQuery} query | ||
* @returns {Promise<Buffer>} | ||
*/ | ||
public async xlsx( | ||
tenantId: number, | ||
query: IInventoryValuationReportQuery | ||
): Promise<Buffer> { | ||
const table = await this.inventoryValuationTable.table(tenantId, query); | ||
|
||
const tableSheet = new TableSheet(table.table); | ||
const tableCsv = tableSheet.convertToXLSX(); | ||
|
||
return tableSheet.convertToBuffer(tableCsv, 'xlsx'); | ||
} | ||
|
||
/** | ||
* Retrieves the trial balance sheet in CSV format. | ||
* @param {number} tenantId | ||
* @param {IInventoryValuationReportQuery} query | ||
* @returns {Promise<Buffer>} | ||
*/ | ||
public async csv( | ||
tenantId: number, | ||
query: IInventoryValuationReportQuery | ||
): Promise<string> { | ||
const table = await this.inventoryValuationTable.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
103 changes: 103 additions & 0 deletions
103
.../src/services/FinancialStatements/InventoryValuationSheet/InventoryValuationSheetTable.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,103 @@ | ||
import * as R from 'ramda'; | ||
import { | ||
IInventoryValuationItem, | ||
IInventoryValuationSheetData, | ||
IInventoryValuationTotal, | ||
ITableColumn, | ||
ITableColumnAccessor, | ||
ITableRow, | ||
} from '@/interfaces'; | ||
import { tableRowMapper } from '@/utils'; | ||
import FinancialSheet from '../FinancialSheet'; | ||
import { FinancialSheetStructure } from '../FinancialSheetStructure'; | ||
import { FinancialTable } from '../FinancialTable'; | ||
import { ROW_TYPE } from './_constants'; | ||
|
||
export class InventoryValuationSheetTable extends R.compose( | ||
FinancialTable, | ||
FinancialSheetStructure | ||
)(FinancialSheet) { | ||
private readonly data: IInventoryValuationSheetData; | ||
|
||
/** | ||
* Constructor method. | ||
* @param {IInventoryValuationSheetData} data | ||
*/ | ||
constructor(data: IInventoryValuationSheetData) { | ||
super(); | ||
this.data = data; | ||
} | ||
|
||
/** | ||
* Retrieves the common columns accessors. | ||
* @returns {ITableColumnAccessor} | ||
*/ | ||
private commonColumnsAccessors(): ITableColumnAccessor[] { | ||
return [ | ||
{ key: 'item_name', accessor: 'name' }, | ||
{ key: 'quantity', accessor: 'quantityFormatted' }, | ||
{ key: 'valuation', accessor: 'valuationFormatted' }, | ||
{ key: 'average', accessor: 'averageFormatted' }, | ||
]; | ||
} | ||
|
||
/** | ||
* Maps the given total node to table row. | ||
* @param {IInventoryValuationTotal} total | ||
* @returns {ITableRow} | ||
*/ | ||
private totalRowMapper = (total: IInventoryValuationTotal): ITableRow => { | ||
const accessors = this.commonColumnsAccessors(); | ||
const meta = { | ||
rowTypes: [ROW_TYPE.TOTAL], | ||
}; | ||
return tableRowMapper(total, accessors, meta); | ||
}; | ||
|
||
/** | ||
* Maps the given item node to table row. | ||
* @param {IInventoryValuationItem} item | ||
* @returns {ITableRow} | ||
*/ | ||
private itemRowMapper = (item: IInventoryValuationItem): ITableRow => { | ||
const accessors = this.commonColumnsAccessors(); | ||
const meta = { | ||
rowTypes: [ROW_TYPE.ITEM], | ||
}; | ||
return tableRowMapper(item, accessors, meta); | ||
}; | ||
|
||
/** | ||
* Maps the given items nodes to table rowes. | ||
* @param {IInventoryValuationItem[]} items | ||
* @returns {ITableRow[]} | ||
*/ | ||
private itemsRowsMapper = (items: IInventoryValuationItem[]): ITableRow[] => { | ||
return R.map(this.itemRowMapper)(items); | ||
}; | ||
|
||
/** | ||
* Retrieves the table rows. | ||
* @returns {ITableRow[]} | ||
*/ | ||
public tableRows(): ITableRow[] { | ||
const itemsRows = this.itemsRowsMapper(this.data.items); | ||
const totalRow = this.totalRowMapper(this.data.total); | ||
|
||
return [...itemsRows, totalRow]; | ||
} | ||
|
||
/** | ||
* Retrieves the table columns. | ||
* @returns {ITableColumn[]} | ||
*/ | ||
public tableColumns(): ITableColumn[] { | ||
const columns = [ | ||
{ key: 'item_name', label: 'Item Name' }, | ||
{ key: 'quantity', label: 'Quantity' }, | ||
{ key: 'valuation', label: 'Valuation' }, | ||
{ key: 'average', label: 'Average' }, | ||
]; | ||
return R.compose(this.tableColumnsCellIndexing)(columns); | ||
} | ||
} |
Oops, something went wrong.