Skip to content

Commit

Permalink
Merge pull request #165 from icefoganalytics/test
Browse files Browse the repository at this point in the history
CSGDSE
  • Loading branch information
datajohnson authored Sep 29, 2023
2 parents 7654cbd + e7e6693 commit eaf4404
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 562 deletions.
31 changes: 30 additions & 1 deletion src/api/routes/admin/csg-threshold-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const CSGDEP_REQUEST_TYPE_ID = 32;
const CSGD_REQUEST_TYPE_ID = 29;
const CSGTU_REQUEST_TYPE_ID = 28;
const CSGFT_REQUEST_TYPE_ID = 35;
const CSGDSE_REQUEST_TYPE_ID = 30;

export const csgThresholdRouter = express.Router();

Expand Down Expand Up @@ -133,6 +134,35 @@ csgThresholdRouter.get("/csgtu/:application_id", async (req: Request, res: Respo
res.status(404).send();
});

csgThresholdRouter.get("/csgdse/:application_id", async (req: Request, res: Response) => {
const { application_id } = req.params;

let funding_request = await db("sfa.funding_request")
.where({ application_id, request_type_id: CSGDSE_REQUEST_TYPE_ID })
.orderBy("id", "desc")
.first();

if (funding_request) {
let assessment = await db("sfa.assessment")
.where({
funding_request_id: funding_request.id,
})
.orderBy("id", "desc")
.first();

let disbursements = await db("sfa.disbursement")
.where({
funding_request_id: funding_request.id,
})
.orderBy("issue_date")
.orderBy("id");

return res.json({ data: { funding_request, assessment, disbursements } });
}

res.status(404).send();
});

