mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
Merge branch 'develop' into optimize-printing
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { APAgingSummaryExportInjectable } from './APAgingSummaryExportInjectable';
|
||||
import { APAgingSummaryTableInjectable } from './APAgingSummaryTableInjectable';
|
||||
import { IAPAgingSummaryQuery } from '@/interfaces';
|
||||
import { APAgingSummaryService } from './APAgingSummaryService';
|
||||
|
||||
@Service()
|
||||
export class APAgingSummaryApplication {
|
||||
@Inject()
|
||||
private APAgingSummaryTable: APAgingSummaryTableInjectable;
|
||||
|
||||
@Inject()
|
||||
private APAgingSummaryExport: APAgingSummaryExportInjectable;
|
||||
|
||||
@Inject()
|
||||
private APAgingSummarySheet: APAgingSummaryService;
|
||||
|
||||
/**
|
||||
* Retrieve the A/P aging summary in sheet format.
|
||||
* @param {number} tenantId
|
||||
* @param {IAPAgingSummaryQuery} query
|
||||
*/
|
||||
public sheet(tenantId: number, query: IAPAgingSummaryQuery) {
|
||||
return this.APAgingSummarySheet.APAgingSummary(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the A/P aging summary in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {IAPAgingSummaryQuery} query
|
||||
*/
|
||||
public table(tenantId: number, query: IAPAgingSummaryQuery) {
|
||||
return this.APAgingSummaryTable.table(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the A/P aging summary in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {IAPAgingSummaryQuery} query
|
||||
*/
|
||||
public csv(tenantId: number, query: IAPAgingSummaryQuery) {
|
||||
return this.APAgingSummaryExport.csv(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the A/P aging summary in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {IAPAgingSummaryQuery} query
|
||||
*/
|
||||
public xlsx(tenantId: number, query: IAPAgingSummaryQuery) {
|
||||
return this.APAgingSummaryExport.xlsx(tenantId, query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { APAgingSummaryTableInjectable } from './APAgingSummaryTableInjectable';
|
||||
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||
import { IAPAgingSummaryQuery } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export class APAgingSummaryExportInjectable {
|
||||
@Inject()
|
||||
private APAgingSummaryTable: APAgingSummaryTableInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the A/P aging summary sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {IAPAgingSummaryQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async xlsx(tenantId: number, query: IAPAgingSummaryQuery) {
|
||||
const table = await this.APAgingSummaryTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToXLSX();
|
||||
|
||||
return tableSheet.convertToBuffer(tableCsv, 'xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the A/P aging summary sheet in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {IAPAgingSummaryQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async csv(
|
||||
tenantId: number,
|
||||
query: IAPAgingSummaryQuery
|
||||
): Promise<string> {
|
||||
const table = await this.APAgingSummaryTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToCSV();
|
||||
|
||||
return tableCsv;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
import moment from 'moment';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { IAPAgingSummaryQuery, IARAgingSummaryMeta } from '@/interfaces';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import APAgingSummarySheet from './APAgingSummarySheet';
|
||||
import { Tenant } from '@/system/models';
|
||||
import { isEmpty } from 'lodash';
|
||||
import APAgingSummaryTable from './APAgingSummaryTable';
|
||||
|
||||
@Service()
|
||||
export default class PayableAgingSummaryService {
|
||||
export class APAgingSummaryService {
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@@ -18,7 +17,7 @@ export default class PayableAgingSummaryService {
|
||||
/**
|
||||
* Default report query.
|
||||
*/
|
||||
get defaultQuery(): IAPAgingSummaryQuery {
|
||||
private get defaultQuery(): IAPAgingSummaryQuery {
|
||||
return {
|
||||
asDate: moment().format('YYYY-MM-DD'),
|
||||
agingDaysBefore: 30,
|
||||
@@ -119,21 +118,4 @@ export default class PayableAgingSummaryService {
|
||||
meta: this.reportMetadata(tenantId),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves A/P aging summary in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {IAPAgingSummaryQuery} query
|
||||
*/
|
||||
async APAgingSummaryTable(tenantId: number, query: IAPAgingSummaryQuery) {
|
||||
const report = await this.APAgingSummary(tenantId, query);
|
||||
const table = new APAgingSummaryTable(report.data, query, {});
|
||||
|
||||
return {
|
||||
columns: table.tableColumns(),
|
||||
rows: table.tableRows(),
|
||||
meta: report.meta,
|
||||
query: report.query,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { IAPAgingSummaryQuery, IAPAgingSummaryTable } from '@/interfaces';
|
||||
import { APAgingSummaryService } from './APAgingSummaryService';
|
||||
import APAgingSummaryTable from './APAgingSummaryTable';
|
||||
|
||||
@Service()
|
||||
export class APAgingSummaryTableInjectable {
|
||||
@Inject()
|
||||
private APAgingSummarySheet: APAgingSummaryService;
|
||||
|
||||
/**
|
||||
* Retrieves A/P aging summary in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {IAPAgingSummaryQuery} query
|
||||
* @returns {Promise<IAPAgingSummaryTable>}
|
||||
*/
|
||||
public async table(
|
||||
tenantId: number,
|
||||
query: IAPAgingSummaryQuery
|
||||
): Promise<IAPAgingSummaryTable> {
|
||||
const report = await this.APAgingSummarySheet.APAgingSummary(
|
||||
tenantId,
|
||||
query
|
||||
);
|
||||
const table = new APAgingSummaryTable(report.data, query, {});
|
||||
|
||||
return {
|
||||
table: {
|
||||
columns: table.tableColumns(),
|
||||
rows: table.tableRows(),
|
||||
},
|
||||
meta: report.meta,
|
||||
query: report.query,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { IARAgingSummaryQuery } from '@/interfaces';
|
||||
import { ARAgingSummaryTableInjectable } from './ARAgingSummaryTableInjectable';
|
||||
import { ARAgingSummaryExportInjectable } from './ARAgingSummaryExportInjectable';
|
||||
import ARAgingSummaryService from './ARAgingSummaryService';
|
||||
|
||||
@Service()
|
||||
export class ARAgingSummaryApplication {
|
||||
@Inject()
|
||||
private ARAgingSummaryTable: ARAgingSummaryTableInjectable;
|
||||
|
||||
@Inject()
|
||||
private ARAgingSummaryExport: ARAgingSummaryExportInjectable;
|
||||
|
||||
@Inject()
|
||||
private ARAgingSummarySheet: ARAgingSummaryService;
|
||||
|
||||
/**
|
||||
* Retrieve the A/R aging summary sheet.
|
||||
* @param {number} tenantId
|
||||
* @param {IAPAgingSummaryQuery} query
|
||||
*/
|
||||
public sheet(tenantId: number, query: IARAgingSummaryQuery) {
|
||||
return this.ARAgingSummarySheet.ARAgingSummary(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the A/R aging summary in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {IAPAgingSummaryQuery} query
|
||||
*/
|
||||
public table(tenantId: number, query: IARAgingSummaryQuery) {
|
||||
return this.ARAgingSummaryTable.table(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the A/R aging summary in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {IAPAgingSummaryQuery} query
|
||||
*/
|
||||
public xlsx(tenantId: number, query: IARAgingSummaryQuery) {
|
||||
return this.ARAgingSummaryExport.xlsx(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the A/R aging summary in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {IAPAgingSummaryQuery} query
|
||||
*/
|
||||
public csv(tenantId: number, query: IARAgingSummaryQuery) {
|
||||
return this.ARAgingSummaryExport.csv(tenantId, query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||
import { ARAgingSummaryTableInjectable } from './ARAgingSummaryTableInjectable';
|
||||
import { IARAgingSummaryQuery } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export class ARAgingSummaryExportInjectable {
|
||||
@Inject()
|
||||
private ARAgingSummaryTable: ARAgingSummaryTableInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the A/R aging summary sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {IARAgingSummaryQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async xlsx(
|
||||
tenantId: number,
|
||||
query: IARAgingSummaryQuery
|
||||
): Promise<Buffer> {
|
||||
const table = await this.ARAgingSummaryTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToXLSX();
|
||||
|
||||
return tableSheet.convertToBuffer(tableCsv, 'xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the A/R aging summary sheet in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {ICashFlowStatementQuery} query
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public async csv(
|
||||
tenantId: number,
|
||||
query: IARAgingSummaryQuery
|
||||
): Promise<string> {
|
||||
const table = await this.ARAgingSummaryTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToCSV();
|
||||
|
||||
return tableCsv;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import { IARAgingSummaryQuery, IARAgingSummaryMeta } from '@/interfaces';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import ARAgingSummarySheet from './ARAgingSummarySheet';
|
||||
import { Tenant } from '@/system/models';
|
||||
import ARAgingSummaryTable from './ARAgingSummaryTable';
|
||||
|
||||
@Service()
|
||||
export default class ARAgingSummaryService {
|
||||
@@ -118,21 +117,4 @@ export default class ARAgingSummaryService {
|
||||
meta: this.reportMetadata(tenantId),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves A/R aging summary in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {IARAgingSummaryQuery} query
|
||||
*/
|
||||
async ARAgingSummaryTable(tenantId: number, query: IARAgingSummaryQuery) {
|
||||
const report = await this.ARAgingSummary(tenantId, query);
|
||||
const table = new ARAgingSummaryTable(report.data, query, {});
|
||||
|
||||
return {
|
||||
columns: table.tableColumns(),
|
||||
rows: table.tableRows(),
|
||||
meta: report.meta,
|
||||
query,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { IARAgingSummaryQuery, IARAgingSummaryTable } from '@/interfaces';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import ARAgingSummaryTable from './ARAgingSummaryTable';
|
||||
import ARAgingSummaryService from './ARAgingSummaryService';
|
||||
|
||||
@Service()
|
||||
export class ARAgingSummaryTableInjectable {
|
||||
@Inject()
|
||||
private ARAgingSummarySheet: ARAgingSummaryService;
|
||||
|
||||
/**
|
||||
* Retrieves A/R aging summary in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {IARAgingSummaryQuery} query
|
||||
* @returns {Promise<IARAgingSummaryTable>}
|
||||
*/
|
||||
public async table(
|
||||
tenantId: number,
|
||||
query: IARAgingSummaryQuery
|
||||
): Promise<IARAgingSummaryTable> {
|
||||
const report = await this.ARAgingSummarySheet.ARAgingSummary(
|
||||
tenantId,
|
||||
query
|
||||
);
|
||||
const table = new ARAgingSummaryTable(report.data, query, {});
|
||||
|
||||
return {
|
||||
table: {
|
||||
columns: table.tableColumns(),
|
||||
rows: table.tableRows(),
|
||||
},
|
||||
meta: report.meta,
|
||||
query,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { IBalanceSheetQuery } from '@/interfaces';
|
||||
import { BalanceSheetExportInjectable } from './BalanceSheetExportInjectable';
|
||||
import { BalanceSheetTableInjectable } from './BalanceSheetTableInjectable';
|
||||
import BalanceSheetStatementService from './BalanceSheetInjectable';
|
||||
|
||||
@Service()
|
||||
export class BalanceSheetApplication {
|
||||
@Inject()
|
||||
public balanceSheetExport: BalanceSheetExportInjectable;
|
||||
|
||||
@Inject()
|
||||
public balanceSheetTable: BalanceSheetTableInjectable;
|
||||
|
||||
@Inject()
|
||||
public balanceSheet: BalanceSheetStatementService;
|
||||
|
||||
/**
|
||||
* Retrieves the balnace sheet in json format.
|
||||
* @param {numnber} tenantId
|
||||
* @param {IBalanceSheetQuery} query
|
||||
* @returns {Promise<IBalanceSheetStatement>}
|
||||
*/
|
||||
public sheet(tenantId: number, query: IBalanceSheetQuery) {
|
||||
return this.balanceSheet.balanceSheet(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the balance sheet in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {IBalanceSheetQuery} query
|
||||
* @returns {Promise<IBalanceSheetTable>}
|
||||
*/
|
||||
public table(tenantId: number, query: IBalanceSheetQuery) {
|
||||
return this.balanceSheetTable.table(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the balance sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {IBalanceSheetQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public xlsx(tenantId: number, query: IBalanceSheetQuery) {
|
||||
return this.balanceSheetExport.xlsx(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the balance sheet in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {IBalanceSheetQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public csv(tenantId: number, query: IBalanceSheetQuery): Promise<string> {
|
||||
return this.balanceSheetExport.csv(tenantId, query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { BalanceSheetTableInjectable } from './BalanceSheetTableInjectable';
|
||||
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||
import { IBalanceSheetQuery } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export class BalanceSheetExportInjectable {
|
||||
@Inject()
|
||||
private balanceSheetTable: BalanceSheetTableInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the trial balance sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITrialBalanceSheetQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async xlsx(tenantId: number, query: IBalanceSheetQuery) {
|
||||
const table = await this.balanceSheetTable.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 {ITrialBalanceSheetQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async csv(
|
||||
tenantId: number,
|
||||
query: IBalanceSheetQuery
|
||||
): Promise<string> {
|
||||
const table = await this.balanceSheetTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToCSV();
|
||||
|
||||
return tableCsv;
|
||||
}
|
||||
}
|
||||
@@ -19,13 +19,10 @@ export default class BalanceSheetStatementService
|
||||
implements IBalanceSheetStatementService
|
||||
{
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject('logger')
|
||||
logger: any;
|
||||
private tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
inventoryService: InventoryService;
|
||||
private inventoryService: InventoryService;
|
||||
|
||||
/**
|
||||
* Defaults balance sheet filter query.
|
||||
@@ -94,10 +91,8 @@ export default class BalanceSheetStatementService
|
||||
|
||||
/**
|
||||
* Retrieve balance sheet statement.
|
||||
* -------------
|
||||
* @param {number} tenantId
|
||||
* @param {IBalanceSheetQuery} query
|
||||
*
|
||||
* @return {IBalanceSheetStatement}
|
||||
*/
|
||||
public async balanceSheet(
|
||||
@@ -0,0 +1,42 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import BalanceSheetStatementService from './BalanceSheetInjectable';
|
||||
import BalanceSheetTable from './BalanceSheetTable';
|
||||
import { IBalanceSheetQuery, IBalanceSheetTable } from '@/interfaces';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
|
||||
@Service()
|
||||
export class BalanceSheetTableInjectable {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
@Inject()
|
||||
private balanceSheetService: BalanceSheetStatementService;
|
||||
|
||||
/**
|
||||
* Retrieves the balance sheet in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {number} query
|
||||
* @returns {Promise<IBalanceSheetTable>}
|
||||
*/
|
||||
public async table(
|
||||
tenantId: number,
|
||||
filter: IBalanceSheetQuery
|
||||
): Promise<IBalanceSheetTable> {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
|
||||
const { data, query, meta } = await this.balanceSheetService.balanceSheet(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
const table = new BalanceSheetTable(data, query, i18n);
|
||||
|
||||
return {
|
||||
table: {
|
||||
columns: table.tableColumns(),
|
||||
rows: table.tableRows(),
|
||||
},
|
||||
query,
|
||||
meta,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { ICashFlowStatementQuery } from '@/interfaces';
|
||||
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||
import { CashflowTableInjectable } from './CashflowTableInjectable';
|
||||
|
||||
@Service()
|
||||
export class CashflowExportInjectable {
|
||||
@Inject()
|
||||
private cashflowSheetTable: CashflowTableInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the cashflow sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {ICashFlowStatementQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async xlsx(
|
||||
tenantId: number,
|
||||
query: ICashFlowStatementQuery
|
||||
): Promise<Buffer> {
|
||||
const table = await this.cashflowSheetTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToXLSX();
|
||||
|
||||
return tableSheet.convertToBuffer(tableCsv, 'xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the cashflow sheet in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {ICashFlowStatementQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async csv(
|
||||
tenantId: number,
|
||||
query: ICashFlowStatementQuery
|
||||
): Promise<string> {
|
||||
const table = await this.cashflowSheetTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToCSV();
|
||||
|
||||
return tableCsv;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { CashflowExportInjectable } from './CashflowExportInjectable';
|
||||
import { ICashFlowStatementQuery } from '@/interfaces';
|
||||
import CashFlowStatementService from './CashFlowService';
|
||||
import { CashflowTableInjectable } from './CashflowTableInjectable';
|
||||
|
||||
@Service()
|
||||
export class CashflowSheetApplication {
|
||||
@Inject()
|
||||
private cashflowExport: CashflowExportInjectable;
|
||||
|
||||
@Inject()
|
||||
private cashflowSheet: CashFlowStatementService;
|
||||
|
||||
@Inject()
|
||||
private cashflowTable: CashflowTableInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the cashflow sheet
|
||||
* @param {number} tenantId
|
||||
* @param {ICashFlowStatementQuery} query
|
||||
*/
|
||||
public async sheet(tenantId: number, query: ICashFlowStatementQuery) {
|
||||
return this.cashflowSheet.cashFlow(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the cashflow sheet in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {ICashFlowStatementQuery} query
|
||||
*/
|
||||
public async table(tenantId: number, query: ICashFlowStatementQuery) {
|
||||
return this.cashflowTable.table(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the cashflow sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {ICashFlowStatementQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async xlsx(tenantId: number, query: ICashFlowStatementQuery) {
|
||||
return this.cashflowExport.xlsx(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the cashflow sheet in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {ICashFlowStatementQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async csv(
|
||||
tenantId: number,
|
||||
query: ICashFlowStatementQuery
|
||||
): Promise<string> {
|
||||
return this.cashflowExport.csv(tenantId, query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Inject, Service } from "typedi";
|
||||
import { ICashFlowStatementQuery, ICashFlowStatementTable } from "@/interfaces";
|
||||
import HasTenancyService from "@/services/Tenancy/TenancyService";
|
||||
import CashFlowTable from "./CashFlowTable";
|
||||
import CashFlowStatementService from "./CashFlowService";
|
||||
|
||||
@Service()
|
||||
export class CashflowTableInjectable {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
@Inject()
|
||||
private cashflowSheet: CashFlowStatementService;
|
||||
|
||||
/**
|
||||
* Retrieves the cash flow table.
|
||||
* @returns {Promise<ICashFlowStatementTable>}
|
||||
*/
|
||||
public async table(
|
||||
tenantId: number,
|
||||
query: ICashFlowStatementQuery
|
||||
): Promise<ICashFlowStatementTable> {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
|
||||
const cashflowDOO = await this.cashflowSheet.cashFlow(tenantId, query);
|
||||
const cashflowTable = new CashFlowTable(cashflowDOO, i18n);
|
||||
|
||||
return {
|
||||
table: {
|
||||
columns: cashflowTable.tableColumns(),
|
||||
rows: cashflowTable.tableRows(),
|
||||
},
|
||||
query: cashflowDOO.query,
|
||||
meta: cashflowDOO.meta,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { CustomerBalanceSummaryExportInjectable } from './CustomerBalanceSummaryExportInjectable';
|
||||
import { CustomerBalanceSummaryTableInjectable } from './CustomerBalanceSummaryTableInjectable';
|
||||
import { ICustomerBalanceSummaryQuery } from '@/interfaces';
|
||||
import { CustomerBalanceSummaryService } from './CustomerBalanceSummaryService';
|
||||
|
||||
@Service()
|
||||
export class CustomerBalanceSummaryApplication {
|
||||
@Inject()
|
||||
private customerBalanceSummaryTable: CustomerBalanceSummaryTableInjectable;
|
||||
|
||||
@Inject()
|
||||
private customerBalanceSummaryExport: CustomerBalanceSummaryExportInjectable;
|
||||
|
||||
@Inject()
|
||||
private customerBalanceSummarySheet: CustomerBalanceSummaryService;
|
||||
|
||||
/**
|
||||
* Retrieves the customer balance sheet in json format.
|
||||
* @param {number} tenantId
|
||||
* @param {ICustomerBalanceSummaryQuery} query
|
||||
* @returns {Promise<ICustomerBalanceSummarySheet>}
|
||||
*/
|
||||
public sheet(tenantId: number, query: ICustomerBalanceSummaryQuery) {
|
||||
return this.customerBalanceSummarySheet.customerBalanceSummary(
|
||||
tenantId,
|
||||
query
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the customer balance sheet in json format.
|
||||
* @param {number} tenantId
|
||||
* @param {ICustomerBalanceSummaryQuery} query
|
||||
* @returns {Promise<ICustomerBalanceSummaryTable>}
|
||||
*/
|
||||
public table(tenantId: number, query: ICustomerBalanceSummaryQuery) {
|
||||
return this.customerBalanceSummaryTable.table(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the customer balance sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {ICustomerBalanceSummaryQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public xlsx(tenantId: number, query: ICustomerBalanceSummaryQuery) {
|
||||
return this.customerBalanceSummaryExport.xlsx(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the customer balance sheet in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {ICustomerBalanceSummaryQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public csv(tenantId: number, query: ICustomerBalanceSummaryQuery) {
|
||||
return this.customerBalanceSummaryExport.csv(tenantId, query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { ICustomerBalanceSummaryQuery } from '@/interfaces';
|
||||
import { CustomerBalanceSummaryTableInjectable } from './CustomerBalanceSummaryTableInjectable';
|
||||
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||
|
||||
@Service()
|
||||
export class CustomerBalanceSummaryExportInjectable {
|
||||
@Inject()
|
||||
private customerBalanceSummaryTable: CustomerBalanceSummaryTableInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the cashflow sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {ICustomerBalanceSummaryQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async xlsx(tenantId: number, query: ICustomerBalanceSummaryQuery) {
|
||||
const table = await this.customerBalanceSummaryTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToXLSX();
|
||||
|
||||
return tableSheet.convertToBuffer(tableCsv, 'xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the cashflow sheet in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {ICustomerBalanceSummaryQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async csv(
|
||||
tenantId: number,
|
||||
query: ICustomerBalanceSummaryQuery
|
||||
): Promise<string> {
|
||||
const table = await this.customerBalanceSummaryTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToCSV();
|
||||
|
||||
return tableCsv;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
import { Inject } from 'typedi';
|
||||
import moment from 'moment';
|
||||
import { isEmpty, map } from 'lodash';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import * as R from 'ramda';
|
||||
import {
|
||||
ICustomerBalanceSummaryService,
|
||||
@@ -11,28 +9,21 @@ import {
|
||||
ILedgerEntry,
|
||||
} from '@/interfaces';
|
||||
import { CustomerBalanceSummaryReport } from './CustomerBalanceSummary';
|
||||
|
||||
import Ledger from '@/services/Accounting/Ledger';
|
||||
import CustomerBalanceSummaryRepository from './CustomerBalanceSummaryRepository';
|
||||
import { Tenant } from '@/system/models';
|
||||
|
||||
export default class CustomerBalanceSummaryService
|
||||
export class CustomerBalanceSummaryService
|
||||
implements ICustomerBalanceSummaryService
|
||||
{
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject('logger')
|
||||
logger: any;
|
||||
|
||||
@Inject()
|
||||
reportRepository: CustomerBalanceSummaryRepository;
|
||||
private reportRepository: CustomerBalanceSummaryRepository;
|
||||
|
||||
/**
|
||||
* Defaults balance sheet filter query.
|
||||
* @return {ICustomerBalanceSummaryQuery}
|
||||
*/
|
||||
get defaultQuery(): ICustomerBalanceSummaryQuery {
|
||||
private get defaultQuery(): ICustomerBalanceSummaryQuery {
|
||||
return {
|
||||
asDate: moment().format('YYYY-MM-DD'),
|
||||
numberFormat: {
|
||||
@@ -43,13 +34,12 @@ export default class CustomerBalanceSummaryService
|
||||
negativeFormat: 'mines',
|
||||
},
|
||||
percentageColumn: false,
|
||||
|
||||
|
||||
noneZero: false,
|
||||
noneTransactions: true,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the customers ledger entries mapped from accounts transactions.
|
||||
* @param {number} tenantId
|
||||
@@ -75,7 +65,7 @@ export default class CustomerBalanceSummaryService
|
||||
* @param {ICustomerBalanceSummaryQuery} query
|
||||
* @return {Promise<ICustomerBalanceSummaryStatement>}
|
||||
*/
|
||||
async customerBalanceSummary(
|
||||
public async customerBalanceSummary(
|
||||
tenantId: number,
|
||||
query: ICustomerBalanceSummaryQuery
|
||||
): Promise<ICustomerBalanceSummaryStatement> {
|
||||
@@ -86,13 +76,6 @@ export default class CustomerBalanceSummaryService
|
||||
// Merges the default query and request query.
|
||||
const filter = { ...this.defaultQuery, ...query };
|
||||
|
||||
this.logger.info(
|
||||
'[customer_balance_summary] trying to calculate the report.',
|
||||
{
|
||||
filter,
|
||||
tenantId,
|
||||
}
|
||||
);
|
||||
// Retrieve the customers list ordered by the display name.
|
||||
const customers = await this.reportRepository.getCustomers(
|
||||
tenantId,
|
||||
@@ -111,7 +94,7 @@ export default class CustomerBalanceSummaryService
|
||||
ledger,
|
||||
customers,
|
||||
filter,
|
||||
tenant.metadata.baseCurrency,
|
||||
tenant.metadata.baseCurrency
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { CustomerBalanceSummaryService } from './CustomerBalanceSummaryService';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import {
|
||||
ICustomerBalanceSummaryQuery,
|
||||
ICustomerBalanceSummaryTable,
|
||||
} from '@/interfaces';
|
||||
import { CustomerBalanceSummaryTable } from './CustomerBalanceSummaryTableRows';
|
||||
|
||||
@Service()
|
||||
export class CustomerBalanceSummaryTableInjectable {
|
||||
@Inject()
|
||||
private customerBalanceSummaryService: CustomerBalanceSummaryService;
|
||||
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Retrieves the customer balance sheet in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {ICustomerBalanceSummaryQuery} filter
|
||||
* @returns {Promise<ICustomerBalanceSummaryTable>}
|
||||
*/
|
||||
public async table(
|
||||
tenantId: number,
|
||||
filter: ICustomerBalanceSummaryQuery
|
||||
): Promise<ICustomerBalanceSummaryTable> {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
const { data, query } =
|
||||
await this.customerBalanceSummaryService.customerBalanceSummary(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
const tableRows = new CustomerBalanceSummaryTable(data, filter, i18n);
|
||||
|
||||
return {
|
||||
table: {
|
||||
columns: tableRows.tableColumns(),
|
||||
rows: tableRows.tableRows(),
|
||||
},
|
||||
query,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ enum TABLE_ROWS_TYPES {
|
||||
TOTAL = 'TOTAL',
|
||||
}
|
||||
|
||||
export default class CustomerBalanceSummaryTable {
|
||||
export class CustomerBalanceSummaryTable {
|
||||
report: ICustomerBalanceSummaryData;
|
||||
query: ICustomerBalanceSummaryQuery;
|
||||
i18n: any;
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { ITableRow } from '@/interfaces';
|
||||
import { flatNestedTree } from '@/utils/deepdash';
|
||||
import { repeat } from 'lodash';
|
||||
|
||||
interface FlatNestTreeOpts {
|
||||
nestedPrefix?: string;
|
||||
nestedPrefixIndex?: number;
|
||||
}
|
||||
|
||||
export class FinancialTableStructure {
|
||||
/**
|
||||
* Converts the given table object with nested rows in flat rows.
|
||||
* @param {ITableRow[]}
|
||||
* @param {FlatNestTreeOpts}
|
||||
* @returns {ITableRow[]}
|
||||
*/
|
||||
public static flatNestedTree = (
|
||||
obj: ITableRow[],
|
||||
options?: FlatNestTreeOpts
|
||||
): ITableRow[] => {
|
||||
const parsedOptions = {
|
||||
nestedPrefix: ' ',
|
||||
nestedPrefixIndex: 0,
|
||||
...options,
|
||||
};
|
||||
const { nestedPrefixIndex, nestedPrefix } = parsedOptions;
|
||||
|
||||
return flatNestedTree(
|
||||
obj,
|
||||
(item, key, context) => {
|
||||
const cells = item.cells.map((cell, index) => {
|
||||
return {
|
||||
...cell,
|
||||
value:
|
||||
(context.depth > 1 && nestedPrefixIndex === index
|
||||
? repeat(nestedPrefix, context.depth)
|
||||
: '') + cell.value,
|
||||
};
|
||||
});
|
||||
return {
|
||||
...item,
|
||||
cells,
|
||||
};
|
||||
},
|
||||
parsedOptions
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -29,7 +29,7 @@ enum INodeTypes {
|
||||
CLOSING_ENTRY = 'CLOSING_ENTRY',
|
||||
}
|
||||
|
||||
export default class InventoryDetails extends FinancialSheet {
|
||||
export class InventoryDetails extends FinancialSheet {
|
||||
readonly inventoryTransactionsByItemId: Map<number, IInventoryTransaction[]>;
|
||||
readonly openingBalanceTransactions: Map<number, IInventoryTransaction>;
|
||||
readonly query: IInventoryDetailsQuery;
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import {
|
||||
IInventoryDetailsQuery,
|
||||
IInvetoryItemDetailsTable,
|
||||
} from '@/interfaces';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { InventoryDetailsExportInjectable } from './InventoryDetailsExportInjectable';
|
||||
import { InventoryDetailsTableInjectable } from './InventoryDetailsTableInjectable';
|
||||
import { InventoryDetailsService } from './InventoryDetailsService';
|
||||
|
||||
@Service()
|
||||
export class InventortyDetailsApplication {
|
||||
@Inject()
|
||||
private inventoryDetailsExport: InventoryDetailsExportInjectable;
|
||||
|
||||
@Inject()
|
||||
private inventoryDetailsTable: InventoryDetailsTableInjectable;
|
||||
|
||||
@Inject()
|
||||
private inventoryDetails: InventoryDetailsService;
|
||||
|
||||
/**
|
||||
* Retrieves the inventory details report in sheet format.
|
||||
* @param {number} tenantId
|
||||
* @param {IInventoryDetailsQuery} query
|
||||
* @returns {Promise<IInvetoryItemDetailDOO>}
|
||||
*/
|
||||
public sheet(tenantId: number, query: IInventoryDetailsQuery) {
|
||||
return this.inventoryDetails.inventoryDetails(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the inventory details report in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {IInventoryDetailsQuery} query
|
||||
* @returns
|
||||
*/
|
||||
public table(
|
||||
tenantId: number,
|
||||
query: IInventoryDetailsQuery
|
||||
): Promise<IInvetoryItemDetailsTable> {
|
||||
return this.inventoryDetailsTable.table(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the inventory details report in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {IInventoryDetailsQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public xlsx(
|
||||
tenantId: number,
|
||||
query: IInventoryDetailsQuery
|
||||
): Promise<Buffer> {
|
||||
return this.inventoryDetailsExport.xlsx(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the inventory details report in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {IInventoryDetailsQuery} query
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public csv(tenantId: number, query: IInventoryDetailsQuery): Promise<string> {
|
||||
return this.inventoryDetailsExport.csv(tenantId, query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { IInventoryDetailsQuery } from '@/interfaces';
|
||||
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||
import { InventoryDetailsTableInjectable } from './InventoryDetailsTableInjectable';
|
||||
|
||||
@Service()
|
||||
export class InventoryDetailsExportInjectable {
|
||||
@Inject()
|
||||
private inventoryDetailsTable: InventoryDetailsTableInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the trial balance sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {IInventoryDetailsQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async xlsx(tenantId: number, query: IInventoryDetailsQuery) {
|
||||
const table = await this.inventoryDetailsTable.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 {IInventoryDetailsQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async csv(
|
||||
tenantId: number,
|
||||
query: IInventoryDetailsQuery
|
||||
): Promise<string> {
|
||||
const table = await this.inventoryDetailsTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToCSV();
|
||||
|
||||
return tableCsv;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
IInventoryItemDetailMeta,
|
||||
} from '@/interfaces';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import InventoryDetails from './InventoryDetails';
|
||||
import { InventoryDetails } from './InventoryDetails';
|
||||
import FinancialSheet from '../FinancialSheet';
|
||||
import InventoryDetailsRepository from './InventoryDetailsRepository';
|
||||
import InventoryService from '@/services/Inventory/Inventory';
|
||||
@@ -14,7 +14,7 @@ import { parseBoolean } from 'utils';
|
||||
import { Tenant } from '@/system/models';
|
||||
|
||||
@Service()
|
||||
export default class InventoryDetailsService extends FinancialSheet {
|
||||
export class InventoryDetailsService extends FinancialSheet {
|
||||
@Inject()
|
||||
private tenancy: TenancyService;
|
||||
|
||||
|
||||
@@ -20,13 +20,13 @@ enum IROW_TYPE {
|
||||
|
||||
const MAP_CONFIG = { childrenPath: 'children', pathFormat: 'array' };
|
||||
|
||||
export default class InventoryDetailsTable {
|
||||
export class InventoryDetailsTable {
|
||||
i18n: any;
|
||||
report: any;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
* @param {ICashFlowStatement} reportStatement - Report statement.
|
||||
* @param {ICashFlowStatement} report - Report statement.
|
||||
*/
|
||||
constructor(reportStatement, i18n) {
|
||||
this.report = reportStatement;
|
||||
@@ -172,7 +172,7 @@ export default class InventoryDetailsTable {
|
||||
* Retrieve the table rows of the inventory item details.
|
||||
* @returns {ITableRow[]}
|
||||
*/
|
||||
public tableData = (): ITableRow[] => {
|
||||
public tableRows = (): ITableRow[] => {
|
||||
return this.itemsMapper(this.report.data);
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { InventoryDetailsTable } from './InventoryDetailsTable';
|
||||
import {
|
||||
IInventoryDetailsQuery,
|
||||
IInvetoryItemDetailsTable,
|
||||
} from '@/interfaces';
|
||||
import { InventoryDetailsService } from './InventoryDetailsService';
|
||||
|
||||
@Service()
|
||||
export class InventoryDetailsTableInjectable {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
@Inject()
|
||||
private inventoryDetails: InventoryDetailsService;
|
||||
|
||||
/**
|
||||
* Retrieves the inventory item details in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {IInventoryDetailsQuery} query
|
||||
* @returns {Promise<IInvetoryItemDetailsTable>}
|
||||
*/
|
||||
public async table(
|
||||
tenantId: number,
|
||||
query: IInventoryDetailsQuery
|
||||
): Promise<IInvetoryItemDetailsTable> {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
|
||||
const inventoryDetails = await this.inventoryDetails.inventoryDetails(
|
||||
tenantId,
|
||||
query
|
||||
);
|
||||
const table = new InventoryDetailsTable(inventoryDetails, i18n);
|
||||
|
||||
return {
|
||||
table: {
|
||||
rows: table.tableRows(),
|
||||
columns: table.tableColumns(),
|
||||
},
|
||||
query: inventoryDetails.query,
|
||||
meta: inventoryDetails.meta,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { ProfitLossSheetExportInjectable } from './ProfitLossSheetExportInjectable';
|
||||
import { ProfitLossSheetTableInjectable } from './ProfitLossSheetTableInjectable';
|
||||
import { IProfitLossSheetQuery, IProfitLossSheetTable } from '@/interfaces';
|
||||
import ProfitLossSheetService from './ProfitLossSheetService';
|
||||
|
||||
@Service()
|
||||
export class ProfitLossSheetApplication {
|
||||
@Inject()
|
||||
private profitLossTable: ProfitLossSheetTableInjectable;
|
||||
|
||||
@Inject()
|
||||
private profitLossExport: ProfitLossSheetExportInjectable;
|
||||
|
||||
@Inject()
|
||||
private profitLossSheet: ProfitLossSheetService;
|
||||
|
||||
/**
|
||||
* Retreives the profit/loss sheet.
|
||||
* @param {number} tenantId
|
||||
* @param {IProfitLossSheetQuery} query
|
||||
* @returns {}
|
||||
*/
|
||||
public sheet(tenantId: number, query: IProfitLossSheetQuery) {
|
||||
return this.profitLossSheet.profitLossSheet(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the profit/loss sheet table format.
|
||||
* @param {number} tenantId
|
||||
* @param {IProfitLossSheetQuery} query
|
||||
* @returns {Promise<IProfitLossSheetTable>}
|
||||
*/
|
||||
public table(
|
||||
tenantId: number,
|
||||
query: IProfitLossSheetQuery
|
||||
): Promise<IProfitLossSheetTable> {
|
||||
return this.profitLossTable.table(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the profit/loss sheet in csv format.
|
||||
* @param {number} tenantId
|
||||
* @param {IProfitLossSheetQuery} query
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public csv(tenantId: number, query: IProfitLossSheetQuery): Promise<string> {
|
||||
return this.profitLossExport.csv(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the profit/loss sheet in xlsx format.
|
||||
* @param {number} tenantId
|
||||
* @param {IProfitLossSheetQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public xlsx(tenantId: number, query: IProfitLossSheetQuery): Promise<Buffer> {
|
||||
return this.profitLossExport.xlsx(tenantId, query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { IProfitLossSheetQuery } from '@/interfaces';
|
||||
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||
import { ProfitLossSheetTableInjectable } from './ProfitLossSheetTableInjectable';
|
||||
|
||||
@Service()
|
||||
export class ProfitLossSheetExportInjectable {
|
||||
@Inject()
|
||||
private profitLossSheetTable: ProfitLossSheetTableInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the profit/loss sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {IProfitLossSheetQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async xlsx(tenantId: number, query: IProfitLossSheetQuery) {
|
||||
const table = await this.profitLossSheetTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToXLSX();
|
||||
|
||||
return tableSheet.convertToBuffer(tableCsv, 'xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the profit/loss sheet in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {IProfitLossSheetQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async csv(
|
||||
tenantId: number,
|
||||
query: IProfitLossSheetQuery
|
||||
): Promise<string> {
|
||||
const table = await this.profitLossSheetTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToCSV();
|
||||
|
||||
return tableCsv;
|
||||
}
|
||||
}
|
||||
@@ -16,39 +16,10 @@ import { ProfitLossSheetRepository } from './ProfitLossSheetRepository';
|
||||
@Service()
|
||||
export default class ProfitLossSheetService {
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject('logger')
|
||||
logger: any;
|
||||
private tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
inventoryService: InventoryService;
|
||||
|
||||
/**
|
||||
* Retrieve the trial balance sheet meta.
|
||||
* @param {number} tenantId - Tenant id.
|
||||
* @returns {ITrialBalanceSheetMeta}
|
||||
*/
|
||||
reportMetadata(tenantId: number): IProfitLossSheetMeta {
|
||||
const settings = this.tenancy.settings(tenantId);
|
||||
|
||||
const isCostComputeRunning =
|
||||
this.inventoryService.isItemsCostComputeRunning(tenantId);
|
||||
const organizationName = settings.get({
|
||||
group: 'organization',
|
||||
key: 'name',
|
||||
});
|
||||
const baseCurrency = settings.get({
|
||||
group: 'organization',
|
||||
key: 'base_currency',
|
||||
});
|
||||
|
||||
return {
|
||||
isCostComputeRunning: parseBoolean(isCostComputeRunning, false),
|
||||
organizationName,
|
||||
baseCurrency,
|
||||
};
|
||||
}
|
||||
private inventoryService: InventoryService;
|
||||
|
||||
/**
|
||||
* Retrieve profit/loss sheet statement.
|
||||
@@ -56,7 +27,7 @@ export default class ProfitLossSheetService {
|
||||
* @param {IProfitLossSheetQuery} query
|
||||
* @return { }
|
||||
*/
|
||||
profitLossSheet = async (
|
||||
public profitLossSheet = async (
|
||||
tenantId: number,
|
||||
query: IProfitLossSheetQuery
|
||||
): Promise<{
|
||||
@@ -70,13 +41,6 @@ export default class ProfitLossSheetService {
|
||||
// Merges the given query with default filter query.
|
||||
const filter = mergeQueryWithDefaults(query);
|
||||
|
||||
// Get the given accounts or throw not found service error.
|
||||
// if (filter.accountsIds.length > 0) {
|
||||
// await this.accountsService.getAccountsOrThrowError(
|
||||
// tenantId,
|
||||
// filter.accountsIds
|
||||
// );
|
||||
// }
|
||||
const tenant = await Tenant.query()
|
||||
.findById(tenantId)
|
||||
.withGraphFetched('metadata');
|
||||
@@ -101,4 +65,30 @@ export default class ProfitLossSheetService {
|
||||
meta: this.reportMetadata(tenantId),
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the trial balance sheet meta.
|
||||
* @param {number} tenantId - Tenant id.
|
||||
* @returns {ITrialBalanceSheetMeta}
|
||||
*/
|
||||
private reportMetadata(tenantId: number): IProfitLossSheetMeta {
|
||||
const settings = this.tenancy.settings(tenantId);
|
||||
|
||||
const isCostComputeRunning =
|
||||
this.inventoryService.isItemsCostComputeRunning(tenantId);
|
||||
const organizationName = settings.get({
|
||||
group: 'organization',
|
||||
key: 'name',
|
||||
});
|
||||
const baseCurrency = settings.get({
|
||||
group: 'organization',
|
||||
key: 'base_currency',
|
||||
});
|
||||
|
||||
return {
|
||||
isCostComputeRunning: parseBoolean(isCostComputeRunning, false),
|
||||
organizationName,
|
||||
baseCurrency,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import ProfitLossSheetService from './ProfitLossSheetService';
|
||||
import { ProfitLossSheetTable } from './ProfitLossSheetTable';
|
||||
import { IProfitLossSheetQuery, IProfitLossSheetTable } from '@/interfaces';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
|
||||
@Service()
|
||||
export class ProfitLossSheetTableInjectable {
|
||||
@Inject()
|
||||
private profitLossSheet: ProfitLossSheetService;
|
||||
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Retrieves the profit/loss sheet in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {IProfitLossSheetQuery} filter
|
||||
* @returns {Promise<IProfitLossSheetTable>}
|
||||
*/
|
||||
public async table(
|
||||
tenantId: number,
|
||||
filter: IProfitLossSheetQuery
|
||||
): Promise<IProfitLossSheetTable> {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
|
||||
const { data, query, meta } = await this.profitLossSheet.profitLossSheet(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
const table = new ProfitLossSheetTable(data, query, i18n);
|
||||
|
||||
return {
|
||||
table: {
|
||||
rows: table.tableRows(),
|
||||
columns: table.tableColumns(),
|
||||
},
|
||||
query,
|
||||
meta,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -87,10 +87,6 @@ export default class SalesByItemsReportService {
|
||||
...this.defaultQuery,
|
||||
...query,
|
||||
};
|
||||
this.logger.info('[sales_by_items] trying to calculate the report.', {
|
||||
filter,
|
||||
tenantId,
|
||||
});
|
||||
// Inventory items for sales report.
|
||||
const inventoryItems = await Item.query().onBuild((q) => {
|
||||
q.where('type', 'inventory');
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { SalesTaxLiabilitySummaryQuery } from '@/interfaces/SalesTaxLiabilitySummary';
|
||||
import { SalesTaxLiabilitySummaryTableInjectable } from './SalesTaxLiabilitySummaryTableInjectable';
|
||||
import { SalesTaxLiabilitySummaryExportInjectable } from './SalesTaxLiabilitySummaryExportInjectable';
|
||||
import { SalesTaxLiabilitySummaryService } from './SalesTaxLiabilitySummaryService';
|
||||
|
||||
@Service()
|
||||
export class SalesTaxLiabilitySummaryApplication {
|
||||
@Inject()
|
||||
private salesTaxLiabilitySheet: SalesTaxLiabilitySummaryService;
|
||||
|
||||
@Inject()
|
||||
private salesTaxLiabilityExport: SalesTaxLiabilitySummaryExportInjectable;
|
||||
|
||||
@Inject()
|
||||
private salesTaxLiabilityTable: SalesTaxLiabilitySummaryTableInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the sales tax liability summary in json format.
|
||||
* @param {number} tenantId
|
||||
* @param {SalesTaxLiabilitySummaryQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public sheet(tenantId: number, query: SalesTaxLiabilitySummaryQuery) {
|
||||
return this.salesTaxLiabilitySheet.salesTaxLiability(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the sales tax liability summary in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {SalesTaxLiabilitySummaryQuery} query
|
||||
* @return {Promise<Buffer>}
|
||||
*/
|
||||
public table(tenantId: number, query: SalesTaxLiabilitySummaryQuery) {
|
||||
return this.salesTaxLiabilityTable.table(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the sales tax liability summary in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {SalesTaxLiabilitySummaryQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public xlsx(
|
||||
tenantId: number,
|
||||
query: SalesTaxLiabilitySummaryQuery
|
||||
): Promise<Buffer> {
|
||||
return this.salesTaxLiabilityExport.xlsx(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the sales tax liability summary in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {SalesTaxLiabilitySummaryQuery} query
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public csv(
|
||||
tenantId: number,
|
||||
query: SalesTaxLiabilitySummaryQuery
|
||||
): Promise<string> {
|
||||
return this.salesTaxLiabilityExport.csv(tenantId, query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { SalesTaxLiabilitySummaryQuery } from '@/interfaces/SalesTaxLiabilitySummary';
|
||||
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { SalesTaxLiabilitySummaryTableInjectable } from './SalesTaxLiabilitySummaryTableInjectable';
|
||||
|
||||
@Service()
|
||||
export class SalesTaxLiabilitySummaryExportInjectable {
|
||||
@Inject()
|
||||
private salesTaxLiabilityTable: SalesTaxLiabilitySummaryTableInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the cashflow sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {ICashFlowStatementQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async xlsx(
|
||||
tenantId: number,
|
||||
query: SalesTaxLiabilitySummaryQuery
|
||||
): Promise<Buffer> {
|
||||
const table = await this.salesTaxLiabilityTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToXLSX();
|
||||
|
||||
return tableSheet.convertToBuffer(tableCsv, 'xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the cashflow sheet in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {ICashFlowStatementQuery} query
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public async csv(
|
||||
tenantId: number,
|
||||
query: SalesTaxLiabilitySummaryQuery
|
||||
): Promise<string> {
|
||||
const table = await this.salesTaxLiabilityTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToCSV();
|
||||
|
||||
return tableCsv;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
SalesTaxLiabilitySummaryQuery,
|
||||
} from '@/interfaces/SalesTaxLiabilitySummary';
|
||||
import { SalesTaxLiabilitySummary } from './SalesTaxLiabilitySummary';
|
||||
import { SalesTaxLiabilitySummaryTable } from './SalesTaxLiabilitySummaryTable';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
|
||||
@Service()
|
||||
@@ -47,32 +46,6 @@ export class SalesTaxLiabilitySummaryService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve sales tax liability summary table.
|
||||
* @param {number} tenantId
|
||||
* @param {SalesTaxLiabilitySummaryQuery} query
|
||||
* @returns
|
||||
*/
|
||||
public async salesTaxLiabilitySummaryTable(
|
||||
tenantId: number,
|
||||
query: SalesTaxLiabilitySummaryQuery
|
||||
) {
|
||||
const report = await this.salesTaxLiability(tenantId, query);
|
||||
|
||||
// Creates the sales tax liability summary table.
|
||||
const table = new SalesTaxLiabilitySummaryTable(report.data, query);
|
||||
|
||||
return {
|
||||
table: {
|
||||
rows: table.tableRows(),
|
||||
columns: table.tableColumns(),
|
||||
},
|
||||
data: report.data,
|
||||
query: report.query,
|
||||
meta: report.meta,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the report meta.
|
||||
* @param {number} tenantId -
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import {
|
||||
ISalesTaxLiabilitySummaryTable,
|
||||
SalesTaxLiabilitySummaryQuery,
|
||||
} from '@/interfaces/SalesTaxLiabilitySummary';
|
||||
import { SalesTaxLiabilitySummaryTable } from './SalesTaxLiabilitySummaryTable';
|
||||
import { SalesTaxLiabilitySummaryService } from './SalesTaxLiabilitySummaryService';
|
||||
|
||||
@Service()
|
||||
export class SalesTaxLiabilitySummaryTableInjectable {
|
||||
@Inject()
|
||||
private salesTaxLiability: SalesTaxLiabilitySummaryService;
|
||||
|
||||
/**
|
||||
* Retrieve sales tax liability summary table.
|
||||
* @param {number} tenantId
|
||||
* @param {SalesTaxLiabilitySummaryQuery} query
|
||||
* @returns {Promise<ISalesTaxLiabilitySummaryTable>}
|
||||
*/
|
||||
public async table(
|
||||
tenantId: number,
|
||||
query: SalesTaxLiabilitySummaryQuery
|
||||
): Promise<ISalesTaxLiabilitySummaryTable> {
|
||||
const report = await this.salesTaxLiability.salesTaxLiability(
|
||||
tenantId,
|
||||
query
|
||||
);
|
||||
// Creates the sales tax liability summary table.
|
||||
const table = new SalesTaxLiabilitySummaryTable(report.data, query);
|
||||
|
||||
return {
|
||||
table: {
|
||||
rows: table.tableRows(),
|
||||
columns: table.tableColumns(),
|
||||
},
|
||||
query: report.query,
|
||||
meta: report.meta,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -139,11 +139,4 @@ export default class TransactionsByCustomers extends TransactionsByContact {
|
||||
public reportData(): ITransactionsByCustomersData {
|
||||
return this.customersMapper(this.customers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the report columns.
|
||||
*/
|
||||
public reportColumns() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import {
|
||||
ITransactionsByCustomersFilter,
|
||||
ITransactionsByCustomersStatement,
|
||||
} from '@/interfaces';
|
||||
import { TransactionsByCustomersTableInjectable } from './TransactionsByCustomersTableInjectable';
|
||||
import { TransactionsByCustomersExportInjectable } from './TransactionsByCustomersExportInjectable';
|
||||
import { TransactionsByCustomersSheet } from './TransactionsByCustomersService';
|
||||
|
||||
@Service()
|
||||
export class TransactionsByCustomerApplication {
|
||||
@Inject()
|
||||
private transactionsByCustomersTable: TransactionsByCustomersTableInjectable;
|
||||
|
||||
@Inject()
|
||||
private transactionsByCustomersExport: TransactionsByCustomersExportInjectable;
|
||||
|
||||
@Inject()
|
||||
private transactionsByCustomersSheet: TransactionsByCustomersSheet;
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by customers sheet in json format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByCustomersFilter} query
|
||||
* @returns {Promise<ITransactionsByCustomersStatement>}
|
||||
*/
|
||||
public sheet(
|
||||
tenantId: number,
|
||||
query: ITransactionsByCustomersFilter
|
||||
): Promise<ITransactionsByCustomersStatement> {
|
||||
return this.transactionsByCustomersSheet.transactionsByCustomers(
|
||||
tenantId,
|
||||
query
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by vendors sheet in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByCustomersFilter} query
|
||||
* @returns {Promise<ITransactionsByCustomersTable>}
|
||||
*/
|
||||
public table(tenantId: number, query: ITransactionsByCustomersFilter) {
|
||||
return this.transactionsByCustomersTable.table(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by vendors sheet in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByCustomersFilter} query
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public csv(
|
||||
tenantId: number,
|
||||
query: ITransactionsByCustomersFilter
|
||||
): Promise<string> {
|
||||
return this.transactionsByCustomersExport.csv(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by vendors sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByCustomersFilter} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public xlsx(
|
||||
tenantId: number,
|
||||
query: ITransactionsByCustomersFilter
|
||||
): Promise<Buffer> {
|
||||
return this.transactionsByCustomersExport.xlsx(tenantId, query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { ITransactionsByCustomersFilter } from '@/interfaces';
|
||||
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||
import { TransactionsByCustomersTableInjectable } from './TransactionsByCustomersTableInjectable';
|
||||
|
||||
@Service()
|
||||
export class TransactionsByCustomersExportInjectable {
|
||||
@Inject()
|
||||
private transactionsByCustomerTable: TransactionsByCustomersTableInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the cashflow sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByCustomersFilter} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async xlsx(
|
||||
tenantId: number,
|
||||
query: ITransactionsByCustomersFilter
|
||||
): Promise<Buffer> {
|
||||
const table = await this.transactionsByCustomerTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToXLSX();
|
||||
|
||||
return tableSheet.convertToBuffer(tableCsv, 'xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the cashflow sheet in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByCustomersFilter} query
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public async csv(
|
||||
tenantId: number,
|
||||
query: ITransactionsByCustomersFilter
|
||||
): Promise<string> {
|
||||
const table = await this.transactionsByCustomerTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToCSV();
|
||||
|
||||
return tableCsv;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
import { Inject } from 'typedi';
|
||||
import { isEmpty, map } from 'lodash';
|
||||
import { IAccount, IAccountTransaction } from '@/interfaces';
|
||||
import { ACCOUNT_TYPE } from '@/data/AccountTypes';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { Inject } from 'typedi';
|
||||
|
||||
export default class TransactionsByCustomersRepository {
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Retrieve the report customers.
|
||||
* @param {number} tenantId
|
||||
* @param {number} tenantId
|
||||
* @returns {Promise<ICustomer[]>}
|
||||
*/
|
||||
public async getCustomers(tenantId: number, customersIds?: number[]) {
|
||||
|
||||
@@ -13,23 +13,20 @@ import Ledger from '@/services/Accounting/Ledger';
|
||||
import TransactionsByCustomersRepository from './TransactionsByCustomersRepository';
|
||||
import { Tenant } from '@/system/models';
|
||||
|
||||
export default class TransactionsByCustomersService
|
||||
export class TransactionsByCustomersSheet
|
||||
implements ITransactionsByCustomersService
|
||||
{
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject('logger')
|
||||
logger: any;
|
||||
private tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
reportRepository: TransactionsByCustomersRepository;
|
||||
private reportRepository: TransactionsByCustomersRepository;
|
||||
|
||||
/**
|
||||
* Defaults balance sheet filter query.
|
||||
* @return {ICustomerBalanceSummaryQuery}
|
||||
*/
|
||||
get defaultQuery(): ITransactionsByCustomersFilter {
|
||||
private get defaultQuery(): ITransactionsByCustomersFilter {
|
||||
return {
|
||||
fromDate: moment().startOf('month').format('YYYY-MM-DD'),
|
||||
toDate: moment().format('YYYY-MM-DD'),
|
||||
@@ -165,7 +162,6 @@ export default class TransactionsByCustomersService
|
||||
|
||||
return {
|
||||
data: reportInstance.reportData(),
|
||||
columns: reportInstance.reportColumns(),
|
||||
query: filter,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as R from 'ramda';
|
||||
import { tableRowMapper, tableMapper } from 'utils';
|
||||
import { ITransactionsByCustomersCustomer, ITableRow } from '@/interfaces';
|
||||
import { tableRowMapper } from 'utils';
|
||||
import { ITransactionsByCustomersCustomer, ITableRow, ITableColumn } from '@/interfaces';
|
||||
import TransactionsByContactsTableRows from '../TransactionsByContact/TransactionsByContactTableRows';
|
||||
|
||||
enum ROW_TYPE {
|
||||
@@ -10,17 +10,14 @@ enum ROW_TYPE {
|
||||
CUSTOMER = 'CUSTOMER',
|
||||
}
|
||||
|
||||
export default class TransactionsByCustomersTableRows extends TransactionsByContactsTableRows {
|
||||
export class TransactionsByCustomersTable extends TransactionsByContactsTableRows {
|
||||
private customersTransactions: ITransactionsByCustomersCustomer[];
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
* @param {ITransactionsByCustomersCustomer[]} customersTransactions - Customers transactions.
|
||||
*/
|
||||
constructor(
|
||||
customersTransactions: ITransactionsByCustomersCustomer[],
|
||||
i18n
|
||||
) {
|
||||
constructor(customersTransactions: ITransactionsByCustomersCustomer[], i18n) {
|
||||
super();
|
||||
this.customersTransactions = customersTransactions;
|
||||
this.i18n = i18n;
|
||||
@@ -75,4 +72,12 @@ export default class TransactionsByCustomersTableRows extends TransactionsByCont
|
||||
this.customersTransactions
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the table columns of transactions by customers report.
|
||||
* @returns {ITableColumn[]}
|
||||
*/
|
||||
public tableColumns = (): ITableColumn[] => {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { ITransactionsByCustomersFilter, ITransactionsByCustomersTable } from '@/interfaces';
|
||||
import { TransactionsByCustomersSheet } from './TransactionsByCustomersService';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { TransactionsByCustomersTable } from './TransactionsByCustomersTable';
|
||||
|
||||
@Service()
|
||||
export class TransactionsByCustomersTableInjectable {
|
||||
@Inject()
|
||||
private transactionsByCustomerService: TransactionsByCustomersSheet;
|
||||
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by customers sheet in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByCustomersFilter} filter
|
||||
* @returns {Promise<ITransactionsByCustomersFilter>}
|
||||
*/
|
||||
public async table(
|
||||
tenantId: number,
|
||||
filter: ITransactionsByCustomersFilter
|
||||
): Promise<ITransactionsByCustomersTable> {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
|
||||
const customersTransactions =
|
||||
await this.transactionsByCustomerService.transactionsByCustomers(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
const table = new TransactionsByCustomersTable(
|
||||
customersTransactions.data,
|
||||
i18n
|
||||
);
|
||||
return {
|
||||
table: {
|
||||
rows: table.tableRows(),
|
||||
columns: table.tableColumns(),
|
||||
},
|
||||
query: customersTransactions.query,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -137,11 +137,4 @@ export default class TransactionsByVendors extends TransactionsByContact {
|
||||
public reportData(): ITransactionsByVendorsData {
|
||||
return this.vendorsMapper(this.contacts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the report columns.
|
||||
*/
|
||||
public reportColumns() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import {
|
||||
ITransactionsByVendorTable,
|
||||
ITransactionsByVendorsFilter,
|
||||
ITransactionsByVendorsStatement,
|
||||
} from '@/interfaces';
|
||||
import { TransactionsByVendorExportInjectable } from './TransactionsByVendorExportInjectable';
|
||||
import { TransactionsByVendorTableInjectable } from './TransactionsByVendorTableInjectable';
|
||||
import { TransactionsByVendorsInjectable } from './TransactionsByVendorInjectable';
|
||||
|
||||
@Service()
|
||||
export class TransactionsByVendorApplication {
|
||||
@Inject()
|
||||
private transactionsByVendorTable: TransactionsByVendorTableInjectable;
|
||||
|
||||
@Inject()
|
||||
private transactionsByVendorExport: TransactionsByVendorExportInjectable;
|
||||
|
||||
@Inject()
|
||||
private transactionsByVendorSheet: TransactionsByVendorsInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by vendor in sheet format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByVendorsFilter} query
|
||||
* @returns {Promise<ITransactionsByVendorsStatement>}
|
||||
*/
|
||||
public sheet(
|
||||
tenantId: number,
|
||||
query: ITransactionsByVendorsFilter
|
||||
): Promise<ITransactionsByVendorsStatement> {
|
||||
return this.transactionsByVendorSheet.transactionsByVendors(
|
||||
tenantId,
|
||||
query
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by vendor in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByVendorsFilter} query
|
||||
* @returns {Promise<ITransactionsByVendorTable>}
|
||||
*/
|
||||
public table(
|
||||
tenantId: number,
|
||||
query: ITransactionsByVendorsFilter
|
||||
): Promise<ITransactionsByVendorTable> {
|
||||
return this.transactionsByVendorTable.table(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by vendor in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByVendorsFilter} query
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public csv(
|
||||
tenantId: number,
|
||||
query: ITransactionsByVendorsFilter
|
||||
): Promise<string> {
|
||||
return this.transactionsByVendorExport.csv(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by vendor in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByVendorsFilter} query
|
||||
*/
|
||||
public xlsx(
|
||||
tenantId: number,
|
||||
query: ITransactionsByVendorsFilter
|
||||
): Promise<Buffer> {
|
||||
return this.transactionsByVendorExport.xlsx(tenantId, query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { ITransactionsByVendorsFilter } from '@/interfaces';
|
||||
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||
import { TransactionsByVendorTableInjectable } from './TransactionsByVendorTableInjectable';
|
||||
|
||||
@Service()
|
||||
export class TransactionsByVendorExportInjectable {
|
||||
@Inject()
|
||||
private transactionsByVendorTable: TransactionsByVendorTableInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the cashflow sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByVendorsFilter} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async xlsx(
|
||||
tenantId: number,
|
||||
query: ITransactionsByVendorsFilter
|
||||
): Promise<Buffer> {
|
||||
const table = await this.transactionsByVendorTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToXLSX();
|
||||
|
||||
return tableSheet.convertToBuffer(tableCsv, 'xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the cashflow sheet in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {ICashFlowStatementQuery} query
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public async csv(
|
||||
tenantId: number,
|
||||
query: ITransactionsByVendorsFilter
|
||||
): Promise<string> {
|
||||
const table = await this.transactionsByVendorTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToCSV();
|
||||
|
||||
return tableCsv;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Inject } from 'typedi';
|
||||
import moment from 'moment';
|
||||
import * as R from 'ramda';
|
||||
import { map } from 'lodash';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import {
|
||||
ITransactionsByVendorsService,
|
||||
@@ -14,17 +13,14 @@ import Ledger from '@/services/Accounting/Ledger';
|
||||
import TransactionsByVendorRepository from './TransactionsByVendorRepository';
|
||||
import { Tenant } from '@/system/models';
|
||||
|
||||
export default class TransactionsByVendorsService
|
||||
export class TransactionsByVendorsInjectable
|
||||
implements ITransactionsByVendorsService
|
||||
{
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject('logger')
|
||||
logger: any;
|
||||
private tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
reportRepository: TransactionsByVendorRepository;
|
||||
private reportRepository: TransactionsByVendorRepository;
|
||||
|
||||
/**
|
||||
* Defaults balance sheet filter query.
|
||||
@@ -136,7 +132,7 @@ export default class TransactionsByVendorsService
|
||||
const { accountRepository } = this.tenancy.repositories(tenantId);
|
||||
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
|
||||
|
||||
const tenant = await Tenant.query()
|
||||
.findById(tenantId)
|
||||
.withGraphFetched('metadata');
|
||||
@@ -171,7 +167,6 @@ export default class TransactionsByVendorsService
|
||||
);
|
||||
return {
|
||||
data: reportInstance.reportData(),
|
||||
columns: reportInstance.reportColumns(),
|
||||
query: filter,
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
import * as R from 'ramda';
|
||||
import { tableRowMapper } from 'utils';
|
||||
import { ITransactionsByVendorsVendor, ITableRow } from '@/interfaces';
|
||||
import {
|
||||
ITransactionsByVendorsVendor,
|
||||
ITableRow,
|
||||
ITableColumn,
|
||||
} from '@/interfaces';
|
||||
import TransactionsByContactsTableRows from '../TransactionsByContact/TransactionsByContactTableRows';
|
||||
|
||||
enum ROW_TYPE {
|
||||
@@ -10,16 +14,15 @@ enum ROW_TYPE {
|
||||
VENDOR = 'VENDOR',
|
||||
}
|
||||
|
||||
export default class TransactionsByVendorsTableRows extends TransactionsByContactsTableRows {
|
||||
vendorsTransactions: ITransactionsByVendorsVendor[];
|
||||
export class TransactionsByVendorsTable extends TransactionsByContactsTableRows {
|
||||
private vendorsTransactions: ITransactionsByVendorsVendor[];
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
* @param {ITransactionsByVendorsVendor[]} vendorsTransactions -
|
||||
* @param {any} i18n
|
||||
*/
|
||||
constructor(
|
||||
vendorsTransactions: ITransactionsByVendorsVendor[],
|
||||
i18n
|
||||
) {
|
||||
constructor(vendorsTransactions: ITransactionsByVendorsVendor[], i18n) {
|
||||
super();
|
||||
|
||||
this.vendorsTransactions = vendorsTransactions;
|
||||
@@ -73,4 +76,12 @@ export default class TransactionsByVendorsTableRows extends TransactionsByContac
|
||||
public tableRows = (): ITableRow[] => {
|
||||
return R.map(this.vendorRowsMapper)(this.vendorsTransactions);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the table columns of transactions by vendors report.
|
||||
* @returns {ITableColumn[]}
|
||||
*/
|
||||
public tableColumns = (): ITableColumn[] => {
|
||||
return [];
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { TransactionsByVendorsTable } from './TransactionsByVendorTable';
|
||||
import {
|
||||
ITransactionsByVendorTable,
|
||||
ITransactionsByVendorsFilter,
|
||||
} from '@/interfaces';
|
||||
import { TransactionsByVendorsInjectable } from './TransactionsByVendorInjectable';
|
||||
|
||||
@Service()
|
||||
export class TransactionsByVendorTableInjectable {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
@Inject()
|
||||
private transactionsByVendor: TransactionsByVendorsInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by vendor in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByReferenceQuery} query
|
||||
* @returns {Promise<ITransactionsByVendorTable>}
|
||||
*/
|
||||
public async table(
|
||||
tenantId: number,
|
||||
query: ITransactionsByVendorsFilter
|
||||
): Promise<ITransactionsByVendorTable> {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
|
||||
const sheet = await this.transactionsByVendor.transactionsByVendors(
|
||||
tenantId,
|
||||
query
|
||||
);
|
||||
const table = new TransactionsByVendorsTable(sheet.data, i18n);
|
||||
|
||||
return {
|
||||
table: {
|
||||
rows: table.tableRows(),
|
||||
columns: table.tableColumns(),
|
||||
},
|
||||
query,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||
import { ITrialBalanceSheetQuery } from '@/interfaces';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { TrialBalanceSheetTableInjectable } from './TrialBalanceSheetTableInjectable';
|
||||
|
||||
@Service()
|
||||
export class TrialBalanceExportInjectable {
|
||||
@Inject()
|
||||
private trialBalanceSheetTable: TrialBalanceSheetTableInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the trial balance sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITrialBalanceSheetQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async xlsx(tenantId: number, query: ITrialBalanceSheetQuery) {
|
||||
const table = await this.trialBalanceSheetTable.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 {ITrialBalanceSheetQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async csv(
|
||||
tenantId: number,
|
||||
query: ITrialBalanceSheetQuery
|
||||
): Promise<string> {
|
||||
const table = await this.trialBalanceSheetTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToCSV();
|
||||
|
||||
return tableCsv;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { TrialBalanceSheetTableInjectable } from './TrialBalanceSheetTableInjectable';
|
||||
import { TrialBalanceExportInjectable } from './TrialBalanceExportInjectable';
|
||||
import { ITrialBalanceSheetQuery, ITrialBalanceStatement } from '@/interfaces';
|
||||
import TrialBalanceSheetService from './TrialBalanceSheetInjectable';
|
||||
|
||||
@Service()
|
||||
export class TrialBalanceSheetApplication {
|
||||
@Inject()
|
||||
private sheetService: TrialBalanceSheetService;
|
||||
|
||||
@Inject()
|
||||
private tablable: TrialBalanceSheetTableInjectable;
|
||||
|
||||
@Inject()
|
||||
private exportable: TrialBalanceExportInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the trial balance sheet.
|
||||
* @param {number} tenantId
|
||||
* @param {ITrialBalanceSheetQuery} query
|
||||
* @returns {Promise<ITrialBalanceStatement>}
|
||||
*/
|
||||
public sheet(
|
||||
tenantId: number,
|
||||
query: ITrialBalanceSheetQuery
|
||||
): Promise<ITrialBalanceStatement> {
|
||||
return this.sheetService.trialBalanceSheet(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the trial balance sheet in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITrialBalanceSheetQuery} query
|
||||
* @returns {Promise<ITrialBalanceSheetTable>}
|
||||
*/
|
||||
public table(tenantId: number, query: ITrialBalanceSheetQuery) {
|
||||
return this.tablable.table(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the trial balance sheet in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITrialBalanceSheetQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public csv(tenantId: number, query: ITrialBalanceSheetQuery) {
|
||||
return this.exportable.csv(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the trial balance sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITrialBalanceSheetQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async xlsx(tenantId: number, query: ITrialBalanceSheetQuery) {
|
||||
return this.exportable.xlsx(tenantId, query);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import moment from 'moment';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import Journal from '@/services/Accounting/JournalPoster';
|
||||
import {
|
||||
ITrialBalanceSheetMeta,
|
||||
ITrialBalanceSheetQuery,
|
||||
@@ -13,7 +12,6 @@ import InventoryService from '@/services/Inventory/Inventory';
|
||||
import { parseBoolean } from 'utils';
|
||||
import { Tenant } from '@/system/models';
|
||||
import { TrialBalanceSheetRepository } from './TrialBalanceSheetRepository';
|
||||
import { TrialBalanceSheetTable } from './TrialBalanceSheetTable';
|
||||
|
||||
@Service()
|
||||
export default class TrialBalanceSheetService extends FinancialSheet {
|
||||
@@ -30,7 +28,7 @@ export default class TrialBalanceSheetService extends FinancialSheet {
|
||||
* Defaults trial balance sheet filter query.
|
||||
* @return {IBalanceSheetQuery}
|
||||
*/
|
||||
get defaultQuery(): ITrialBalanceSheetQuery {
|
||||
private get defaultQuery(): ITrialBalanceSheetQuery {
|
||||
return {
|
||||
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
||||
toDate: moment().format('YYYY-MM-DD'),
|
||||
@@ -54,7 +52,7 @@ export default class TrialBalanceSheetService extends FinancialSheet {
|
||||
* @param {number} tenantId - Tenant id.
|
||||
* @returns {ITrialBalanceSheetMeta}
|
||||
*/
|
||||
reportMetadata(tenantId: number): ITrialBalanceSheetMeta {
|
||||
private reportMetadata(tenantId: number): ITrialBalanceSheetMeta {
|
||||
const settings = this.tenancy.settings(tenantId);
|
||||
|
||||
const isCostComputeRunning =
|
||||
@@ -89,7 +87,6 @@ export default class TrialBalanceSheetService extends FinancialSheet {
|
||||
...this.defaultQuery,
|
||||
...query,
|
||||
};
|
||||
|
||||
const tenant = await Tenant.query()
|
||||
.findById(tenantId)
|
||||
.withGraphFetched('metadata');
|
||||
@@ -120,27 +117,4 @@ export default class TrialBalanceSheetService extends FinancialSheet {
|
||||
meta: this.reportMetadata(tenantId),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the trial balance sheet table.
|
||||
* @param {number} tenantId
|
||||
* @param {ITrialBalanceSheetQuery} query
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
public async trialBalanceSheetTable(
|
||||
tenantId: number,
|
||||
query: ITrialBalanceSheetQuery
|
||||
) {
|
||||
const trialBalance = await this.trialBalanceSheet(tenantId, query);
|
||||
const table = new TrialBalanceSheetTable(trialBalance.data, query, {});
|
||||
|
||||
return {
|
||||
table: {
|
||||
columns: table.tableColumns(),
|
||||
rows: table.tableRows(),
|
||||
},
|
||||
meta: trialBalance.meta,
|
||||
query: trialBalance.query,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { ITrialBalanceSheetQuery, ITrialBalanceSheetTable } from '@/interfaces';
|
||||
import { TrialBalanceSheetTable } from './TrialBalanceSheetTable';
|
||||
import TrialBalanceSheetService from './TrialBalanceSheetInjectable';
|
||||
|
||||
@Service()
|
||||
export class TrialBalanceSheetTableInjectable {
|
||||
@Inject()
|
||||
private sheet: TrialBalanceSheetService;
|
||||
|
||||
/**
|
||||
* Retrieves the trial balance sheet table.
|
||||
* @param {number} tenantId
|
||||
* @param {ITrialBalanceSheetQuery} query
|
||||
* @returns {Promise<ITrialBalanceSheetTable>}
|
||||
*/
|
||||
public async table(
|
||||
tenantId: number,
|
||||
query: ITrialBalanceSheetQuery
|
||||
): Promise<ITrialBalanceSheetTable> {
|
||||
const trialBalance = await this.sheet.trialBalanceSheet(tenantId, query);
|
||||
const table = new TrialBalanceSheetTable(trialBalance.data, query, {});
|
||||
|
||||
return {
|
||||
table: {
|
||||
columns: table.tableColumns(),
|
||||
rows: table.tableRows(),
|
||||
},
|
||||
meta: trialBalance.meta,
|
||||
query: trialBalance.query,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -101,8 +101,4 @@ export class VendorBalanceSummaryReport extends ContactBalanceSummaryReport {
|
||||
|
||||
return { vendors, total };
|
||||
}
|
||||
|
||||
reportColumns() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { IVendorBalanceSummaryQuery } from '@/interfaces';
|
||||
import { VendorBalanceSummaryTableInjectable } from './VendorBalanceSummaryTableInjectable';
|
||||
import { VendorBalanceSummaryExportInjectable } from './VendorBalanceSummaryExportInjectable';
|
||||
import { VendorBalanceSummaryService } from './VendorBalanceSummaryService';
|
||||
|
||||
@Service()
|
||||
export class VendorBalanceSummaryApplication {
|
||||
@Inject()
|
||||
private vendorBalanceSummaryTable: VendorBalanceSummaryTableInjectable;
|
||||
|
||||
@Inject()
|
||||
private vendorBalanceSummarySheet: VendorBalanceSummaryService;
|
||||
|
||||
@Inject()
|
||||
private vendorBalanceSummaryExport: VendorBalanceSummaryExportInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the vendor balance summary sheet in sheet format.
|
||||
* @param {number} tenantId
|
||||
* @param {IVendorBalanceSummaryQuery} query
|
||||
*/
|
||||
public sheet(tenantId: number, query: IVendorBalanceSummaryQuery) {
|
||||
return this.vendorBalanceSummarySheet.vendorBalanceSummary(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the vendor balance summary sheet in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {IVendorBalanceSummaryQuery} query
|
||||
* @returns {}
|
||||
*/
|
||||
public table(tenantId: number, query: IVendorBalanceSummaryQuery) {
|
||||
return this.vendorBalanceSummaryTable.table(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the vendor balance summary sheet in xlsx format.
|
||||
* @param {number} tenantId
|
||||
* @param {IVendorBalanceSummaryQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public xlsx(
|
||||
tenantId: number,
|
||||
query: IVendorBalanceSummaryQuery
|
||||
): Promise<Buffer> {
|
||||
return this.vendorBalanceSummaryExport.xlsx(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the vendor balance summary sheet in csv format.
|
||||
* @param {number} tenantId
|
||||
* @param {IVendorBalanceSummaryQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public csv(
|
||||
tenantId: number,
|
||||
query: IVendorBalanceSummaryQuery
|
||||
): Promise<string> {
|
||||
return this.vendorBalanceSummaryExport.csv(tenantId, query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { IVendorBalanceSummaryQuery } from '@/interfaces';
|
||||
import { VendorBalanceSummaryTableInjectable } from './VendorBalanceSummaryTableInjectable';
|
||||
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||
|
||||
@Service()
|
||||
export class VendorBalanceSummaryExportInjectable {
|
||||
@Inject()
|
||||
private customerBalanceSummaryTable: VendorBalanceSummaryTableInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the vendor balance summary sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {IVendorBalanceSummaryQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async xlsx(tenantId: number, query: IVendorBalanceSummaryQuery) {
|
||||
const table = await this.customerBalanceSummaryTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToXLSX();
|
||||
|
||||
return tableSheet.convertToBuffer(tableCsv, 'xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the vendor balance summary sheet in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {IVendorBalanceSummaryQuery} query
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public async csv(
|
||||
tenantId: number,
|
||||
query: IVendorBalanceSummaryQuery
|
||||
): Promise<string> {
|
||||
const table = await this.customerBalanceSummaryTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToCSV();
|
||||
|
||||
return tableCsv;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import { ACCOUNT_TYPE } from '@/data/AccountTypes';
|
||||
@Service()
|
||||
export default class VendorBalanceSummaryRepository {
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Retrieve the report vendors.
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Inject } from 'typedi';
|
||||
import moment from 'moment';
|
||||
import { map } from 'lodash';
|
||||
import * as R from 'ramda';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import {
|
||||
IVendor,
|
||||
IVendorBalanceSummaryService,
|
||||
IVendorBalanceSummaryQuery,
|
||||
IVendorBalanceSummaryStatement,
|
||||
@@ -15,15 +13,12 @@ import Ledger from '@/services/Accounting/Ledger';
|
||||
import VendorBalanceSummaryRepository from './VendorBalanceSummaryRepository';
|
||||
import { Tenant } from '@/system/models';
|
||||
|
||||
export default class VendorBalanceSummaryService
|
||||
export class VendorBalanceSummaryService
|
||||
implements IVendorBalanceSummaryService
|
||||
{
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject('logger')
|
||||
logger: any;
|
||||
|
||||
@Inject()
|
||||
reportRepo: VendorBalanceSummaryRepository;
|
||||
|
||||
@@ -31,7 +26,7 @@ export default class VendorBalanceSummaryService
|
||||
* Defaults balance sheet filter query.
|
||||
* @return {IVendorBalanceSummaryQuery}
|
||||
*/
|
||||
get defaultQuery(): IVendorBalanceSummaryQuery {
|
||||
private get defaultQuery(): IVendorBalanceSummaryQuery {
|
||||
return {
|
||||
asDate: moment().format('YYYY-MM-DD'),
|
||||
numberFormat: {
|
||||
@@ -72,7 +67,7 @@ export default class VendorBalanceSummaryService
|
||||
* @param {IVendorBalanceSummaryQuery} query -
|
||||
* @return {Promise<IVendorBalanceSummaryStatement>}
|
||||
*/
|
||||
async vendorBalanceSummary(
|
||||
public async vendorBalanceSummary(
|
||||
tenantId: number,
|
||||
query: IVendorBalanceSummaryQuery
|
||||
): Promise<IVendorBalanceSummaryStatement> {
|
||||
@@ -81,13 +76,7 @@ export default class VendorBalanceSummaryService
|
||||
.withGraphFetched('metadata');
|
||||
|
||||
const filter = { ...this.defaultQuery, ...query };
|
||||
this.logger.info(
|
||||
'[customer_balance_summary] trying to calculate the report.',
|
||||
{
|
||||
filter,
|
||||
tenantId,
|
||||
}
|
||||
);
|
||||
|
||||
// Retrieve the vendors transactions.
|
||||
const vendorsEntries = await this.getReportVendorsEntries(
|
||||
tenantId,
|
||||
@@ -111,7 +100,6 @@ export default class VendorBalanceSummaryService
|
||||
|
||||
return {
|
||||
data: reportInstance.reportData(),
|
||||
columns: reportInstance.reportColumns(),
|
||||
query: filter,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import {
|
||||
IVendorBalanceSummaryQuery,
|
||||
IVendorBalanceSummaryTable,
|
||||
} from '@/interfaces';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { VendorBalanceSummaryTable } from './VendorBalanceSummaryTableRows';
|
||||
import { VendorBalanceSummaryService } from './VendorBalanceSummaryService';
|
||||
|
||||
@Service()
|
||||
export class VendorBalanceSummaryTableInjectable {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
@Inject()
|
||||
private vendorBalanceSummarySheet: VendorBalanceSummaryService;
|
||||
|
||||
/**
|
||||
* Retrieves the vendor balance summary sheet in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {IVendorBalanceSummaryQuery} query
|
||||
* @returns {Promise<IVendorBalanceSummaryTable>}
|
||||
*/
|
||||
public async table(
|
||||
tenantId: number,
|
||||
query: IVendorBalanceSummaryQuery
|
||||
): Promise<IVendorBalanceSummaryTable> {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
|
||||
const { data } = await this.vendorBalanceSummarySheet.vendorBalanceSummary(
|
||||
tenantId,
|
||||
query
|
||||
);
|
||||
const table = new VendorBalanceSummaryTable(data, query, i18n);
|
||||
|
||||
return {
|
||||
table: {
|
||||
columns: table.tableColumns(),
|
||||
rows: table.tableRows(),
|
||||
},
|
||||
query,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ enum TABLE_ROWS_TYPES {
|
||||
TOTAL = 'TOTAL',
|
||||
}
|
||||
|
||||
export default class VendorBalanceSummaryTable {
|
||||
export class VendorBalanceSummaryTable {
|
||||
i18n: any;
|
||||
report: IVendorBalanceSummaryData;
|
||||
query: IVendorBalanceSummaryQuery;
|
||||
|
||||
Reference in New Issue
Block a user