Skip to content

Commit

Permalink
Merge pull request #482 from bcgov/restore-5.5
Browse files Browse the repository at this point in the history
Restore 5.5
  • Loading branch information
mgtennant authored Oct 24, 2024
2 parents 5100144 + 8b99b4d commit 4a0f650
Show file tree
Hide file tree
Showing 17 changed files with 278 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default function ApiaryInspectionDetailsEdit({
initialValues,
site,
}) {
console.log("ApiaryInspectionDetailsEdit");
const {
setValue,
register,
Expand Down
2 changes: 0 additions & 2 deletions app/client/src/features/inspections/CreateInspectionPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ export default function CreateInspectionPage() {

const submissionLabel = submitting ? "Submitting..." : "Create";

console.log(inspection.status);

if (inspection.status === REQUEST_STATUS.FULFILLED) {
return <Redirect to={`${SITES_PATHNAME}/${id}`} />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default function InspectionDetailsViewEdit({
site,
licence,
}) {
console.log("InspectionDetailsViewEdit");
const { status, error, mode } = inspection;

const dispatch = useDispatch();
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function submissionController(
clearErrors,
dispatch
) {
console.log("CreateTrailerInspectionPage");
const onSubmit = async (data) => {
switch (licence.data.licenceTypeId) {
case LicenceTypeConstants.LICENCE_TYPE_ID_DAIRY_TANK_TRUCK: {
Expand Down Expand Up @@ -109,7 +108,6 @@ export default function CreateTrailerInspectionPage() {

const submissionLabel = submitting ? "Submitting..." : "Create";

console.log(inspection);
if (inspection.status === REQUEST_STATUS.FULFILLED) {
return <Redirect to={`${TRAILERS_PATHNAME}/${id}`} />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default function TrailerInspectionDetailsEdit({
initialValues,
trailer,
}) {
console.log("TrailerInspectionDetailsEdit");
const {
setValue,
register,
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
1 change: 0 additions & 1 deletion app/server/routes/v1/inspections.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ router.get("/trailer/:inspectionId(\\d+)", async (req, res, next) => {
});

router.post("/trailer", async (req, res, next) => {
console.log("create trailer route");
const now = new Date();

const payload = inspection.convertTrailerInspectionToPhysicalModel(
Expand Down
Binary file modified app/server/static/templates/certificates/Dairy-Farm.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 4a0f650

Please sign in to comment.