Skip to content

Commit

Permalink
Revert "Merge pull request #490 from bcgov/bf-revert-5.5-2"
Browse files Browse the repository at this point in the history
This reverts commit d28dd6b, reversing
changes made to 3ab5d9c.
  • Loading branch information
mgtennant committed Dec 9, 2024
1 parent d28dd6b commit c1b4a33
Show file tree
Hide file tree
Showing 13 changed files with 435 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/client/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<title>Agriculture Licencing System</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this application</noscript>
<noscript>You need to enable JavaScript to run this application.</noscript>
<div id="root"></div>
</body>
</html>
83 changes: 83 additions & 0 deletions app/client/src/features/reports/ReportLicenceComments.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React, { useEffect } from "react";
import { useForm } from "react-hook-form";
import { useSelector, useDispatch } from "react-redux";
import { Row, Col, Form, Button } from "react-bootstrap";

import DocGenDownloadBar from "../../components/DocGenDownloadBar";

import {
generateReport,
fetchReportJob,
selectReportsJob,
completeReportJob,
startLicenceCommentsJob,
} from "./reportsSlice";

import { REPORTS } from "../../utilities/constants";

export default function ReportLicenceComments() {
const dispatch = useDispatch();

const job = useSelector(selectReportsJob);
const { pendingDocuments } = job;

const form = useForm({
reValidateMode: "onBlur",
});
const { register, watch } = form;

const watchLicenceNumber = watch("licenceNumber", null);

useEffect(() => {
if (job.id && job.type === REPORTS.LICENCE_COMMENTS) {
dispatch(fetchReportJob());

if (pendingDocuments?.length > 0) {
dispatch(generateReport(pendingDocuments[0].documentId));
} else {
dispatch(completeReportJob(job.id));
}
}
}, [pendingDocuments]); // eslint-disable-line react-hooks/exhaustive-deps

const onGenerateReport = () => {
dispatch(
startLicenceCommentsJob({
licenceNumber: watchLicenceNumber,
})
);
};

return (
<>
<Row>
<Col lg={3}>
<Form.Label>Licence Number</Form.Label>
<Form.Control
id="licenceNumber"
type="text"
name="licenceNumber"
defaultValue={null}
{...register("licenceNumber")}
/>
</Col>
<Col sm={2}>
<Form.Label>&nbsp;</Form.Label>
<Button
variant="primary"
type="button"
onClick={() => onGenerateReport()}
block
>
Generate Report
</Button>
</Col>
</Row>
<div className="mt-3">
<DocGenDownloadBar job={job} />
</div>
</>
);
}

ReportLicenceComments.propTypes = {};
16 changes: 16 additions & 0 deletions app/client/src/features/reports/Reports.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import ReportLicenceExpiry from "./ReportLicenceExpiry";
import { clearReportsJob } from "./reportsSlice";
import RenderOnRole from "../../components/RenderOnRole";
import ReportDairyTrailerInspection from "./ReportDairyTrailerInspection";
import ReportLicenceComments from "./ReportLicenceComments";