csgThresholdRouter.get("/csgft/:application_id", async (req: Request, res: Response) => {
const { application_id } = req.params;

Expand Down Expand Up @@ -176,7 +206,6 @@ csgThresholdRouter.post(
delete assessment.disbursements;

let assessmentInsert = await db("sfa.assessment").insert(assessment).returning("*");

if (assessmentInsert.length > 0 && disbursements && isArray(disbursements)) {
for (let disb of disbursements) {
disb.assessment_id = assessmentInsert[0].id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const state = {
parentAssessment: {},
parentDisbursements: [],
baseRate: 200, // hardcoded as it is not stored in the database yet

services: [],
equipment: [],
};
const getters = {
previousDisbursements(state) {
Expand All @@ -23,17 +26,18 @@ const getters = {

return formatMoney(total);
},
monthlyRate(state) {
return formatMoney(state.baseRate);
},
studyMonths(state) {
return state.assessment.study_months;
},
assessedAmount(state) {
if (isUndefined(state.assessment.study_months)) return formatMoney(0);
let totalEquipment = 0;
for (let item of state.equipment) {
totalEquipment += item.approve_amount;
}

let total = state.assessment.study_months * state.baseRate;
return formatMoney(total);
let totalServices = 0;
for (let item of state.services) {
totalServices += item.approve_amount;
}

return formatMoney(totalEquipment + totalServices);
},
netAmount(state, getters) {
return formatMoney(getters.netAmountRaw);
Expand All @@ -46,21 +50,12 @@ const getters = {
},
};
const mutations = {
SET_THRESHOLDS(state, value) {
state.csgThresholds = value;
},
SET_FUNDINGREQUEST(state, value) {
state.fundingRequest = value;
},
SET_PARENTASSESSMENT(state, value) {
state.parentAssessment = value;
},
SET_ASSESSMENT(state, value) {
state.assessment = value;
},
SET_PARENTDISBURSEMENTS(state, value) {
state.parentDisbursements = value;
},
SET_DISBURSEMENTS(state, value) {
for (let v of value) {
v.due_date = v.due_date ? moment.utc(v.due_date).format("YYYY-MM-DD") : undefined;
Expand All @@ -69,117 +64,57 @@ const mutations = {

state.disbursements = value;
},
SET_EQUIPMENT(state, value) {
state.equipment = value;
},
SET_SERVICES(state, value) {
state.services = value;
},
};
const actions = {
async initialize(store, app) {
console.log("Initializing CSGTP Store");
store.dispatch("loadThresholds", app.academic_year_id);
store.dispatch("loadCSLFTAssessment", { id: app.id, refreshChild: true });
},

async loadThresholds({ commit }, academicYear) {
axios.get(`${CSG_THRESHOLD_URL}/${academicYear}`).then((resp) => {
commit("SET_THRESHOLDS", resp.data.data);
});
},
console.log("Initializing CSGDSE Store");
store.dispatch("loadCSGDSEAssessment", { id: app.id, refreshChild: true });

async loadCSLFTAssessment({ commit, dispatch }, { id, refreshChild }) {
axios.get(`${CSG_THRESHOLD_URL}/cslft/${id}`).then((resp) => {
commit("SET_PARENTASSESSMENT", resp.data.data.assessment);
commit("SET_PARENTDISBURSEMENTS", resp.data.data.disbursements);

if (refreshChild) {
dispatch("loadCSGFTAssessment", id);
}
});
store.commit(
"SET_EQUIPMENT",
app.disability_equipments.filter((e) => e.verified_equipment_need)
);
store.commit(
"SET_SERVICES",
app.disability_services.filter((s) => s.verified_service_need)
);
},

loadCSGFTAssessment({ commit, state }, applicationId) {
axios.get(`${CSG_THRESHOLD_URL}/csgtu/${applicationId}`).then((resp) => {
loadCSGDSEAssessment({ commit, state }, { id }) {
axios.get(`${CSG_THRESHOLD_URL}/csgdse/${id}`).then((resp) => {
commit("SET_FUNDINGREQUEST", resp.data.data.funding_request);
commit("SET_DISBURSEMENTS", resp.data.data.disbursements);

if (resp.data.data.assessment) {
let assessment = resp.data.data.assessment;
assessment.assessed_date = moment.utc(assessment.assessed_date).format("YYYY-MM-DD");
assessment.classes_start_date = moment.utc(assessment.classes_start_date).format("YYYY-MM-DD");
assessment.classes_end_date = moment.utc(assessment.classes_end_date).format("YYYY-MM-DD");

commit("SET_ASSESSMENT", resp.data.data.assessment);
} else {
if (state.parentAssessment) {
let parent = state.parentAssessment;
let assessment = {
assessed_date: moment().format("YYYY-MM-DD"),
study_weeks: parent.study_weeks,
classes_start_date: moment.utc(parent.classes_start_date).format("YYYY-MM-DD"),
classes_end_date: moment.utc(parent.classes_end_date).format("YYYY-MM-DD"),
study_months: parent.study_months,
family_size: parent.family_size,
dependent_count: parent.dependent_count,
student_ln150_income: parent.student_ln150_income,
spouse_ln150_income: parent.spouse_ln150_income,
relocation_total: parent.relocation_total,
discretionary_cost: parent.discretionary_cost,
discretionary_cost_actual: parent.discretionary_cost_actual,
tuition_estimate: parent.tuition_estimate,
books_supplies_cost: parent.books_supplies_cost,
r_trans_16wk: parent.r_trans_16wk,
shelter_month: parent.shelter_month,
p_trans_month: parent.p_trans_month,
day_care_allowable: parent.day_care_allowable,
day_care_actual: parent.day_care_actual,
depend_food_allowable: parent.depend_food_allowable,
depend_tran_allowable: parent.depend_tran_allowable,
spouse_expected_contribution: parent.spouse_expected_contribution,
student_expected_contribution: parent.student_expected_contribution,
student_contrib_exempt: parent.student_contrib_exempt,
spouse_contrib_exempt: parent.spouse_contrib_exempt,
student_contribution_review: parent.student_contribution_review,
spouse_contribution_review: parent.spouse_contribution_review,
parent_contribution_review: parent.parent_contribution_review,
};

commit("SET_ASSESSMENT", assessment);
}
let assessment = {
assessed_date: moment().format("YYYY-MM-DD"),
student_contrib_exempt: false,
spouse_contrib_exempt: false,
student_contribution_review: false,
spouse_contribution_review: false,
parent_contribution_review: false,
};
commit("SET_ASSESSMENT", assessment);
}
});
},

async recalculate({ state, dispatch, commit }) {
dispatch("loadCSLFTAssessment", { id: state.fundingRequest.application_id, refreshChild: false }).then(() => {
let parent = state.parentAssessment;

dispatch("loadCSGDSEAssessment", { id: state.fundingRequest.application_id, refreshChild: false }).then(() => {
let assessment = {
id: state.assessment.id,
assessed_date: moment().format("YYYY-MM-DD"),
study_weeks: parent.study_weeks,
classes_start_date: moment.utc(parent.classes_start_date).format("YYYY-MM-DD"),
classes_end_date: moment.utc(parent.classes_end_date).format("YYYY-MM-DD"),
study_months: parent.study_months,
family_size: parent.family_size,
dependent_count: parent.dependent_count,
student_ln150_income: parent.student_ln150_income,
spouse_ln150_income: parent.spouse_ln150_income,
relocation_total: parent.relocation_total,
discretionary_cost: parent.discretionary_cost,
discretionary_cost_actual: parent.discretionary_cost_actual,
tuition_estimate: parent.tuition_estimate,
books_supplies_cost: parent.books_supplies_cost,
r_trans_16wk: parent.r_trans_16wk,
shelter_month: parent.shelter_month,
p_trans_month: parent.p_trans_month,
day_care_allowable: parent.day_care_allowable,
day_care_actual: parent.day_care_actual,
depend_food_allowable: parent.depend_food_allowable,
depend_tran_allowable: parent.depend_tran_allowable,
spouse_expected_contribution: parent.spouse_expected_contribution,
student_expected_contribution: parent.student_expected_contribution,
student_contrib_exempt: parent.student_contrib_exempt,
spouse_contrib_exempt: parent.spouse_contrib_exempt,
student_contribution_review: parent.student_contribution_review,
spouse_contribution_review: parent.spouse_contribution_review,
parent_contribution_review: parent.parent_contribution_review,
};

commit("SET_ASSESSMENT", assessment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<template v-slot:activator="{ on, attrs }">
<v-text-field
v-model="assessment.assessed_date"
label="Assesssed date"
label="Assessed date"
append-icon="mdi-calendar"
readonly
outlined
Expand Down
Loading

0 comments on commit eaf4404

Please sign in to comment.