diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts index deab37677f..8491557b64 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts @@ -154,7 +154,7 @@ describe( }, ]); }); - + // TODO: Add test for full-time. it( "Should create a notification for the ministry and student for a blocked disbursement when the total assessed award is 0" + " and there are no previously existing notifications for the disbursement.", diff --git a/sources/packages/backend/libs/integrations/src/services/disbursement-schedule/e-cert-calculation/part-time-calculation-process.ts b/sources/packages/backend/libs/integrations/src/services/disbursement-schedule/e-cert-calculation/part-time-calculation-process.ts index 8552093e87..6570ad58d9 100644 --- a/sources/packages/backend/libs/integrations/src/services/disbursement-schedule/e-cert-calculation/part-time-calculation-process.ts +++ b/sources/packages/backend/libs/integrations/src/services/disbursement-schedule/e-cert-calculation/part-time-calculation-process.ts @@ -8,6 +8,7 @@ import { CreateBCTotalGrantsStep, PersistCalculationsStep, ValidateDisbursementPartTimeStep, + ApplyStopBCFundingRestrictionPartTimeStep, RestrictionBypassesResolutionStep, } from "../e-cert-processing-steps"; import { ECertGenerationService } from "../e-cert-generation.service"; @@ -30,6 +31,7 @@ export class PartTimeCalculationProcess extends ECertCalculationProcess { private readonly createBCTotalGrantsStep: CreateBCTotalGrantsStep, private readonly persistCalculationsStep: PersistCalculationsStep, private readonly restrictionBypassesResolutionStep: RestrictionBypassesResolutionStep, + private readonly applyStopBCFundingRestrictionPartTimeStep: ApplyStopBCFundingRestrictionPartTimeStep, ) { super(dataSource, eCertNotificationService); } @@ -61,6 +63,7 @@ export class PartTimeCalculationProcess extends ECertCalculationProcess { this.createBCTotalGrantsStep, this.persistCalculationsStep, this.restrictionBypassesResolutionStep, + this.applyStopBCFundingRestrictionPartTimeStep, ]; } } diff --git a/sources/packages/backend/libs/integrations/src/services/disbursement-schedule/e-cert-processing-steps/apply-stop-bc-funding-restriction-part-time-step.ts b/sources/packages/backend/libs/integrations/src/services/disbursement-schedule/e-cert-processing-steps/apply-stop-bc-funding-restriction-part-time-step.ts new file mode 100644 index 0000000000..4cb770be53 --- /dev/null +++ b/sources/packages/backend/libs/integrations/src/services/disbursement-schedule/e-cert-processing-steps/apply-stop-bc-funding-restriction-part-time-step.ts @@ -0,0 +1,55 @@ +import { Injectable } from "@nestjs/common"; +import { EntityManager } from "typeorm"; +import { Restriction, RestrictionActionType } from "@sims/sims-db"; +import { + getRestrictionByActionType, + shouldStopBCFunding, +} from "./e-cert-steps-utils"; +import { ECertProcessStep } from "./e-cert-steps-models"; +import { ProcessSummary } from "@sims/utilities/logger"; +import { EligibleECertDisbursement } from "../disbursement-schedule.models"; + +/** + * Check active student restriction that should stop + * any BC funding from being disbursed. + */ +@Injectable() +export class ApplyStopBCFundingRestrictionPartTimeStep + implements ECertProcessStep +{ + /** + * Check active student restriction that should stop any BC funding from being disbursed. + * In case some is present, BC awards will be updated to not be disbursed. + * @param eCertDisbursement eligible disbursement to be potentially added to an e-Cert. + * @param _entityManager not used for this step. + * @param log cumulative log summary. + */ + executeStep( + eCertDisbursement: EligibleECertDisbursement, + _entityManager: EntityManager, + log: ProcessSummary, + ): boolean { + log.info( + `Checking '${RestrictionActionType.StopPartTimeBCFunding}' restriction.`, + ); + for (const disbursementValue of eCertDisbursement.disbursement + .disbursementValues) { + if (shouldStopBCFunding(eCertDisbursement, disbursementValue)) { + log.info(`Applying restriction for ${disbursementValue.valueCode}.`); + const restriction = getRestrictionByActionType( + eCertDisbursement, + RestrictionActionType.StopPartTimeBCFunding, + ); + disbursementValue.restrictionAmountSubtracted = + disbursementValue.valueAmount - + (disbursementValue.disbursedAmountSubtracted ?? 0) - + (disbursementValue.overawardAmountSubtracted ?? 0); + disbursementValue.effectiveAmount = 0; + disbursementValue.restrictionSubtracted = { + id: restriction.id, + } as Restriction; + } + } + return true; + } +} diff --git a/sources/packages/backend/libs/integrations/src/services/disbursement-schedule/e-cert-processing-steps/index.ts b/sources/packages/backend/libs/integrations/src/services/disbursement-schedule/e-cert-processing-steps/index.ts index f241c92079..89c623729f 100644 --- a/sources/packages/backend/libs/integrations/src/services/disbursement-schedule/e-cert-processing-steps/index.ts +++ b/sources/packages/backend/libs/integrations/src/services/disbursement-schedule/e-cert-processing-steps/index.ts @@ -10,3 +10,4 @@ export * from "./validate-disbursement-base"; export * from "./validate-disbursement-full-time-step"; export * from "./validate-disbursement-part-time-step"; export * from "./restriction-bypasses-resolution-step"; +export * from "./apply-stop-bc-funding-restriction-part-time-step";