Skip to content

Commit

Permalink
Merge pull request #195 from icefoganalytics/test
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
datajohnson authored Oct 31, 2023
2 parents 49b4f07 + 47677d4 commit 465536b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 41 deletions.
32 changes: 16 additions & 16 deletions src/api/repositories/assessment/assessment-yg-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ export class AssessmentYukonGrant extends AssessmentBaseRepository {
assess.weekly_amount = yg_cost.weekly_amount || 0;
}

const disburse_required = await this.getScalarValue<number>("fn_disbursments_required", [
/* const disburse_required = await this.getScalarValue<number>("fn_disbursments_required", [
application_id,
assessment_id || 0,
"NULL",
]);
]); */

let disbursed_amt = null;

Expand All @@ -108,18 +108,18 @@ export class AssessmentYukonGrant extends AssessmentBaseRepository {
disbursed_amt = disbursedAmounts.reduce((a, b) => a + b, 0);
}

if (disbursed_amt) {
if (disbursed_amt) {
assess.previous_disbursement = disbursed_amt;

if (disburse_required > 0 && disburse_required < 1) {
/* if (disburse_required > 0 && disburse_required < 1) {
assess.disbursements_required = 1;
} else {
assess.disbursements_required = Math.floor(disburse_required);
}
} */
} else {
assess.previous_disbursement = 0;
assess.disbursements_required = Math.floor(disburse_required);
}
//assess.disbursements_required = Math.floor(disburse_required);
}

assess.over_award = 0;
assess.assessment_adj_amount = 0;
Expand All @@ -129,7 +129,7 @@ export class AssessmentYukonGrant extends AssessmentBaseRepository {
assess.air_travel_disbursement_period = undefined;

assess.assessed_amount = await this.getScalarValue<number>("fn_get_total", [
String(assess.disbursements_required),
"1", //String(assess.disbursements_required),
this.application.academic_year_id || 0,
String(assess.living_costs),
String(assess.allowed_tuition),
Expand All @@ -142,7 +142,7 @@ export class AssessmentYukonGrant extends AssessmentBaseRepository {
]);

assess.pre_leg_amount = await this.getScalarValue<number>("fn_get_old_total", [
String(assess.disbursements_required),
"1", //String(assess.disbursements_required),
String(this.application.academic_year_id),
String(assess.living_costs),
String(assess.allowed_tuition),
Expand Down Expand Up @@ -193,11 +193,11 @@ export class AssessmentYukonGrant extends AssessmentBaseRepository {
assessment.destination_city_id || 0,
]);

const disburse_required = await this.getScalarValue<number>("fn_disbursments_required", [
/* const disburse_required = await this.getScalarValue<number>("fn_disbursments_required", [
application_id,
assessment?.id || 0,
program_division || 0,
]);
]); */

let disbursed_amt = null;

Expand All @@ -208,18 +208,18 @@ export class AssessmentYukonGrant extends AssessmentBaseRepository {
if (disbursed_amt) {
assess.previous_disbursement = disbursed_amt;

if (disburse_required > 0 && disburse_required < 1) {
/* if (disburse_required > 0 && disburse_required < 1) {
assess.disbursements_required = 1;
} else {
assess.disbursements_required = Math.floor(disburse_required);
}
} */
} else {
assess.previous_disbursement = 0;
assess.disbursements_required = Math.floor(disburse_required);
//assess.disbursements_required = Math.floor(disburse_required);
}

assess.assessed_amount = await this.getScalarValue<number>("fn_get_total", [
assess.disbursements_required || 0,
"1", //assess.disbursements_required || 0,
this.application.academic_year_id || 0,
String(assess.living_costs),
String(assess.allowed_tuition),
Expand All @@ -232,7 +232,7 @@ export class AssessmentYukonGrant extends AssessmentBaseRepository {
]);

assess.pre_leg_amount = await this.getScalarValue<number>("fn_get_old_total", [
assess.disbursements_required || 0,
"1", //assess.disbursements_required || 0,
String(this.application.academic_year_id),
String(assessment.living_costs),
String(assessment.allowed_tuition),
Expand Down
20 changes: 19 additions & 1 deletion src/api/routes/admin/csg-threshold-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ csgThresholdRouter.post(
.where({ application_id })
.whereIn("request_type_id", [CSGPT_REQUEST_TYPE_ID, CSGD_REQUEST_TYPE_ID, CSPTDEP_REQUEST_TYPE_ID])
.join("sfa.disbursement", "funding_request.id", "disbursement.funding_request_id")
.whereNull("disbursement.transaction_number");
.whereNull("disbursement.transaction_number")
.orWhere("disbursement.transaction_number", "");

for (let cd of childDisbursements) {
await db("sfa.disbursement").where({ id: cd.id }).update({ transaction_number });
Expand Down Expand Up @@ -533,6 +534,23 @@ csgThresholdRouter.put(
transaction_number = (await db.raw(`select next value for sfa.csl_transaction_seq as nextval`))[0].nextval;
}

let fundingRequest = await db("sfa.funding_request").where({ id: funding_request_id }).first();

if (fundingRequest && fundingRequest.request_type_id == CSLPT_REQUEST_TYPE_ID) {
if (generateTransactions === true) {
let childDisbursements = await db("sfa.funding_request")
.select("disbursement.*")
.where({ application_id })
.whereIn("request_type_id", [CSGPT_REQUEST_TYPE_ID, CSGD_REQUEST_TYPE_ID, CSPTDEP_REQUEST_TYPE_ID])
.join("sfa.disbursement", "funding_request.id", "disbursement.funding_request_id")
.whereNull("disbursement.transaction_number")
.orWhere("disbursement.transaction_number", "");
for (let cd of childDisbursements) {
await db("sfa.disbursement").where({ id: cd.id }).update({ transaction_number });
}
}
}

for (let disb of disbursements) {
disb.assessment_id = assessment_id;
disb.funding_request_id = funding_request_id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const getters = {
(state.assessment.parent1_income || 0) +
(state.assessment.parent2_income || 0)
: 0;
return formatMoney(val);
return val;
},

threshold(state) {
Expand Down Expand Up @@ -57,55 +57,50 @@ const getters = {
let contribution =
(state.assessment.spouse_expected_contribution || 0) + state.assessment.student_expected_contribution;

return formatMoney(totalCosts > contribution ? totalCosts - contribution : 0);
return totalCosts > contribution ? totalCosts - contribution : 0;
}
return "$0.00";
return 0;
},

phaseOutRate(state, getters) {
let income = parse(getters.familyIncome, { currency: "usd" });
let income = getters.familyIncome;

if (income >= getters.threshold.income_cutoff) return 0;
else if (income > getters.threshold.income_threshold) return getters.threshold.phase_out_rate;
else return 0;
},

monthlyRate(state, getters) {
if (isUndefined(getters.threshold.phase_out_rate) || isUndefined(getters.familyIncome)) return formatMoney(0);
if (isUndefined(getters.threshold.phase_out_rate) || isUndefined(getters.familyIncome)) return 0;

let rate = Math.max(
0,
Math.min(
state.baseRate,
state.baseRate -
getters.threshold.phase_out_rate *
(parse(getters.familyIncome, { currency: "usd" }) - getters.threshold.income_threshold)
state.baseRate - getters.threshold.phase_out_rate * (getters.familyIncome - getters.threshold.income_threshold)
)
);

return formatMoney(rate);
return Math.round(rate * 100) / 100;
},
assessedAmount(state, getters) {
if (isUndefined(state.assessment.study_months)) return formatMoney(0);

return state.assessment
? formatMoney(parse(getters.monthlyRate, { currency: "usd" }) * state.assessment.study_months)
: formatMoney(0);
return state.assessment ? getters.monthlyRate * state.assessment.study_months : 0;
},
previousDisbursements(state) {
let amounts = state.disbursements.map((d) => d.disbursed_amount);
let total = amounts.reduce((t, a) => {
return t + a;
}, 0);

return formatMoney(total);
return total;
},
netAmount(state, getters) {
return formatMoney(getters.netAmountRaw);
return getters.netAmountRaw;
},
netAmountRaw(state, getters) {
let rawVal =
parse(getters.assessedAmount, { currency: "usd" }) - parse(getters.previousDisbursements, { currency: "usd" });
let rawVal = getters.assessedAmount - getters.previousDisbursements;
if (rawVal > 0 && rawVal < 100) return 100.0;
return Object.is(Math.round(rawVal), -0) ? 0 : Math.round(rawVal);
},
Expand Down Expand Up @@ -216,7 +211,7 @@ const actions = {
student_contribution_review: parent.student_contribution_review,
spouse_contribution_review: parent.spouse_contribution_review,
parent_contribution_review: parent.parent_contribution_review,
assessed_amount: parse(getters.assessedAmount, { currency: "usd" }),
assessed_amount: getters.assessedAmount,
};

commit("SET_ASSESSMENT", assessment);
Expand Down Expand Up @@ -260,7 +255,7 @@ const actions = {
student_contribution_review: parent.student_contribution_review,
spouse_contribution_review: parent.spouse_contribution_review,
parent_contribution_review: parent.parent_contribution_review,
assessed_amount: parse(getters.assessedAmount, { currency: "usd" }),
assessed_amount: getters.assessedAmount,
};

commit("SET_ASSESSMENT", assessment);
Expand Down Expand Up @@ -353,6 +348,8 @@ export default {
namespaced: true,
};

window.debugThing = { state, getters };

function formatMoney(input) {
if (isNumber(input)) {
return Intl.NumberFormat("en", {
Expand Down
12 changes: 6 additions & 6 deletions src/web/src/components/application/assessments/views/CSGFT.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
hide-details
label="Family income"
readonly
v-model="familyIncome"
:value="formatMoney(familyIncome)"
append-icon="mdi-calculator"
></v-text-field>
</v-col>
Expand All @@ -191,7 +191,7 @@
background-color="#ddd"
readonly
label="Monthly rate"
v-model="monthlyRate"
:value="formatMoney(monthlyRate)"
append-icon="mdi-lock"
></v-text-field>
</v-col>
Expand All @@ -202,7 +202,7 @@
background-color="#ddd"
label="Assessed need"
readonly
v-model="assessedNeed"
:value="formatMoney(assessedNeed)"
append-icon="mdi-lock"
></v-text-field>
<v-text-field
Expand All @@ -211,7 +211,7 @@
background-color="#ddd"
label="Assessed amount"
readonly
v-model="assessedAmount"
:value="formatMoney(assessedAmount)"
append-icon="mdi-calculator"
></v-text-field>
<v-text-field
Expand All @@ -221,7 +221,7 @@
hide-details
label="Previous disbursements"
readonly
v-model="previousDisbursements"
:value="formatMoney(previousDisbursements)"
append-icon="mdi-calculator"
></v-text-field>
</v-col>
Expand All @@ -248,7 +248,7 @@
hide-details
label="Net amount"
readonly
v-model="netAmount"
:value="netAmount"
append-icon="mdi-calculator"
></v-text-field
></v-col>
Expand Down

0 comments on commit 465536b

Please sign in to comment.