mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
draft: AR and AP aging summary report.
This commit is contained in:
@@ -2,7 +2,6 @@ import moment from 'moment';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { IARAgingSummaryQuery } from 'interfaces';
|
||||
import TenancyService from 'services/Tenancy/TenancyService';
|
||||
import Journal from 'services/Accounting/JournalPoster';
|
||||
import ARAgingSummarySheet from './ARAgingSummarySheet';
|
||||
|
||||
@Service()
|
||||
@@ -31,63 +30,48 @@ export default class ARAgingSummaryService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retreive th accounts receivable aging summary data and columns.
|
||||
* @param {number} tenantId
|
||||
* @param query
|
||||
*
|
||||
* @param {number} tenantId
|
||||
* @param query
|
||||
*/
|
||||
async ARAgingSummary(tenantId: number, query: IARAgingSummaryQuery) {
|
||||
const {
|
||||
customerRepository,
|
||||
accountRepository,
|
||||
transactionsRepository,
|
||||
accountTypeRepository
|
||||
saleInvoiceRepository
|
||||
} = this.tenancy.repositories(tenantId);
|
||||
|
||||
const { Account } = this.tenancy.models(tenantId);
|
||||
const filter = {
|
||||
...this.defaultQuery,
|
||||
...query,
|
||||
};
|
||||
this.logger.info('[AR_Aging_Summary] try to calculate the report.', { tenantId, filter });
|
||||
|
||||
this.logger.info('[AR_Aging_Summary] try to calculate the report.', {
|
||||
tenantId,
|
||||
filter,
|
||||
});
|
||||
// Settings tenant service.
|
||||
const settings = this.tenancy.settings(tenantId);
|
||||
const baseCurrency = settings.get({ group: 'organization', key: 'base_currency' });
|
||||
|
||||
// Retrieve all accounts graph on the storage.
|
||||
const accountsGraph = await accountRepository.getDependencyGraph();
|
||||
|
||||
const baseCurrency = settings.get({
|
||||
group: 'organization',
|
||||
key: 'base_currency',
|
||||
});
|
||||
// Retrieve all customers from the storage.
|
||||
const customers = await customerRepository.all();
|
||||
|
||||
// Retrieve AR account type.
|
||||
const ARType = await accountTypeRepository.getByKey('accounts_receivable');
|
||||
// Retrieve all due sale invoices.
|
||||
const dueSaleInvoices = await saleInvoiceRepository.dueInvoices();
|
||||
|
||||
// Retreive AR account.
|
||||
const ARAccount = await Account.query().findOne('account_type_id', ARType.id);
|
||||
|
||||
// Retrieve journal transactions based on the given query.
|
||||
const transactions = await transactionsRepository.journal({
|
||||
toDate: filter.asDate,
|
||||
contactType: 'customer',
|
||||
contactsIds: customers.map(customer => customer.id),
|
||||
});
|
||||
// Converts transactions array to journal collection.
|
||||
const journal = Journal.fromTransactions(transactions, tenantId, accountsGraph);
|
||||
|
||||
// AR aging summary report instnace.
|
||||
// AR aging summary report instance.
|
||||
const ARAgingSummaryReport = new ARAgingSummarySheet(
|
||||
tenantId,
|
||||
filter,
|
||||
customers,
|
||||
journal,
|
||||
ARAccount,
|
||||
dueSaleInvoices,
|
||||
baseCurrency
|
||||
);
|
||||
// AR aging summary report data and columns.
|
||||
const data = ARAgingSummaryReport.reportData();
|
||||
const columns = ARAgingSummaryReport.reportColumns();
|
||||
|
||||
return { data, columns };
|
||||
return { data, columns, query: filter };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user