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