mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
feat: WIP transactions by customers/vendors.
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hapi/boom": "^7.4.3",
|
"@hapi/boom": "^7.4.3",
|
||||||
"@types/i18n": "^0.8.7",
|
"@types/i18n": "^0.8.7",
|
||||||
|
"accepts": "^1.3.7",
|
||||||
"accounting": "^0.4.1",
|
"accounting": "^0.4.1",
|
||||||
"agenda": "^3.1.0",
|
"agenda": "^3.1.0",
|
||||||
"agendash": "^1.0.0",
|
"agendash": "^1.0.0",
|
||||||
@@ -69,6 +70,7 @@
|
|||||||
"objection-filter": "^4.0.1",
|
"objection-filter": "^4.0.1",
|
||||||
"objection-soft-delete": "^1.0.7",
|
"objection-soft-delete": "^1.0.7",
|
||||||
"pluralize": "^8.0.0",
|
"pluralize": "^8.0.0",
|
||||||
|
"ramda": "^0.27.1",
|
||||||
"rate-limiter-flexible": "^2.1.14",
|
"rate-limiter-flexible": "^2.1.14",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"ts-transformer-keys": "^0.4.2",
|
"ts-transformer-keys": "^0.4.2",
|
||||||
@@ -105,25 +107,5 @@
|
|||||||
"webpack-cli": "^4.6.0",
|
"webpack-cli": "^4.6.0",
|
||||||
"rimraf": "^3.0.2"
|
"rimraf": "^3.0.2"
|
||||||
},
|
},
|
||||||
"_moduleAliases": {
|
|
||||||
"loaders": "build/loaders",
|
|
||||||
"collection": "build/collection",
|
|
||||||
"config": "build/config",
|
|
||||||
"api": "build/api",
|
|
||||||
"data": "build/data",
|
|
||||||
"database": "build/database",
|
|
||||||
"decorators": "build/decorators",
|
|
||||||
"exceptions": "build/exceptions",
|
|
||||||
"interfaces": "build/interfaces",
|
|
||||||
"jobs": "build/jobs",
|
|
||||||
"lib": "build/lib",
|
|
||||||
"utils": "build/utils",
|
|
||||||
"locales": "build/locales",
|
|
||||||
"models": "build/models",
|
|
||||||
"repositories": "build/repositories",
|
|
||||||
"services": "build/services",
|
|
||||||
"subscribers": "build/subscribers",
|
|
||||||
"system": "build/system"
|
|
||||||
},
|
|
||||||
"_moduleAliases": {}
|
"_moduleAliases": {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { Response, Request, NextFunction } from 'express';
|
import { Response, Request, NextFunction } from 'express';
|
||||||
import { matchedData, validationResult } from "express-validator";
|
import { matchedData, validationResult } from 'express-validator';
|
||||||
import { camelCase, snakeCase, omit, set, get } from "lodash";
|
import accepts from 'accepts';
|
||||||
import { mapKeysDeep } from 'utils'
|
import { camelCase, snakeCase, omit, set, get } from 'lodash';
|
||||||
|
import { mapKeysDeep } from 'utils';
|
||||||
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||||
|
|
||||||
export default class BaseController {
|
export default class BaseController {
|
||||||
@@ -60,11 +61,17 @@ export default class BaseController {
|
|||||||
* Transform the given data to response.
|
* Transform the given data to response.
|
||||||
* @param {any} data
|
* @param {any} data
|
||||||
*/
|
*/
|
||||||
transfromToResponse(data: any, translatable?: string | string[], req?: Request) {
|
transfromToResponse(
|
||||||
|
data: any,
|
||||||
|
translatable?: string | string[],
|
||||||
|
req?: Request
|
||||||
|
) {
|
||||||
const response = mapKeysDeep(data, (v, k) => snakeCase(k));
|
const response = mapKeysDeep(data, (v, k) => snakeCase(k));
|
||||||
|
|
||||||
if (translatable) {
|
if (translatable) {
|
||||||
const translatables = Array.isArray(translatable) ? translatable : [translatable];
|
const translatables = Array.isArray(translatable)
|
||||||
|
? translatable
|
||||||
|
: [translatable];
|
||||||
|
|
||||||
translatables.forEach((path) => {
|
translatables.forEach((path) => {
|
||||||
const value = get(response, path);
|
const value = get(response, path);
|
||||||
@@ -81,4 +88,13 @@ export default class BaseController {
|
|||||||
asyncMiddleware(callback) {
|
asyncMiddleware(callback) {
|
||||||
return asyncMiddleware(callback);
|
return asyncMiddleware(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {Request} req
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
accepts(req) {
|
||||||
|
return accepts(req);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { query } from 'express-validator';
|
import { query } from 'express-validator';
|
||||||
import { Inject } from 'typedi';
|
import { Inject } from 'typedi';
|
||||||
|
import { ICustomerBalanceSummaryStatement } from 'interfaces';
|
||||||
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||||
import CustomerBalanceSummary from 'services/FinancialStatements/CustomerBalanceSummary/CustomerBalanceSummaryService';
|
import CustomerBalanceSummary from 'services/FinancialStatements/CustomerBalanceSummary/CustomerBalanceSummaryService';
|
||||||
import BaseFinancialReportController from '../BaseFinancialReportController';
|
import BaseFinancialReportController from '../BaseFinancialReportController';
|
||||||
@@ -37,36 +38,73 @@ export default class CustomerBalanceSummaryReportController extends BaseFinancia
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transformes the balance summary statement to table rows.
|
||||||
|
* @param {ICustomerBalanceSummaryStatement} statement -
|
||||||
|
*/
|
||||||
|
private transformToTableRows({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
}: ICustomerBalanceSummaryStatement) {
|
||||||
|
return {
|
||||||
|
table: {
|
||||||
|
rows: this.customerBalanceSummaryTableRows.tableRowsTransformer(data),
|
||||||
|
columns: this.transfromToResponse(columns),
|
||||||
|
},
|
||||||
|
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.
|
* Retrieve payable aging summary report.
|
||||||
* @param {Request} req -
|
* @param {Request} req -
|
||||||
* @param {Response} res -
|
* @param {Response} res -
|
||||||
* @param {NextFunction} next -
|
* @param {NextFunction} next -
|
||||||
*/
|
*/
|
||||||
async customerBalanceSummary(req: Request, res: Response, next: NextFunction) {
|
async customerBalanceSummary(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) {
|
||||||
const { tenantId, settings } = req;
|
const { tenantId, settings } = req;
|
||||||
const filter = this.matchedQueryData(req);
|
const filter = this.matchedQueryData(req);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const {
|
const customerBalanceSummary = await this.customerBalanceSummaryService.customerBalanceSummary(
|
||||||
data,
|
|
||||||
columns,
|
|
||||||
query,
|
|
||||||
} = await this.customerBalanceSummaryService.customerBalanceSummary(
|
|
||||||
tenantId,
|
tenantId,
|
||||||
filter
|
filter
|
||||||
);
|
);
|
||||||
|
|
||||||
const tableRows = this.customerBalanceSummaryTableRows.tableRowsTransformer(
|
const accept = this.accepts(req);
|
||||||
data
|
const acceptType = accept.types(['json', 'application/json+table']);
|
||||||
);
|
|
||||||
return res.status( 200).send({
|
switch (acceptType) {
|
||||||
table: {
|
case 'application/json+table':
|
||||||
rows: tableRows
|
return res
|
||||||
},
|
.status(200)
|
||||||
columns: this.transfromToResponse(columns),
|
.send(this.transformToTableRows(customerBalanceSummary));
|
||||||
query: this.transfromToResponse(query),
|
case 'application/json':
|
||||||
});
|
default:
|
||||||
|
return res
|
||||||
|
.status(200)
|
||||||
|
.send(this.transformToJsonResponse(customerBalanceSummary));
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { query } from 'express-validator';
|
import { query } from 'express-validator';
|
||||||
import { Inject } from 'typedi';
|
import { Inject } from 'typedi';
|
||||||
|
import { ITransactionsByCustomersStatement } from 'interfaces';
|
||||||
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||||
import BaseFinancialReportController from '../BaseFinancialReportController';
|
import BaseFinancialReportController from '../BaseFinancialReportController';
|
||||||
import TransactionsByCustomersService from 'services/FinancialStatements/TransactionsByCustomer/TransactionsByCustomersService';
|
import TransactionsByCustomersService from 'services/FinancialStatements/TransactionsByCustomer/TransactionsByCustomersService';
|
||||||
@@ -40,6 +41,33 @@ export default class TransactionsByCustomersReportController extends BaseFinanci
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transformes the statement to table rows response.
|
||||||
|
* @param {ITransactionsByCustomersStatement} statement -
|
||||||
|
*/
|
||||||
|
transformToTableResponse({ data }: ITransactionsByCustomersStatement) {
|
||||||
|
return {
|
||||||
|
table: {
|
||||||
|
rows: this.transactionsByCustomersTableRows.tableRows(data),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transformes the statement to json response.
|
||||||
|
* @param {ITransactionsByCustomersStatement} statement -
|
||||||
|
*/
|
||||||
|
transfromToJsonResponse({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
}: ITransactionsByCustomersStatement) {
|
||||||
|
return {
|
||||||
|
data: this.transfromToResponse(data),
|
||||||
|
columns: this.transfromToResponse(columns),
|
||||||
|
query: this.transfromToResponse(query),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve payable aging summary report.
|
* Retrieve payable aging summary report.
|
||||||
* @param {Request} req -
|
* @param {Request} req -
|
||||||
@@ -55,26 +83,24 @@ export default class TransactionsByCustomersReportController extends BaseFinanci
|
|||||||
const filter = this.matchedQueryData(req);
|
const filter = this.matchedQueryData(req);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const {
|
const transactionsByCustomers = await this.transactionsByCustomersService.transactionsByCustomers(
|
||||||
data,
|
|
||||||
columns,
|
|
||||||
query,
|
|
||||||
} = await this.transactionsByCustomersService.transactionsByCustomers(
|
|
||||||
tenantId,
|
tenantId,
|
||||||
filter
|
filter
|
||||||
);
|
);
|
||||||
|
const accept = this.accepts(req);
|
||||||
|
const acceptType = accept.types(['json', 'application/json+table']);
|
||||||
|
|
||||||
return res.status(200).send({
|
switch (acceptType) {
|
||||||
table: {
|
case 'json':
|
||||||
rows: this.transactionsByCustomersTableRows.tableRows(data),
|
return res
|
||||||
},
|
.status(200)
|
||||||
});
|
.send(this.transfromToJsonResponse(transactionsByCustomers));
|
||||||
|
case 'application/json+table':
|
||||||
return res.status(200).send({
|
default:
|
||||||
data: this.transfromToResponse(data),
|
return res
|
||||||
columns: this.transfromToResponse(columns),
|
.status(200)
|
||||||
query: this.transfromToResponse(query),
|
.send(this.transformToTableResponse(transactionsByCustomers));
|
||||||
});
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
|||||||
import BaseFinancialReportController from '../BaseFinancialReportController';
|
import BaseFinancialReportController from '../BaseFinancialReportController';
|
||||||
import TransactionsByVendorsTableRows from 'services/FinancialStatements/TransactionsByVendor/TransactionsByVendorTableRows';
|
import TransactionsByVendorsTableRows from 'services/FinancialStatements/TransactionsByVendor/TransactionsByVendorTableRows';
|
||||||
import TransactionsByVendorsService from 'services/FinancialStatements/TransactionsByVendor/TransactionsByVendorService';
|
import TransactionsByVendorsService from 'services/FinancialStatements/TransactionsByVendor/TransactionsByVendorService';
|
||||||
|
import { ITransactionsByVendorsStatement } from 'interfaces';
|
||||||
export default class TransactionsByVendorsReportController extends BaseFinancialReportController {
|
export default class TransactionsByVendorsReportController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
transactionsByVendorsService: TransactionsByVendorsService;
|
transactionsByVendorsService: TransactionsByVendorsService;
|
||||||
@@ -40,41 +40,63 @@ export default class TransactionsByVendorsReportController extends BaseFinancial
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transformes the report statement to table rows.
|
||||||
|
* @param {ITransactionsByVendorsStatement} statement -
|
||||||
|
*/
|
||||||
|
transformToTableRows({ data }: ITransactionsByVendorsStatement) {
|
||||||
|
return {
|
||||||
|
table: {
|
||||||
|
data: this.transactionsByVendorsTableRows.tableRows(data),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transformes the report statement to json response.
|
||||||
|
* @param {ITransactionsByVendorsStatement} statement -
|
||||||
|
*/
|
||||||
|
transformToJsonResponse({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
query,
|
||||||
|
}: ITransactionsByVendorsStatement) {
|
||||||
|
return {
|
||||||
|
data: this.transfromToResponse(data),
|
||||||
|
columns: this.transfromToResponse(columns),
|
||||||
|
query: this.transfromToResponse(query),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve payable aging summary report.
|
* Retrieve payable aging summary report.
|
||||||
* @param {Request} req -
|
* @param {Request} req -
|
||||||
* @param {Response} res -
|
* @param {Response} res -
|
||||||
* @param {NextFunction} next -
|
* @param {NextFunction} next -
|
||||||
*/
|
*/
|
||||||
async transactionsByVendors(
|
async transactionsByVendors(req: Request, res: Response, next: NextFunction) {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
next: NextFunction
|
|
||||||
) {
|
|
||||||
const { tenantId } = req;
|
const { tenantId } = req;
|
||||||
const filter = this.matchedQueryData(req);
|
const filter = this.matchedQueryData(req);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const {
|
const transactionsByVendors = await this.transactionsByVendorsService.transactionsByVendors(
|
||||||
data,
|
|
||||||
columns,
|
|
||||||
query,
|
|
||||||
} = await this.transactionsByVendorsService.transactionsByVendors(
|
|
||||||
tenantId,
|
tenantId,
|
||||||
filter
|
filter
|
||||||
);
|
);
|
||||||
|
const accept = this.accepts(req);
|
||||||
|
const acceptType = accept.types(['json', 'application/json+table']);
|
||||||
|
|
||||||
return res.status(200).send({
|
switch (acceptType) {
|
||||||
table: {
|
case 'application/json+table':
|
||||||
rows: this.transactionsByVendorsTableRows.tableRows(data),
|
return res
|
||||||
},
|
.status(200)
|
||||||
});
|
.send(this.transformToTableRows(transactionsByVendors));
|
||||||
|
case 'json':
|
||||||
return res.status(200).send({
|
default:
|
||||||
data: this.transfromToResponse(data),
|
return res
|
||||||
columns: this.transfromToResponse(columns),
|
.status(200)
|
||||||
query: this.transfromToResponse(query),
|
.send(this.transformToJsonResponse(transactionsByVendors));
|
||||||
});
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
|||||||
import BaseFinancialReportController from '../BaseFinancialReportController';
|
import BaseFinancialReportController from '../BaseFinancialReportController';
|
||||||
import VendorBalanceSummaryTableRows from 'services/FinancialStatements/VendorBalanceSummary/VendorBalanceSummaryTableRows';
|
import VendorBalanceSummaryTableRows from 'services/FinancialStatements/VendorBalanceSummary/VendorBalanceSummaryTableRows';
|
||||||
import VendorBalanceSummaryService from 'services/FinancialStatements/VendorBalanceSummary/VendorBalanceSummaryService';
|
import VendorBalanceSummaryService from 'services/FinancialStatements/VendorBalanceSummary/VendorBalanceSummaryService';
|
||||||
|
import { IVendorBalanceSummaryStatement } from 'interfaces';
|
||||||
export default class VendorBalanceSummaryReportController extends BaseFinancialReportController {
|
export default class VendorBalanceSummaryReportController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
vendorBalanceSummaryService: VendorBalanceSummaryService;
|
vendorBalanceSummaryService: VendorBalanceSummaryService;
|
||||||
@@ -37,6 +37,30 @@ export default class VendorBalanceSummaryReportController extends BaseFinancialR
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transformes the report statement to table rows.
|
||||||
|
* @param {IVendorBalanceSummaryStatement} statement -
|
||||||
|
*/
|
||||||
|
transformToTableRows({ data }: IVendorBalanceSummaryStatement) {
|
||||||
|
return {
|
||||||
|
table: {
|
||||||
|
data: this.vendorBalanceSummaryTableRows.tableRowsTransformer(data),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transformes the report statement to raw json.
|
||||||
|
* @param {IVendorBalanceSummaryStatement} statement -
|
||||||
|
*/
|
||||||
|
transformToJsonResponse({ data, columns }: IVendorBalanceSummaryStatement) {
|
||||||
|
return {
|
||||||
|
data: this.transfromToResponse(data),
|
||||||
|
columns: this.transfromToResponse(columns),
|
||||||
|
query: this.transfromToResponse(query),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve vendors balance summary.
|
* Retrieve vendors balance summary.
|
||||||
* @param {Request} req -
|
* @param {Request} req -
|
||||||
@@ -48,25 +72,26 @@ export default class VendorBalanceSummaryReportController extends BaseFinancialR
|
|||||||
const filter = this.matchedQueryData(req);
|
const filter = this.matchedQueryData(req);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const {
|
const vendorBalanceSummary = await this.vendorBalanceSummaryService.vendorBalanceSummary(
|
||||||
data,
|
|
||||||
columns,
|
|
||||||
query,
|
|
||||||
} = await this.vendorBalanceSummaryService.vendorBalanceSummary(
|
|
||||||
tenantId,
|
tenantId,
|
||||||
filter
|
filter
|
||||||
);
|
);
|
||||||
|
const accept = this.accepts(req);
|
||||||
|
const acceptType = accept.types(['json', 'application/json+table']);
|
||||||
|
|
||||||
const tableRows = this.vendorBalanceSummaryTableRows.tableRowsTransformer(
|
switch (acceptType) {
|
||||||
data
|
case 'application/json+table':
|
||||||
);
|
return res
|
||||||
return res.status( 200).send({
|
.status(200)
|
||||||
table: {
|
.send(this.transformToTableRows(vendorBalanceSummary));
|
||||||
rows: tableRows
|
case 'json':
|
||||||
},
|
default:
|
||||||
columns: this.transfromToResponse(columns),
|
return res
|
||||||
query: this.transfromToResponse(query),
|
.status(200)
|
||||||
});
|
.send(this.transformToJsonResponse(vendorBalanceSummary));
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).send({});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
IContactBalanceSummaryContact,
|
IContactBalanceSummaryContact,
|
||||||
IContactBalanceSummaryTotal,
|
IContactBalanceSummaryTotal,
|
||||||
IContactBalanceSummaryAmount,
|
IContactBalanceSummaryAmount,
|
||||||
IContactBalanceSummaryPercentage
|
IContactBalanceSummaryPercentage,
|
||||||
} from 'interfaces';
|
} from 'interfaces';
|
||||||
|
|
||||||
export class ContactBalanceSummaryReport extends FinancialSheet {
|
export class ContactBalanceSummaryReport extends FinancialSheet {
|
||||||
@@ -90,7 +90,14 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
|
|||||||
return contacts.map(camparsionPercentageOfColummn);
|
return contacts.map(camparsionPercentageOfColummn);
|
||||||
}
|
}
|
||||||
|
|
||||||
getContactTotalFormat(amount: number) {
|
/**
|
||||||
|
* Retrieve the contact total format.
|
||||||
|
* @param {number} amount -
|
||||||
|
* @return {IContactBalanceSummaryAmount}
|
||||||
|
*/
|
||||||
|
protected getContactTotalFormat(
|
||||||
|
amount: number
|
||||||
|
): IContactBalanceSummaryAmount {
|
||||||
return {
|
return {
|
||||||
amount,
|
amount,
|
||||||
formattedAmount: this.formatNumber(amount),
|
formattedAmount: this.formatNumber(amount),
|
||||||
@@ -103,7 +110,7 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
|
|||||||
* @param {number} amount
|
* @param {number} amount
|
||||||
* @returns {IContactBalanceSummaryAmount}
|
* @returns {IContactBalanceSummaryAmount}
|
||||||
*/
|
*/
|
||||||
getTotalFormat(amount: number): IContactBalanceSummaryAmount {
|
protected getTotalFormat(amount: number): IContactBalanceSummaryAmount {
|
||||||
return {
|
return {
|
||||||
amount,
|
amount,
|
||||||
formattedAmount: this.formatNumber(amount),
|
formattedAmount: this.formatNumber(amount),
|
||||||
@@ -116,7 +123,9 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
|
|||||||
* @param {number} amount
|
* @param {number} amount
|
||||||
* @returns {IContactBalanceSummaryPercentage}
|
* @returns {IContactBalanceSummaryPercentage}
|
||||||
*/
|
*/
|
||||||
getPercentageMeta(amount: number): IContactBalanceSummaryPercentage {
|
protected getPercentageMeta(
|
||||||
|
amount: number
|
||||||
|
): IContactBalanceSummaryPercentage {
|
||||||
return {
|
return {
|
||||||
amount,
|
amount,
|
||||||
formattedAmount: this.formatPercentage(amount),
|
formattedAmount: this.formatPercentage(amount),
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ export default class FinancialSheet {
|
|||||||
* Transformes the number format query to settings
|
* Transformes the number format query to settings
|
||||||
*/
|
*/
|
||||||
protected transfromFormatQueryToSettings(): IFormatNumberSettings {
|
protected transfromFormatQueryToSettings(): IFormatNumberSettings {
|
||||||
console.log(this.numberFormat, 'XX');
|
|
||||||
const { numberFormat } = this;
|
const { numberFormat } = this;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import moment from 'moment';
|
||||||
import { tableMapper, tableRowMapper } from 'utils';
|
import { tableMapper, tableRowMapper } from 'utils';
|
||||||
import {
|
import {
|
||||||
ITransactionsByContactsContact,
|
ITransactionsByContactsContact,
|
||||||
@@ -12,6 +13,11 @@ enum ROW_TYPE {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default class TransactionsByContactsTableRows {
|
export default class TransactionsByContactsTableRows {
|
||||||
|
|
||||||
|
private dateAccessor(value) {
|
||||||
|
return moment(value.date).format('YYYY MMM DD');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the table rows of contact transactions.
|
* Retrieve the table rows of contact transactions.
|
||||||
* @param {ITransactionsByCustomersCustomer} contact
|
* @param {ITransactionsByCustomersCustomer} contact
|
||||||
@@ -21,7 +27,7 @@ export default class TransactionsByContactsTableRows {
|
|||||||
contact: ITransactionsByContactsContact
|
contact: ITransactionsByContactsContact
|
||||||
): ITableRow[] {
|
): ITableRow[] {
|
||||||
const columns = [
|
const columns = [
|
||||||
{ key: 'date', accessor: 'date' },
|
{ key: 'date', accessor: this.dateAccessor },
|
||||||
{ key: 'account', accessor: 'account.name' },
|
{ key: 'account', accessor: 'account.name' },
|
||||||
{ key: 'referenceType', accessor: 'referenceType' },
|
{ key: 'referenceType', accessor: 'referenceType' },
|
||||||
{ key: 'transactionType', accessor: 'transactionType' },
|
{ key: 'transactionType', accessor: 'transactionType' },
|
||||||
@@ -62,9 +68,9 @@ export default class TransactionsByContactsTableRows {
|
|||||||
contact: ITransactionsByContactsContact
|
contact: ITransactionsByContactsContact
|
||||||
): ITableRow {
|
): ITableRow {
|
||||||
const columns = [
|
const columns = [
|
||||||
{ key: 'openingBalanceLabel', value: 'Closing balance' },
|
{ key: 'closingBalanceLabel', value: 'Closing balance' },
|
||||||
{
|
{
|
||||||
key: 'openingBalanceValue',
|
key: 'closingBalanceValue',
|
||||||
accessor: 'closingBalance.formattedAmount',
|
accessor: 'closingBalance.formattedAmount',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ export default class TransactionsByCustomersTableRows extends TransactionsByCont
|
|||||||
return {
|
return {
|
||||||
...tableRowMapper(customer, columns, { rowTypes: [ROW_TYPE.CUSTOMER] }),
|
...tableRowMapper(customer, columns, { rowTypes: [ROW_TYPE.CUSTOMER] }),
|
||||||
children: R.pipe(
|
children: R.pipe(
|
||||||
R.append(this.contactOpeningBalance(customer)),
|
|
||||||
R.concat(this.contactTransactions(customer)),
|
R.concat(this.contactTransactions(customer)),
|
||||||
|
R.prepend(this.contactOpeningBalance(customer)),
|
||||||
R.append(this.contactClosingBalance(customer))
|
R.append(this.contactClosingBalance(customer))
|
||||||
)([]),
|
)([]),
|
||||||
};
|
};
|
||||||
@@ -35,7 +35,7 @@ export default class TransactionsByCustomersTableRows extends TransactionsByCont
|
|||||||
* @returns {ITableRow[]}
|
* @returns {ITableRow[]}
|
||||||
*/
|
*/
|
||||||
private customerRowsMapper(customer: ITransactionsByCustomersCustomer) {
|
private customerRowsMapper(customer: ITransactionsByCustomersCustomer) {
|
||||||
return R.pipe(R.append(this.customerDetails(customer))).bind(this)([]);
|
return R.pipe(this.customerDetails).bind(this)(customer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,6 +9,12 @@ export function tableMapper(
|
|||||||
return data.map((object) => tableRowMapper(object, columns, rowsMeta));
|
return data.map((object) => tableRowMapper(object, columns, rowsMeta));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAccessor(object, accessor) {
|
||||||
|
return typeof accessor === 'function'
|
||||||
|
? accessor(object)
|
||||||
|
: get(object, accessor);
|
||||||
|
}
|
||||||
|
|
||||||
export function tableRowMapper(
|
export function tableRowMapper(
|
||||||
object: Object,
|
object: Object,
|
||||||
columns: IColumnMapperMeta[],
|
columns: IColumnMapperMeta[],
|
||||||
@@ -16,7 +22,7 @@ export function tableRowMapper(
|
|||||||
): ITableRow {
|
): ITableRow {
|
||||||
const cells = columns.map((column) => ({
|
const cells = columns.map((column) => ({
|
||||||
key: column.key,
|
key: column.key,
|
||||||
value: column.value ? column.value : get(object, column.accessor),
|
value: column.value ? column.value : getAccessor(object, column.accessor),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user