Skip to content

Commit

Permalink
Merge pull request #168 from icefoganalytics/test
Browse files Browse the repository at this point in the history
Adding ability to regenerate ecert export
  • Loading branch information
datajohnson authored Oct 3, 2023
2 parents f1146ef + bac1dbb commit b84259a
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 9 deletions.
79 changes: 72 additions & 7 deletions src/api/routes/admin/csl-certificate-export-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,78 @@ cslCertificateExportRouter.get(
return res.status(200).json({ success: false, data1: results, data2: results2, batch: CSL_CERT_SEQ_P });
}
} else {
return res
.status(200)
.json({
success: false,
batch: CSL_CERT_SEQ_P,
message: "There are no records between " + FROM_DATE_P + " and " + TO_DATE_P,
});
return res.status(200).json({
success: false,
batch: CSL_CERT_SEQ_P,
message: "There are no records between " + FROM_DATE_P + " and " + TO_DATE_P,
});
}
} catch (error: any) {
console.log(error);
return res.status(404).send();
}
}
);

cslCertificateExportRouter.get(
"/:FROM_DATE_P/:TO_DATE_P/:CSL_CERT_SEQ_P/:IS_PREVIEW/regenerate",
[
param("CSL_CERT_SEQ_P").isInt().notEmpty(),
param("FROM_DATE_P").notEmpty(),
param("TO_DATE_P").notEmpty(),
param("IS_PREVIEW").notEmpty(),
],
//ReturnValidationErrors,
async (req: Request, res: Response) => {
const { filter = true } = req.query;
const { CSL_CERT_SEQ_P, FROM_DATE_P, TO_DATE_P, IS_PREVIEW } = req.params;

try {
const results = await db
.select(
"s.id",
db.raw("CONCAT(p.last_name, ', ', p.first_name) AS name"),
db.raw("ISNULL(ROUND(d.disbursed_amount, 0), 0) AS csl_amount"),
"d.transaction_number",
"d.issue_date",
"d.due_date",
"r.description"
)
.from("sfa.student AS s")
.join("sfa.person AS p", "s.person_id", "=", "p.id")
.join("sfa.application AS hd", "s.id", "=", "hd.student_id")
.join("sfa.funding_request AS fr", "hd.id", "=", "fr.application_id")
.join("sfa.disbursement AS d", "fr.id", "=", "d.funding_request_id")
.join("sfa.request_type AS r", "fr.request_type_id", "=", "r.id")
.join("sfa.msfaa AS m", "s.id", "=", "m.student_id")
.where(IS_PREVIEW === "1" ? "d.csl_cert_seq_number_prev" : "d.csl_cert_seq_number", "=", CSL_CERT_SEQ_P)
.andWhere("d.issue_date", ">=", FROM_DATE_P)
.andWhere("d.issue_date", "<=", TO_DATE_P)
.andWhere("m.msfaa_status", "=", "Received")
.andWhere(
db.raw(
"((m.is_full_time = CASE d.disbursement_type_id WHEN 4 THEN 1 ELSE 0 END) OR hd.academic_year_id <= 2012) "
)
);

if (results.length) {
const results2 = await db.raw("SELECT sfa.fn_cert_data_regen(?, ?, ?) as fileText", [
CSL_CERT_SEQ_P,
FROM_DATE_P,
TO_DATE_P,
]);

if (results2[0].fileText) {
return res.status(200).json({ success: true, data1: results, data2: results2, batch: CSL_CERT_SEQ_P });
} else {
return res.status(200).json({ success: false, data1: results, data2: results2, batch: CSL_CERT_SEQ_P });
}
} else {
return res.status(200).json({
success: false,
batch: CSL_CERT_SEQ_P,
message: "There are no records between " + FROM_DATE_P + " and " + TO_DATE_P,
});
}
} catch (error: any) {
console.log(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</v-col>
<v-col>
<div class="text-right">
<v-btn-toggle v-model="icon">
<v-btn-toggle v-model="icon" class="mb-6">
<v-btn
:disabled="disabled.flag"
class="my-0"
Expand Down Expand Up @@ -102,6 +102,25 @@
</div>
</v-col>
</v-row>
<v-divider class="my-4" />
<v-row>
<v-col class="d-flex">
<v-text-field
label="Sequence"
dense
outlined
background-color="white"
hide-details
v-model="sequence"
></v-text-field>
<v-btn class="ml-4" style="height: 40px" @click="regenerateReport(0)" color="secondary">
Regenerate
<v-icon right>
mdi-refresh
</v-icon>
</v-btn>
</v-col>
</v-row>
</v-card-text>
</v-card>

Expand Down Expand Up @@ -142,6 +161,8 @@ export default {
modalTitle: null,
disabled: { flag: true },
isLoading: { flag: false },
sequence: "",
}),
components: {
Modal,
Expand Down Expand Up @@ -173,7 +194,6 @@ export default {
let newFlag = { flag: true };
this.disabled = newFlag;
let newLoading = { flag: true };
this.isLoading = newFlag;
let resInsert;
if (isPreview) {
Expand All @@ -191,10 +211,14 @@ export default {
} else {
let resInsert2;
if (isPreview === 1) {
this.sequence = resInsert.data.data;
resInsert2 = await axios.get(
CSL_CERTIFICATE_EXPORT + `/${this.from.date}/${this.to.date}/${resInsert.data.data}/1`
);
} else {
this.sequence = resInsert.data.data;
resInsert2 = await axios.get(
CSL_CERTIFICATE_EXPORT + `/${this.from.date}/${this.to.date}/${resInsert.data.data}/0`
);
Expand Down Expand Up @@ -231,6 +255,53 @@ export default {
}
}
},
async regenerateReport() {
Vue.nextTick(() => {
this.icon = "99"; // no toggle
});
if (this.from.date === "" || this.from.date === null || this.to.date === "" || this.to.date === null) {
this.modalTitle = "Error";
this.modalText = "Please fill in all the fields";
this.openModal();
} else {
let newFlag = { flag: true };
this.disabled = newFlag;
this.isLoading = newFlag;
let resInsert2 = await axios.get(
`${CSL_CERTIFICATE_EXPORT}/${this.from.date}/${this.to.date}/${this.sequence}/0/regenerate`
);
if (resInsert2.data.success) {
this.tableData = resInsert2.data.data1;
this.batch = resInsert2.data.batch;
this.generatePDF(isPreview);
let FileSaver = require("file-saver");
const regex = /PPYT\.EDU\.CERTS\.D\d+\.001/;
const match = resInsert2.data.data2[0]["fileText"] ? resInsert2.data.data2[0]["fileText"].match(regex) : "";
const resultado = match ? match[0] : "";
let blob = new Blob([resInsert2.data.data2[0]["fileText"].replace(/PPYT\.EDU\.CERTS\.D\d+\.001/, "")], {
type: "text/plain;charset=utf-8",
});
FileSaver.saveAs(blob, `${isPreview === 1 ? "PREVIEW_" : ""}${resultado}.txt`);
let newFlag = { flag: false };
this.disabled = newFlag;
this.isLoading = newFlag;
} else {
this.$emit("showError", resInsert2.data.message);
let newFlag = { flag: false };
this.disabled = newFlag;
let newLoading = { flag: false };
this.isLoading = newLoading;
}
}
},
strMonth(month) {
let stringMonth = "";
switch (parseInt(month)) {
Expand Down

0 comments on commit b84259a

Please sign in to comment.