export default function Reports() {
const dispatch = useDispatch();
Expand Down Expand Up @@ -70,6 +71,9 @@ export default function Reports() {
case REPORTS.DAIRY_TEST_THRESHOLD:
control = <ReportDairyThreshold />;
break;
case REPORTS.LICENCE_COMMENTS:
control = <ReportLicenceComments />;
break;
case REPORTS.LICENCE_LOCATION:
control = <ReportLicenceTypeLocation />;
break;
Expand Down Expand Up @@ -193,6 +197,18 @@ export default function Reports() {
</option>
</RenderOnRole>

<RenderOnRole
roles={[
SYSTEM_ROLES.READ_ONLY,
SYSTEM_ROLES.USER,
SYSTEM_ROLES.SYSTEM_ADMIN,
]}
>
<option value={REPORTS.LICENCE_COMMENTS}>
Licence Comments
</option>
</RenderOnRole>

<RenderOnRole
roles={[
SYSTEM_ROLES.READ_ONLY,
Expand Down
21 changes: 21 additions & 0 deletions app/client/src/features/reports/reportsSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,24 @@ export const startLicenceTypeLocationJob = createAsyncThunk(
}
);

export const startLicenceCommentsJob = createAsyncThunk(
"reports/startLicenceCommentsJob",
async (payload, thunkApi) => {
try {
const response = await Api.post(
`documents/reports/startJob/licenceComments`,
payload
);
return response.data;
} catch (error) {
if (error instanceof ApiError) {
return thunkApi.rejectWithValue(error.serialize());
}
return thunkApi.rejectWithValue({ code: -1, description: error.message });
}
}
);

export const startLicenceExpiryJob = createAsyncThunk(
"reports/startLicenceExpiryJob",
async (payload, thunkApi) => {
Expand Down Expand Up @@ -379,6 +397,9 @@ export const reportsSlice = createSlice({
[startLicenceExpiryJob.pending]: pendingStartJobReducer,
[startLicenceExpiryJob.fulfilled]: fulfilledStartJobReducer,
[startLicenceExpiryJob.rejected]: rejectionStartJobReducer,
[startLicenceCommentsJob.pending]: pendingStartJobReducer,
[startLicenceCommentsJob.fulfilled]: fulfilledStartJobReducer,
[startLicenceCommentsJob.rejected]: rejectionStartJobReducer,

[fetchReportJob.pending]: (state) => {
state.job.status = REQUEST_STATUS.PENDING;
Expand Down
1 change: 1 addition & 0 deletions app/client/src/utilities/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const REPORTS = {
DAIRY_FARM_QUALITY: "DAIRY_FARM_QUALITY",
DAIRY_FARM_TANK: "DAIRY_FARM_TANK",
DAIRY_TEST_THRESHOLD: "DAIRY_TEST_THRESHOLD",
LICENCE_COMMENTS: "LICENCE_COMMENTS",
LICENCE_LOCATION: "LICENCE_LOCATION",
LICENCE_EXPIRY: "LICENCE_EXPIRY",
DAIRY_TRAILER_INSPECTION: "TRAILER INSPECTION",
Expand Down
39 changes: 37 additions & 2 deletions app/server/routes/v1/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,21 @@ async function startLicenceTypeLocationJob(licenceTypeId) {
return { jobId, documents };
}

async function startLicenceCommentsJob(licenceNumber) {
const [procedureResult] = await prisma.$transaction([
prisma.$queryRawUnsafe(
`CALL mals_app.pr_generate_print_json_licence_comments('${licenceNumber}', NULL)`,
licenceNumber
),
]);

const jobId = procedureResult[0].iop_print_job_id;

const documents = await getPendingDocuments(jobId);

return { jobId, documents };
}

async function startLicenceExpiryJob(startDate, endDate) {
const [procedureResult] = await prisma.$transaction([
prisma.$queryRawUnsafe(
Expand Down Expand Up @@ -1462,6 +1477,17 @@ router.post("/reports/startJob/licenceTypeLocation", async (req, res, next) => {
.finally(async () => prisma.$disconnect());
});

router.post("/reports/startJob/licenceComments", async (req, res, next) => {
const licenceNumber = req.body.licenceNumber;

await startLicenceCommentsJob(licenceNumber)
.then(({ jobId, documents }) => {
return res.send({ jobId, documents, type: REPORTS.LICENCE_COMMENTS });
})
.catch(next)
.finally(async () => prisma.$disconnect());
});

router.post("/reports/startJob/licenceExpiry", async (req, res, next) => {
const startDate = formatDate(new Date(req.body.startDate));
const endDate = formatDate(new Date(req.body.endDate));
Expand Down Expand Up @@ -1543,7 +1569,17 @@ router.post("/download/:jobId(\\d+)", async (req, res, next) => {
const zip = new AdmZip();
let fileName = null;
documents.forEach((document) => {
if (job.printCategory === constants.DOCUMENT_TYPE_REPORT) {
if (
job.printCategory === constants.DOCUMENT_TYPE_REPORT &&
document.document_type === constants.REPORTS.LICENCE_COMMENTS
) {
fileName = `${document.document_json.Licence_Number}-${document.document_type}.xlsx`;
} else if (
job.printCategory === constants.DOCUMENT_TYPE_REPORT &&
document.document_type === constants.REPORTS.DAIRY_TRAILER_INSPECTION
) {
fileName = `${document.document_json.LicenceNumber}-${document.document_type}.xlsx`;
} else if (job.printCategory === constants.DOCUMENT_TYPE_REPORT) {
fileName = `${document.document_json.Licence_Type}-${document.document_type}.xlsx`;
} else if (
document.document_type === constants.DOCUMENT_TYPE_DAIRY_INFRACTION
Expand All @@ -1552,7 +1588,6 @@ router.post("/download/:jobId(\\d+)", async (req, res, next) => {
} else {
fileName = `${document.licence_number}-${document.document_type}.docx`;
}

zip.addFile(fileName, document.document_binary);
});

Expand Down
Binary file modified app/server/static/templates/certificates/Dairy-Farm.docx
Binary file not shown.
Binary file modified app/server/static/templates/certificates/Purchase-Live-Poultry.docx
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions app/server/utilities/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,6 @@ module.exports = Object.freeze({
DAIRY_TRAILER_INSPECTION: "TRAILER INSPECTION",
LICENCE_LOCATION: "LICENCE_LOCATION",
LICENCE_EXPIRY: "LICENCE_EXPIRY",
LICENCE_COMMENTS: "LICENCE_COMMENTS",
},
});
2 changes: 2 additions & 0 deletions app/server/utilities/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ function getReportsTemplateName(documentType) {
return "Licence_Expiry_Species_NoSpecies_Template";
case constants.REPORTS.DAIRY_TRAILER_INSPECTION:
return "Dairy_Trailer_Inspection_Template";
case constants.REPORTS.LICENCE_COMMENTS:
return "Licence_Comments_Template";
default:
return null;
}
Expand Down
Loading

0 comments on commit c1b4a33

Please sign in to comment.