From 3fdb9e8c3acfbf6102a51d0b6eb63dfef36edf78 Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Wed, 15 Jan 2025 16:36:35 +0000 Subject: [PATCH] enforcement pdf fixes --- .env.local | 4 +- components/case/representation/index.js | 2 +- components/pdftemplates/enforcement_pdf.js | 173 +++++++++++++----- .../pdftemplates/lpaQuestionnaire_pdf.js | 1 + pages/api/file/generatepdf.js | 22 +++ 5 files changed, 157 insertions(+), 45 deletions(-) diff --git a/.env.local b/.env.local index 74fef70a..fb79879b 100644 --- a/.env.local +++ b/.env.local @@ -138,7 +138,9 @@ APPLICATIONINSIGHTS_CONNECTIONSTRING = InstrumentationKey=7a06e24a-793c-47bc-898 //NEXT_PUBLIC_APP_INSIGHT = InstrumentationKey=cc60e8e7-5b30-4c2b-a176-8b96b21b12df;IngestionEndpoint=https://ukwest-0.in.applicationinsights.azure.com/;LiveEndpoint=https://ukwest.livediagnostics.monitor.azure.com/;ApplicationId=2a4094be-6fd1-46ab-a67d-5f241692b129 // Preprod Connection string -NEXT_PUBLIC_APP_INSIGHT = InstrumentationKey=7370f0f9-834d-4c7a-b3c4-9951fcad5ad2;IngestionEndpoint=https://ukwest-0.in.applicationinsights.azure.com/;LiveEndpoint=https://ukwest.livediagnostics.monitor.azure.com/;ApplicationId=04362cb7-6dfc-469e-8274-12243e8be851 +//NEXT_PUBLIC_APP_INSIGHT = InstrumentationKey=7370f0f9-834d-4c7a-b3c4-9951fcad5ad2;IngestionEndpoint=https://ukwest-0.in.applicationinsights.azure.com/;LiveEndpoint=https://ukwest.livediagnostics.monitor.azure.com/;ApplicationId=04362cb7-6dfc-469e-8274-12243e8be851 + +NEXT_PUBLIC_APP_INSIGHT = InstrumentationKey=a41b91bf-f7dc-4f44-bb66-a67df4eee435;IngestionEndpoint=https://uksouth-1.in.applicationinsights.azure.com/;LiveEndpoint=https://uksouth.livediagnostics.monitor.azure.com/;ApplicationId=473d0632-16f1-4065-8984-d6bac62402c0 // Prod Connection string //NEXT_PUBLIC_APP_INSIGHT = InstrumentationKey=61f358c2-8075-4164-b897-17bc6dd31fee;IngestionEndpoint=https://ukwest-0.in.applicationinsights.azure.com/;LiveEndpoint=https://ukwest.livediagnostics.monitor.azure.com/;ApplicationId=0c297349-396b-4dc6-8b56-85f5c680adc6 diff --git a/components/case/representation/index.js b/components/case/representation/index.js index 06faf301..04bf9c92 100644 --- a/components/case/representation/index.js +++ b/components/case/representation/index.js @@ -874,7 +874,7 @@ let MakeRepresentation = (props) => { : Object.assign(values, { "filesList": props.currentView.fileList, }), - console.log("Rep Updated - props.caseReference"), + console.log("Rep Updated - ", props.caseReference), uploadRepresentationFiles(values); }; diff --git a/components/pdftemplates/enforcement_pdf.js b/components/pdftemplates/enforcement_pdf.js index ba2579d2..fa7898a9 100644 --- a/components/pdftemplates/enforcement_pdf.js +++ b/components/pdftemplates/enforcement_pdf.js @@ -10,6 +10,18 @@ import { import Html from "react-pdf-html"; import { getFormCollectionByID, bytesToSize } from "../../components/utils"; +import transLookupCY from "../../locales/cy/myrepresentations.json"; +import transLookupEN from "../../locales/en/myrepresentations.json"; + +const getTrans = (locale, key) => { + let jsonQuery = `$.${key}`; + + let jsonObj = locale == "cy" ? transLookupCY : transLookupEN; + + //console.log(locale, jsonObj[key]); + return jsonObj[key]; +}; + const styles = StyleSheet.create({ page: { backgroundColor: "white", @@ -29,7 +41,7 @@ const styles = StyleSheet.create({ logoImage: { width: "200pt" }, questionBullet: { width: "5%", fontSize: 12 }, questionText: { width: "30%", fontSize: 12 }, - questionTextMid: { width: "80%", fontSize: 12 }, + questionTextMid: { width: "75%", fontSize: 12, marginRight: 10 }, questionTextWide: { width: "95%", fontSize: 12, marginBottom: 5 }, questionAnswer: { color: "#757575", @@ -41,6 +53,28 @@ const styles = StyleSheet.create({ paddingLeft: 10, backgroundColor: "white", }, + questionAnswerSmall: { + color: "#757575", + width: "300", + fontSize: 12, + padding: 5, + border: 1, + borderColor: "#eee", + paddingLeft: 10, + paddingRight: 10, + backgroundColor: "white", + marginRight: 10, + }, + questionAnswerSmaller: { + color: "#757575", + width: "90", + fontSize: 12, + padding: 5, + border: 1, + borderColor: "#eee", + paddingLeft: 10, + backgroundColor: "white", + }, questionAnswerMid: { color: "#757575", width: "20%", @@ -53,15 +87,23 @@ const styles = StyleSheet.create({ }, questionAnswerWide: { color: "#757575", - width: "95%", + width: "100%", fontSize: 12, - marginLeft: "5%", border: 1, borderColor: "#eee", backgroundColor: "white", padding: 5, }, + questionAnswerFull: { + color: "#757575", + width: "100%", + fontSize: 10, + padding: 5, + border: 1, + borderColor: "#eee", + backgroundColor: "white", + }, sectionContainer: { backgroundColor: "#F8F8F8", padding: 10, @@ -174,8 +216,9 @@ export const EnforcementQuestionnaire_pdf = ({ docProps }) => { > 1. - {t( - "myrepresentations:s78-section-question-1" + {getTrans( + docProps.locale, + "s78-section-question-1" )} : @@ -192,13 +235,14 @@ export const EnforcementQuestionnaire_pdf = ({ docProps }) => { > 2. - {t( - "myrepresentations:s78-section-question-2" + {getTrans( + docProps.locale, + "s78-section-question-2" )} : - {values.lpaRef} + {values.lpaReference} { }} > - {t("myrepresentations:s78-section-heading-one")} + {getTrans( + docProps.locale, + "s78-section-heading-one" + )} @@ -681,16 +728,26 @@ export const EnforcementQuestionnaire_pdf = ({ docProps }) => { - 18. - - LPA’s adopted Local Development Plan and - Proposals Map - - + + + 18. + + + LPA’s adopted Local Development Plan and + Proposals Map + + + {CleanHTML(values.LPAldpAndMap)} @@ -699,16 +756,26 @@ export const EnforcementQuestionnaire_pdf = ({ docProps }) => { - 19. - - Adopted local guidance relevant to the - proposal: - - + + + 19. + + + Adopted local guidance relevant to the + proposal: + + + {CleanHTML(values.LPAlocalGuidance)} @@ -1271,7 +1338,7 @@ export const EnforcementQuestionnaire_pdf = ({ docProps }) => { {CleanHTML( - values.enforcementNoticePlan + values.enforcementNoticePlanEvidence )} @@ -1506,11 +1573,23 @@ export const EnforcementQuestionnaire_pdf = ({ docProps }) => { }} > Signed: - + {values.caseOfficer} @@ -1521,10 +1600,16 @@ export const EnforcementQuestionnaire_pdf = ({ docProps }) => { alignItems: "center", }} > - + Date: - + {formatDates(values.signedDate)} @@ -1534,6 +1619,7 @@ export const EnforcementQuestionnaire_pdf = ({ docProps }) => { style={{ flexDirection: "row", marginBottom: 10, + alignItems: "center", }} > @@ -1559,17 +1645,24 @@ export const EnforcementQuestionnaire_pdf = ({ docProps }) => { - - - List of attached files - + + + List of attached files + + @@ -1586,12 +1679,13 @@ export const EnforcementQuestionnaire_pdf = ({ docProps }) => { > {p.name} -{" "} {bytesToSize( - p.size + p.size || + p.contentLength )}{" "} {"\n"} @@ -1602,13 +1696,6 @@ export const EnforcementQuestionnaire_pdf = ({ docProps }) => { - - - * Regulation 45 of the Town and Country Planning - (Environmental Impact Assessment) (Wales) - Regulations 2017 (as amended). - - { style={{ flexDirection: "row", marginBottom: 10, + alignItems: "center", }} > diff --git a/pages/api/file/generatepdf.js b/pages/api/file/generatepdf.js index d3f10092..85bcbfe0 100644 --- a/pages/api/file/generatepdf.js +++ b/pages/api/file/generatepdf.js @@ -94,6 +94,7 @@ import ReactPDF, { import middleware from "../middleware/middleware"; import nextConnect from "next-connect"; import fs from "fs"; +import { EnforcementQuestionnaire_pdf } from "../../../components/pdftemplates/enforcement_pdf"; import { lpaQuestionnaire_pdf } from "../../../components/pdftemplates/lpaQuestionnaire_pdf"; import { finalComments_pdf } from "../../../components/pdftemplates/finalComments_pdf"; import { statement_pdf } from "../../../components/pdftemplates/statement_pdf"; @@ -182,6 +183,21 @@ export default async function handler(req, res) { console.log(values.docProps.locale); switch (values.docProps.representationType) { case "Questionnaire": + switch (values.docProps.appealType) { + case 846040005: + case 846040006: + case 846040007: + return EnforcementQuestionnaire_pdf( + values, + values.docProps.locale + ); + default: + return lpaQuestionnaire_pdf( + values, + values.docProps.locale + ); + } + return lpaQuestionnaire_pdf(values, values.docProps.locale); break; case "Final comments": @@ -268,6 +284,12 @@ export default async function handler(req, res) { // "\n/////////////////////////" // ); + // umcomment to render pdf locally + // ReactPDF.render( + // , + // process.cwd() + `/tmp/${reqBodyobj.repfile_name}.pdf` + // ); + const renderedPDF = await ReactPDF.renderToStream( );