Skip to content

Commit

Permalink
Merge pull request #323 from icefoganalytics/test
Browse files Browse the repository at this point in the history
Overawards
  • Loading branch information
datajohnson authored Dec 15, 2024
2 parents a4d4d87 + 600da8c commit 3322fea
Show file tree
Hide file tree
Showing 12 changed files with 490 additions and 60 deletions.
22 changes: 22 additions & 0 deletions src/api/data/migrations/022_overaward.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Knex } from "knex";

exports.up = async function (knex: Knex) {
await knex.schema.createTable("sfa.overaward", (t) => {
t.increments("id").primary();
t.integer("student_id").notNullable().references("id").inTable("sfa.student");
t.integer("academic_year_id").references("id").inTable("sfa.academic_year");
t.integer("application_id").references("id").inTable("sfa.application");
t.integer("funding_request_id").references("id").inTable("sfa.funding_request");
t.integer("assessment_id").references("id").inTable("sfa.assessment");
t.float("amount").notNullable();
t.string("created_by", 150).notNullable();
t.specificType("create_date", "DATETIME2(0)").notNullable().defaultTo(knex.fn.now(), {
constraintName: "sfa_overaward_create_date_default",
});
t.text("note");
});
};

exports.down = async function (knex: Knex) {
await knex.schema.dropTable("sfa.overaward");
};
15 changes: 14 additions & 1 deletion src/api/routes/admin/csg-threshold-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,20 @@ csgThresholdRouter.post(
let existingOveraward = student.pre_over_award_amount ?? 0;
existingOveraward += Math.abs(loaded.net_amount);

await db("sfa.student").where({ id: application.student_id }).update({ pre_over_award_amount: existingOveraward });
const amount = Math.round(loaded.net_amount * 100) / 100;

await db("sfa.overaward").insert({
student_id: student.id,
academic_year_id: application.academic_year_id,
application_id: fundingRequest.application_id,
funding_request_id,
assessment_id,
created_by: req.user.email,
note: "Created from overaward in CLSFT Assessment",
amount,
});

//await db("sfa.student").where({ id: application.student_id }).update({ pre_over_award_amount: existingOveraward });

//await db("sfa.assessment").where({ id: assessment_id }).update(recalc);
return res.status(200).json({ data: "Assessment Saved" });
Expand Down
23 changes: 19 additions & 4 deletions src/api/routes/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import ReportingController from "@/controllers/admin/reporting-controller";
import { csgThresholdRouter } from "./csg-threshold-router";
import { yeaImportRouter } from "./yea-import-router";
import { catalogRouter } from "./catalog/catalog-router";
import { overawardRouter } from "./overaward-router";

export const adminRouter = express.Router();
//adminRouter.use("/", RequireServerAuth, RequireAdmin)
Expand Down Expand Up @@ -164,25 +165,39 @@ adminRouter.use("/csl-certificate-audit-report", cslCertificateAuditReportRouter
adminRouter.use("/csl-msfaa-send", cslMsfaaSendRouter);
adminRouter.use("/csl-restricted-data", cslRestrictedData);

adminRouter.use("/overaward", overawardRouter);

adminRouter.use("/reporting", pathFormatMiddleware);
adminRouter.use("/reporting/fundingStatus/:years", routedTo(ReportingController, "runFundingStatusReport"));
adminRouter.use("/reporting/staYukonUniversity/:academic_year_id", routedTo(ReportingController, "runSTAYukonUniversityReport"));
adminRouter.use(
"/reporting/staYukonUniversity/:academic_year_id",
routedTo(ReportingController, "runSTAYukonUniversityReport")
);
adminRouter.use(
"/reporting/scholarshipQualified/:academic_year_id",
routedTo(ReportingController, "runScholarshipReport")
);
adminRouter.use("/reporting/nars2022", routedTo(ReportingController, "runNars2022FTReport"));
adminRouter.use("/reporting/nars2022pt", routedTo(ReportingController, "runNars2022PTReport"));
adminRouter.use("/reporting/nars2022dis/:academic_year_id", routedTo(ReportingController, "runNars2022DisabilityReport"));
adminRouter.use("/reporting/nars2022disrcl/:academic_year_id", routedTo(ReportingController, "runNars2022DisabilityRCLReport"));
adminRouter.use(
"/reporting/nars2022dis/:academic_year_id",
routedTo(ReportingController, "runNars2022DisabilityReport")
);
adminRouter.use(
"/reporting/nars2022disrcl/:academic_year_id",
routedTo(ReportingController, "runNars2022DisabilityRCLReport")
);

adminRouter.use("/reporting/nars2023", routedTo(ReportingController, "runNars2023FTReport"));
adminRouter.use("/reporting/nars2023pt", routedTo(ReportingController, "runNars2023PTReport"));
adminRouter.use("/reporting/nars2023dis", routedTo(ReportingController, "runNars2023DisabilityReport"));
adminRouter.use("/reporting/nars2023disrcl", routedTo(ReportingController, "runNars2023DisabilityRCLReport"));

adminRouter.use("/reporting/step/:academic_year_id", routedTo(ReportingController, "runStepReport"));
adminRouter.use("/reporting/approvedFunding/:academic_year_id", routedTo(ReportingController, "runApprovedFundingReport"));
adminRouter.use(
"/reporting/approvedFunding/:academic_year_id",
routedTo(ReportingController, "runApprovedFundingReport")
);
adminRouter.use("/reporting/t4a/:tax_year", routedTo(ReportingController, "runT4AReport"));
adminRouter.use("/reporting/vendor-update", routedTo(ReportingController, "runVendorUpdateReport"));

Expand Down
106 changes: 106 additions & 0 deletions src/api/routes/admin/overaward-router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import express, { Request, Response } from "express";
import knex from "knex";
import { DB_CONFIG } from "../../config";
import { RequireAdmin } from "../auth";
import { cleanNumber } from "@/models";
import { create } from "lodash";

const db = knex(DB_CONFIG);

export const overawardRouter = express.Router();

overawardRouter.use(RequireAdmin);

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

if (!studentId) return res.status(404).json({ success: false, message: "Student Id no provided" });

try {
const student = await db("sfa.student").where({ id: studentId }).first();
if (!student) return res.status(404).json({ success: false, message: "Student not found" });

const overaward = await db("sfa.overaward").where({ student_id: studentId }).orderBy("create_date", "asc");

res.json({ success: true, data: overaward, netOveraward: overaward.reduce((acc, curr) => acc + curr.amount, 0) });
} catch (error: any) {
console.log(error);
return res.status(500).send();
}
});

