fix: AR/AP aging report

This commit is contained in:
Ahmed Bouhuolia
2025-06-21 20:15:42 +02:00
parent 4d52059dba
commit 91976842a7
23 changed files with 265 additions and 126 deletions

View File

@@ -2,7 +2,6 @@ import * as R from 'ramda';
import { isEmpty, sum } from 'lodash';
import { IAgingPeriod } from '../AgingSummary/AgingSummary.types';
import {
IARAgingSummaryQuery,
IARAgingSummaryCustomer,
IARAgingSummaryData,
IARAgingSummaryColumns,
@@ -11,23 +10,31 @@ import {
import { AgingSummaryReport } from '../AgingSummary/AgingSummary';
import { allPassedConditionsPass } from '@/utils/all-conditions-passed';
import { ModelObject } from 'objection';
import { Customer } from '@/modules/Customers/models/Customer';
import { ARAgingSummaryRepository } from './ARAgingSummaryRepository';
import { Customer } from '@/modules/Customers/models/Customer';
import { SaleInvoice } from '@/modules/SaleInvoices/models/SaleInvoice';
import { ARAgingSummaryQueryDto } from './ARAgingSummaryQuery.dto';
export class ARAgingSummarySheet extends AgingSummaryReport {
readonly query: IARAgingSummaryQuery;
readonly query: ARAgingSummaryQueryDto;
readonly agingPeriods: IAgingPeriod[];
readonly repository: ARAgingSummaryRepository;
readonly overdueInvoicesByContactId: Record<
string,
ModelObject<SaleInvoice>[]
>;
readonly currentInvoicesByContactId: Record<
number,
Array<ModelObject<SaleInvoice>>
>;
/**
* Constructor method.
* @param {number} tenantId
* @param {IARAgingSummaryQuery} query
* @param {ICustomer[]} customers
* @param {IJournalPoster} journal
* @param {ARAgingSummaryQueryDto} query - Query
* @param {ARAgingSummaryRepository} repository - Repository.
*/
constructor(
query: IARAgingSummaryQuery,
query: ARAgingSummaryQueryDto,
repository: ARAgingSummaryRepository,
) {
super();
@@ -36,6 +43,11 @@ export class ARAgingSummarySheet extends AgingSummaryReport {
this.repository = repository;
this.numberFormat = this.query.numberFormat;
this.overdueInvoicesByContactId =
this.repository.overdueInvoicesByContactId;
this.currentInvoicesByContactId =
this.repository.currentInvoicesByContactId;
// Initializes the aging periods.
this.agingPeriods = this.agingRangePeriods(
this.query.asDate,