mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
feat: select customers/vendors in AR/AP summary aging report.
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
import { Router, Request, Response } 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 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 { findPhoneNumbersInText } from 'libphonenumber-js';
|
|
||||||
|
|
||||||
export default class APAgingSummaryReportController extends BaseController {
|
export default class APAgingSummaryReportController extends BaseController {
|
||||||
@Inject()
|
@Inject()
|
||||||
@@ -34,8 +33,9 @@ export default class APAgingSummaryReportController extends BaseController {
|
|||||||
query('aging_periods').optional().isNumeric().toInt(),
|
query('aging_periods').optional().isNumeric().toInt(),
|
||||||
query('number_format.no_cents').optional().isBoolean().toBoolean(),
|
query('number_format.no_cents').optional().isBoolean().toBoolean(),
|
||||||
query('number_format.1000_divide').optional().isBoolean().toBoolean(),
|
query('number_format.1000_divide').optional().isBoolean().toBoolean(),
|
||||||
query('vendors_ids.*').isNumeric().toInt(),
|
query('vendors_ids').optional().isArray({ min: 1 }),
|
||||||
query('none_zero').optional().isBoolean().toBoolean(),
|
query('vendors_ids.*').isInt({ min: 1 }).toInt(),
|
||||||
|
query('none_zero').default(true).isBoolean().toBoolean(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
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, oneOf } from 'express-validator';
|
import { query, oneOf } from 'express-validator';
|
||||||
|
import { IARAgingSummaryQuery } from 'interfaces';
|
||||||
import BaseController from '../BaseController';
|
import BaseController from '../BaseController';
|
||||||
import ARAgingSummaryService from 'services/FinancialStatements/AgingSummary/ARAgingSummaryService';
|
import ARAgingSummaryService from 'services/FinancialStatements/AgingSummary/ARAgingSummaryService';
|
||||||
|
|
||||||
@@ -34,13 +36,8 @@ export default class ARAgingSummaryReportController extends BaseController {
|
|||||||
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.no_cents').optional().isBoolean().toBoolean(),
|
||||||
query('number_format.1000_divide').optional().isBoolean().toBoolean(),
|
query('number_format.1000_divide').optional().isBoolean().toBoolean(),
|
||||||
oneOf(
|
query('customers_ids').optional().isArray({ min: 1 }),
|
||||||
[
|
query('customers_ids.*').isInt({ min: 1 }).toInt(),
|
||||||
query('customer_ids').optional().isArray({ min: 1 }),
|
|
||||||
query('customer_ids.*').isNumeric().toInt(),
|
|
||||||
],
|
|
||||||
[query('customer_ids').optional().isNumeric().toInt()]
|
|
||||||
),
|
|
||||||
query('none_zero').default(true).isBoolean().toBoolean(),
|
query('none_zero').default(true).isBoolean().toBoolean(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,9 +26,10 @@ export interface IARAgingSummaryTotal {
|
|||||||
current: IAgingPeriodTotal,
|
current: IAgingPeriodTotal,
|
||||||
aging: (IAgingPeriodTotal & IAgingPeriod)[],
|
aging: (IAgingPeriodTotal & IAgingPeriod)[],
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface IARAgingSummaryData {
|
export interface IARAgingSummaryData {
|
||||||
customers: IARAgingSummaryCustomer[],
|
customers: IARAgingSummaryCustomer[],
|
||||||
total: IARAgingSummaryTotal,
|
total: IARAgingSummaryTotal,
|
||||||
}
|
};
|
||||||
|
|
||||||
export type IARAgingSummaryColumns = IAgingPeriod[];
|
export type IARAgingSummaryColumns = IAgingPeriod[];
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { IAPAgingSummaryQuery } from 'interfaces';
|
||||||
import TenancyService from 'services/Tenancy/TenancyService';
|
import TenancyService from 'services/Tenancy/TenancyService';
|
||||||
import APAgingSummarySheet from './APAgingSummarySheet';
|
import APAgingSummarySheet from './APAgingSummarySheet';
|
||||||
|
|
||||||
@@ -25,27 +26,26 @@ export default class PayableAgingSummaryService {
|
|||||||
},
|
},
|
||||||
vendorsIds: [],
|
vendorsIds: [],
|
||||||
noneZero: false,
|
noneZero: false,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Retrieve A/P aging summary report.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId -
|
||||||
* @param query
|
* @param {IAPAgingSummaryQuery} query -
|
||||||
*/
|
*/
|
||||||
async APAgingSummary(tenantId: number, query) {
|
async APAgingSummary(tenantId: number, query: IAPAgingSummaryQuery) {
|
||||||
const {
|
const { vendorRepository, billRepository } = this.tenancy.repositories(
|
||||||
vendorRepository,
|
tenantId
|
||||||
billRepository
|
);
|
||||||
} = this.tenancy.repositories(tenantId);
|
|
||||||
const { Bill } = this.tenancy.models(tenantId);
|
|
||||||
|
|
||||||
const filter = {
|
const filter = {
|
||||||
...this.defaultQuery,
|
...this.defaultQuery,
|
||||||
...query,
|
...query,
|
||||||
};
|
};
|
||||||
this.logger.info('[AR_Aging_Summary] trying to prepairing the report.', {
|
this.logger.info('[AR_Aging_Summary] trying to prepairing the report.', {
|
||||||
tenantId, filter,
|
tenantId,
|
||||||
|
filter,
|
||||||
});
|
});
|
||||||
// Settings tenant service.
|
// Settings tenant service.
|
||||||
const settings = this.tenancy.settings(tenantId);
|
const settings = this.tenancy.settings(tenantId);
|
||||||
@@ -54,12 +54,15 @@ export default class PayableAgingSummaryService {
|
|||||||
key: 'base_currency',
|
key: 'base_currency',
|
||||||
});
|
});
|
||||||
// Retrieve all vendors from the storage.
|
// Retrieve all vendors from the storage.
|
||||||
const vendors = await vendorRepository.all();
|
const vendors =
|
||||||
|
filter.vendorsIds.length > 0
|
||||||
|
? await vendorRepository.findWhereIn('id', filter.vendorsIds)
|
||||||
|
: await vendorRepository.all();
|
||||||
|
|
||||||
// Retrieve all overdue vendors bills.
|
// Retrieve all overdue vendors bills.
|
||||||
const overdueBills = await billRepository.overdueBills(
|
const overdueBills = await billRepository.overdueBills(filter.asDate);
|
||||||
filter.asDate,
|
|
||||||
);
|
// Retrieve all due vendors bills.
|
||||||
const dueBills = await billRepository.dueBills(filter.asDate);
|
const dueBills = await billRepository.dueBills(filter.asDate);
|
||||||
|
|
||||||
// A/P aging summary report instance.
|
// A/P aging summary report instance.
|
||||||
@@ -69,7 +72,7 @@ export default class PayableAgingSummaryService {
|
|||||||
vendors,
|
vendors,
|
||||||
overdueBills,
|
overdueBills,
|
||||||
dueBills,
|
dueBills,
|
||||||
baseCurrency,
|
baseCurrency
|
||||||
);
|
);
|
||||||
// A/P aging summary report data and columns.
|
// A/P aging summary report data and columns.
|
||||||
const data = APAgingSummaryReport.reportData();
|
const data = APAgingSummaryReport.reportData();
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { Inject, Service } from 'typedi';
|
|||||||
import { IARAgingSummaryQuery } from 'interfaces';
|
import { IARAgingSummaryQuery } from 'interfaces';
|
||||||
import TenancyService from 'services/Tenancy/TenancyService';
|
import TenancyService from 'services/Tenancy/TenancyService';
|
||||||
import ARAgingSummarySheet from './ARAgingSummarySheet';
|
import ARAgingSummarySheet from './ARAgingSummarySheet';
|
||||||
import SaleInvoiceRepository from 'repositories/SaleInvoiceRepository';
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class ARAgingSummaryService {
|
export default class ARAgingSummaryService {
|
||||||
@@ -31,9 +30,9 @@ export default class ARAgingSummaryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Retrieve A/R aging summary report.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId - Tenant id.
|
||||||
* @param query
|
* @param {IARAgingSummaryQuery} query -
|
||||||
*/
|
*/
|
||||||
async ARAgingSummary(tenantId: number, query: IARAgingSummaryQuery) {
|
async ARAgingSummary(tenantId: number, query: IARAgingSummaryQuery) {
|
||||||
const {
|
const {
|
||||||
@@ -56,7 +55,10 @@ export default class ARAgingSummaryService {
|
|||||||
key: 'base_currency',
|
key: 'base_currency',
|
||||||
});
|
});
|
||||||
// Retrieve all customers from the storage.
|
// Retrieve all customers from the storage.
|
||||||
const customers = await customerRepository.all();
|
const customers =
|
||||||
|
filter.customersIds.length > 0
|
||||||
|
? await customerRepository.findWhereIn('id', filter.customersIds)
|
||||||
|
: await customerRepository.all();
|
||||||
|
|
||||||
// Retrieve all overdue sale invoices.
|
// Retrieve all overdue sale invoices.
|
||||||
const overdueSaleInvoices = await saleInvoiceRepository.overdueInvoices(
|
const overdueSaleInvoices = await saleInvoiceRepository.overdueInvoices(
|
||||||
|
|||||||
Reference in New Issue
Block a user