overawardRouter.post("/:studentId", async (req: Request, res: Response) => {
const { studentId } = req.params;
const { academic_year_id, amount, note } = req.body;

if (!studentId) return res.status(404).json({ success: false, message: "Student Id no provided" });

try {
const student = await db("sfa.student").where({ id: studentId }).first();
if (!student) return res.status(404).json({ success: false, message: "Student not found" });

const roundedAmount = Math.round(cleanNumber(amount) * 100) / 100;

await db("sfa.overaward").insert({
student_id: studentId,
academic_year_id,
amount: roundedAmount,
note,
created_by: req.user.email,
});

res.json({ success: true });
} catch (error: any) {
console.log(error);
return res.status(500).send();
}
});

overawardRouter.put("/:studentId/:overawardId", async (req: Request, res: Response) => {
const { studentId, overawardId } = req.params;
const { academic_year_id, amount, note } = req.body;

if (!studentId) return res.status(404).json({ success: false, message: "Student Id no provided" });

try {
const student = await db("sfa.student").where({ id: studentId }).first();
if (!student) return res.status(404).json({ success: false, message: "Student not found" });

const overaward = await db("sfa.overaward").where({ id: overawardId }).first();
if (!overaward) return res.status(404).json({ success: false, message: "Overaward not found" });

const roundedAmount = Math.round(cleanNumber(amount) * 100) / 100;

await db("sfa.overaward").where({ id: overawardId }).update({
academic_year_id,
amount: roundedAmount,
note,
});

res.json({ success: true });
} catch (error: any) {
console.log(error);
return res.status(500).send();
}
});

overawardRouter.delete("/:studentId/:overawardId", async (req: Request, res: Response) => {
const { studentId, overawardId } = req.params;

if (!studentId) return res.status(404).json({ success: false, message: "Student Id no provided" });

try {
const student = await db("sfa.student").where({ id: studentId }).first();
if (!student) return res.status(404).json({ success: false, message: "Student not found" });

const overaward = await db("sfa.overaward").where({ id: overawardId }).first();
if (!overaward) return res.status(404).json({ success: false, message: "Overaward not found" });

await db("sfa.overaward").where({ id: overawardId }).delete();

res.json({ success: true });
} catch (error: any) {
console.log(error);
return res.status(500).send();
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ const actions = {
});
},
async recordOveraward({ state }) {
console.log("RECORDing OVERAWRD");
let url = `${CSG_THRESHOLD_URL}/funding-request/${state.fundingRequest.id}/assessment/${state.assessment.id}/record-overaward`;

return axios.post(url).then(async (resp) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,7 @@
check_completion_menu = false;
}
"
@change="
doSaveApp(
'csl_clearance_date',
application.csl_clearance_date
)
"
@change="doSaveApp('csl_clearance_date', application.csl_clearance_date)"
></v-date-picker>
</v-menu>
</div>
Expand All @@ -124,16 +119,11 @@
application.csl_restriction_comment = e;
}
"
@change="
doSaveApp(
'csl_restriction_comment',
application.csl_restriction_comment
)
"
@change="doSaveApp('csl_restriction_comment', application.csl_restriction_comment)"
></v-textarea>
</div>

<div class="col-md-6">
<!-- <div class="col-md-6">
<v-text-field
outlined
dense
Expand All @@ -151,7 +141,7 @@
"
v-currency="{ currency: 'USD', locale: 'en' }"
></v-text-field>
</div>
</div> -->

<div class="col-md-12">
<hr />
Expand All @@ -173,12 +163,7 @@
v-model="warningOptions"
@change="
() => {
doSaveStudent(
'csl_warn_code',
student.csl_warn_code,
'studentInfo',
student.id
);
doSaveStudent('csl_warn_code', student.csl_warn_code, 'studentInfo', student.id);
}
"
></v-select>
Expand Down Expand Up @@ -215,14 +200,7 @@
scholastic_letter_menu = false;
}
"
@change="
doSaveStudent(
'csl_letter_date',
student.csl_letter_date,
'studentInfo',
student.id
)
"
@change="doSaveStudent('csl_letter_date', student.csl_letter_date, 'studentInfo', student.id)"
></v-date-picker>
</v-menu>
</div>
Expand Down Expand Up @@ -334,16 +312,9 @@ export default {
},
methods: {
doSaveStudent(field, value, type, extraId = null, addressType = "") {
store.dispatch("updateStudent", [
field,
value,
type,
extraId,
this,
addressType,
]);
store.dispatch("updateStudent", [field, value, type, extraId, this, addressType]);
},
concatenateText(item) {
concatenateText(item) {
return this.cslCodes.id + " - " + this.cslCodes.definition;
},
doSaveApp(field, value) {
Expand Down
Loading

0 comments on commit 3322fea

Please sign in to comment.