diff --git a/src/api/repositories/assessment/assessment-cslft-repository-v2.ts b/src/api/repositories/assessment/assessment-cslft-repository-v2.ts index dec5731f..f47756c9 100644 --- a/src/api/repositories/assessment/assessment-cslft-repository-v2.ts +++ b/src/api/repositories/assessment/assessment-cslft-repository-v2.ts @@ -110,23 +110,24 @@ export class AssessmentCslftRepositoryV2 { .first(); } - async create(fundingRequestId: number | string): Promise { + async create( + fundingRequestId: number | string, + assessmentId: number | string = 9999999 + ): Promise { await this.load(parseInt(`${fundingRequestId}`)); - /* if (ftLoan) csl_ft = Math.ceil(ftLoan.disbursed_amount); - if (ftGrant) csg_ft = Math.ceil(ftGrant.disbursed_amount); - if (ftDepGrant) csg_ftdep = Math.ceil(ftDepGrant.disbursed_amount); - if (disGrant) csg_d = Math.ceil(disGrant.disbursed_amount); - if (disSEGrant) csg_dse = Math.ceil(disSEGrant.disbursed_amount); - if (topup) topup_fund = Math.ceil(topup.disbursed_amount); */ - try { let assess = await this.calculateBase(); - assess.id = 9999999; + assess.id = parseInt(`${assessmentId}`); await this.calculateCosts(assess); await this.calculateContribution(assess); await this.calculateParental(assess); + + let full = await this.postLoad(assess, this.application.id); + + assess.csl_assessed_need = full.csl_assessed_need; + await this.calculateAward(assess); return assess; } catch (error) { @@ -311,7 +312,6 @@ export class AssessmentCslftRepositoryV2 { if (input.csl_classification == 3) { // married - use student and spouse - if (input.student_contrib_exempt == "NO") { input.student_contrib_exempt_reason = "Not Exempt"; @@ -319,9 +319,8 @@ export class AssessmentCslftRepositoryV2 { total_contribution += input.student_contribution_override; } else { //input.student_previous_contribution = 0; // not sure what to do with this??? - - input.student_contrib_exempt_reason = ""; - total_contribution += input.student_contribution + input.student_other_resources; + //input.student_contrib_exempt_reason = ""; + total_contribution += input.student_contribution; // + input.student_other_resources; } } else { input.student_contrib_exempt_reason = "Exempt: "; @@ -334,18 +333,20 @@ export class AssessmentCslftRepositoryV2 { } if (input.spouse_contrib_exempt == "NO") { + input.spouse_contrib_exempt_reason = "Not Exempt"; + if (input.spouse_contribution_override) { - input.spouse_contrib_exempt_reason = "Not Exempt"; total_contribution += input.spouse_contribution_override; } else { - input.spouse_contrib_exempt_reason = "Exempt: "; - - if (this.application.spouse_study_emp_status_id != 4) input.spouse_contrib_exempt_reason += "Not employed"; - else if (this.spouseIsFullTimeStudent()) input.spouse_contrib_exempt_reason += "Full-time student"; - //input.spouse_previous_contribution = 0; // again not sure about this total_contribution += input.spouse_contribution; } + } else { + input.spouse_contrib_exempt_reason = "Exempt: "; + + if (this.application.spouse_study_emp_status_id != 4) input.spouse_contrib_exempt_reason += "Not employed"; + else if (this.spouseIsFullTimeStudent()) input.spouse_contrib_exempt_reason += "Full-time student"; + else input.spouse_contrib_exempt_reason += "Family income threshold not met"; } } else if (input.csl_classification == 1) { input.student_contrib_exempt_reason = "Not Applicable"; @@ -363,7 +364,7 @@ export class AssessmentCslftRepositoryV2 { total_contribution += input.student_contribution_override; } else { //input.student_previous_contribution = 0; // not sure what to do with this??? - total_contribution += input.student_contribution + input.student_other_resources; + total_contribution += input.student_contribution /* + input.student_other_resources */; } } else { input.student_contrib_exempt_reason = "Exempt: "; @@ -381,20 +382,7 @@ export class AssessmentCslftRepositoryV2 { } input.total_contribution = total_contribution; input.total_resources = input.total_contribution; - input.csl_assessed_need = input.total_costs - input.total_resources; - - /* assess.csl_assessed_need_pct = 0.6; - assess.csl_assessed_need_net = assess.csl_assessed_need * assess.csl_assessed_need_pct; - assess.total_grants; - assess.max_allowable; - assess.calculated_award; - assess.requested_amount; - assess.actual_award; - assess.previous_certs; - assess.preview_disburse; - assess.netAmount; */ - input.csl_assessed_need_pct = input.csl_assessed_need * 0.6; input.max_allowable = 0; @@ -404,7 +392,7 @@ export class AssessmentCslftRepositoryV2 { } const minVal = Math.min( - input.csl_assessed_need_pct - input.total_grant_awarded - input.total_contribution, + input.csl_assessed_need_pct - input.total_grant_awarded /* - input.total_contribution */, input.max_allowable ); input.calculated_award = Math.max(0, minVal); @@ -417,31 +405,6 @@ export class AssessmentCslftRepositoryV2 { input.previous_cert = prev.sum ?? 0; - /* -parent_discretionary_income -parent_contribution -*/ - - /* - // Family Size and Income - switch (this.assessment.csl_classification) { - case 1: - this.assessment.family_income = (this.assessment.parent1_income ?? 0) + (this.assessment.parent2_income ?? 0); - break; - case 4: - this.assessment.family_income = this.assessment.student_ln150_income ?? 0; - break; - case 3: - this.assessment.family_income = - (this.assessment.student_ln150_income ?? 0) + (this.assessment.spouse_ln150_income ?? 0); - break; - default: - this.assessment.family_income = this.assessment.student_ln150_income ?? 0; - } - */ - - //console.log("CONTIR", input); - input.previous_disbursement = sumBy( this.disbursements.filter((d) => d.assessment_id == input.id), "disbursed_amount" @@ -455,6 +418,10 @@ parent_contribution input.previous_cert - input.previous_disbursement - (input.return_uncashable_cert ?? 0); + + input.net_amount = Math.round(input.net_amount * 100) / 100; + input.net_amount = input.net_amount == -0 ? 0 : input.net_amount; + return input; } @@ -506,12 +473,12 @@ parent_contribution } const calculated_award_min = Math.min( - sixty - (assess.total_grant_awarded ?? 0) - total_contribution, + sixty - (assess.total_grant_awarded ?? 0) /* - total_contribution */, max_allowable ?? 0 ); const calculated_award: number = Math.max(0, Math.round(calculated_award_min)); - if (!assess.csl_full_amt_flag) { + if (assess.csl_full_amt_flag == 0) { assess.assessed_amount = Math.max( Math.min(calculated_award, assess.csl_request_amount ?? 0) - (assess.over_award ?? 0) - @@ -577,8 +544,6 @@ parent_contribution this.application.csl_classification, this.application.study_accom_code ); - - console.log("CAT IS", this.application.category_id); } async loadLookups() { @@ -642,7 +607,7 @@ parent_contribution assess.period = assess.study_months <= 4 ? "S" : "P"; assess.csl_request_amount = this.fundingRequest.csl_request_amount; - assess.csl_full_amt_flag = this.fundingRequest.is_csl_full_amount ? 1 : undefined; + assess.csl_full_amt_flag = this.fundingRequest.is_csl_full_amount == true ? 1 : 0; let family = await calculateFamilySize( this.db, @@ -832,11 +797,6 @@ parent_contribution }); } - /* assess.totalCapped = cleanDollars( - costsCapped.reduce((a: number, i: any) => { - return a + i.total; - }, 0) - ); */ assess.uncapped_costs_total = cleanDollars( costsUncapped.reduce((a: number, i: any) => { return a + i.total; @@ -922,7 +882,9 @@ parent_contribution .raw(`SELECT d.assessment_id, SUM(d.disbursed_amount) disbursed, SUM(a.student_contribution) student_contribution, SUM(a.spouse_contribution) spouse_contribution FROM sfa.disbursement d INNER JOIN sfa.assessment a ON d.assessment_id = a.id INNER JOIN sfa.funding_request fr ON fr.id = d.funding_request_id INNER JOIN sfa.application ap on ap.id = fr.application_id WHERE ap.academic_year_id = ${this.application.academic_year_id} - AND fr.request_type_id IN (3,4) AND ap.student_id = ${this.application.student_id} AND a.id < ${assess.id} GROUP BY d.assessment_id HAVING SUM(d.disbursed_amount) > 0`); + AND fr.request_type_id IN (3,4) AND ap.id = ${this.application.id} AND a.id < ${assess.id} GROUP BY d.assessment_id HAVING SUM(d.disbursed_amount) > 0`); + + console.log("PREV", assess.id); if (previousContributions && previousContributions.length > 0) { assess.student_previous_contribution = previousContributions.reduce((a: number, i: any) => { @@ -970,6 +932,7 @@ parent_contribution ? 0 : Math.round(assess.spouse_expected_contribution ?? 0 /* - assess.spouse_previous_contribution */); } else { + assess.spouse_contrib_exempt = "YES"; assess.spouse_expected_contribution = 0; assess.spouse_previous_contribution = 0; assess.spouse_contribution = 0; @@ -1015,7 +978,7 @@ parent_contribution assess.over_award = this.student.pre_over_award_amount ?? 0; // Calculate the totaln_disbursments_required - if (!assess.csl_full_amt_flag) { + if (assess.csl_full_amt_flag == 0) { assess.assessed_amount = Math.max( Math.min(calculated_award, assess.csl_request_amount ?? 0) - (assess.over_award ?? 0) - diff --git a/src/api/routes/admin/csg-threshold-router.ts b/src/api/routes/admin/csg-threshold-router.ts index 4c76e094..9dc086d9 100644 --- a/src/api/routes/admin/csg-threshold-router.ts +++ b/src/api/routes/admin/csg-threshold-router.ts @@ -149,9 +149,10 @@ csgThresholdRouter.put( const { assessment_id, funding_request_id } = req.params; let repo = new AssessmentCslftRepositoryV2(db); - let recalc = await repo.create(funding_request_id); + let recalc = await repo.create(funding_request_id, assessment_id); delete (recalc as any).id; + delete (recalc as any).assessment_type_id; (recalc as any).student_contribution_override = null; (recalc as any).spouse_contribution_override = null; (recalc as any).parent_contribution_override = null;