mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
feat: export reports csv and xlsx (#286)
This commit is contained in:
@@ -100,7 +100,8 @@
|
||||
"tsyringe": "^4.3.0",
|
||||
"typedi": "^0.8.0",
|
||||
"uniqid": "^5.2.0",
|
||||
"winston": "^3.2.1"
|
||||
"winston": "^3.2.1",
|
||||
"xlsx": "^0.18.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash": "^4.14.158",
|
||||
|
||||
@@ -2,19 +2,20 @@ import { Router, Request, Response, NextFunction } from 'express';
|
||||
import { query } from 'express-validator';
|
||||
import { Inject } from 'typedi';
|
||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||
import APAgingSummaryReportService from '@/services/FinancialStatements/AgingSummary/APAgingSummaryService';
|
||||
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||
import { APAgingSummaryApplication } from '@/services/FinancialStatements/AgingSummary/APAgingSummaryApplication';
|
||||
|
||||
export default class APAgingSummaryReportController extends BaseFinancialReportController {
|
||||
@Inject()
|
||||
APAgingSummaryService: APAgingSummaryReportService;
|
||||
private APAgingSummaryApp: APAgingSummaryApplication;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
*/
|
||||
router() {
|
||||
public router() {
|
||||
const router = Router();
|
||||
|
||||
router.get(
|
||||
@@ -28,8 +29,9 @@ export default class APAgingSummaryReportController extends BaseFinancialReportC
|
||||
|
||||
/**
|
||||
* Validation schema.
|
||||
* @returns {ValidationChain[]}
|
||||
*/
|
||||
get validationSchema() {
|
||||
private get validationSchema() {
|
||||
return [
|
||||
...this.sheetNumberFormatValidationSchema,
|
||||
query('as_date').optional().isISO8601(),
|
||||
@@ -49,42 +51,58 @@ export default class APAgingSummaryReportController extends BaseFinancialReportC
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve payable aging summary report.
|
||||
* Retrieves payable aging summary report.
|
||||
* @param {Request} req -
|
||||
* @param {Response} res -
|
||||
* @param {NextFunction} next -
|
||||
*/
|
||||
async payableAgingSummary(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId, settings } = req;
|
||||
private async payableAgingSummary(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId } = req;
|
||||
const filter = this.matchedQueryData(req);
|
||||
|
||||
try {
|
||||
const accept = this.accepts(req);
|
||||
const acceptType = accept.types(['json', 'application/json+table']);
|
||||
const acceptType = accept.types([
|
||||
ACCEPT_TYPE.APPLICATION_JSON,
|
||||
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
|
||||
ACCEPT_TYPE.APPLICATION_CSV,
|
||||
ACCEPT_TYPE.APPLICATION_XLSX,
|
||||
]);
|
||||
// Retrieves the json table format.
|
||||
if (ACCEPT_TYPE.APPLICATION_JSON_TABLE === acceptType) {
|
||||
const table = await this.APAgingSummaryApp.table(tenantId, filter);
|
||||
|
||||
switch (acceptType) {
|
||||
case 'application/json+table':
|
||||
const table = await this.APAgingSummaryService.APAgingSummaryTable(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
return res.status(200).send({
|
||||
table: {
|
||||
rows: table.rows,
|
||||
columns: table.columns,
|
||||
},
|
||||
meta: table.meta,
|
||||
query: table.query,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
const { data, columns, query, meta } =
|
||||
await this.APAgingSummaryService.APAgingSummary(tenantId, filter);
|
||||
return res.status(200).send(table);
|
||||
// Retrieves the csv format.
|
||||
} else if (ACCEPT_TYPE.APPLICATION_CSV === acceptType) {
|
||||
const csv = await this.APAgingSummaryApp.csv(tenantId, filter);
|
||||
|
||||
return res.status(200).send({
|
||||
data: this.transfromToResponse(data),
|
||||
columns: this.transfromToResponse(columns),
|
||||
query: this.transfromToResponse(query),
|
||||
meta: this.transfromToResponse(meta),
|
||||
});
|
||||
break;
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
|
||||
res.setHeader('Content-Type', 'text/csv');
|
||||
|
||||
return res.send(csv);
|
||||
// Retrieves the xlsx format.
|
||||
} else if (ACCEPT_TYPE.APPLICATION_XLSX === acceptType) {
|
||||
const buffer = await this.APAgingSummaryApp.xlsx(tenantId, filter);
|
||||
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
'attachment; filename=output.xlsx'
|
||||
);
|
||||
res.setHeader(
|
||||
'Content-Type',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
);
|
||||
return res.send(buffer);
|
||||
// Retrieves the json format.
|
||||
} else {
|
||||
const sheet = await this.APAgingSummaryApp.sheet(tenantId, filter);
|
||||
|
||||
return res.status(200).send(sheet);
|
||||
}
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -5,16 +5,18 @@ import ARAgingSummaryService from '@/services/FinancialStatements/AgingSummary/A
|
||||
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||
import { ARAgingSummaryApplication } from '@/services/FinancialStatements/AgingSummary/ARAgingSummaryApplication';
|
||||
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||
|
||||
@Service()
|
||||
export default class ARAgingSummaryReportController extends BaseFinancialReportController {
|
||||
@Inject()
|
||||
ARAgingSummaryService: ARAgingSummaryService;
|
||||
ARAgingSummaryApp: ARAgingSummaryApplication;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
*/
|
||||
router() {
|
||||
public router() {
|
||||
const router = Router();
|
||||
|
||||
router.get(
|
||||
@@ -30,7 +32,7 @@ export default class ARAgingSummaryReportController extends BaseFinancialReportC
|
||||
/**
|
||||
* AR aging summary validation roles.
|
||||
*/
|
||||
get validationSchema() {
|
||||
private get validationSchema() {
|
||||
return [
|
||||
...this.sheetNumberFormatValidationSchema,
|
||||
|
||||
@@ -52,41 +54,53 @@ export default class ARAgingSummaryReportController extends BaseFinancialReportC
|
||||
|
||||
/**
|
||||
* Retrieve AR aging summary report.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
*/
|
||||
async receivableAgingSummary(req: Request, res: Response) {
|
||||
const { tenantId, settings } = req;
|
||||
private async receivableAgingSummary(req: Request, res: Response) {
|
||||
const { tenantId } = req;
|
||||
const filter = this.matchedQueryData(req);
|
||||
|
||||
try {
|
||||
const accept = this.accepts(req);
|
||||
const acceptType = accept.types(['json', 'application/json+table']);
|
||||
|
||||
switch (acceptType) {
|
||||
case 'application/json+table':
|
||||
const table = await this.ARAgingSummaryService.ARAgingSummaryTable(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
return res.status(200).send({
|
||||
table: {
|
||||
rows: table.rows,
|
||||
columns: table.columns,
|
||||
},
|
||||
meta: table.meta,
|
||||
query: table.query,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
const { data, columns, query, meta } =
|
||||
await this.ARAgingSummaryService.ARAgingSummary(tenantId, filter);
|
||||
const acceptType = accept.types([
|
||||
ACCEPT_TYPE.APPLICATION_JSON,
|
||||
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
|
||||
ACCEPT_TYPE.APPLICATION_CSV,
|
||||
ACCEPT_TYPE.APPLICATION_XLSX,
|
||||
]);
|
||||
// Retrieves the xlsx format.
|
||||
if (ACCEPT_TYPE.APPLICATION_XLSX === acceptType) {
|
||||
const buffer = await this.ARAgingSummaryApp.xlsx(tenantId, filter);
|
||||
|
||||
return res.status(200).send({
|
||||
data: this.transfromToResponse(data),
|
||||
columns: this.transfromToResponse(columns),
|
||||
query: this.transfromToResponse(query),
|
||||
meta: this.transfromToResponse(meta),
|
||||
});
|
||||
break;
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
'attachment; filename=output.xlsx'
|
||||
);
|
||||
res.setHeader(
|
||||
'Content-Type',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
);
|
||||
return res.send(buffer);
|
||||
// Retrieves the table format.
|
||||
} else if (ACCEPT_TYPE.APPLICATION_JSON_TABLE === acceptType) {
|
||||
const table = await this.ARAgingSummaryApp.table(tenantId, filter);
|
||||
|
||||
return res.status(200).send(table);
|
||||
// Retrieves the csv format.
|
||||
} else if (ACCEPT_TYPE.APPLICATION_CSV === acceptType) {
|
||||
const buffer = await this.ARAgingSummaryApp.csv(tenantId, filter);
|
||||
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
|
||||
res.setHeader('Content-Type', 'text/csv');
|
||||
|
||||
return res.send(buffer);
|
||||
// Retrieves the json format.
|
||||
} else {
|
||||
const sheet = await this.ARAgingSummaryApp.sheet(tenantId, filter);
|
||||
|
||||
return res.status(200).send(sheet);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
@@ -3,25 +3,21 @@ import { Router, Request, Response, NextFunction } from 'express';
|
||||
import { query, ValidationChain } from 'express-validator';
|
||||
import { castArray } from 'lodash';
|
||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||
import BalanceSheetStatementService from '@/services/FinancialStatements/BalanceSheet/BalanceSheetService';
|
||||
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||
import BalanceSheetTable from '@/services/FinancialStatements/BalanceSheet/BalanceSheetTable';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { BalanceSheetApplication } from '@/services/FinancialStatements/BalanceSheet/BalanceSheetApplication';
|
||||
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||
|
||||
@Service()
|
||||
export default class BalanceSheetStatementController extends BaseFinancialReportController {
|
||||
@Inject()
|
||||
balanceSheetService: BalanceSheetStatementService;
|
||||
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
private balanceSheetApp: BalanceSheetApplication;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
*/
|
||||
router() {
|
||||
public router() {
|
||||
const router = Router();
|
||||
|
||||
router.get(
|
||||
@@ -38,7 +34,7 @@ export default class BalanceSheetStatementController extends BaseFinancialReport
|
||||
* Balance sheet validation schecma.
|
||||
* @returns {ValidationChain[]}
|
||||
*/
|
||||
get balanceSheetValidationSchema(): ValidationChain[] {
|
||||
private get balanceSheetValidationSchema(): ValidationChain[] {
|
||||
return [
|
||||
...this.sheetNumberFormatValidationSchema,
|
||||
query('accounting_method').optional().isIn(['cash', 'accrual']),
|
||||
@@ -84,10 +80,12 @@ export default class BalanceSheetStatementController extends BaseFinancialReport
|
||||
|
||||
/**
|
||||
* Retrieve the balance sheet.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
async balanceSheet(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId, settings } = req;
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
private async balanceSheet(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
|
||||
let filter = this.matchedQueryData(req);
|
||||
|
||||
@@ -95,29 +93,45 @@ export default class BalanceSheetStatementController extends BaseFinancialReport
|
||||
...filter,
|
||||
accountsIds: castArray(filter.accountsIds),
|
||||
};
|
||||
|
||||
try {
|
||||
const { data, columns, query, meta } =
|
||||
await this.balanceSheetService.balanceSheet(tenantId, filter);
|
||||
|
||||
const accept = this.accepts(req);
|
||||
const acceptType = accept.types(['json', 'application/json+table']);
|
||||
|
||||
const table = new BalanceSheetTable(data, query, i18n);
|
||||
const acceptType = accept.types([
|
||||
ACCEPT_TYPE.APPLICATION_JSON,
|
||||
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
|
||||
ACCEPT_TYPE.APPLICATION_XLSX,
|
||||
ACCEPT_TYPE.APPLICATION_CSV,
|
||||
]);
|
||||
// Retrieves the json table format.
|
||||
if (ACCEPT_TYPE.APPLICATION_JSON_TABLE == acceptType) {
|
||||
const table = await this.balanceSheetApp.table(tenantId, filter);
|
||||
|
||||
switch (acceptType) {
|
||||
case 'application/json+table':
|
||||
return res.status(200).send({
|
||||
table: {
|
||||
rows: table.tableRows(),
|
||||
columns: table.tableColumns(),
|
||||
},
|
||||
query,
|
||||
meta,
|
||||
});
|
||||
case 'json':
|
||||
default:
|
||||
return res.status(200).send({ data, columns, query, meta });
|
||||
return res.status(200).send(table);
|
||||
// Retrieves the csv format.
|
||||
} else if (ACCEPT_TYPE.APPLICATION_CSV === acceptType) {
|
||||
const buffer = await this.balanceSheetApp.csv(tenantId, filter);
|
||||
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
|
||||
res.setHeader('Content-Type', 'text/csv');
|
||||
|
||||
return res.send(buffer);
|
||||
// Retrieves the xlsx format.
|
||||
} else if (ACCEPT_TYPE.APPLICATION_XLSX === acceptType) {
|
||||
const buffer = await this.balanceSheetApp.xlsx(tenantId, filter);
|
||||
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
'attachment; filename=output.xlsx'
|
||||
);
|
||||
res.setHeader(
|
||||
'Content-Type',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
);
|
||||
return res.send(buffer);
|
||||
} else {
|
||||
const sheet = await this.balanceSheetApp.sheet(tenantId, filter);
|
||||
|
||||
return res.status(200).send(sheet);
|
||||
}
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -8,29 +8,20 @@ import {
|
||||
ValidationChain,
|
||||
} from 'express';
|
||||
import BaseFinancialReportController from '../BaseFinancialReportController';
|
||||
import CashFlowStatementService from '@/services/FinancialStatements/CashFlow/CashFlowService';
|
||||
import {
|
||||
ICashFlowStatementDOO,
|
||||
ICashFlowStatement,
|
||||
AbilitySubject,
|
||||
ReportsAction,
|
||||
} from '@/interfaces';
|
||||
import CashFlowTable from '@/services/FinancialStatements/CashFlow/CashFlowTable';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||
import { CashflowSheetApplication } from '@/services/FinancialStatements/CashFlow/CashflowSheetApplication';
|
||||
|
||||
@Service()
|
||||
export default class CashFlowController extends BaseFinancialReportController {
|
||||
@Inject()
|
||||
cashFlowService: CashFlowStatementService;
|
||||
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
private cashflowSheetApp: CashflowSheetApplication;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
*/
|
||||
router() {
|
||||
public router() {
|
||||
const router = Router();
|
||||
|
||||
router.get(
|
||||
@@ -47,7 +38,7 @@ export default class CashFlowController extends BaseFinancialReportController {
|
||||
* Balance sheet validation schecma.
|
||||
* @returns {ValidationChain[]}
|
||||
*/
|
||||
get cashflowValidationSchema(): ValidationChain[] {
|
||||
private get cashflowValidationSchema(): ValidationChain[] {
|
||||
return [
|
||||
...this.sheetNumberFormatValidationSchema,
|
||||
query('from_date').optional(),
|
||||
@@ -67,41 +58,6 @@ export default class CashFlowController extends BaseFinancialReportController {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the cashflow statment to json response.
|
||||
* @param {ICashFlowStatement} cashFlow -
|
||||
*/
|
||||
private transformJsonResponse(cashFlowDOO: ICashFlowStatementDOO) {
|
||||
const { data, query, meta } = cashFlowDOO;
|
||||
|
||||
return {
|
||||
data: this.transfromToResponse(data),
|
||||
query: this.transfromToResponse(query),
|
||||
meta: this.transfromToResponse(meta),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Transformes the report statement to table rows.
|
||||
* @param {ITransactionsByVendorsStatement} statement -
|
||||
*/
|
||||
private transformToTableRows(
|
||||
cashFlowDOO: ICashFlowStatementDOO,
|
||||
tenantId: number
|
||||
) {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
const cashFlowTable = new CashFlowTable(cashFlowDOO, i18n);
|
||||
|
||||
return {
|
||||
table: {
|
||||
data: cashFlowTable.tableRows(),
|
||||
columns: cashFlowTable.tableColumns(),
|
||||
},
|
||||
query: this.transfromToResponse(cashFlowDOO.query),
|
||||
meta: this.transfromToResponse(cashFlowDOO.meta),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the cash flow statment.
|
||||
* @param {Request} req
|
||||
@@ -109,26 +65,52 @@ export default class CashFlowController extends BaseFinancialReportController {
|
||||
* @param {NextFunction} next
|
||||
* @returns {Response}
|
||||
*/
|
||||
async cashFlow(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId, settings } = req;
|
||||
public async cashFlow(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
const filter = {
|
||||
...this.matchedQueryData(req),
|
||||
};
|
||||
|
||||
try {
|
||||
const cashFlow = await this.cashFlowService.cashFlow(tenantId, filter);
|
||||
|
||||
const accept = this.accepts(req);
|
||||
const acceptType = accept.types(['json', 'application/json+table']);
|
||||
|
||||
switch (acceptType) {
|
||||
case 'application/json+table':
|
||||
return res
|
||||
.status(200)
|
||||
.send(this.transformToTableRows(cashFlow, tenantId));
|
||||
case 'json':
|
||||
default:
|
||||
return res.status(200).send(this.transformJsonResponse(cashFlow));
|
||||
const acceptType = accept.types([
|
||||
ACCEPT_TYPE.APPLICATION_JSON,
|
||||
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
|
||||
ACCEPT_TYPE.APPLICATION_CSV,
|
||||
ACCEPT_TYPE.APPLICATION_XLSX,
|
||||
]);
|
||||
// Retrieves the json table format.
|
||||
if (ACCEPT_TYPE.APPLICATION_JSON_TABLE === acceptType) {
|
||||
const table = await this.cashflowSheetApp.table(tenantId, filter);
|
||||
|
||||
return res.status(200).send(table);
|
||||
// Retrieves the csv format.
|
||||
} else if (ACCEPT_TYPE.APPLICATION_CSV === acceptType) {
|
||||
const buffer = await this.cashflowSheetApp.csv(tenantId, filter);
|
||||
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
|
||||
res.setHeader('Content-Type', 'text/csv');
|
||||
|
||||
return res.status(200).send(buffer);
|
||||
// Retrieves the pdf format.
|
||||
} else if (ACCEPT_TYPE.APPLICATION_XLSX === acceptType) {
|
||||
const buffer = await this.cashflowSheetApp.xlsx(tenantId, filter);
|
||||
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
'attachment; filename=output.xlsx'
|
||||
);
|
||||
res.setHeader(
|
||||
'Content-Type',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
);
|
||||
return res.send(buffer);
|
||||
// Retrieves the json format.
|
||||
} else {
|
||||
const cashflow = await this.cashflowSheetApp.sheet(tenantId, filter);
|
||||
|
||||
return res.status(200).send(cashflow);
|
||||
}
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -1,29 +1,21 @@
|
||||
import { Router, Request, Response, NextFunction } from 'express';
|
||||
import { query } from 'express-validator';
|
||||
import { Inject } from 'typedi';
|
||||
import {
|
||||
AbilitySubject,
|
||||
ICustomerBalanceSummaryStatement,
|
||||
ReportsAction,
|
||||
} from '@/interfaces';
|
||||
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||
import CustomerBalanceSummary from '@/services/FinancialStatements/CustomerBalanceSummary/CustomerBalanceSummaryService';
|
||||
import BaseFinancialReportController from '../BaseFinancialReportController';
|
||||
import CustomerBalanceSummaryTableRows from '@/services/FinancialStatements/CustomerBalanceSummary/CustomerBalanceSummaryTableRows';
|
||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||
import { CustomerBalanceSummaryApplication } from '@/services/FinancialStatements/CustomerBalanceSummary/CustomerBalanceSummaryApplication';
|
||||
|
||||
export default class CustomerBalanceSummaryReportController extends BaseFinancialReportController {
|
||||
@Inject()
|
||||
customerBalanceSummaryService: CustomerBalanceSummary;
|
||||
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
private customerBalanceSummaryApp: CustomerBalanceSummaryApplication;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
*/
|
||||
router() {
|
||||
public router() {
|
||||
const router = Router();
|
||||
|
||||
router.get(
|
||||
@@ -42,7 +34,7 @@ export default class CustomerBalanceSummaryReportController extends BaseFinancia
|
||||
/**
|
||||
* Validation schema.
|
||||
*/
|
||||
get validationSchema() {
|
||||
private get validationSchema() {
|
||||
return [
|
||||
...this.sheetNumberFormatValidationSchema,
|
||||
|
||||
@@ -62,75 +54,67 @@ export default class CustomerBalanceSummaryReportController extends BaseFinancia
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Transformes the balance summary statement to table rows.
|
||||
* @param {ICustomerBalanceSummaryStatement} statement -
|
||||
*/
|
||||
private transformToTableRows(
|
||||
tenantId,
|
||||
{ data, query }: ICustomerBalanceSummaryStatement
|
||||
) {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
const tableRows = new CustomerBalanceSummaryTableRows(data, query, i18n);
|
||||
|
||||
return {
|
||||
table: {
|
||||
columns: tableRows.tableColumns(),
|
||||
data: tableRows.tableRows(),
|
||||
},
|
||||
query: this.transfromToResponse(query),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Transformes the balance summary statement to raw json.
|
||||
* @param {ICustomerBalanceSummaryStatement} customerBalance -
|
||||
*/
|
||||
private transformToJsonResponse({
|
||||
data,
|
||||
columns,
|
||||
query,
|
||||
}: ICustomerBalanceSummaryStatement) {
|
||||
return {
|
||||
data: this.transfromToResponse(data),
|
||||
columns: this.transfromToResponse(columns),
|
||||
query: this.transfromToResponse(query),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve payable aging summary report.
|
||||
* @param {Request} req -
|
||||
* @param {Response} res -
|
||||
* @param {NextFunction} next -
|
||||
*/
|
||||
async customerBalanceSummary(
|
||||
private async customerBalanceSummary(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId, settings } = req;
|
||||
const { tenantId } = req;
|
||||
const filter = this.matchedQueryData(req);
|
||||
|
||||
try {
|
||||
const customerBalanceSummary =
|
||||
await this.customerBalanceSummaryService.customerBalanceSummary(
|
||||
const accept = this.accepts(req);
|
||||
const acceptType = accept.types([
|
||||
ACCEPT_TYPE.APPLICATION_JSON,
|
||||
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
|
||||
ACCEPT_TYPE.APPLICATION_CSV,
|
||||
ACCEPT_TYPE.APPLICATION_XLSX,
|
||||
]);
|
||||
|
||||
// Retrieves the xlsx format.
|
||||
if (ACCEPT_TYPE.APPLICATION_XLSX === acceptType) {
|
||||
const buffer = await this.customerBalanceSummaryApp.xlsx(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
const accept = this.accepts(req);
|
||||
const acceptType = accept.types(['json', 'application/json+table']);
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
'attachment; filename=output.xlsx'
|
||||
);
|
||||
res.setHeader(
|
||||
'Content-Type',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
);
|
||||
return res.send(buffer);
|
||||
// Retrieves the csv format.
|
||||
} else if (ACCEPT_TYPE.APPLICATION_CSV === acceptType) {
|
||||
const buffer = await this.customerBalanceSummaryApp.csv(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
|
||||
res.setHeader('Content-Type', 'text/csv');
|
||||
|
||||
switch (acceptType) {
|
||||
case 'application/json+table':
|
||||
return res
|
||||
.status(200)
|
||||
.send(this.transformToTableRows(tenantId, customerBalanceSummary));
|
||||
case 'application/json':
|
||||
default:
|
||||
return res
|
||||
.status(200)
|
||||
.send(this.transformToJsonResponse(customerBalanceSummary));
|
||||
return res.send(buffer);
|
||||
// Retrieves the json table format.
|
||||
} else if (ACCEPT_TYPE.APPLICATION_JSON_TABLE === acceptType) {
|
||||
const table = await this.customerBalanceSummaryApp.table(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
return res.status(200).send(table);
|
||||
} else {
|
||||
const sheet = await this.customerBalanceSummaryApp.sheet(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
return res.status(200).send(sheet);
|
||||
}
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -8,24 +8,20 @@ import {
|
||||
ValidationChain,
|
||||
} from 'express';
|
||||
import BaseController from '@/api/controllers/BaseController';
|
||||
import InventoryDetailsService from '@/services/FinancialStatements/InventoryDetails/InventoryDetailsService';
|
||||
import InventoryDetailsTable from '@/services/FinancialStatements/InventoryDetails/InventoryDetailsTable';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
||||
import { InventortyDetailsApplication } from '@/services/FinancialStatements/InventoryDetails/InventoryDetailsApplication';
|
||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||
|
||||
@Service()
|
||||
export default class InventoryDetailsController extends BaseController {
|
||||
@Inject()
|
||||
inventoryDetailsService: InventoryDetailsService;
|
||||
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
private inventoryItemDetailsApp: InventortyDetailsApplication;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
*/
|
||||
router() {
|
||||
public router() {
|
||||
const router = Router();
|
||||
|
||||
router.get(
|
||||
@@ -45,7 +41,7 @@ export default class InventoryDetailsController extends BaseController {
|
||||
* Balance sheet validation schecma.
|
||||
* @returns {ValidationChain[]}
|
||||
*/
|
||||
get validationSchema(): ValidationChain[] {
|
||||
private get validationSchema(): ValidationChain[] {
|
||||
return [
|
||||
query('number_format.precision')
|
||||
.optional()
|
||||
@@ -77,69 +73,66 @@ export default class InventoryDetailsController extends BaseController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the cashflow statment to json response.
|
||||
* @param {ICashFlowStatement} cashFlow -
|
||||
*/
|
||||
private transformJsonResponse(inventoryDetails) {
|
||||
const { data, query, meta } = inventoryDetails;
|
||||
|
||||
return {
|
||||
data: this.transfromToResponse(data),
|
||||
query: this.transfromToResponse(query),
|
||||
meta: this.transfromToResponse(meta),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Transformes the report statement to table rows.
|
||||
*/
|
||||
private transformToTableRows(inventoryDetails, tenantId: number) {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
const inventoryDetailsTable = new InventoryDetailsTable(
|
||||
inventoryDetails,
|
||||
i18n
|
||||
);
|
||||
|
||||
return {
|
||||
table: {
|
||||
data: inventoryDetailsTable.tableData(),
|
||||
columns: inventoryDetailsTable.tableColumns(),
|
||||
},
|
||||
query: this.transfromToResponse(inventoryDetails.query),
|
||||
meta: this.transfromToResponse(inventoryDetails.meta),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the cash flow statment.
|
||||
* Retrieve the inventory item details sheet.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
* @returns {Response}
|
||||
*/
|
||||
async inventoryDetails(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId, settings } = req;
|
||||
private async inventoryDetails(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId } = req;
|
||||
const filter = {
|
||||
...this.matchedQueryData(req),
|
||||
};
|
||||
|
||||
try {
|
||||
const inventoryDetails =
|
||||
await this.inventoryDetailsService.inventoryDetails(tenantId, filter);
|
||||
|
||||
const accept = this.accepts(req);
|
||||
const acceptType = accept.types(['json', 'application/json+table']);
|
||||
const acceptType = accept.types([
|
||||
ACCEPT_TYPE.APPLICATION_JSON,
|
||||
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
|
||||
ACCEPT_TYPE.APPLICATION_CSV,
|
||||
ACCEPT_TYPE.APPLICATION_XLSX,
|
||||
]);
|
||||
// Retrieves the csv format.
|
||||
if (acceptType === ACCEPT_TYPE.APPLICATION_CSV) {
|
||||
const buffer = await this.inventoryItemDetailsApp.csv(tenantId, filter);
|
||||
|
||||
switch (acceptType) {
|
||||
case 'application/json+table':
|
||||
return res
|
||||
.status(200)
|
||||
.send(this.transformToTableRows(inventoryDetails, tenantId));
|
||||
case 'json':
|
||||
default:
|
||||
return res
|
||||
.status(200)
|
||||
.send(this.transformJsonResponse(inventoryDetails));
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
|
||||
res.setHeader('Content-Type', 'text/csv');
|
||||
|
||||
return res.send(buffer);
|
||||
// Retrieves the xlsx format.
|
||||
} else if (acceptType === ACCEPT_TYPE.APPLICATION_XLSX) {
|
||||
const buffer = await this.inventoryItemDetailsApp.xlsx(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
'attachment; filename=output.xlsx'
|
||||
);
|
||||
res.setHeader(
|
||||
'Content-Type',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
);
|
||||
return res.send(buffer);
|
||||
// Retrieves the json table format.
|
||||
} else if (acceptType === ACCEPT_TYPE.APPLICATION_JSON_TABLE) {
|
||||
const table = await this.inventoryItemDetailsApp.table(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
return res.status(200).send(table);
|
||||
} else {
|
||||
const sheet = await this.inventoryItemDetailsApp.sheet(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
return res.status(200).send(sheet);
|
||||
}
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -1,24 +1,20 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import { Router, Request, Response, NextFunction } from 'express';
|
||||
import { query, ValidationChain } from 'express-validator';
|
||||
import ProfitLossSheetService from '@/services/FinancialStatements/ProfitLossSheet/ProfitLossSheetService';
|
||||
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
||||
import { ProfitLossSheetTable } from '@/services/FinancialStatements/ProfitLossSheet/ProfitLossSheetTable';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||
import { ProfitLossSheetApplication } from '@/services/FinancialStatements/ProfitLossSheet/ProfitLossSheetApplication';
|
||||
@Service()
|
||||
export default class ProfitLossSheetController extends BaseFinancialReportController {
|
||||
@Inject()
|
||||
profitLossSheetService: ProfitLossSheetService;
|
||||
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
private profitLossSheetApp: ProfitLossSheetApplication;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
*/
|
||||
router() {
|
||||
public router() {
|
||||
const router = Router();
|
||||
|
||||
router.get(
|
||||
@@ -34,7 +30,7 @@ export default class ProfitLossSheetController extends BaseFinancialReportContro
|
||||
/**
|
||||
* Validation schema.
|
||||
*/
|
||||
get validationSchema(): ValidationChain[] {
|
||||
private get validationSchema(): ValidationChain[] {
|
||||
return [
|
||||
...this.sheetNumberFormatValidationSchema,
|
||||
query('basis').optional(),
|
||||
@@ -85,37 +81,54 @@ export default class ProfitLossSheetController extends BaseFinancialReportContro
|
||||
* @param {Request} req -
|
||||
* @param {Response} res -
|
||||
*/
|
||||
async profitLossSheet(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId, settings } = req;
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
private async profitLossSheet(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId } = req;
|
||||
const filter = this.matchedQueryData(req);
|
||||
|
||||
const accept = this.accepts(req);
|
||||
|
||||
const acceptType = accept.types([
|
||||
ACCEPT_TYPE.APPLICATION_JSON,
|
||||
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
|
||||
ACCEPT_TYPE.APPLICATION_CSV,
|
||||
ACCEPT_TYPE.APPLICATION_XLSX,
|
||||
]);
|
||||
try {
|
||||
const { data, query, meta } =
|
||||
await this.profitLossSheetService.profitLossSheet(tenantId, filter);
|
||||
// Retrieves the csv format.
|
||||
if (acceptType === ACCEPT_TYPE.APPLICATION_CSV) {
|
||||
const sheet = await this.profitLossSheetApp.csv(tenantId, filter);
|
||||
|
||||
const accept = this.accepts(req);
|
||||
const acceptType = accept.types(['json', 'application/json+table']);
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
|
||||
res.setHeader('Content-Type', 'text/csv');
|
||||
|
||||
switch (acceptType) {
|
||||
case 'application/json+table':
|
||||
const table = new ProfitLossSheetTable(data, query, i18n);
|
||||
return res.send(sheet);
|
||||
// Retrieves the json table format.
|
||||
} else if (acceptType === ACCEPT_TYPE.APPLICATION_JSON_TABLE) {
|
||||
const table = await this.profitLossSheetApp.table(tenantId, filter);
|
||||
|
||||
return res.status(200).send({
|
||||
table: {
|
||||
rows: table.tableRows(),
|
||||
columns: table.tableColumns(),
|
||||
},
|
||||
query,
|
||||
meta,
|
||||
});
|
||||
case 'json':
|
||||
default:
|
||||
return res.status(200).send({
|
||||
data,
|
||||
query,
|
||||
meta,
|
||||
});
|
||||
return res.status(200).send(table);
|
||||
// Retrieves the xlsx format.
|
||||
} else if (acceptType === ACCEPT_TYPE.APPLICATION_XLSX) {
|
||||
const sheet = await this.profitLossSheetApp.xlsx(tenantId, filter);
|
||||
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
'attachment; filename=output.xlsx'
|
||||
);
|
||||
res.setHeader(
|
||||
'Content-Type',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
);
|
||||
return res.send(sheet);
|
||||
// Retrieves the json format.
|
||||
} else {
|
||||
const sheet = await this.profitLossSheetApp.sheet(tenantId, filter);
|
||||
|
||||
return res.status(200).send(sheet);
|
||||
}
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -16,15 +16,12 @@ export default class SalesByItemsReportController extends BaseFinancialReportCon
|
||||
/**
|
||||
* Router constructor.
|
||||
*/
|
||||
router() {
|
||||
public router() {
|
||||
const router = Router();
|
||||
|
||||
router.get(
|
||||
'/',
|
||||
CheckPolicies(
|
||||
ReportsAction.READ_SALES_BY_ITEMS,
|
||||
AbilitySubject.Report
|
||||
),
|
||||
CheckPolicies(ReportsAction.READ_SALES_BY_ITEMS, AbilitySubject.Report),
|
||||
this.validationSchema,
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.purchasesByItems.bind(this))
|
||||
@@ -35,7 +32,7 @@ export default class SalesByItemsReportController extends BaseFinancialReportCon
|
||||
/**
|
||||
* Validation schema.
|
||||
*/
|
||||
get validationSchema(): ValidationChain[] {
|
||||
private get validationSchema(): ValidationChain[] {
|
||||
return [
|
||||
query('from_date').optional().isISO8601(),
|
||||
query('to_date').optional().isISO8601(),
|
||||
@@ -63,7 +60,11 @@ export default class SalesByItemsReportController extends BaseFinancialReportCon
|
||||
* @param {Request} req -
|
||||
* @param {Response} res -
|
||||
*/
|
||||
async purchasesByItems(req: Request, res: Response, next: NextFunction) {
|
||||
private async purchasesByItems(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId } = req;
|
||||
const filter = this.matchedQueryData(req);
|
||||
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
import { Inject } from 'typedi';
|
||||
import { Router, Request, Response, NextFunction } from 'express';
|
||||
import { query } from 'express-validator';
|
||||
import { Inject } from 'typedi';
|
||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||
import BaseFinancialReportController from '../BaseFinancialReportController';
|
||||
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||
import { SalesTaxLiabilitySummaryService } from '@/services/FinancialStatements/SalesTaxLiabilitySummary/SalesTaxLiabilitySummaryService';
|
||||
import { SalesTaxLiabilitySummaryApplication } from '@/services/FinancialStatements/SalesTaxLiabilitySummary/SalesTaxLiabilitySummaryApplication';
|
||||
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||
|
||||
export default class SalesTaxLiabilitySummary extends BaseFinancialReportController {
|
||||
@Inject()
|
||||
private salesTaxLiabilitySummaryService: SalesTaxLiabilitySummaryService;
|
||||
private salesTaxLiabilitySummaryApp: SalesTaxLiabilitySummaryApplication;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
*/
|
||||
router() {
|
||||
public router() {
|
||||
const router = Router();
|
||||
|
||||
router.get(
|
||||
@@ -31,8 +32,9 @@ export default class SalesTaxLiabilitySummary extends BaseFinancialReportControl
|
||||
|
||||
/**
|
||||
* Validation schema.
|
||||
* @returns {ValidationChain[]}
|
||||
*/
|
||||
get validationSchema() {
|
||||
private get validationSchema() {
|
||||
return [
|
||||
query('from_date').optional().isISO8601(),
|
||||
query('to_date').optional().isISO8601(),
|
||||
@@ -45,7 +47,7 @@ export default class SalesTaxLiabilitySummary extends BaseFinancialReportControl
|
||||
* @param {Response} res -
|
||||
* @param {NextFunction} next -
|
||||
*/
|
||||
async salesTaxLiabilitySummary(
|
||||
private async salesTaxLiabilitySummary(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
@@ -55,33 +57,52 @@ export default class SalesTaxLiabilitySummary extends BaseFinancialReportControl
|
||||
|
||||
try {
|
||||
const accept = this.accepts(req);
|
||||
const acceptType = accept.types(['json', 'application/json+table']);
|
||||
const acceptType = accept.types([
|
||||
ACCEPT_TYPE.APPLICATION_JSON,
|
||||
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
|
||||
ACCEPT_TYPE.APPLICATION_CSV,
|
||||
ACCEPT_TYPE.APPLICATION_XLSX,
|
||||
]);
|
||||
|
||||
switch (acceptType) {
|
||||
case 'application/json+table':
|
||||
const salesTaxLiabilityTable =
|
||||
await this.salesTaxLiabilitySummaryService.salesTaxLiabilitySummaryTable(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
// Retrieves the json table format.
|
||||
if (acceptType === ACCEPT_TYPE.APPLICATION_JSON_TABLE) {
|
||||
const table = await this.salesTaxLiabilitySummaryApp.table(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
return res.status(200).send(table);
|
||||
// Retrieves the xlsx format.
|
||||
} else if (acceptType === ACCEPT_TYPE.APPLICATION_XLSX) {
|
||||
const buffer = await this.salesTaxLiabilitySummaryApp.xlsx(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
'attachment; filename=output.xlsx'
|
||||
);
|
||||
res.setHeader(
|
||||
'Content-Type',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
);
|
||||
return res.send(buffer);
|
||||
// Retrieves the csv format.
|
||||
} else if (acceptType === ACCEPT_TYPE.APPLICATION_CSV) {
|
||||
const buffer = await this.salesTaxLiabilitySummaryApp.csv(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
|
||||
res.setHeader('Content-Type', 'text/csv');
|
||||
|
||||
return res.status(200).send({
|
||||
table: salesTaxLiabilityTable.table,
|
||||
query: salesTaxLiabilityTable.query,
|
||||
meta: salesTaxLiabilityTable.meta,
|
||||
});
|
||||
case 'json':
|
||||
default:
|
||||
const salesTaxLiability =
|
||||
await this.salesTaxLiabilitySummaryService.salesTaxLiability(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
return res.status(200).send({
|
||||
data: salesTaxLiability.data,
|
||||
query: salesTaxLiability.query,
|
||||
meta: salesTaxLiability.meta,
|
||||
});
|
||||
return res.send(buffer);
|
||||
// Retrieves the json format.
|
||||
} else {
|
||||
const sheet = await this.salesTaxLiabilitySummaryApp.sheet(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
return res.status(200).send(sheet);
|
||||
}
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -1,30 +1,22 @@
|
||||
import { Router, Request, Response, NextFunction } from 'express';
|
||||
import { query } from 'express-validator';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import {
|
||||
AbilitySubject,
|
||||
ITransactionsByCustomersStatement,
|
||||
ReportsAction,
|
||||
} from '@/interfaces';
|
||||
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||
import BaseFinancialReportController from '../BaseFinancialReportController';
|
||||
import TransactionsByCustomersService from '@/services/FinancialStatements/TransactionsByCustomer/TransactionsByCustomersService';
|
||||
import TransactionsByCustomersTableRows from '@/services/FinancialStatements/TransactionsByCustomer/TransactionsByCustomersTableRows';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||
import { TransactionsByCustomerApplication } from '@/services/FinancialStatements/TransactionsByCustomer/TransactionsByCustomersApplication';
|
||||
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||
|
||||
@Service()
|
||||
export default class TransactionsByCustomersReportController extends BaseFinancialReportController {
|
||||
@Inject()
|
||||
transactionsByCustomersService: TransactionsByCustomersService;
|
||||
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
private transactionsByCustomersApp: TransactionsByCustomerApplication;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
*/
|
||||
router() {
|
||||
public router() {
|
||||
const router = Router();
|
||||
|
||||
router.get(
|
||||
@@ -58,45 +50,13 @@ export default class TransactionsByCustomersReportController extends BaseFinanci
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Transformes the statement to table rows response.
|
||||
* @param {ITransactionsByCustomersStatement} statement -
|
||||
*/
|
||||
private transformToTableResponse(customersTransactions, tenantId) {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
const table = new TransactionsByCustomersTableRows(
|
||||
customersTransactions,
|
||||
i18n
|
||||
);
|
||||
return {
|
||||
table: {
|
||||
rows: table.tableRows(),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Transformes the statement to json response.
|
||||
* @param {ITransactionsByCustomersStatement} statement -
|
||||
*/
|
||||
private transfromToJsonResponse(
|
||||
data,
|
||||
columns
|
||||
): ITransactionsByCustomersStatement {
|
||||
return {
|
||||
data: this.transfromToResponse(data),
|
||||
columns: this.transfromToResponse(columns),
|
||||
query: this.transfromToResponse(query),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve payable aging summary report.
|
||||
* @param {Request} req -
|
||||
* @param {Response} res -
|
||||
* @param {NextFunction} next -
|
||||
*/
|
||||
async transactionsByCustomers(
|
||||
private async transactionsByCustomers(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
@@ -104,25 +64,51 @@ export default class TransactionsByCustomersReportController extends BaseFinanci
|
||||
const { tenantId } = req;
|
||||
const filter = this.matchedQueryData(req);
|
||||
|
||||
const accept = this.accepts(req);
|
||||
const acceptType = accept.types([
|
||||
ACCEPT_TYPE.APPLICATION_JSON,
|
||||
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
|
||||
ACCEPT_TYPE.APPLICATION_CSV,
|
||||
ACCEPT_TYPE.APPLICATION_XLSX,
|
||||
]);
|
||||
try {
|
||||
const report =
|
||||
await this.transactionsByCustomersService.transactionsByCustomers(
|
||||
// Retrieves the json table format.
|
||||
if (ACCEPT_TYPE.APPLICATION_JSON_TABLE === acceptType) {
|
||||
const table = await this.transactionsByCustomersApp.table(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
const accept = this.accepts(req);
|
||||
const acceptType = accept.types(['json', 'application/json+table']);
|
||||
return res.status(200).send(table);
|
||||
// Retrieve the csv format.
|
||||
} else if (ACCEPT_TYPE.APPLICATION_CSV === acceptType) {
|
||||
const csv = await this.transactionsByCustomersApp.csv(tenantId, filter);
|
||||
|
||||
switch (acceptType) {
|
||||
case 'json':
|
||||
return res
|
||||
.status(200)
|
||||
.send(this.transfromToJsonResponse(report.data, report.columns));
|
||||
case 'application/json+table':
|
||||
default:
|
||||
return res
|
||||
.status(200)
|
||||
.send(this.transformToTableResponse(report.data, tenantId));
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
|
||||
res.setHeader('Content-Type', 'text/csv');
|
||||
|
||||
return res.send(csv);
|
||||
// Retrieve the xlsx format.
|
||||
} else if (ACCEPT_TYPE.APPLICATION_XLSX === acceptType) {
|
||||
const buffer = await this.transactionsByCustomersApp.xlsx(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
'attachment; filename=output.xlsx'
|
||||
);
|
||||
res.setHeader(
|
||||
'Content-Type',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
);
|
||||
return res.send(buffer);
|
||||
// Retrieve the json format.
|
||||
} else {
|
||||
const sheet = await this.transactionsByCustomersApp.sheet(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
return res.status(200).send(sheet);
|
||||
}
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -3,27 +3,19 @@ import { query, ValidationChain } from 'express-validator';
|
||||
import { Inject } from 'typedi';
|
||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||
import BaseFinancialReportController from '../BaseFinancialReportController';
|
||||
import TransactionsByVendorsTableRows from '@/services/FinancialStatements/TransactionsByVendor/TransactionsByVendorTableRows';
|
||||
import TransactionsByVendorsService from '@/services/FinancialStatements/TransactionsByVendor/TransactionsByVendorService';
|
||||
import {
|
||||
AbilitySubject,
|
||||
ITransactionsByVendorsStatement,
|
||||
ReportsAction,
|
||||
} from '@/interfaces';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||
import { TransactionsByVendorApplication } from '@/services/FinancialStatements/TransactionsByVendor/TransactionsByVendorApplication';
|
||||
|
||||
export default class TransactionsByVendorsReportController extends BaseFinancialReportController {
|
||||
@Inject()
|
||||
transactionsByVendorsService: TransactionsByVendorsService;
|
||||
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
private transactionsByVendorsApp: TransactionsByVendorApplication;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
*/
|
||||
router() {
|
||||
public router() {
|
||||
const router = Router();
|
||||
|
||||
router.get(
|
||||
@@ -42,7 +34,7 @@ export default class TransactionsByVendorsReportController extends BaseFinancial
|
||||
/**
|
||||
* Validation schema.
|
||||
*/
|
||||
get validationSchema(): ValidationChain[] {
|
||||
private get validationSchema(): ValidationChain[] {
|
||||
return [
|
||||
...this.sheetNumberFormatValidationSchema,
|
||||
|
||||
@@ -58,64 +50,64 @@ export default class TransactionsByVendorsReportController extends BaseFinancial
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Transformes the report statement to table rows.
|
||||
* @param {ITransactionsByVendorsStatement} statement -
|
||||
*/
|
||||
private transformToTableRows(tenantId: number, transactions: any[]) {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
const table = new TransactionsByVendorsTableRows(transactions, i18n);
|
||||
|
||||
return {
|
||||
table: {
|
||||
data: table.tableRows(),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Transformes the report statement to json response.
|
||||
* @param {ITransactionsByVendorsStatement} statement -
|
||||
*/
|
||||
private transformToJsonResponse({
|
||||
data,
|
||||
columns,
|
||||
query,
|
||||
}: ITransactionsByVendorsStatement) {
|
||||
return {
|
||||
data: this.transfromToResponse(data),
|
||||
columns: this.transfromToResponse(columns),
|
||||
query: this.transfromToResponse(query),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve payable aging summary report.
|
||||
* @param {Request} req -
|
||||
* @param {Response} res -
|
||||
* @param {NextFunction} next -
|
||||
*/
|
||||
async transactionsByVendors(req: Request, res: Response, next: NextFunction) {
|
||||
private async transactionsByVendors(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId } = req;
|
||||
const filter = this.matchedQueryData(req);
|
||||
|
||||
try {
|
||||
const report =
|
||||
await this.transactionsByVendorsService.transactionsByVendors(
|
||||
const accept = this.accepts(req);
|
||||
const acceptType = accept.types([
|
||||
ACCEPT_TYPE.APPLICATION_JSON,
|
||||
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
|
||||
ACCEPT_TYPE.APPLICATION_CSV,
|
||||
ACCEPT_TYPE.APPLICATION_XLSX,
|
||||
]);
|
||||
|
||||
// Retrieves the xlsx format.
|
||||
if (ACCEPT_TYPE.APPLICATION_XLSX === acceptType) {
|
||||
const buffer = await this.transactionsByVendorsApp.xlsx(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
const accept = this.accepts(req);
|
||||
const acceptType = accept.types(['json', 'application/json+table']);
|
||||
|
||||
switch (acceptType) {
|
||||
case 'application/json+table':
|
||||
return res
|
||||
.status(200)
|
||||
.send(this.transformToTableRows(tenantId, report.data));
|
||||
case 'json':
|
||||
default:
|
||||
return res.status(200).send(this.transformToJsonResponse(report));
|
||||
res.setHeader('Content-Type', 'application/vnd.openxmlformats');
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
'attachment; filename=report.xlsx'
|
||||
);
|
||||
return res.send(buffer);
|
||||
// Retrieves the csv format.
|
||||
} else if (ACCEPT_TYPE.APPLICATION_CSV === acceptType) {
|
||||
const buffer = await this.transactionsByVendorsApp.csv(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
res.setHeader('Content-Type', 'text/csv');
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=report.csv');
|
||||
return res.send(buffer);
|
||||
// Retrieves the json table format.
|
||||
} else if (ACCEPT_TYPE.APPLICATION_JSON_TABLE === acceptType) {
|
||||
const table = await this.transactionsByVendorsApp.table(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
return res.status(200).send(table);
|
||||
// Retrieves the json format.
|
||||
} else {
|
||||
const sheet = await this.transactionsByVendorsApp.sheet(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
return res.status(200).send(sheet);
|
||||
}
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -3,15 +3,17 @@ import { Request, Response, Router, NextFunction } from 'express';
|
||||
import { query, ValidationChain } from 'express-validator';
|
||||
import { castArray } from 'lodash';
|
||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||
import TrialBalanceSheetService from '@/services/FinancialStatements/TrialBalanceSheet/TrialBalanceSheetService';
|
||||
import TrialBalanceSheetService from '@/services/FinancialStatements/TrialBalanceSheet/TrialBalanceSheetInjectable';
|
||||
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||
import { TrialBalanceSheetApplication } from '@/services/FinancialStatements/TrialBalanceSheet/TrialBalanceSheetApplication';
|
||||
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||
|
||||
@Service()
|
||||
export default class TrialBalanceSheetController extends BaseFinancialReportController {
|
||||
@Inject()
|
||||
trialBalanceSheetService: TrialBalanceSheetService;
|
||||
private trialBalanceSheetApp: TrialBalanceSheetApplication;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
@@ -73,21 +75,46 @@ export default class TrialBalanceSheetController extends BaseFinancialReportCont
|
||||
};
|
||||
try {
|
||||
const accept = this.accepts(req);
|
||||
const acceptType = accept.types(['json', 'application/json+table']);
|
||||
|
||||
if (acceptType === 'application/json+table') {
|
||||
const { table, meta, query } =
|
||||
await this.trialBalanceSheetService.trialBalanceSheetTable(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
const acceptType = accept.types([
|
||||
ACCEPT_TYPE.APPLICATION_JSON,
|
||||
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
|
||||
ACCEPT_TYPE.APPLICATION_CSV,
|
||||
ACCEPT_TYPE.APPLICATION_XLSX,
|
||||
]);
|
||||
// Retrieves in json table format.
|
||||
if (acceptType === ACCEPT_TYPE.APPLICATION_JSON_TABLE) {
|
||||
const { table, meta, query } = await this.trialBalanceSheetApp.table(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
return res.status(200).send({ table, meta, query });
|
||||
// Retrieves in xlsx format
|
||||
} else if (acceptType === ACCEPT_TYPE.APPLICATION_XLSX) {
|
||||
const buffer = await this.trialBalanceSheetApp.xlsx(tenantId, filter);
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
'attachment; filename=output.xlsx'
|
||||
);
|
||||
res.setHeader(
|
||||
'Content-Type',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
);
|
||||
return res.send(buffer);
|
||||
// Retrieves in csv format.
|
||||
} else if (acceptType === ACCEPT_TYPE.APPLICATION_CSV) {
|
||||
const buffer = await this.trialBalanceSheetApp.csv(tenantId, filter);
|
||||
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
|
||||
res.setHeader('Content-Type', 'text/csv');
|
||||
|
||||
return res.send(buffer);
|
||||
// Retrieves in json format.
|
||||
} else {
|
||||
const { data, query, meta } =
|
||||
await this.trialBalanceSheetService.trialBalanceSheet(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
const { data, query, meta } = await this.trialBalanceSheetApp.sheet(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
return res.status(200).send({ data, query, meta });
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -3,27 +3,19 @@ import { query } from 'express-validator';
|
||||
import { Inject } from 'typedi';
|
||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||
import BaseFinancialReportController from '../BaseFinancialReportController';
|
||||
import VendorBalanceSummaryTableRows from '@/services/FinancialStatements/VendorBalanceSummary/VendorBalanceSummaryTableRows';
|
||||
import VendorBalanceSummaryService from '@/services/FinancialStatements/VendorBalanceSummary/VendorBalanceSummaryService';
|
||||
import {
|
||||
AbilitySubject,
|
||||
IVendorBalanceSummaryStatement,
|
||||
ReportsAction,
|
||||
} from '@/interfaces';
|
||||
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||
import { VendorBalanceSummaryApplication } from '@/services/FinancialStatements/VendorBalanceSummary/VendorBalanceSummaryApplication';
|
||||
|
||||
export default class VendorBalanceSummaryReportController extends BaseFinancialReportController {
|
||||
@Inject()
|
||||
vendorBalanceSummaryService: VendorBalanceSummaryService;
|
||||
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
private vendorBalanceSummaryApp: VendorBalanceSummaryApplication;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
*/
|
||||
router() {
|
||||
public router() {
|
||||
const router = Router();
|
||||
|
||||
router.get(
|
||||
@@ -41,7 +33,7 @@ export default class VendorBalanceSummaryReportController extends BaseFinancialR
|
||||
/**
|
||||
* Validation schema.
|
||||
*/
|
||||
get validationSchema() {
|
||||
private get validationSchema() {
|
||||
return [
|
||||
...this.sheetNumberFormatValidationSchema,
|
||||
query('as_date').optional().isISO8601(),
|
||||
@@ -59,73 +51,62 @@ export default class VendorBalanceSummaryReportController extends BaseFinancialR
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Transformes the report statement to table rows.
|
||||
* @param {IVendorBalanceSummaryStatement} statement -
|
||||
*/
|
||||
private transformToTableRows(
|
||||
tenantId: number,
|
||||
{ data, query }: IVendorBalanceSummaryStatement
|
||||
) {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
const tableData = new VendorBalanceSummaryTableRows(
|
||||
data,
|
||||
query,
|
||||
i18n
|
||||
);
|
||||
return {
|
||||
table: {
|
||||
columns: tableData.tableColumns(),
|
||||
data: tableData.tableRows(),
|
||||
},
|
||||
query,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Transformes the report statement to raw json.
|
||||
* @param {IVendorBalanceSummaryStatement} statement -
|
||||
*/
|
||||
private transformToJsonResponse({
|
||||
data,
|
||||
columns,
|
||||
}: IVendorBalanceSummaryStatement) {
|
||||
return {
|
||||
data: this.transfromToResponse(data),
|
||||
columns: this.transfromToResponse(columns),
|
||||
query: this.transfromToResponse(query),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve vendors balance summary.
|
||||
* @param {Request} req -
|
||||
* @param {Response} res -
|
||||
* @param {NextFunction} next -
|
||||
*/
|
||||
async vendorBalanceSummary(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId, settings } = req;
|
||||
public async vendorBalanceSummary(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
const { tenantId } = req;
|
||||
const filter = this.matchedQueryData(req);
|
||||
|
||||
try {
|
||||
const vendorBalanceSummary =
|
||||
await this.vendorBalanceSummaryService.vendorBalanceSummary(
|
||||
const accept = this.accepts(req);
|
||||
const acceptType = accept.types([
|
||||
ACCEPT_TYPE.APPLICATION_JSON,
|
||||
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
|
||||
ACCEPT_TYPE.APPLICATION_CSV,
|
||||
ACCEPT_TYPE.APPLICATION_XLSX,
|
||||
]);
|
||||
|
||||
// Retrieves the csv format.
|
||||
if (acceptType === ACCEPT_TYPE.APPLICATION_CSV) {
|
||||
const buffer = await this.vendorBalanceSummaryApp.csv(tenantId, filter);
|
||||
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
|
||||
res.setHeader('Content-Type', 'text/csv');
|
||||
|
||||
return res.send(buffer);
|
||||
} else if (acceptType === ACCEPT_TYPE.APPLICATION_XLSX) {
|
||||
const buffer = await this.vendorBalanceSummaryApp.xlsx(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
const accept = this.accepts(req);
|
||||
const acceptType = accept.types(['json', 'application/json+table']);
|
||||
|
||||
switch (acceptType) {
|
||||
case 'application/json+table':
|
||||
return res
|
||||
.status(200)
|
||||
.send(this.transformToTableRows(tenantId, vendorBalanceSummary));
|
||||
case 'json':
|
||||
default:
|
||||
return res
|
||||
.status(200)
|
||||
.send(this.transformToJsonResponse(vendorBalanceSummary));
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
'attachment; filename=output.xlsx'
|
||||
);
|
||||
res.setHeader('Content-Type', 'application/vnd.openxmlformats');
|
||||
return res.send(buffer);
|
||||
// Retrieves the json table format.
|
||||
} else if (acceptType === ACCEPT_TYPE.APPLICATION_JSON_TABLE) {
|
||||
const table = await this.vendorBalanceSummaryApp.table(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
return res.status(200).send(table);
|
||||
// Retrieves the json format.
|
||||
} else {
|
||||
const sheet = await this.vendorBalanceSummaryApp.sheet(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
return res.status(200).send(sheet);
|
||||
}
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
IAgingSummaryData,
|
||||
} from './AgingReport';
|
||||
import { INumberFormatQuery } from './FinancialStatements';
|
||||
import { IFinancialTable } from './Table';
|
||||
|
||||
export interface IAPAgingSummaryQuery extends IAgingSummaryQuery {
|
||||
vendorsIds: number[];
|
||||
@@ -34,3 +35,8 @@ export interface IAPAgingSummaryMeta {
|
||||
baseCurrency: string;
|
||||
organizationName: string;
|
||||
}
|
||||
|
||||
export interface IAPAgingSummaryTable extends IFinancialTable {
|
||||
query: IAPAgingSummaryQuery;
|
||||
meta: IAPAgingSummaryMeta;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
IAgingSummaryContact,
|
||||
IAgingSummaryData,
|
||||
} from './AgingReport';
|
||||
import { IFinancialTable } from './Table';
|
||||
|
||||
export interface IARAgingSummaryQuery extends IAgingSummaryQuery {
|
||||
customersIds: number[];
|
||||
@@ -26,3 +27,8 @@ export interface IARAgingSummaryMeta {
|
||||
organizationName: string;
|
||||
baseCurrency: string;
|
||||
}
|
||||
|
||||
export interface IARAgingSummaryTable extends IFinancialTable {
|
||||
meta: IARAgingSummaryMeta;
|
||||
query: IARAgingSummaryQuery;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
IFormatNumberSettings,
|
||||
IFinancialSheetBranchesQuery,
|
||||
} from './FinancialStatements';
|
||||
import { IFinancialTable } from './Table';
|
||||
|
||||
// Balance sheet schema nodes types.
|
||||
export enum BALANCE_SHEET_SCHEMA_NODE_TYPE {
|
||||
@@ -215,3 +216,8 @@ export enum IAccountTransactionsGroupBy {
|
||||
Month = 'month',
|
||||
Week = 'week',
|
||||
}
|
||||
|
||||
export interface IBalanceSheetTable extends IFinancialTable {
|
||||
meta: IBalanceSheetMeta;
|
||||
query: IBalanceSheetQuery;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { INumberFormatQuery } from './FinancialStatements';
|
||||
import { IAccount } from './Account';
|
||||
import { ILedger } from './Ledger';
|
||||
import { ITableRow } from './Table';
|
||||
import { IFinancialTable, ITableRow } from './Table';
|
||||
|
||||
export interface ICashFlowStatementQuery {
|
||||
fromDate: Date | string;
|
||||
@@ -101,6 +101,11 @@ export interface ICashFlowStatementDOO {
|
||||
query: ICashFlowStatementQuery;
|
||||
}
|
||||
|
||||
export interface ICashFlowStatementTable extends IFinancialTable {
|
||||
meta: ICashFlowStatementMeta;
|
||||
query: ICashFlowStatementQuery;
|
||||
}
|
||||
|
||||
export interface ICashFlowStatementService {
|
||||
cashFlow(
|
||||
tenantId: number,
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { INumberFormatQuery } from './FinancialStatements';
|
||||
|
||||
import {
|
||||
IContactBalanceSummaryQuery,
|
||||
IContactBalanceSummaryAmount,
|
||||
IContactBalanceSummaryPercentage,
|
||||
IContactBalanceSummaryTotal,
|
||||
} from './ContactBalanceSummary';
|
||||
import { IFinancialTable } from './Table';
|
||||
|
||||
export interface ICustomerBalanceSummaryQuery
|
||||
extends IContactBalanceSummaryQuery {
|
||||
@@ -19,7 +18,7 @@ export interface ICustomerBalanceSummaryPercentage
|
||||
extends IContactBalanceSummaryPercentage {}
|
||||
|
||||
export interface ICustomerBalanceSummaryCustomer {
|
||||
id: number,
|
||||
id: number;
|
||||
customerName: string;
|
||||
total: ICustomerBalanceSummaryAmount;
|
||||
percentageOfColumn?: ICustomerBalanceSummaryPercentage;
|
||||
@@ -47,3 +46,7 @@ export interface ICustomerBalanceSummaryService {
|
||||
query: ICustomerBalanceSummaryQuery
|
||||
): Promise<ICustomerBalanceSummaryStatement>;
|
||||
}
|
||||
|
||||
export interface ICustomerBalanceSummaryTable extends IFinancialTable {
|
||||
query: ICustomerBalanceSummaryQuery;
|
||||
}
|
||||
|
||||
7
packages/server/src/interfaces/Http.ts
Normal file
7
packages/server/src/interfaces/Http.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export const ACCEPT_TYPE = {
|
||||
APPLICATION_PDF: 'application/pdf',
|
||||
APPLICATION_JSON: 'application/json',
|
||||
APPLICATION_JSON_TABLE: 'application/json+table',
|
||||
APPLICATION_XLSX: 'application/xlsx',
|
||||
APPLICATION_CSV: 'application/csv',
|
||||
};
|
||||
@@ -1,13 +1,12 @@
|
||||
import {
|
||||
INumberFormatQuery,
|
||||
} from './FinancialStatements';
|
||||
import { INumberFormatQuery } from './FinancialStatements';
|
||||
import { IFinancialTable } from './Table';
|
||||
|
||||
export interface IInventoryDetailsQuery {
|
||||
fromDate: Date | string;
|
||||
toDate: Date | string;
|
||||
numberFormat: INumberFormatQuery;
|
||||
noneTransactions: boolean;
|
||||
itemsIds: number[]
|
||||
itemsIds: number[];
|
||||
|
||||
warehousesIds?: number[];
|
||||
branchesIds?: number[];
|
||||
@@ -66,7 +65,7 @@ export interface IInventoryDetailsItemTransaction {
|
||||
cost: IInventoryDetailsNumber;
|
||||
value: IInventoryDetailsNumber;
|
||||
profitMargin: IInventoryDetailsNumber;
|
||||
|
||||
|
||||
rate: IInventoryDetailsNumber;
|
||||
|
||||
runningQuantity: IInventoryDetailsNumber;
|
||||
@@ -80,7 +79,6 @@ export type IInventoryDetailsNode =
|
||||
| IInventoryDetailsItemTransaction;
|
||||
export type IInventoryDetailsData = IInventoryDetailsItem[];
|
||||
|
||||
|
||||
export interface IInventoryItemDetailMeta {
|
||||
isCostComputeRunning: boolean;
|
||||
organizationName: string;
|
||||
@@ -91,4 +89,9 @@ export interface IInvetoryItemDetailDOO {
|
||||
data: IInventoryDetailsData;
|
||||
query: IInventoryDetailsQuery;
|
||||
meta: IInventoryItemDetailMeta;
|
||||
}
|
||||
}
|
||||
|
||||
export interface IInvetoryItemDetailsTable extends IFinancialTable {
|
||||
query: IInventoryDetailsQuery;
|
||||
meta: IInventoryItemDetailMeta;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
IFinancialSheetBranchesQuery,
|
||||
INumberFormatQuery,
|
||||
} from './FinancialStatements';
|
||||
import { IFinancialTable } from './Table';
|
||||
|
||||
export enum ProfitLossAggregateNodeId {
|
||||
INCOME = 'INCOME',
|
||||
@@ -177,3 +178,9 @@ export enum ProfitLossSheetRowType {
|
||||
ACCOUNT = 'ACCOUNT',
|
||||
TOTAL = 'TOTAL',
|
||||
}
|
||||
|
||||
|
||||
export interface IProfitLossSheetTable extends IFinancialTable{
|
||||
meta: IProfitLossSheetMeta;
|
||||
query: IProfitLossSheetQuery;
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import { IFinancialTable } from "./Table";
|
||||
|
||||
export interface SalesTaxLiabilitySummaryQuery {
|
||||
fromDate: Date;
|
||||
toDate: Date;
|
||||
@@ -49,3 +51,8 @@ export interface SalesTaxLiabilitySummaryMeta {
|
||||
organizationName: string;
|
||||
baseCurrency: string;
|
||||
}
|
||||
|
||||
export interface ISalesTaxLiabilitySummaryTable extends IFinancialTable {
|
||||
query: SalesTaxLiabilitySummaryQuery;
|
||||
meta: SalesTaxLiabilitySummaryMeta;
|
||||
}
|
||||
@@ -10,7 +10,7 @@ export interface ITableCell {
|
||||
}
|
||||
|
||||
export type ITableRow = {
|
||||
rows: ITableCell[];
|
||||
cells: ITableCell[];
|
||||
};
|
||||
|
||||
export interface ITableColumn {
|
||||
@@ -28,4 +28,13 @@ export interface ITable {
|
||||
export interface ITableColumnAccessor {
|
||||
key: string;
|
||||
accessor: string;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ITableData {
|
||||
columns: ITableColumn[];
|
||||
rows: ITableRow[];
|
||||
}
|
||||
|
||||
export interface IFinancialTable {
|
||||
table: ITableData;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { IFinancialTable, ITableData } from './Table';
|
||||
import {
|
||||
ITransactionsByContactsAmount,
|
||||
ITransactionsByContactsTransaction,
|
||||
@@ -26,6 +27,11 @@ export type ITransactionsByCustomersData = ITransactionsByCustomersCustomer[];
|
||||
|
||||
export interface ITransactionsByCustomersStatement {
|
||||
data: ITransactionsByCustomersData;
|
||||
query: ITransactionsByCustomersFilter;
|
||||
}
|
||||
|
||||
export interface ITransactionsByCustomersTable extends IFinancialTable {
|
||||
query: ITransactionsByCustomersFilter;
|
||||
}
|
||||
|
||||
export interface ITransactionsByCustomersService {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { IFinancialTable } from './Table';
|
||||
import {
|
||||
ITransactionsByContactsAmount,
|
||||
ITransactionsByContactsTransaction,
|
||||
@@ -34,3 +35,7 @@ export interface ITransactionsByVendorsService {
|
||||
filter: ITransactionsByVendorsFilter
|
||||
): Promise<ITransactionsByVendorsStatement>;
|
||||
}
|
||||
|
||||
export interface ITransactionsByVendorTable extends IFinancialTable {
|
||||
query: ITransactionsByVendorsFilter;
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { INumberFormatQuery } from './FinancialStatements';
|
||||
import { IFinancialTable } from './Table';
|
||||
|
||||
export interface ITrialBalanceSheetQuery {
|
||||
fromDate: Date | string;
|
||||
@@ -48,3 +49,8 @@ export interface ITrialBalanceStatement {
|
||||
query: ITrialBalanceSheetQuery;
|
||||
meta: ITrialBalanceSheetMeta;
|
||||
}
|
||||
|
||||
export interface ITrialBalanceSheetTable extends IFinancialTable {
|
||||
meta: ITrialBalanceSheetMeta;
|
||||
query: ITrialBalanceSheetQuery;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { INumberFormatQuery } from './FinancialStatements';
|
||||
import { IFinancialTable } from './Table';
|
||||
|
||||
export interface IVendorBalanceSummaryQuery {
|
||||
asDate: Date;
|
||||
vendorsIds: number[],
|
||||
vendorsIds: number[];
|
||||
numberFormat: INumberFormatQuery;
|
||||
percentageColumn: boolean;
|
||||
noneTransactions: boolean;
|
||||
@@ -45,6 +46,10 @@ export interface IVendorBalanceSummaryStatement {
|
||||
export interface IVendorBalanceSummaryService {
|
||||
vendorBalanceSummary(
|
||||
tenantId: number,
|
||||
query: IVendorBalanceSummaryQuery,
|
||||
query: IVendorBalanceSummaryQuery
|
||||
): Promise<IVendorBalanceSummaryStatement>;
|
||||
}
|
||||
|
||||
export interface IVendorBalanceSummaryTable extends IFinancialTable {
|
||||
query: IVendorBalanceSummaryQuery;
|
||||
}
|
||||
|
||||
134
packages/server/src/lib/Xlsx/TableSheet.tsx
Normal file
134
packages/server/src/lib/Xlsx/TableSheet.tsx
Normal file
@@ -0,0 +1,134 @@
|
||||
import xlsx, { WorkBook } from 'xlsx';
|
||||
import { IFinancialTable, ITableData } from '@/interfaces';
|
||||
import { FinancialTableStructure } from '@/services/FinancialStatements/FinancialTableStructure';
|
||||
|
||||
interface ITableSheet {
|
||||
convertToXLSX(): WorkBook;
|
||||
convertToCSV(): string;
|
||||
convertToBuffer(workbook: WorkBook, fileType: string): Buffer;
|
||||
}
|
||||
|
||||
export class TableSheet implements ITableSheet {
|
||||
private table: ITableData;
|
||||
|
||||
constructor(table: ITableData) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the columns labels.
|
||||
* @returns {string[]}
|
||||
*/
|
||||
private get columns() {
|
||||
return this.table.columns.map((col) => col.label);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the columns accessors.
|
||||
* @returns {string[]}
|
||||
*/
|
||||
private get columnsAccessors() {
|
||||
return this.table.columns.map((col, index) => {
|
||||
return `${index}`;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the rows data cellIndex/Value.
|
||||
* @returns {Record<string, string>}
|
||||
*/
|
||||
private get rows() {
|
||||
const computedRows = FinancialTableStructure.flatNestedTree(
|
||||
this.table.rows
|
||||
);
|
||||
return computedRows.map((row) => {
|
||||
const entries = row.cells.map((cell, index) => {
|
||||
return [`${index}`, cell.value];
|
||||
});
|
||||
return Object.fromEntries(entries);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the table to a CSV string.
|
||||
* @returns {string}
|
||||
*/
|
||||
public convertToCSV(): string {
|
||||
// Define custom headers
|
||||
const headers = this.columns;
|
||||
|
||||
// Convert data to worksheet with headers
|
||||
const worksheet = xlsx.utils.json_to_sheet(this.rows, {
|
||||
header: this.columnsAccessors,
|
||||
});
|
||||
// Add custom headers to the worksheet
|
||||
xlsx.utils.sheet_add_aoa(worksheet, [headers], { origin: 'A1' });
|
||||
|
||||
// Convert worksheet to CSV format
|
||||
const csvOutput = xlsx.utils.sheet_to_csv(worksheet);
|
||||
|
||||
return csvOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the array of objects to an XLSX file with styled headers
|
||||
* @returns {Workbook}
|
||||
*/
|
||||
public convertToXLSX(): WorkBook {
|
||||
// Create a new workbook and a worksheet
|
||||
const workbook = xlsx.utils.book_new();
|
||||
const worksheet = xlsx.utils.json_to_sheet(this.rows, {
|
||||
header: this.columnsAccessors,
|
||||
});
|
||||
// Add custom headers to the worksheet
|
||||
xlsx.utils.sheet_add_aoa(worksheet, [this.columns], {
|
||||
origin: 'A1',
|
||||
});
|
||||
// Adjust column width.
|
||||
worksheet['!cols'] = this.computeXlsxColumnsWidths(this.rows);
|
||||
|
||||
// Append the worksheet to the workbook
|
||||
xlsx.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
|
||||
|
||||
return workbook;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given workbook to buffer of the given file type
|
||||
* @param {WorkBook} workbook
|
||||
* @param {string} fileType
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public convertToBuffer(workbook: WorkBook, fileType: 'xlsx' | 'csv'): Buffer {
|
||||
return xlsx.write(workbook, {
|
||||
type: 'buffer',
|
||||
bookType: fileType,
|
||||
cellStyles: true,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts and computes the columns width.
|
||||
* @param {} rows
|
||||
* @returns {{wch: number}[]}
|
||||
*/
|
||||
private computeXlsxColumnsWidths = (rows): { wch: number }[] => {
|
||||
const cols = [{ wch: 60 }];
|
||||
|
||||
this.columns.map((column) => {
|
||||
cols.push({ wch: column.length });
|
||||
});
|
||||
rows.forEach((row) => {
|
||||
const entries = Object.entries(row);
|
||||
|
||||
entries.forEach(([key, value]) => {
|
||||
if (cols[key]) {
|
||||
cols[key].wch = Math.max(cols[key].wch, String(value).length);
|
||||
} else {
|
||||
cols[key] = { wch: String(value).length };
|
||||
}
|
||||
});
|
||||
});
|
||||
return cols;
|
||||
};
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -78,6 +78,27 @@ const filterNodesDeep = (predicate, nodes) => {
|
||||
);
|
||||
};
|
||||
|
||||
const flatNestedTree = (obj, mapper, options) => {
|
||||
return reduceDeep(
|
||||
obj,
|
||||
(accumulator, value, key, parentValue, context) => {
|
||||
const computedValue = _.omit(value, ['children']);
|
||||
const mappedValue = mapper
|
||||
? mapper(computedValue, key, context)
|
||||
: computedValue;
|
||||
|
||||
accumulator.push(mappedValue);
|
||||
return accumulator;
|
||||
},
|
||||
[],
|
||||
{
|
||||
childrenPath: 'children',
|
||||
pathFormat: 'array',
|
||||
...options,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export {
|
||||
iteratee,
|
||||
condense,
|
||||
@@ -103,4 +124,5 @@ export {
|
||||
someDeep,
|
||||
mapValuesDeepReverse,
|
||||
filterNodesDeep,
|
||||
flatNestedTree,
|
||||
};
|
||||
|
||||
@@ -22,7 +22,9 @@ export function tableRowMapper(
|
||||
): ITableRow {
|
||||
const cells = columns.map((column) => ({
|
||||
key: column.key,
|
||||
value: column.value ? column.value : getAccessor(object, column.accessor),
|
||||
value: column.value
|
||||
? column.value
|
||||
: getAccessor(object, column.accessor) || '',
|
||||
}));
|
||||
|
||||
return {
|
||||
|
||||
@@ -15,6 +15,7 @@ import { DashboardActionsBar, FormattedMessage as T, Icon } from '@/components';
|
||||
import { useAPAgingSummaryContext } from './APAgingSummaryProvider';
|
||||
|
||||
import NumberFormatDropdown from '@/components/NumberFormatDropdown';
|
||||
import { APAgingSummaryExportMenu } from './components';
|
||||
|
||||
import withAPAgingSummary from './withAPAgingSummary';
|
||||
import withAPAgingSummaryActions from './withAPAgingSummaryActions';
|
||||
@@ -106,11 +107,18 @@ function APAgingSummaryActionsBar({
|
||||
icon={<Icon icon="print-16" iconSize={16} />}
|
||||
text={<T id={'print'} />}
|
||||
/>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="file-export-16" iconSize={16} />}
|
||||
text={<T id={'export'} />}
|
||||
/>
|
||||
<Popover
|
||||
content={<APAgingSummaryExportMenu />}
|
||||
interactionKind={PopoverInteractionKind.CLICK}
|
||||
placement="bottom-start"
|
||||
minimal
|
||||
>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="file-export-16" iconSize={16} />}
|
||||
text={<T id={'export'} />}
|
||||
/>
|
||||
</Popover>
|
||||
</NavbarGroup>
|
||||
</DashboardActionsBar>
|
||||
);
|
||||
|
||||
@@ -27,6 +27,7 @@ function APAgingSummaryProvider({ filter, ...props }) {
|
||||
isAPAgingLoading,
|
||||
isAPAgingFetching,
|
||||
refetch,
|
||||
query,
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,10 +1,23 @@
|
||||
// @ts-nocheck
|
||||
import React, { useMemo } from 'react';
|
||||
import { useRef } from 'react';
|
||||
import classNames from 'classnames';
|
||||
|
||||
import { If } from '@/components';
|
||||
import { AppToaster, If, Stack } from '@/components';
|
||||
import FinancialLoadingBar from '../FinancialLoadingBar';
|
||||
import { useAPAgingSummaryContext } from './APAgingSummaryProvider';
|
||||
import { agingSummaryDynamicColumns } from '../AgingSummary/dynamicColumns';
|
||||
import {
|
||||
Classes,
|
||||
Intent,
|
||||
Menu,
|
||||
MenuItem,
|
||||
ProgressBar,
|
||||
Text,
|
||||
} from '@blueprintjs/core';
|
||||
import {
|
||||
useAPAgingSheetCsvExport,
|
||||
useAPAgingSheetXlsxExport,
|
||||
} from '@/hooks/query';
|
||||
|
||||
/**
|
||||
* Retrieve AP aging summary columns.
|
||||
@@ -29,3 +42,87 @@ export function APAgingSummarySheetLoadingBar() {
|
||||
</If>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A/P aging summary export menu.
|
||||
* @returns {JSX.Element}
|
||||
*/
|
||||
export function APAgingSummaryExportMenu() {
|
||||
const toastKey = useRef(null);
|
||||
const commonToastConfig = {
|
||||
isCloseButtonShown: true,
|
||||
timeout: 2000,
|
||||
};
|
||||
const { query } = useAPAgingSummaryContext();
|
||||
|
||||
const openProgressToast = (amount: number) => {
|
||||
return (
|
||||
<Stack spacing={8}>
|
||||
<Text>The report has been exported successfully.</Text>
|
||||
<ProgressBar
|
||||
className={classNames('toast-progress', {
|
||||
[Classes.PROGRESS_NO_STRIPES]: amount >= 100,
|
||||
})}
|
||||
intent={amount < 100 ? Intent.PRIMARY : Intent.SUCCESS}
|
||||
value={amount / 100}
|
||||
/>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
// Export the report to xlsx.
|
||||
const { mutateAsync: xlsxExport } = useAPAgingSheetXlsxExport(query, {
|
||||
onDownloadProgress: (xlsxExportProgress: number) => {
|
||||
if (!toastKey.current) {
|
||||
toastKey.current = AppToaster.show({
|
||||
message: openProgressToast(xlsxExportProgress),
|
||||
...commonToastConfig,
|
||||
});
|
||||
} else {
|
||||
AppToaster.show(
|
||||
{
|
||||
message: openProgressToast(xlsxExportProgress),
|
||||
...commonToastConfig,
|
||||
},
|
||||
toastKey.current,
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
// Export the report to csv.
|
||||
const { mutateAsync: csvExport } = useAPAgingSheetCsvExport(query, {
|
||||
onDownloadProgress: (xlsxExportProgress: number) => {
|
||||
if (!toastKey.current) {
|
||||
toastKey.current = AppToaster.show({
|
||||
message: openProgressToast(xlsxExportProgress),
|
||||
...commonToastConfig,
|
||||
});
|
||||
} else {
|
||||
AppToaster.show(
|
||||
{
|
||||
message: openProgressToast(xlsxExportProgress),
|
||||
...commonToastConfig,
|
||||
},
|
||||
toastKey.current,
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
// Handle csv export button click.
|
||||
const handleCsvExportBtnClick = () => {
|
||||
csvExport();
|
||||
};
|
||||
// Handle xlsx export button click.
|
||||
const handleXlsxExportBtnClick = () => {
|
||||
xlsxExport();
|
||||
};
|
||||
|
||||
return (
|
||||
<Menu>
|
||||
<MenuItem
|
||||
text={'XLSX (Microsoft Excel)'}
|
||||
onClick={handleXlsxExportBtnClick}
|
||||
/>
|
||||
<MenuItem text={'CSV'} onClick={handleCsvExportBtnClick} />
|
||||
</Menu>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import withARAgingSummaryActions from './withARAgingSummaryActions';
|
||||
import withARAgingSummary from './withARAgingSummary';
|
||||
|
||||
import { compose, safeInvoke } from '@/utils';
|
||||
import { ARAgingSummaryExportMenu } from './components';
|
||||
|
||||
/**
|
||||
* A/R Aging summary sheet - Actions bar.
|
||||
@@ -107,11 +108,18 @@ function ARAgingSummaryActionsBar({
|
||||
icon={<Icon icon="print-16" iconSize={16} />}
|
||||
text={<T id={'print'} />}
|
||||
/>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="file-export-16" iconSize={16} />}
|
||||
text={<T id={'export'} />}
|
||||
/>
|
||||
<Popover
|
||||
content={<ARAgingSummaryExportMenu />}
|
||||
interactionKind={PopoverInteractionKind.CLICK}
|
||||
placement="bottom-start"
|
||||
minimal
|
||||
>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="file-export-16" iconSize={16} />}
|
||||
text={<T id={'export'} />}
|
||||
/>
|
||||
</Popover>
|
||||
</NavbarGroup>
|
||||
</DashboardActionsBar>
|
||||
);
|
||||
|
||||
@@ -1,10 +1,23 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import React, { useRef } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import {
|
||||
Classes,
|
||||
Intent,
|
||||
Menu,
|
||||
MenuItem,
|
||||
ProgressBar,
|
||||
Text,
|
||||
} from '@blueprintjs/core';
|
||||
|
||||
import { useARAgingSummaryContext } from './ARAgingSummaryProvider';
|
||||
import { If, FormattedMessage as T } from '@/components';
|
||||
import { AppToaster, If, Stack, FormattedMessage as T } from '@/components';
|
||||
import FinancialLoadingBar from '../FinancialLoadingBar';
|
||||
import { agingSummaryDynamicColumns } from '../AgingSummary/dynamicColumns';
|
||||
import {
|
||||
useARAgingSheetCsvExport,
|
||||
useARAgingSheetXlsxExport,
|
||||
} from '@/hooks/query';
|
||||
|
||||
/**
|
||||
* Retrieve AR aging summary columns.
|
||||
@@ -29,3 +42,88 @@ export function ARAgingSummarySheetLoadingBar() {
|
||||
</If>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A/R aging summary export menu.
|
||||
* @returns {JSX.Element}
|
||||
*/
|
||||
export function ARAgingSummaryExportMenu() {
|
||||
const toastKey = useRef(null);
|
||||
const commonToastConfig = {
|
||||
isCloseButtonShown: true,
|
||||
timeout: 2000,
|
||||
};
|
||||
const { query } = useARAgingSummaryContext();
|
||||
|
||||
const openProgressToast = (amount: number) => {
|
||||
return (
|
||||
<Stack spacing={8}>
|
||||
<Text>The report has been exported successfully.</Text>
|
||||
<ProgressBar
|
||||
className={classNames('toast-progress', {
|
||||
[Classes.PROGRESS_NO_STRIPES]: amount >= 100,
|
||||
})}
|
||||
intent={amount < 100 ? Intent.PRIMARY : Intent.SUCCESS}
|
||||
value={amount / 100}
|
||||
/>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
|
||||
// Export the report to xlsx.
|
||||
const { mutateAsync: xlsxExport } = useARAgingSheetXlsxExport(query, {
|
||||
onDownloadProgress: (xlsxExportProgress: number) => {
|
||||
if (!toastKey.current) {
|
||||
toastKey.current = AppToaster.show({
|
||||
message: openProgressToast(xlsxExportProgress),
|
||||
...commonToastConfig,
|
||||
});
|
||||
} else {
|
||||
AppToaster.show(
|
||||
{
|
||||
message: openProgressToast(xlsxExportProgress),
|
||||
...commonToastConfig,
|
||||
},
|
||||
toastKey.current,
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
// Export the report to csv.
|
||||
const { mutateAsync: csvExport } = useARAgingSheetCsvExport(query, {
|
||||
onDownloadProgress: (xlsxExportProgress: number) => {
|
||||
if (!toastKey.current) {
|
||||
toastKey.current = AppToaster.show({
|
||||
message: openProgressToast(xlsxExportProgress),
|
||||
...commonToastConfig,
|
||||
});
|
||||
} else {
|
||||
AppToaster.show(
|
||||
{
|
||||
message: openProgressToast(xlsxExportProgress),
|
||||
...commonToastConfig,
|
||||
},
|
||||
toastKey.current,
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
// Handle csv export button click.
|
||||
const handleCsvExportBtnClick = () => {
|
||||
csvExport();
|
||||
};
|
||||
// Handle xlsx export button click.
|
||||
const handleXlsxExportBtnClick = () => {
|
||||
xlsxExport();
|
||||
};
|
||||
|
||||
return (
|
||||
<Menu>
|
||||
<MenuItem
|
||||
text={'XLSX (Microsoft Excel)'}
|
||||
onClick={handleXlsxExportBtnClick}
|
||||
/>
|
||||
<MenuItem text={'CSV'} onClick={handleCsvExportBtnClick} />
|
||||
</Menu>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import {
|
||||
NavbarGroup,
|
||||
Button,
|
||||
@@ -13,11 +12,12 @@ import classNames from 'classnames';
|
||||
import { DashboardActionsBar, FormattedMessage as T, Icon } from '@/components';
|
||||
|
||||
import NumberFormatDropdown from '@/components/NumberFormatDropdown';
|
||||
import { BalanceSheetExportMenu } from './components';
|
||||
|
||||
import { compose, saveInvoke } from '@/utils';
|
||||
import { useBalanceSheetContext } from './BalanceSheetProvider';
|
||||
import withBalanceSheet from './withBalanceSheet';
|
||||
import withBalanceSheetActions from './withBalanceSheetActions';
|
||||
import { compose, saveInvoke } from '@/utils';
|
||||
|
||||
/**
|
||||
* Balance sheet - actions bar.
|
||||
@@ -114,11 +114,18 @@ function BalanceSheetActionsBar({
|
||||
icon={<Icon icon="print-16" iconSize={16} />}
|
||||
text={<T id={'print'} />}
|
||||
/>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="file-export-16" iconSize={16} />}
|
||||
text={<T id={'export'} />}
|
||||
/>
|
||||
<Popover
|
||||
content={<BalanceSheetExportMenu />}
|
||||
interactionKind={PopoverInteractionKind.CLICK}
|
||||
placement="bottom-start"
|
||||
minimal
|
||||
>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="file-export-16" iconSize={16} />}
|
||||
text={<T id={'export'} />}
|
||||
/>
|
||||
</Popover>
|
||||
</NavbarGroup>
|
||||
</DashboardActionsBar>
|
||||
);
|
||||
|
||||
@@ -1,13 +1,32 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Button } from '@blueprintjs/core';
|
||||
import React, { useRef } from 'react';
|
||||
import {
|
||||
Button,
|
||||
Classes,
|
||||
Intent,
|
||||
Menu,
|
||||
MenuItem,
|
||||
ProgressBar,
|
||||
Text,
|
||||
} from '@blueprintjs/core';
|
||||
import classNames from 'classnames';
|
||||
|
||||
import { FormattedMessage as T, Icon, If } from '@/components';
|
||||
import {
|
||||
FormattedMessage as T,
|
||||
Icon,
|
||||
If,
|
||||
Stack,
|
||||
AppToaster,
|
||||
} from '@/components';
|
||||
|
||||
import FinancialLoadingBar from '../FinancialLoadingBar';
|
||||
import { useBalanceSheetContext } from './BalanceSheetProvider';
|
||||
import { FinancialComputeAlert } from '../FinancialReportPage';
|
||||
import { dynamicColumns } from './dynamicColumns';
|
||||
import {
|
||||
useBalanceSheetCsvExport,
|
||||
useBalanceSheetXlsxExport,
|
||||
} from '@/hooks/query';
|
||||
|
||||
/**
|
||||
* Balance sheet alerts.
|
||||
@@ -66,3 +85,88 @@ export const useBalanceSheetColumns = () => {
|
||||
[table],
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the balance sheet export menu.
|
||||
* @returns {JSX.Element}
|
||||
*/
|
||||
export const BalanceSheetExportMenu = () => {
|
||||
const toastKey = useRef(null);
|
||||
const commonToastConfig = {
|
||||
isCloseButtonShown: true,
|
||||
timeout: 2000,
|
||||
};
|
||||
const { query } = useBalanceSheetContext();
|
||||
|
||||
const openProgressToast = (amount: number) => {
|
||||
return (
|
||||
<Stack spacing={8}>
|
||||
<Text>The report has been exported successfully.</Text>
|
||||
<ProgressBar
|
||||
className={classNames('toast-progress', {
|
||||
[Classes.PROGRESS_NO_STRIPES]: amount >= 100,
|
||||
})}
|
||||
intent={amount < 100 ? Intent.PRIMARY : Intent.SUCCESS}
|
||||
value={amount / 100}
|
||||
/>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
|
||||
// Export the report to xlsx.
|
||||
const { mutateAsync: xlsxExport } = useBalanceSheetXlsxExport(query, {
|
||||
onDownloadProgress: (xlsxExportProgress: number) => {
|
||||
if (!toastKey.current) {
|
||||
toastKey.current = AppToaster.show({
|
||||
message: openProgressToast(xlsxExportProgress),
|
||||
...commonToastConfig,
|
||||
});
|
||||
} else {
|
||||
AppToaster.show(
|
||||
{
|
||||
message: openProgressToast(xlsxExportProgress),
|
||||
...commonToastConfig,
|
||||
},
|
||||
toastKey.current,
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
// Export the report to csv.
|
||||
const { mutateAsync: csvExport } = useBalanceSheetCsvExport(query, {
|
||||
onDownloadProgress: (xlsxExportProgress: number) => {
|
||||
if (!toastKey.current) {
|
||||
toastKey.current = AppToaster.show({
|
||||
message: openProgressToast(xlsxExportProgress),
|
||||
...commonToastConfig,
|
||||
});
|
||||
} else {
|
||||
AppToaster.show(
|
||||
{
|
||||
message: openProgressToast(xlsxExportProgress),
|
||||
...commonToastConfig,
|
||||
},
|
||||
toastKey.current,
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
// Handle csv export button click.
|
||||
const handleCsvExportBtnClick = () => {
|
||||
csvExport().then(() => {});
|
||||
};
|
||||
// Handle xlsx export button click.
|
||||
const handleXlsxExportBtnClick = () => {
|
||||
xlsxExport().then(() => {});
|
||||
};
|
||||
|
||||
return (
|
||||
<Menu>
|
||||
<MenuItem
|
||||
text={'XLSX (Microsoft Excel)'}
|
||||
onClick={handleXlsxExportBtnClick}
|
||||
/>
|
||||
<MenuItem text={'CSV'} onClick={handleCsvExportBtnClick} />
|
||||
</Menu>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -19,6 +19,7 @@ import withCashFlowStatement from './withCashFlowStatement';
|
||||
import withCashFlowStatementActions from './withCashFlowStatementActions';
|
||||
|
||||
import { compose, saveInvoke } from '@/utils';
|
||||
import { CashflowSheetExportMenu } from './components';
|
||||
|
||||
/**
|
||||
* Cash flow statement actions bar.
|
||||
@@ -115,11 +116,18 @@ function CashFlowStatementActionsBar({
|
||||
icon={<Icon icon="print-16" iconSize={16} />}
|
||||
text={<T id={'print'} />}
|
||||
/>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="file-export-16" iconSize={16} />}
|
||||
text={<T id={'export'} />}
|
||||
/>
|
||||
<Popover
|
||||
content={<CashflowSheetExportMenu />}
|
||||
interactionKind={PopoverInteractionKind.CLICK}
|
||||
placement="bottom-start"
|
||||
minimal
|
||||
>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="file-export-16" iconSize={16} />}
|
||||
text={<T id={'export'} />}
|
||||
/>
|
||||
</Popover>
|
||||
</NavbarGroup>
|
||||
</DashboardActionsBar>
|
||||
);
|
||||
|
||||
@@ -1,8 +1,27 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Button } from '@blueprintjs/core';
|
||||
import React, { useRef } from 'react';
|
||||
import {
|
||||
Button,
|
||||
Classes,
|
||||
Intent,
|
||||
Menu,
|
||||
MenuItem,
|
||||
ProgressBar,
|
||||
Text,
|
||||
} from '@blueprintjs/core';
|
||||
import classNames from 'classnames';
|
||||
|
||||
import { Icon, If, FormattedMessage as T } from '@/components';
|
||||
import {
|
||||
AppToaster,
|
||||
Icon,
|
||||
If,
|
||||
Stack,
|
||||
FormattedMessage as T,
|
||||
} from '@/components';
|
||||
import {
|
||||
useCashFlowStatementCsvExport,
|
||||
useCashFlowStatementXlsxExport,
|
||||
} from '@/hooks/query';
|
||||
import FinancialLoadingBar from '../FinancialLoadingBar';
|
||||
|
||||
import { dynamicColumns } from './dynamicColumns';
|
||||
@@ -65,3 +84,88 @@ export function CashFlowStatementAlerts() {
|
||||
</FinancialComputeAlert>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cashflow sheet export menu.
|
||||
* @returns {JSX.Element}
|
||||
*/
|
||||
export function CashflowSheetExportMenu() {
|
||||
const toastKey = useRef(null);
|
||||
const commonToastConfig = {
|
||||
isCloseButtonShown: true,
|
||||
timeout: 2000,
|
||||
};
|
||||
const { query } = useCashFlowStatementContext();
|
||||
|
||||
const openProgressToast = (amount: number) => {
|
||||
return (
|
||||
<Stack spacing={8}>
|
||||
<Text>The report has been exported successfully.</Text>
|
||||
<ProgressBar
|
||||
className={classNames('toast-progress', {
|
||||
[Classes.PROGRESS_NO_STRIPES]: amount >= 100,
|
||||
})}
|
||||
intent={amount < 100 ? Intent.PRIMARY : Intent.SUCCESS}
|
||||
value={amount / 100}
|
||||
/>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
|
||||
// Export the report to xlsx.
|
||||
const { mutateAsync: xlsxExport } = useCashFlowStatementXlsxExport(query, {
|
||||
onDownloadProgress: (xlsxExportProgress: number) => {
|
||||
if (!toastKey.current) {
|
||||
toastKey.current = AppToaster.show({
|
||||
message: openProgressToast(xlsxExportProgress),
|
||||
...commonToastConfig,
|
||||
});
|
||||
} else {
|
||||
AppToaster.show(
|
||||
{
|
||||
message: openProgressToast(xlsxExportProgress),
|
||||
...commonToastConfig,
|
||||
},
|
||||
toastKey.current,
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
// Export the report to csv.
|
||||
const { mutateAsync: csvExport } = useCashFlowStatementCsvExport(query, {
|
||||
onDownloadProgress: (xlsxExportProgress: number) => {
|
||||
if (!toastKey.current) {
|
||||
toastKey.current = AppToaster.show({
|
||||
message: openProgressToast(xlsxExportProgress),
|
||||
...commonToastConfig,
|
||||
});
|
||||
} else {
|
||||
AppToaster.show(
|
||||
{
|
||||
message: openProgressToast(xlsxExportProgress),
|
||||
...commonToastConfig,
|
||||
},
|
||||
toastKey.current,
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
// Handle csv export button click.
|
||||
const handleCsvExportBtnClick = () => {
|
||||
csvExport();
|
||||
};
|
||||
// Handle xlsx export button click.
|
||||
const handleXlsxExportBtnClick = () => {
|
||||
xlsxExport();
|
||||
};
|
||||
|
||||
return (
|
||||
<Menu>
|
||||
<MenuItem
|
||||
text={'XLSX (Microsoft Excel)'}
|
||||
onClick={handleXlsxExportBtnClick}
|
||||
/>
|
||||
<MenuItem text={'CSV'} onClick={handleCsvExportBtnClick} />
|
||||
</Menu>
|
||||
);
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user