mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
feat: format amount rows of financial statemnets.
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hapi/boom": "^7.4.3",
|
"@hapi/boom": "^7.4.3",
|
||||||
"@types/i18n": "^0.8.7",
|
"@types/i18n": "^0.8.7",
|
||||||
|
"accounting": "^0.4.1",
|
||||||
"agenda": "^3.1.0",
|
"agenda": "^3.1.0",
|
||||||
"agendash": "^1.0.0",
|
"agendash": "^1.0.0",
|
||||||
"app-root-path": "^3.0.0",
|
"app-root-path": "^3.0.0",
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
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 BaseController from 'api/controllers/BaseController';
|
|
||||||
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||||
import APAgingSummaryReportService from 'services/FinancialStatements/AgingSummary/APAgingSummaryService';
|
import APAgingSummaryReportService from 'services/FinancialStatements/AgingSummary/APAgingSummaryService';
|
||||||
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
|
|
||||||
export default class APAgingSummaryReportController extends BaseController {
|
export default class APAgingSummaryReportController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
APAgingSummaryService: APAgingSummaryReportService;
|
APAgingSummaryService: APAgingSummaryReportService;
|
||||||
|
|
||||||
@@ -28,11 +28,10 @@ export default class APAgingSummaryReportController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
get validationSchema() {
|
get validationSchema() {
|
||||||
return [
|
return [
|
||||||
|
...this.sheetNumberFormatValidationSchema,
|
||||||
query('as_date').optional().isISO8601(),
|
query('as_date').optional().isISO8601(),
|
||||||
query('aging_days_before').optional().isNumeric().toInt(),
|
query('aging_days_before').optional().isNumeric().toInt(),
|
||||||
query('aging_periods').optional().isNumeric().toInt(),
|
query('aging_periods').optional().isNumeric().toInt(),
|
||||||
query('number_format.no_cents').optional().isBoolean().toBoolean(),
|
|
||||||
query('number_format.1000_divide').optional().isBoolean().toBoolean(),
|
|
||||||
query('vendors_ids').optional().isArray({ min: 1 }),
|
query('vendors_ids').optional().isArray({ min: 1 }),
|
||||||
query('vendors_ids.*').isInt({ min: 1 }).toInt(),
|
query('vendors_ids.*').isInt({ min: 1 }).toInt(),
|
||||||
query('none_zero').default(true).isBoolean().toBoolean(),
|
query('none_zero').default(true).isBoolean().toBoolean(),
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import { Router, Request, Response } from 'express';
|
import { Router, Request, Response } from 'express';
|
||||||
import { castArray } from 'lodash';
|
import { query } from 'express-validator';
|
||||||
import { query, oneOf } from 'express-validator';
|
|
||||||
import { IARAgingSummaryQuery } from 'interfaces';
|
|
||||||
import BaseController from '../BaseController';
|
|
||||||
import ARAgingSummaryService from 'services/FinancialStatements/AgingSummary/ARAgingSummaryService';
|
import ARAgingSummaryService from 'services/FinancialStatements/AgingSummary/ARAgingSummaryService';
|
||||||
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class ARAgingSummaryReportController extends BaseController {
|
export default class ARAgingSummaryReportController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
ARAgingSummaryService: ARAgingSummaryService;
|
ARAgingSummaryService: ARAgingSummaryService;
|
||||||
|
|
||||||
@@ -31,11 +29,11 @@ export default class ARAgingSummaryReportController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
get validationSchema() {
|
get validationSchema() {
|
||||||
return [
|
return [
|
||||||
|
...this.sheetNumberFormatValidationSchema,
|
||||||
|
|
||||||
query('as_date').optional().isISO8601(),
|
query('as_date').optional().isISO8601(),
|
||||||
query('aging_days_before').optional().isInt({ max: 500 }).toInt(),
|
query('aging_days_before').optional().isInt({ max: 500 }).toInt(),
|
||||||
query('aging_periods').optional().isInt({ max: 12 }).toInt(),
|
query('aging_periods').optional().isInt({ max: 12 }).toInt(),
|
||||||
query('number_format.no_cents').optional().isBoolean().toBoolean(),
|
|
||||||
query('number_format.1000_divide').optional().isBoolean().toBoolean(),
|
|
||||||
query('customers_ids').optional().isArray({ min: 1 }),
|
query('customers_ids').optional().isArray({ min: 1 }),
|
||||||
query('customers_ids.*').isInt({ min: 1 }).toInt(),
|
query('customers_ids.*').isInt({ min: 1 }).toInt(),
|
||||||
query('none_zero').default(true).isBoolean().toBoolean(),
|
query('none_zero').default(true).isBoolean().toBoolean(),
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import { Router, Request, Response, NextFunction } from 'express';
|
|||||||
import { query, ValidationChain } from 'express-validator';
|
import { query, ValidationChain } from 'express-validator';
|
||||||
import { castArray } from 'lodash';
|
import { castArray } from 'lodash';
|
||||||
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||||
import BaseController from '../BaseController';
|
|
||||||
import BalanceSheetStatementService from 'services/FinancialStatements/BalanceSheet/BalanceSheetService';
|
import BalanceSheetStatementService from 'services/FinancialStatements/BalanceSheet/BalanceSheetService';
|
||||||
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class BalanceSheetStatementController extends BaseController {
|
export default class BalanceSheetStatementController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
balanceSheetService: BalanceSheetStatementService;
|
balanceSheetService: BalanceSheetStatementService;
|
||||||
|
|
||||||
@@ -32,6 +32,8 @@ export default class BalanceSheetStatementController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
get balanceSheetValidationSchema(): ValidationChain[] {
|
get balanceSheetValidationSchema(): ValidationChain[] {
|
||||||
return [
|
return [
|
||||||
|
...this.sheetNumberFormatValidationSchema,
|
||||||
|
|
||||||
query('accounting_method').optional().isIn(['cash', 'accural']),
|
query('accounting_method').optional().isIn(['cash', 'accural']),
|
||||||
query('from_date').optional(),
|
query('from_date').optional(),
|
||||||
query('to_date').optional(),
|
query('to_date').optional(),
|
||||||
@@ -39,8 +41,6 @@ export default class BalanceSheetStatementController extends BaseController {
|
|||||||
query('display_columns_by')
|
query('display_columns_by')
|
||||||
.optional({ nullable: true, checkFalsy: true })
|
.optional({ nullable: true, checkFalsy: true })
|
||||||
.isIn(['year', 'month', 'week', 'day', 'quarter']),
|
.isIn(['year', 'month', 'week', 'day', 'quarter']),
|
||||||
query('number_format.no_cents').optional().isBoolean().toBoolean(),
|
|
||||||
query('number_format.divide_1000').optional().isBoolean().toBoolean(),
|
|
||||||
query('account_ids').isArray().optional(),
|
query('account_ids').isArray().optional(),
|
||||||
query('account_ids.*').isNumeric().toInt(),
|
query('account_ids.*').isNumeric().toInt(),
|
||||||
query('none_zero').optional().isBoolean().toBoolean(),
|
query('none_zero').optional().isBoolean().toBoolean(),
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { query } from 'express-validator';
|
||||||
|
import BaseController from "../BaseController";
|
||||||
|
|
||||||
|
export default class BaseFinancialReportController extends BaseController {
|
||||||
|
|
||||||
|
|
||||||
|
get sheetNumberFormatValidationSchema() {
|
||||||
|
return [
|
||||||
|
query('number_format.precision')
|
||||||
|
.optional()
|
||||||
|
.isInt({ min: 0, max: 5 })
|
||||||
|
.toInt(),
|
||||||
|
query('number_format.divide_on_1000').optional().isBoolean().toBoolean(),
|
||||||
|
query('number_format.show_zero').optional().isBoolean().toBoolean(),
|
||||||
|
query('number_format.format_money')
|
||||||
|
.optional()
|
||||||
|
.isIn(['total', 'always', 'none'])
|
||||||
|
.trim(),
|
||||||
|
query('number_format.negative_format')
|
||||||
|
.optional()
|
||||||
|
.isIn(['parentheses', 'mines'])
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { query, ValidationChain } from 'express-validator';
|
import { query, ValidationChain } from 'express-validator';
|
||||||
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
|
||||||
import BaseController from '../BaseController';
|
|
||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
|
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||||
import GeneralLedgerService from 'services/FinancialStatements/GeneralLedger/GeneralLedgerService';
|
import GeneralLedgerService from 'services/FinancialStatements/GeneralLedger/GeneralLedgerService';
|
||||||
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class GeneralLedgerReportController extends BaseController {
|
export default class GeneralLedgerReportController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
generalLedgetService: GeneralLedgerService;
|
generalLedgetService: GeneralLedgerService;
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ import { Inject, Service } from 'typedi';
|
|||||||
import { Request, Response, Router, NextFunction } from 'express';
|
import { Request, Response, Router, NextFunction } from 'express';
|
||||||
import { castArray } from 'lodash';
|
import { castArray } from 'lodash';
|
||||||
import { query, oneOf } from 'express-validator';
|
import { query, oneOf } from 'express-validator';
|
||||||
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
import JournalSheetService from 'services/FinancialStatements/JournalSheet/JournalSheetService';
|
import JournalSheetService from 'services/FinancialStatements/JournalSheet/JournalSheetService';
|
||||||
import BaseController from '../BaseController';
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class JournalSheetController extends BaseController {
|
export default class JournalSheetController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
journalService: JournalSheetService;
|
journalService: JournalSheetService;
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { query, ValidationChain } from 'express-validator';
|
import { query, ValidationChain } from 'express-validator';
|
||||||
import BaseController from '../BaseController';
|
|
||||||
import ProfitLossSheetService from 'services/FinancialStatements/ProfitLossSheet/ProfitLossSheetService';
|
import ProfitLossSheetService from 'services/FinancialStatements/ProfitLossSheet/ProfitLossSheetService';
|
||||||
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class ProfitLossSheetController extends BaseController {
|
export default class ProfitLossSheetController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
profitLossSheetService: ProfitLossSheetService;
|
profitLossSheetService: ProfitLossSheetService;
|
||||||
|
|
||||||
@@ -29,11 +29,10 @@ export default class ProfitLossSheetController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
get validationSchema(): ValidationChain[] {
|
get validationSchema(): ValidationChain[] {
|
||||||
return [
|
return [
|
||||||
|
...this.sheetNumberFormatValidationSchema,
|
||||||
query('basis').optional(),
|
query('basis').optional(),
|
||||||
query('from_date').optional().isISO8601(),
|
query('from_date').optional().isISO8601(),
|
||||||
query('to_date').optional().isISO8601(),
|
query('to_date').optional().isISO8601(),
|
||||||
query('number_format.no_cents').optional().isBoolean(),
|
|
||||||
query('number_format.divide_1000').optional().isBoolean(),
|
|
||||||
query('basis').optional(),
|
query('basis').optional(),
|
||||||
query('none_zero').optional().isBoolean().toBoolean(),
|
query('none_zero').optional().isBoolean().toBoolean(),
|
||||||
query('none_transactions').optional().isBoolean().toBoolean(),
|
query('none_transactions').optional().isBoolean().toBoolean(),
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import { Request, Response, Router, NextFunction } from 'express';
|
import { Request, Response, Router, NextFunction } from 'express';
|
||||||
import { query, ValidationChain } from 'express-validator';
|
import { query, ValidationChain } from 'express-validator';
|
||||||
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
|
||||||
import BaseController from '../BaseController';
|
|
||||||
import TrialBalanceSheetService from 'services/FinancialStatements/TrialBalanceSheet/TrialBalanceSheetService';
|
|
||||||
import { castArray } from 'lodash';
|
import { castArray } from 'lodash';
|
||||||
|
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||||
|
import TrialBalanceSheetService from 'services/FinancialStatements/TrialBalanceSheet/TrialBalanceSheetService';
|
||||||
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class TrialBalanceSheetController extends BaseController {
|
export default class TrialBalanceSheetController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
trialBalanceSheetService: TrialBalanceSheetService;
|
trialBalanceSheetService: TrialBalanceSheetService;
|
||||||
|
|
||||||
@@ -17,7 +17,8 @@ export default class TrialBalanceSheetController extends BaseController {
|
|||||||
router() {
|
router() {
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get('/',
|
router.get(
|
||||||
|
'/',
|
||||||
this.trialBalanceSheetValidationSchema,
|
this.trialBalanceSheetValidationSchema,
|
||||||
this.validationResult,
|
this.validationResult,
|
||||||
asyncMiddleware(this.trialBalanceSheet.bind(this))
|
asyncMiddleware(this.trialBalanceSheet.bind(this))
|
||||||
@@ -31,11 +32,10 @@ export default class TrialBalanceSheetController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
get trialBalanceSheetValidationSchema(): ValidationChain[] {
|
get trialBalanceSheetValidationSchema(): ValidationChain[] {
|
||||||
return [
|
return [
|
||||||
|
...this.sheetNumberFormatValidationSchema,
|
||||||
query('basis').optional(),
|
query('basis').optional(),
|
||||||
query('from_date').optional().isISO8601(),
|
query('from_date').optional().isISO8601(),
|
||||||
query('to_date').optional().isISO8601(),
|
query('to_date').optional().isISO8601(),
|
||||||
query('number_format.no_cents').optional().isBoolean().toBoolean(),
|
|
||||||
query('number_format.1000_divide').optional().isBoolean().toBoolean(),
|
|
||||||
query('account_ids').isArray().optional(),
|
query('account_ids').isArray().optional(),
|
||||||
query('account_ids.*').isNumeric().toInt(),
|
query('account_ids.*').isNumeric().toInt(),
|
||||||
query('basis').optional(),
|
query('basis').optional(),
|
||||||
@@ -46,7 +46,11 @@ export default class TrialBalanceSheetController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* Retrieve the trial balance sheet.
|
* Retrieve the trial balance sheet.
|
||||||
*/
|
*/
|
||||||
public async trialBalanceSheet(req: Request, res: Response, next: NextFunction) {
|
public async trialBalanceSheet(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) {
|
||||||
const { tenantId, settings } = req;
|
const { tenantId, settings } = req;
|
||||||
let filter = this.matchedQueryData(req);
|
let filter = this.matchedQueryData(req);
|
||||||
|
|
||||||
@@ -54,18 +58,29 @@ export default class TrialBalanceSheetController extends BaseController {
|
|||||||
...filter,
|
...filter,
|
||||||
accountsIds: castArray(filter.accountsIds),
|
accountsIds: castArray(filter.accountsIds),
|
||||||
};
|
};
|
||||||
const organizationName = settings.get({ group: 'organization', key: 'name' });
|
const organizationName = settings.get({
|
||||||
const baseCurrency = settings.get({ group: 'organization', key: 'base_currency' });
|
group: 'organization',
|
||||||
|
key: 'name',
|
||||||
|
});
|
||||||
|
const baseCurrency = settings.get({
|
||||||
|
group: 'organization',
|
||||||
|
key: 'base_currency',
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data, query } = await this.trialBalanceSheetService
|
const {
|
||||||
.trialBalanceSheet(tenantId, filter);
|
data,
|
||||||
|
query,
|
||||||
|
} = await this.trialBalanceSheetService.trialBalanceSheet(
|
||||||
|
tenantId,
|
||||||
|
filter
|
||||||
|
);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
organization_name: organizationName,
|
organization_name: organizationName,
|
||||||
base_currency: baseCurrency,
|
base_currency: baseCurrency,
|
||||||
data: this.transfromToResponse(data),
|
data: this.transfromToResponse(data),
|
||||||
query: this.transfromToResponse(query)
|
query: this.transfromToResponse(query),
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
|
|||||||
@@ -2,15 +2,15 @@ import {
|
|||||||
IAgingPeriod,
|
IAgingPeriod,
|
||||||
IAgingPeriodTotal
|
IAgingPeriodTotal
|
||||||
} from './AgingReport';
|
} from './AgingReport';
|
||||||
|
import {
|
||||||
|
INumberFormatQuery
|
||||||
|
} from './FinancialStatements';
|
||||||
|
|
||||||
export interface IAPAgingSummaryQuery {
|
export interface IAPAgingSummaryQuery {
|
||||||
asDate: Date | string;
|
asDate: Date | string;
|
||||||
agingDaysBefore: number;
|
agingDaysBefore: number;
|
||||||
agingPeriods: number;
|
agingPeriods: number;
|
||||||
numberFormat: {
|
numberFormat: INumberFormatQuery;
|
||||||
noCents: boolean;
|
|
||||||
divideOn1000: boolean;
|
|
||||||
};
|
|
||||||
vendorsIds: number[];
|
vendorsIds: number[];
|
||||||
noneZero: boolean;
|
noneZero: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,15 @@ import {
|
|||||||
IAgingPeriod,
|
IAgingPeriod,
|
||||||
IAgingPeriodTotal
|
IAgingPeriodTotal
|
||||||
} from './AgingReport';
|
} from './AgingReport';
|
||||||
|
import {
|
||||||
|
INumberFormatQuery
|
||||||
|
} from './FinancialStatements';
|
||||||
|
|
||||||
export interface IARAgingSummaryQuery {
|
export interface IARAgingSummaryQuery {
|
||||||
asDate: Date | string;
|
asDate: Date | string;
|
||||||
agingDaysBefore: number;
|
agingDaysBefore: number;
|
||||||
agingPeriods: number;
|
agingPeriods: number;
|
||||||
numberFormat: {
|
numberFormat: INumberFormatQuery;
|
||||||
noCents: boolean;
|
|
||||||
divideOn1000: boolean;
|
|
||||||
};
|
|
||||||
customersIds: number[];
|
customersIds: number[];
|
||||||
noneZero: boolean;
|
noneZero: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,74 +1,79 @@
|
|||||||
|
import {
|
||||||
|
INumberFormatQuery,
|
||||||
|
IFormatNumberSettings,
|
||||||
|
} from './FinancialStatements';
|
||||||
|
|
||||||
export interface IBalanceSheetQuery{
|
export interface IBalanceSheetQuery {
|
||||||
displayColumnsType: 'total' | 'date_periods',
|
displayColumnsType: 'total' | 'date_periods';
|
||||||
displayColumnsBy: string,
|
displayColumnsBy: string;
|
||||||
fromDate: Date|string,
|
fromDate: Date | string;
|
||||||
toDate: Date|string,
|
toDate: Date | string;
|
||||||
numberFormat: {
|
numberFormat: INumberFormatQuery;
|
||||||
noCents: boolean,
|
noneZero: boolean;
|
||||||
divideOn1000: boolean,
|
noneTransactions: boolean;
|
||||||
},
|
basis: 'cash' | 'accural';
|
||||||
noneZero: boolean,
|
accountIds: number[];
|
||||||
noneTransactions: boolean,
|
}
|
||||||
basis: 'cash' | 'accural',
|
|
||||||
accountIds: number[],
|
export interface IBalanceSheetFormatNumberSettings
|
||||||
|
extends IFormatNumberSettings {
|
||||||
|
type: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBalanceSheetStatementService {
|
export interface IBalanceSheetStatementService {
|
||||||
balanceSheet(tenantId: number, query: IBalanceSheetQuery): Promise<IBalanceSheetStatement>;
|
balanceSheet(
|
||||||
|
tenantId: number,
|
||||||
|
query: IBalanceSheetQuery
|
||||||
|
): Promise<IBalanceSheetStatement>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBalanceSheetStatementColumns {
|
export interface IBalanceSheetStatementColumns {}
|
||||||
|
|
||||||
}
|
export interface IBalanceSheetStatementData {}
|
||||||
|
|
||||||
export interface IBalanceSheetStatementData {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IBalanceSheetStatement {
|
export interface IBalanceSheetStatement {
|
||||||
query: IBalanceSheetQuery,
|
query: IBalanceSheetQuery;
|
||||||
columns: IBalanceSheetStatementColumns,
|
columns: IBalanceSheetStatementColumns;
|
||||||
data: IBalanceSheetStatementData,
|
data: IBalanceSheetStatementData;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBalanceSheetStructureSection {
|
export interface IBalanceSheetStructureSection {
|
||||||
name: string,
|
name: string;
|
||||||
sectionType?: string,
|
sectionType?: string;
|
||||||
type: 'section' | 'accounts_section',
|
type: 'section' | 'accounts_section';
|
||||||
children?: IBalanceSheetStructureSection[],
|
children?: IBalanceSheetStructureSection[];
|
||||||
accountsTypesRelated?: string[],
|
accountsTypesRelated?: string[];
|
||||||
alwaysShow?: boolean,
|
alwaysShow?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBalanceSheetAccountTotal {
|
export interface IBalanceSheetAccountTotal {
|
||||||
amount: number,
|
amount: number;
|
||||||
formattedAmount: string,
|
formattedAmount: string;
|
||||||
currencyCode: string,
|
currencyCode: string;
|
||||||
date?: string|Date,
|
date?: string | Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBalanceSheetAccount {
|
export interface IBalanceSheetAccount {
|
||||||
id: number,
|
id: number;
|
||||||
index: number,
|
index: number;
|
||||||
name: string,
|
name: string;
|
||||||
code: string,
|
code: string;
|
||||||
parentAccountId: number,
|
parentAccountId: number;
|
||||||
type: 'account',
|
type: 'account';
|
||||||
hasTransactions: boolean,
|
hasTransactions: boolean;
|
||||||
children?: IBalanceSheetAccount[],
|
children?: IBalanceSheetAccount[];
|
||||||
total: IBalanceSheetAccountTotal,
|
total: IBalanceSheetAccountTotal;
|
||||||
totalPeriods?: IBalanceSheetAccountTotal[],
|
totalPeriods?: IBalanceSheetAccountTotal[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBalanceSheetSection {
|
export interface IBalanceSheetSection {
|
||||||
name: string,
|
name: string;
|
||||||
sectionType?: string,
|
sectionType?: string;
|
||||||
type: 'section' | 'accounts_section',
|
type: 'section' | 'accounts_section';
|
||||||
children: IBalanceSheetAccount[] | IBalanceSheetSection[],
|
children: IBalanceSheetAccount[] | IBalanceSheetSection[];
|
||||||
total: IBalanceSheetAccountTotal,
|
total: IBalanceSheetAccountTotal;
|
||||||
totalPeriods?: IBalanceSheetAccountTotal[];
|
totalPeriods?: IBalanceSheetAccountTotal[];
|
||||||
|
|
||||||
accountsTypesRelated?: string[],
|
accountsTypesRelated?: string[];
|
||||||
_forceShow?: boolean,
|
_forceShow?: boolean;
|
||||||
}
|
}
|
||||||
@@ -1,2 +1,19 @@
|
|||||||
|
export interface INumberFormatQuery {
|
||||||
|
precision: number;
|
||||||
|
divideOn1000: boolean;
|
||||||
|
showZero: boolean;
|
||||||
|
formatMoney: 'total' | 'always' | 'none';
|
||||||
|
negativeFormat: 'parentheses' | 'mines';
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IFormatNumberSettings {
|
||||||
|
precision?: number;
|
||||||
|
divideOn1000?: boolean;
|
||||||
|
excerptZero?: boolean;
|
||||||
|
negativeFormat?: 'parentheses' | 'mines';
|
||||||
|
thousand?: string;
|
||||||
|
decimal?: string;
|
||||||
|
zeroSign?: string;
|
||||||
|
symbol?: string;
|
||||||
|
money?: boolean,
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ export interface IJournalEntry {
|
|||||||
referenceType: string,
|
referenceType: string,
|
||||||
referenceId: number,
|
referenceId: number,
|
||||||
|
|
||||||
|
referenceTypeFormatted: string,
|
||||||
|
|
||||||
transactionType?: string,
|
transactionType?: string,
|
||||||
note?: string,
|
note?: string,
|
||||||
userId?: number,
|
userId?: number,
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
|
import {
|
||||||
|
INumberFormatQuery,
|
||||||
|
} from './FinancialStatements';
|
||||||
|
|
||||||
export interface IProfitLossSheetQuery {
|
export interface IProfitLossSheetQuery {
|
||||||
basis: string,
|
basis: string,
|
||||||
fromDate: Date | string,
|
fromDate: Date | string,
|
||||||
toDate: Date | string,
|
toDate: Date | string,
|
||||||
numberFormat: {
|
numberFormat: INumberFormatQuery,
|
||||||
noCents: boolean,
|
|
||||||
divideOn1000: boolean,
|
|
||||||
},
|
|
||||||
noneZero: boolean,
|
noneZero: boolean,
|
||||||
noneTransactions: boolean,
|
noneTransactions: boolean,
|
||||||
accountsIds: number[],
|
accountsIds: number[],
|
||||||
@@ -34,8 +33,8 @@ export interface IProfitLossSheetAccount {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export interface IProfitLossSheetAccountsSection {
|
export interface IProfitLossSheetAccountsSection {
|
||||||
sectionTitle: string,
|
name: string,
|
||||||
entryNormal: 'credit',
|
entryNormal: 'credit' | 'debit',
|
||||||
accounts: IProfitLossSheetAccount[],
|
accounts: IProfitLossSheetAccount[],
|
||||||
total: IProfitLossSheetTotal,
|
total: IProfitLossSheetTotal,
|
||||||
totalPeriods?: IProfitLossSheetTotal[],
|
totalPeriods?: IProfitLossSheetTotal[],
|
||||||
|
|||||||
@@ -1,38 +1,41 @@
|
|||||||
|
import { INumberFormatQuery } from './FinancialStatements';
|
||||||
|
|
||||||
export interface ITrialBalanceSheetQuery {
|
export interface ITrialBalanceSheetQuery {
|
||||||
fromDate: Date|string,
|
fromDate: Date | string;
|
||||||
toDate: Date|string,
|
toDate: Date | string;
|
||||||
numberFormat: {
|
numberFormat: INumberFormatQuery;
|
||||||
noCents: boolean,
|
basis: 'cash' | 'accural';
|
||||||
divideOn1000: boolean,
|
noneZero: boolean;
|
||||||
},
|
noneTransactions: boolean;
|
||||||
basis: 'cash' | 'accural',
|
accountIds: number[];
|
||||||
noneZero: boolean,
|
|
||||||
noneTransactions: boolean,
|
|
||||||
accountIds: number[],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ITrialBalanceAccount {
|
export interface ITrialBalanceTotal {
|
||||||
id: number,
|
credit: number;
|
||||||
parentAccountId: number,
|
debit: number;
|
||||||
name: string,
|
balance: number;
|
||||||
code: string,
|
currencyCode: string;
|
||||||
accountNormal: string,
|
|
||||||
hasTransactions: boolean,
|
|
||||||
|
|
||||||
credit: number,
|
formattedCredit: string;
|
||||||
debit: number,
|
formattedDebit: string;
|
||||||
balance: number,
|
formattedBalance: string;
|
||||||
currencyCode: string,
|
|
||||||
|
|
||||||
formattedCredit: string,
|
|
||||||
formattedDebit: string,
|
|
||||||
formattedBalance: string,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ITrialBalanceSheetData = IBalanceSheetSection[];
|
export interface ITrialBalanceAccount extends ITrialBalanceTotal {
|
||||||
|
id: number;
|
||||||
|
parentAccountId: number;
|
||||||
|
name: string;
|
||||||
|
code: string;
|
||||||
|
accountNormal: string;
|
||||||
|
hasTransactions: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ITrialBalanceSheetData = {
|
||||||
|
accounts: ITrialBalanceAccount[];
|
||||||
|
total: ITrialBalanceTotal;
|
||||||
|
};
|
||||||
|
|
||||||
export interface ITrialBalanceStatement {
|
export interface ITrialBalanceStatement {
|
||||||
data: ITrialBalanceSheetData,
|
data: ITrialBalanceSheetData;
|
||||||
query: ITrialBalanceSheetQuery,
|
query: ITrialBalanceSheetQuery;
|
||||||
}
|
}
|
||||||
@@ -15,14 +15,17 @@ export default class PayableAgingSummaryService {
|
|||||||
/**
|
/**
|
||||||
* Default report query.
|
* Default report query.
|
||||||
*/
|
*/
|
||||||
get defaultQuery() {
|
get defaultQuery(): IAPAgingSummaryQuery {
|
||||||
return {
|
return {
|
||||||
asDate: moment().format('YYYY-MM-DD'),
|
asDate: moment().format('YYYY-MM-DD'),
|
||||||
agingDaysBefore: 30,
|
agingDaysBefore: 30,
|
||||||
agingPeriods: 3,
|
agingPeriods: 3,
|
||||||
numberFormat: {
|
numberFormat: {
|
||||||
noCents: false,
|
precision: 2,
|
||||||
divideOn1000: false,
|
divideOn1000: false,
|
||||||
|
showZero: false,
|
||||||
|
formatMoney: 'total',
|
||||||
|
negativeFormat: 'mines'
|
||||||
},
|
},
|
||||||
vendorsIds: [],
|
vendorsIds: [],
|
||||||
noneZero: false,
|
noneZero: false,
|
||||||
|
|||||||
@@ -15,14 +15,17 @@ export default class ARAgingSummaryService {
|
|||||||
/**
|
/**
|
||||||
* Default report query.
|
* Default report query.
|
||||||
*/
|
*/
|
||||||
get defaultQuery() {
|
get defaultQuery(): IARAgingSummaryQuery {
|
||||||
return {
|
return {
|
||||||
asDate: moment().format('YYYY-MM-DD'),
|
asDate: moment().format('YYYY-MM-DD'),
|
||||||
agingDaysBefore: 30,
|
agingDaysBefore: 30,
|
||||||
agingPeriods: 3,
|
agingPeriods: 3,
|
||||||
numberFormat: {
|
numberFormat: {
|
||||||
no_cents: false,
|
divideOn1000: false,
|
||||||
divide_1000: false,
|
negativeFormat: 'mines',
|
||||||
|
showZero: false,
|
||||||
|
formatMoney: 'total',
|
||||||
|
precision: 2,
|
||||||
},
|
},
|
||||||
customersIds: [],
|
customersIds: [],
|
||||||
noneZero: false,
|
noneZero: false,
|
||||||
@@ -50,6 +53,7 @@ export default class ARAgingSummaryService {
|
|||||||
});
|
});
|
||||||
// Settings tenant service.
|
// Settings tenant service.
|
||||||
const settings = this.tenancy.settings(tenantId);
|
const settings = this.tenancy.settings(tenantId);
|
||||||
|
|
||||||
const baseCurrency = settings.get({
|
const baseCurrency = settings.get({
|
||||||
group: 'organization',
|
group: 'organization',
|
||||||
key: 'base_currency',
|
key: 'base_currency',
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export default class ARAgingSummarySheet extends AgingSummaryReport {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
customerName: customer.displayName,
|
customerName: customer.displayName,
|
||||||
current: this.formatTotalAmount(currentTotal),
|
current: this.formatAmount(currentTotal),
|
||||||
aging: agingPeriods,
|
aging: agingPeriods,
|
||||||
total: this.formatTotalAmount(amount),
|
total: this.formatTotalAmount(amount),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
IARAgingSummaryCustomer,
|
IARAgingSummaryCustomer,
|
||||||
IContact,
|
IContact,
|
||||||
IARAgingSummaryQuery,
|
IARAgingSummaryQuery,
|
||||||
|
IFormatNumberSettings,
|
||||||
} from 'interfaces';
|
} from 'interfaces';
|
||||||
import AgingReport from './AgingReport';
|
import AgingReport from './AgingReport';
|
||||||
import { Dictionary } from 'tsyringe/dist/typings/types';
|
import { Dictionary } from 'tsyringe/dist/typings/types';
|
||||||
@@ -30,7 +31,7 @@ export default abstract class AgingSummaryReport extends AgingReport {
|
|||||||
protected getInitialAgingPeriodsTotal() {
|
protected getInitialAgingPeriodsTotal() {
|
||||||
return this.agingPeriods.map((agingPeriod) => ({
|
return this.agingPeriods.map((agingPeriod) => ({
|
||||||
...agingPeriod,
|
...agingPeriod,
|
||||||
...this.formatTotalAmount(0),
|
...this.formatAmount(0),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,11 +72,14 @@ export default abstract class AgingSummaryReport extends AgingReport {
|
|||||||
agingPeriod.beforeDays <= overdueDays &&
|
agingPeriod.beforeDays <= overdueDays &&
|
||||||
(agingPeriod.toDays > overdueDays || !agingPeriod.toDays);
|
(agingPeriod.toDays > overdueDays || !agingPeriod.toDays);
|
||||||
|
|
||||||
|
const total = isInAgingPeriod
|
||||||
|
? agingPeriod.total + dueAmount
|
||||||
|
: agingPeriod.total;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...agingPeriod,
|
...agingPeriod,
|
||||||
total: isInAgingPeriod
|
total,
|
||||||
? agingPeriod.total + dueAmount
|
formattedAmount: this.formatAmount(total),
|
||||||
: agingPeriod.total,
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return newAgingPeriods;
|
return newAgingPeriods;
|
||||||
@@ -86,14 +90,28 @@ export default abstract class AgingSummaryReport extends AgingReport {
|
|||||||
* @param {number} amount
|
* @param {number} amount
|
||||||
* @return {IAgingPeriodTotal}
|
* @return {IAgingPeriodTotal}
|
||||||
*/
|
*/
|
||||||
protected formatTotalAmount(amount: number): IAgingPeriodTotal {
|
protected formatAmount(
|
||||||
|
amount: number,
|
||||||
|
settings: IFormatNumberSettings = {}
|
||||||
|
): IAgingPeriodTotal {
|
||||||
return {
|
return {
|
||||||
total: amount,
|
total: amount,
|
||||||
formattedTotal: this.formatNumber(amount),
|
formattedTotal: this.formatNumber(amount, settings),
|
||||||
currencyCode: this.baseCurrency,
|
currencyCode: this.baseCurrency,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected formatTotalAmount(
|
||||||
|
amount: number,
|
||||||
|
settings: IFormatNumberSettings = {}
|
||||||
|
): IAgingPeriodTotal {
|
||||||
|
return this.formatAmount(amount, {
|
||||||
|
money: true,
|
||||||
|
excerptZero: false,
|
||||||
|
...settings
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the total of the aging period by the given index.
|
* Calculates the total of the aging period by the given index.
|
||||||
* @param {number} index
|
* @param {number} index
|
||||||
@@ -142,7 +160,7 @@ export default abstract class AgingSummaryReport extends AgingReport {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the current invoices by the given contact id.
|
* Retrieve the current invoices by the given contact id.
|
||||||
* @param {number} contactId
|
* @param {number} contactId - Specific contact id.
|
||||||
* @return {(ISaleInvoice | IBill)[]}
|
* @return {(ISaleInvoice | IBill)[]}
|
||||||
*/
|
*/
|
||||||
protected getCurrentInvoicesByContactId(
|
protected getCurrentInvoicesByContactId(
|
||||||
@@ -153,12 +171,12 @@ export default abstract class AgingSummaryReport extends AgingReport {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the contact total due amount.
|
* Retrieve the contact total due amount.
|
||||||
* @param {number} contactId
|
* @param {number} contactId - Specific contact id.
|
||||||
* @return {number}
|
* @return {number}
|
||||||
*/
|
*/
|
||||||
protected getContactCurrentTotal(contactId: number): number {
|
protected getContactCurrentTotal(contactId: number): number {
|
||||||
const currentInvoices = this.getCurrentInvoicesByContactId(contactId);
|
const currentInvoices = this.getCurrentInvoicesByContactId(contactId);
|
||||||
return sumBy(currentInvoices, invoice => invoice.dueAmount);
|
return sumBy(currentInvoices, (invoice) => invoice.dueAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -169,7 +187,7 @@ export default abstract class AgingSummaryReport extends AgingReport {
|
|||||||
protected getTotalCurrent(
|
protected getTotalCurrent(
|
||||||
customersSummary: IARAgingSummaryCustomer[]
|
customersSummary: IARAgingSummaryCustomer[]
|
||||||
): number {
|
): number {
|
||||||
return sumBy(customersSummary, summary => summary.current.total);
|
return sumBy(customersSummary, (summary) => summary.current.total);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -177,9 +195,7 @@ export default abstract class AgingSummaryReport extends AgingReport {
|
|||||||
* @param {IAgingPeriodTotal[]} agingPeriods
|
* @param {IAgingPeriodTotal[]} agingPeriods
|
||||||
* @return {number}
|
* @return {number}
|
||||||
*/
|
*/
|
||||||
protected getAgingPeriodsTotal(
|
protected getAgingPeriodsTotal(agingPeriods: IAgingPeriodTotal[]): number {
|
||||||
agingPeriods: IAgingPeriodTotal[],
|
|
||||||
): number {
|
|
||||||
return sumBy(agingPeriods, 'total');
|
return sumBy(agingPeriods, 'total');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ export default class BalanceSheetStatement extends FinancialSheet {
|
|||||||
sections: IBalanceSheetSection[]
|
sections: IBalanceSheetSection[]
|
||||||
): IBalanceSheetAccountTotal {
|
): IBalanceSheetAccountTotal {
|
||||||
const amount = sumBy(sections, 'total.amount');
|
const amount = sumBy(sections, 'total.amount');
|
||||||
const formattedAmount = this.formatNumber(amount);
|
const formattedAmount = this.formatTotalNumber(amount);
|
||||||
const currencyCode = this.baseCurrency;
|
const currencyCode = this.baseCurrency;
|
||||||
|
|
||||||
return { amount, formattedAmount, currencyCode };
|
return { amount, formattedAmount, currencyCode };
|
||||||
@@ -89,7 +89,25 @@ export default class BalanceSheetStatement extends FinancialSheet {
|
|||||||
): IBalanceSheetAccountTotal[] {
|
): IBalanceSheetAccountTotal[] {
|
||||||
return this.dateRangeSet.map((date, index) => {
|
return this.dateRangeSet.map((date, index) => {
|
||||||
const amount = sumBy(sections, `totalPeriods[${index}].amount`);
|
const amount = sumBy(sections, `totalPeriods[${index}].amount`);
|
||||||
const formattedAmount = this.formatNumber(amount);
|
|
||||||
|
const formattedAmount = this.formatTotalNumber(amount);
|
||||||
|
const currencyCode = this.baseCurrency;
|
||||||
|
|
||||||
|
return { date, amount, formattedAmount, currencyCode };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve accounts total periods.
|
||||||
|
* @param {Array<IBalanceSheetAccount>} accounts -
|
||||||
|
* @return {IBalanceSheetAccountTotal[]}
|
||||||
|
*/
|
||||||
|
private getAccountsTotalPeriods(
|
||||||
|
accounts: Array<IBalanceSheetAccount>
|
||||||
|
): IBalanceSheetAccountTotal[] {
|
||||||
|
return this.dateRangeSet.map((date, index) => {
|
||||||
|
const amount = sumBy(accounts, `totalPeriods[${index}].amount`);
|
||||||
|
const formattedAmount = this.formatNumber(amount)
|
||||||
const currencyCode = this.baseCurrency;
|
const currencyCode = this.baseCurrency;
|
||||||
|
|
||||||
return { date, amount, formattedAmount, currencyCode };
|
return { date, amount, formattedAmount, currencyCode };
|
||||||
@@ -190,12 +208,12 @@ export default class BalanceSheetStatement extends FinancialSheet {
|
|||||||
}),
|
}),
|
||||||
total: {
|
total: {
|
||||||
amount: totalAmount,
|
amount: totalAmount,
|
||||||
formattedAmount: this.formatNumber(totalAmount),
|
formattedAmount: this.formatTotalNumber(totalAmount),
|
||||||
currencyCode: this.baseCurrency,
|
currencyCode: this.baseCurrency,
|
||||||
},
|
},
|
||||||
...(this.query.displayColumnsType === 'date_periods'
|
...(this.query.displayColumnsType === 'date_periods'
|
||||||
? {
|
? {
|
||||||
totalPeriods: this.getSectionTotalPeriods(filteredAccounts),
|
totalPeriods: this.getAccountsTotalPeriods(filteredAccounts),
|
||||||
}
|
}
|
||||||
: {}),
|
: {}),
|
||||||
};
|
};
|
||||||
@@ -232,7 +250,7 @@ export default class BalanceSheetStatement extends FinancialSheet {
|
|||||||
*/
|
*/
|
||||||
private balanceSheetStructureMapper(
|
private balanceSheetStructureMapper(
|
||||||
structure: IBalanceSheetStructureSection,
|
structure: IBalanceSheetStructureSection,
|
||||||
accounts: IAccount & { type: IAccountType }[]
|
accounts: IAccount & { type: IAccountType }[],
|
||||||
): IBalanceSheetSection {
|
): IBalanceSheetSection {
|
||||||
const result = {
|
const result = {
|
||||||
name: structure.name,
|
name: structure.name,
|
||||||
@@ -276,14 +294,9 @@ export default class BalanceSheetStatement extends FinancialSheet {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
// Mappes the balance sheet scetions only
|
// Mappes the balance sheet scetions only
|
||||||
.map(
|
.map(([sheetSection]: [IBalanceSheetSection]) => {
|
||||||
([sheetSection, structure]: [
|
|
||||||
IBalanceSheetSection,
|
|
||||||
IBalanceSheetStructureSection
|
|
||||||
]) => {
|
|
||||||
return sheetSection;
|
return sheetSection;
|
||||||
}
|
})
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,11 @@ export default class BalanceSheetStatementService
|
|||||||
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
||||||
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
||||||
numberFormat: {
|
numberFormat: {
|
||||||
noCents: false,
|
precision: 2,
|
||||||
divideOn1000: false,
|
divideOn1000: false,
|
||||||
|
showZero: false,
|
||||||
|
formatMoney: 'total',
|
||||||
|
negativeFormat: 'mines'
|
||||||
},
|
},
|
||||||
noneZero: false,
|
noneZero: false,
|
||||||
noneTransactions: false,
|
noneTransactions: false,
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ export default class ProfitLossSheet extends FinancialSheet {
|
|||||||
accounts: IProfitLossSheetAccount[]
|
accounts: IProfitLossSheetAccount[]
|
||||||
): IProfitLossSheetTotal {
|
): IProfitLossSheetTotal {
|
||||||
const amount = sumBy(accounts, 'total.amount');
|
const amount = sumBy(accounts, 'total.amount');
|
||||||
const formattedAmount = this.formatNumber(amount);
|
const formattedAmount = this.formatTotalNumber(amount);
|
||||||
const currencyCode = this.baseCurrency;
|
const currencyCode = this.baseCurrency;
|
||||||
|
|
||||||
return { amount, formattedAmount, currencyCode };
|
return { amount, formattedAmount, currencyCode };
|
||||||
@@ -203,7 +203,7 @@ export default class ProfitLossSheet extends FinancialSheet {
|
|||||||
): IProfitLossSheetTotal[] {
|
): IProfitLossSheetTotal[] {
|
||||||
return this.dateRangeSet.map((date, index) => {
|
return this.dateRangeSet.map((date, index) => {
|
||||||
const amount = sumBy(accounts, `totalPeriods[${index}].amount`);
|
const amount = sumBy(accounts, `totalPeriods[${index}].amount`);
|
||||||
const formattedAmount = this.formatNumber(amount);
|
const formattedAmount = this.formatTotalNumber(amount);
|
||||||
const currencyCode = this.baseCurrency;
|
const currencyCode = this.baseCurrency;
|
||||||
|
|
||||||
return { amount, formattedAmount, currencyCode };
|
return { amount, formattedAmount, currencyCode };
|
||||||
@@ -229,7 +229,7 @@ export default class ProfitLossSheet extends FinancialSheet {
|
|||||||
*/
|
*/
|
||||||
private get incomeSection(): IProfitLossSheetAccountsSection {
|
private get incomeSection(): IProfitLossSheetAccountsSection {
|
||||||
return {
|
return {
|
||||||
sectionTitle: 'Income accounts',
|
name: 'Income accounts',
|
||||||
entryNormal: 'credit',
|
entryNormal: 'credit',
|
||||||
...this.sectionMapper(this.incomeAccounts),
|
...this.sectionMapper(this.incomeAccounts),
|
||||||
};
|
};
|
||||||
@@ -241,7 +241,7 @@ export default class ProfitLossSheet extends FinancialSheet {
|
|||||||
*/
|
*/
|
||||||
private get expensesSection(): IProfitLossSheetAccountsSection {
|
private get expensesSection(): IProfitLossSheetAccountsSection {
|
||||||
return {
|
return {
|
||||||
sectionTitle: 'Expense accounts',
|
name: 'Expense accounts',
|
||||||
entryNormal: 'debit',
|
entryNormal: 'debit',
|
||||||
...this.sectionMapper(this.expensesAccounts),
|
...this.sectionMapper(this.expensesAccounts),
|
||||||
};
|
};
|
||||||
@@ -253,7 +253,7 @@ export default class ProfitLossSheet extends FinancialSheet {
|
|||||||
*/
|
*/
|
||||||
private get otherExpensesSection(): IProfitLossSheetAccountsSection {
|
private get otherExpensesSection(): IProfitLossSheetAccountsSection {
|
||||||
return {
|
return {
|
||||||
sectionTitle: 'Other expenses accounts',
|
name: 'Other expenses accounts',
|
||||||
entryNormal: 'debit',
|
entryNormal: 'debit',
|
||||||
...this.sectionMapper(this.otherExpensesAccounts),
|
...this.sectionMapper(this.otherExpensesAccounts),
|
||||||
};
|
};
|
||||||
@@ -265,7 +265,7 @@ export default class ProfitLossSheet extends FinancialSheet {
|
|||||||
*/
|
*/
|
||||||
private get costOfSalesSection(): IProfitLossSheetAccountsSection {
|
private get costOfSalesSection(): IProfitLossSheetAccountsSection {
|
||||||
return {
|
return {
|
||||||
sectionTitle: 'Cost of sales',
|
name: 'Cost of sales',
|
||||||
entryNormal: 'debit',
|
entryNormal: 'debit',
|
||||||
...this.sectionMapper(this.costOfSalesAccounts),
|
...this.sectionMapper(this.costOfSalesAccounts),
|
||||||
};
|
};
|
||||||
@@ -283,7 +283,7 @@ export default class ProfitLossSheet extends FinancialSheet {
|
|||||||
const totalMines = sumBy(minesSections, `totalPeriods[${index}].amount`);
|
const totalMines = sumBy(minesSections, `totalPeriods[${index}].amount`);
|
||||||
|
|
||||||
const amount = totalPositive - totalMines;
|
const amount = totalPositive - totalMines;
|
||||||
const formattedAmount = this.formatNumber(amount);
|
const formattedAmount = this.formatTotalNumber(amount);
|
||||||
const currencyCode = this.baseCurrency;
|
const currencyCode = this.baseCurrency;
|
||||||
|
|
||||||
return { date, amount, formattedAmount, currencyCode };
|
return { date, amount, formattedAmount, currencyCode };
|
||||||
@@ -298,7 +298,7 @@ export default class ProfitLossSheet extends FinancialSheet {
|
|||||||
const totalMinesSections = sumBy(minesSections, 'total.amount');
|
const totalMinesSections = sumBy(minesSections, 'total.amount');
|
||||||
|
|
||||||
const amount = totalPositiveSections - totalMinesSections;
|
const amount = totalPositiveSections - totalMinesSections;
|
||||||
const formattedAmount = this.formatNumber(amount);
|
const formattedAmount = this.formatTotalNumber(amount);
|
||||||
const currencyCode = this.baseCurrency;
|
const currencyCode = this.baseCurrency;
|
||||||
|
|
||||||
return { amount, formattedAmount, currencyCode };
|
return { amount, formattedAmount, currencyCode };
|
||||||
|
|||||||
@@ -27,8 +27,11 @@ export default class ProfitLossSheetService {
|
|||||||
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
||||||
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
||||||
numberFormat: {
|
numberFormat: {
|
||||||
noCents: false,
|
|
||||||
divideOn1000: false,
|
divideOn1000: false,
|
||||||
|
negativeFormat: 'mines',
|
||||||
|
showZero: false,
|
||||||
|
formatMoney: 'total',
|
||||||
|
precision: 2,
|
||||||
},
|
},
|
||||||
basis: 'accural',
|
basis: 'accural',
|
||||||
noneZero: false,
|
noneZero: false,
|
||||||
@@ -55,16 +58,24 @@ export default class ProfitLossSheetService {
|
|||||||
...this.defaultQuery,
|
...this.defaultQuery,
|
||||||
...query,
|
...query,
|
||||||
};
|
};
|
||||||
this.logger.info('[profit_loss_sheet] trying to calculate the report.', { tenantId, filter });
|
this.logger.info('[profit_loss_sheet] trying to calculate the report.', {
|
||||||
|
tenantId,
|
||||||
|
filter,
|
||||||
|
});
|
||||||
|
|
||||||
// Get the given accounts or throw not found service error.
|
// Get the given accounts or throw not found service error.
|
||||||
if (filter.accountsIds.length > 0) {
|
if (filter.accountsIds.length > 0) {
|
||||||
await this.accountsService.getAccountsOrThrowError(tenantId, filter.accountsIds);
|
await this.accountsService.getAccountsOrThrowError(
|
||||||
|
tenantId,
|
||||||
|
filter.accountsIds
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// Settings tenant service.
|
// Settings tenant service.
|
||||||
const settings = this.tenancy.settings(tenantId);
|
const settings = this.tenancy.settings(tenantId);
|
||||||
const baseCurrency = settings.get({ group: 'organization', key: 'base_currency' });
|
const baseCurrency = settings.get({
|
||||||
|
group: 'organization',
|
||||||
|
key: 'base_currency',
|
||||||
|
});
|
||||||
// Retrieve all accounts on the storage.
|
// Retrieve all accounts on the storage.
|
||||||
const accounts = await accountRepository.all('type');
|
const accounts = await accountRepository.all('type');
|
||||||
const accountsGraph = await accountRepository.getDependencyGraph();
|
const accountsGraph = await accountRepository.getDependencyGraph();
|
||||||
@@ -75,8 +86,11 @@ export default class ProfitLossSheetService {
|
|||||||
toDate: query.toDate,
|
toDate: query.toDate,
|
||||||
});
|
});
|
||||||
// Transform transactions to journal collection.
|
// Transform transactions to journal collection.
|
||||||
const transactionsJournal = Journal.fromTransactions(transactions, tenantId, accountsGraph);
|
const transactionsJournal = Journal.fromTransactions(
|
||||||
|
transactions,
|
||||||
|
tenantId,
|
||||||
|
accountsGraph
|
||||||
|
);
|
||||||
// Profit/Loss report instance.
|
// Profit/Loss report instance.
|
||||||
const profitLossInstance = new ProfitLossSheet(
|
const profitLossInstance = new ProfitLossSheet(
|
||||||
tenantId,
|
tenantId,
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
|
import { sumBy } from 'lodash';
|
||||||
import {
|
import {
|
||||||
ITrialBalanceSheetQuery,
|
ITrialBalanceSheetQuery,
|
||||||
ITrialBalanceAccount,
|
ITrialBalanceAccount,
|
||||||
IAccount,
|
IAccount,
|
||||||
|
ITrialBalanceTotal,
|
||||||
IAccountType,
|
IAccountType,
|
||||||
} from 'interfaces';
|
} from 'interfaces';
|
||||||
import FinancialSheet from '../FinancialSheet';
|
import FinancialSheet from '../FinancialSheet';
|
||||||
import { flatToNestedArray } from 'utils';
|
import { flatToNestedArray } from 'utils';
|
||||||
|
|
||||||
|
const AMOUNT_TYPE = {
|
||||||
|
TOTAL: 'TOTAL',
|
||||||
|
SECTION_TOTAL: 'SECTION_TOTAL',
|
||||||
|
};
|
||||||
|
|
||||||
export default class TrialBalanceSheet extends FinancialSheet {
|
export default class TrialBalanceSheet extends FinancialSheet {
|
||||||
tenantId: number;
|
tenantId: number;
|
||||||
query: ITrialBalanceSheetQuery;
|
query: ITrialBalanceSheetQuery;
|
||||||
@@ -103,10 +110,37 @@ export default class TrialBalanceSheet extends FinancialSheet {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve trial balance total section.
|
||||||
|
* @param {ITrialBalanceAccount[]} accountsBalances
|
||||||
|
* @return {ITrialBalanceTotal}
|
||||||
|
*/
|
||||||
|
private tatalSection(
|
||||||
|
accountsBalances: ITrialBalanceAccount[]
|
||||||
|
): ITrialBalanceTotal {
|
||||||
|
const credit = sumBy(accountsBalances, 'credit');
|
||||||
|
const debit = sumBy(accountsBalances, 'debit');
|
||||||
|
const balance = sumBy(accountsBalances, 'balance');
|
||||||
|
const currencyCode = this.baseCurrency;
|
||||||
|
|
||||||
|
return {
|
||||||
|
credit,
|
||||||
|
debit,
|
||||||
|
balance,
|
||||||
|
currencyCode,
|
||||||
|
formattedCredit: this.formatTotalNumber(credit),
|
||||||
|
formattedDebit: this.formatTotalNumber(debit),
|
||||||
|
formattedBalance: this.formatTotalNumber(balance),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve trial balance sheet statement data.
|
* Retrieve trial balance sheet statement data.
|
||||||
*/
|
*/
|
||||||
public reportData() {
|
public reportData() {
|
||||||
return this.accountsWalker(this.accounts);
|
const accounts = this.accountsWalker(this.accounts);
|
||||||
|
const total = this.tatalSection(accounts);
|
||||||
|
|
||||||
|
return { accounts, total };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import TenancyService from 'services/Tenancy/TenancyService';
|
import TenancyService from 'services/Tenancy/TenancyService';
|
||||||
import { ITrialBalanceSheetQuery, ITrialBalanceStatement } from 'interfaces';
|
|
||||||
import TrialBalanceSheet from './TrialBalanceSheet';
|
|
||||||
import Journal from 'services/Accounting/JournalPoster';
|
import Journal from 'services/Accounting/JournalPoster';
|
||||||
|
import { INumberFormatQuery, ITrialBalanceSheetQuery, ITrialBalanceStatement } from 'interfaces';
|
||||||
|
import TrialBalanceSheet from './TrialBalanceSheet';
|
||||||
|
import FinancialSheet from '../FinancialSheet';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class TrialBalanceSheetService {
|
export default class TrialBalanceSheetService extends FinancialSheet {
|
||||||
@Inject()
|
@Inject()
|
||||||
tenancy: TenancyService;
|
tenancy: TenancyService;
|
||||||
|
|
||||||
@@ -22,8 +23,11 @@ export default class TrialBalanceSheetService {
|
|||||||
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
||||||
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
||||||
numberFormat: {
|
numberFormat: {
|
||||||
noCents: false,
|
|
||||||
divideOn1000: false,
|
divideOn1000: false,
|
||||||
|
negativeFormat: 'mines',
|
||||||
|
showZero: false,
|
||||||
|
formatMoney: 'total',
|
||||||
|
precision: 2,
|
||||||
},
|
},
|
||||||
basis: 'accural',
|
basis: 'accural',
|
||||||
noneZero: false,
|
noneZero: false,
|
||||||
@@ -42,7 +46,7 @@ export default class TrialBalanceSheetService {
|
|||||||
*/
|
*/
|
||||||
public async trialBalanceSheet(
|
public async trialBalanceSheet(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
query: ITrialBalanceSheetQuery
|
query: ITrialBalanceSheetQuery,
|
||||||
): Promise<ITrialBalanceStatement> {
|
): Promise<ITrialBalanceStatement> {
|
||||||
const filter = {
|
const filter = {
|
||||||
...this.defaultQuery,
|
...this.defaultQuery,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import bcrypt from 'bcryptjs';
|
import bcrypt from 'bcryptjs';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import accounting from 'accounting';
|
||||||
import definedOptions from 'data/options';
|
import definedOptions from 'data/options';
|
||||||
|
|
||||||
const hashPassword = (password) =>
|
const hashPassword = (password) =>
|
||||||
@@ -192,7 +193,7 @@ const entriesAmountDiff = (
|
|||||||
.groupBy(idAttribute)
|
.groupBy(idAttribute)
|
||||||
.mapValues((group) => _.sumBy(group, amountAttribute) || 0)
|
.mapValues((group) => _.sumBy(group, amountAttribute) || 0)
|
||||||
.mergeWith(oldEntriesTable, (objValue, srcValue) => {
|
.mergeWith(oldEntriesTable, (objValue, srcValue) => {
|
||||||
return (_.isNumber(objValue) ? objValue - srcValue : srcValue * -1);
|
return _.isNumber(objValue) ? objValue - srcValue : srcValue * -1;
|
||||||
})
|
})
|
||||||
.value();
|
.value();
|
||||||
|
|
||||||
@@ -214,27 +215,56 @@ const convertEmptyStringToNull = (value) => {
|
|||||||
: value;
|
: value;
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatNumber = (balance, { noCents = false, divideOn1000 = false }) => {
|
const getNegativeFormat = (formatName) => {
|
||||||
|
switch (formatName) {
|
||||||
|
case 'parentheses':
|
||||||
|
return '(%s%v)';
|
||||||
|
case 'mines':
|
||||||
|
return '-%s%v';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatNumber = (
|
||||||
|
balance,
|
||||||
|
{
|
||||||
|
precision = 2,
|
||||||
|
divideOn1000 = false,
|
||||||
|
excerptZero = false,
|
||||||
|
negativeFormat = 'mines',
|
||||||
|
thousand = ',',
|
||||||
|
decimal = '.',
|
||||||
|
zeroSign = '',
|
||||||
|
symbol = '$',
|
||||||
|
money = true,
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
const negForamt = getNegativeFormat(negativeFormat);
|
||||||
|
const format = '%s%v';
|
||||||
|
|
||||||
let formattedBalance = parseFloat(balance);
|
let formattedBalance = parseFloat(balance);
|
||||||
|
|
||||||
if (noCents) {
|
|
||||||
formattedBalance = parseInt(formattedBalance, 10);
|
|
||||||
}
|
|
||||||
if (divideOn1000) {
|
if (divideOn1000) {
|
||||||
formattedBalance /= 1000;
|
formattedBalance /= 1000;
|
||||||
}
|
}
|
||||||
return formattedBalance + '';
|
return accounting.formatMoney(
|
||||||
|
formattedBalance,
|
||||||
|
money ? symbol : '',
|
||||||
|
precision,
|
||||||
|
thousand,
|
||||||
|
decimal,
|
||||||
|
{
|
||||||
|
pos: format,
|
||||||
|
neg: negForamt,
|
||||||
|
zero: excerptZero ? zeroSign : format,
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const isBlank = (value) => {
|
const isBlank = (value) => {
|
||||||
return _.isEmpty(value) && !_.isNumber(value) || _.isNaN(value);
|
return (_.isEmpty(value) && !_.isNumber(value)) || _.isNaN(value);
|
||||||
}
|
};
|
||||||
|
|
||||||
function defaultToTransform(
|
function defaultToTransform(value, defaultOrTransformedValue, defaultValue) {
|
||||||
value,
|
|
||||||
defaultOrTransformedValue,
|
|
||||||
defaultValue,
|
|
||||||
) {
|
|
||||||
const _defaultValue =
|
const _defaultValue =
|
||||||
typeof defaultValue === 'undefined'
|
typeof defaultValue === 'undefined'
|
||||||
? defaultOrTransformedValue
|
? defaultOrTransformedValue
|
||||||
@@ -248,7 +278,6 @@ function defaultToTransform(
|
|||||||
: _transfromedValue;
|
: _transfromedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
hashPassword,
|
hashPassword,
|
||||||
origin,
|
origin,
|
||||||
|
|||||||
Reference in New Issue
Block a user