From 2ce248fba84447c6cfec5691765ff709f733bbf6 Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Tue, 26 Sep 2023 13:39:23 +0100 Subject: [PATCH] update pdf templates with attched docs --- actions/azurestorage.js | 4 +- components/case/representation/index.js | 30 ++++- .../representationCompleteSubmit.js | 82 ++++++++++++- components/pdftemplates/finalComments_pdf.js | 90 +++++++------- .../pdftemplates/lpaQuestionnaire_pdf.js | 56 ++++++++- components/pdftemplates/other_pdf.js | 110 ++++++++++++------ components/pdftemplates/statement_pdf.js | 88 +++++++------- .../pdftemplates/writtenStatement_pdf.js | 88 +++++++------- pages/api/file/generatepdf.js | 2 +- pages/api/file/getrepsblob.js | 2 +- 10 files changed, 367 insertions(+), 185 deletions(-) diff --git a/actions/azurestorage.js b/actions/azurestorage.js index f407bcd8..10c41013 100644 --- a/actions/azurestorage.js +++ b/actions/azurestorage.js @@ -615,7 +615,7 @@ export const downloadAllRepsFiles = async (containerName, repsBlobObj) => { console.log("is empt and an array"); for (const prop in repsBlobObj) { - console.log(`Progress - ${prop}: ${repsBlobObj[prop].path}`); + //console.log(`Progress - ${prop}: ${repsBlobObj[prop].path}`); blobClient = containerClient.getBlobClient(repsBlobObj[prop].path); downloadedBlob = await blobClient.download(0); let repBlobObj = await streamToBuffer( @@ -823,7 +823,7 @@ export const getRepsBlobs = async (containerName) => { }); } - console.log("blobObjwwwww:", blobObj); + //console.log("blobObjwwwww:", blobObj); return blobObj; }; diff --git a/components/case/representation/index.js b/components/case/representation/index.js index 217e7b1a..a03a961a 100644 --- a/components/case/representation/index.js +++ b/components/case/representation/index.js @@ -403,6 +403,22 @@ let MakeRepresentation = (props) => { const onHandleSubmit = (values) => { console.log("form values - ", JSON.stringify(values)); + + const buildFileArray = []; + + console.log("attached docs: - ", buildFileArray); + + let setCaseDetailsObj = props.props.searchResultsObj.searchDetailsObj; + + var detailsObj = {}; + + detailsObj = jsonpath.query( + setCaseDetailsObj, + '$..[?(@.pinswg_name=="' + caseReference + '")]' + ); + + detailsObj = detailsObj[0]; + Object.assign(values, { "containerID": props.props.accountDetails.containerID, "appealType": props.props.currentView.caseReference.appealType, @@ -414,8 +430,16 @@ let MakeRepresentation = (props) => { "lastname": props.props.accountDetails.accountDetails.lastname, "emailAddress": props.props.accountDetails.accountDetails.emailaddress1, + "siteAddress": + detailsObj.pinswg_siteaddressline1 + + " " + + detailsObj.pinswg_siteaddressline2 + + " " + + detailsObj.pinswg_siteaddresstown + + " " + + detailsObj.pinswg_siteaddresspostcode, }); - + console.log(values); currentView.representationSubmit != true ? _.isEmpty(currentView.representationCapacity) ? isLPA @@ -431,6 +455,10 @@ let MakeRepresentation = (props) => { console.log("has errors:", props.invalid), props.invalid == false && updateRepresentation(values, false, false), + values.representationDocuments.map((Blob) => + buildFileArray.push({ "name": Blob.name, "size": Blob.size }) + ), + Object.assign(values, { "filesList": buildFileArray }), generateRepPDF( values, props.props.accountDetails.containerID, diff --git a/components/case/representation/representationCompleteSubmit.js b/components/case/representation/representationCompleteSubmit.js index cf43553d..537ddc7b 100644 --- a/components/case/representation/representationCompleteSubmit.js +++ b/components/case/representation/representationCompleteSubmit.js @@ -30,6 +30,56 @@ const RepCompleteSubmit = (props) => { const repFormData = formObj.representationForm.values; + const getThumbnailIconByExtension = (blobName) => { + let fileType = blobName.slice(blobName.lastIndexOf(".") + 1); + + switch (fileType) { + case "html": + return "/assets/images/documenttypes/html.png"; + break; + case "txt": + return "/assets/images/documenttypes/txt.png"; + break; + case "doc": + return "/assets/images/documenttypes/doc.png"; + break; + case "pdf": + return "/assets/images/documenttypes/pdf.png"; + break; + case "docx": + return "/assets/images/documenttypes/docx.png"; + break; + case "csv": + return "/assets/images/documenttypes/csv.png"; + break; + case "xlsx": + return "/assets/images/documenttypes/xlsx.png"; + break; + + case "zip": + return "/assets/images/documenttypes/zip.png"; + break; + case "jpeg": + case "jpg": + return "/assets/images/documenttypes/jpg.png"; + case "png": + return "/assets/images/documenttypes/png.png"; + break; + default: + return "/assets/images/documenttypes/txt.png"; + break; + } + }; + + function bytesToSize(bytes) { + var sizes = ["Bytes", "KB", "MB", "GB", "TB"]; + if (bytes == 0) return "0 Byte"; + var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); + return Math.round(bytes / Math.pow(1024, i), 2) + " " + sizes[i]; + } + + console.log("///////// formObj:", formObj); + return ( <> {currentView.representationSubmitConfirmation == true ? ( @@ -190,7 +240,37 @@ const RepCompleteSubmit = (props) => {
- files + {formObj.representationForm.values + .representationDocuments.length > 0 + ? formObj.representationForm.values.representationDocuments.map( + (blob, i) => ( +
+ {blob.name} + + + {blob.name} ( + {bytesToSize( + blob.size + )} + ) + +
+ ) + ) + : ""}{" "}
diff --git a/components/pdftemplates/finalComments_pdf.js b/components/pdftemplates/finalComments_pdf.js index 32a0b61b..be904405 100644 --- a/components/pdftemplates/finalComments_pdf.js +++ b/components/pdftemplates/finalComments_pdf.js @@ -10,6 +10,7 @@ import ReactPDF, { } from "@react-pdf/renderer"; import { createElement } from "react"; import Html from "react-pdf-html"; +import { getFormCollectionByID } from "../../components/utils"; import renderers, { renderBlock } from "react-pdf-html/dist/renderers"; @@ -87,11 +88,6 @@ const styles = StyleSheet.create({ flexDirection: "column", }, }); -// const renderer_1 = require("@react-pdf/renderer"); -// const renderPara = { -// "p": ({ style, element, children }) => -// createElement(renderer_1.View, { style: style }, children), -// }; export const finalComments_pdf = ({ docProps }) => { //console.log("----", docProps); @@ -104,6 +100,11 @@ export const finalComments_pdf = ({ docProps }) => { return dd + "/" + mm + "/" + yyyy; } let values = docProps; + + let datestr = values.pinswg_name.split("-"); + let signedDate = datestr[2] + "/" + datestr[1] + "/" + datestr[0]; + let appealTypeValue = getFormCollectionByID(values.appealType); + return ( @@ -170,15 +171,7 @@ export const finalComments_pdf = ({ docProps }) => { flexDirection: "row", marginBottom: 10, }} - > - 2. - - LPA reference: - - - {values.lpaRef} - - + > { Site address/grid ref: - 123 Big Street, Small Town, Little County, - XD23 54X + {values.siteAddress} { Case Type: - Planning applicaiton (s78) + {appealTypeValue.value} @@ -241,11 +233,11 @@ export const finalComments_pdf = ({ docProps }) => { Final Comments - - - {values.representationComments} - - + + + + {values.representationComments} + @@ -271,12 +263,32 @@ export const finalComments_pdf = ({ docProps }) => { > 11. - List of attachec files + List of attached files - - - {values.LPAcaseFileAndReps} - + + {values.filesList.map(function (p) { + return ( + + + {p.name} - {p.size} + + + ); + })} @@ -311,7 +323,7 @@ export const finalComments_pdf = ({ docProps }) => { Signed: - {values.caseOfficer} + {values.firstname} {values.lastname} { Date: - {formatDates(values.signedDate)} + {signedDate} @@ -340,28 +352,10 @@ export const finalComments_pdf = ({ docProps }) => { On behalf of: - {values.onBehalfOfLPA} + {values.representationCapacity} - - - * Article 11 of The Town and Country Planning - (Development Management Procedure) (Wales) Order - 2012; Regulation 7 of The Town and Country - Planning (Listed Buildings and Conservation - Areas) (Wales) Regulations 2012 - - - ** Article 12 of The Town and Country Planning - (Development Management Procedure) (Wales) Order - 2012; Section 67/73 of The Town and Country - Planning (Listed Buildings and Conservation - Areas) Act 1990; Regulation 10 of The Town and - Country Planning (Listed Buildings and - Conservation Areas) (Wales) Regulations 2012 - - { Site address/grid ref: - 123 Big Street, Small Town, Little County, - XD23 54X + {values.siteAddress} { Case Type: - Planning applicaiton (s78) + {appealTypeValue.value} @@ -1300,6 +1299,57 @@ export const lpaQuestionnaire_pdf = ({ docProps }) => { + + + + Supporting documents + + + + + + + List of attached files + + + {values.filesList.map(function (p) { + return ( + + + {p.name} - {p.size} + + + ); + })} + + + + * Article 11 of The Town and Country Planning diff --git a/components/pdftemplates/other_pdf.js b/components/pdftemplates/other_pdf.js index 8640a721..9918e9bb 100644 --- a/components/pdftemplates/other_pdf.js +++ b/components/pdftemplates/other_pdf.js @@ -10,6 +10,7 @@ import ReactPDF, { } from "@react-pdf/renderer"; import { createElement } from "react"; import Html from "react-pdf-html"; +import { getFormCollectionByID } from "../../components/utils"; import renderers, { renderBlock } from "react-pdf-html/dist/renderers"; @@ -87,11 +88,6 @@ const styles = StyleSheet.create({ flexDirection: "column", }, }); -// const renderer_1 = require("@react-pdf/renderer"); -// const renderPara = { -// "p": ({ style, element, children }) => -// createElement(renderer_1.View, { style: style }, children), -// }; export const other_pdf = ({ docProps }) => { //console.log("----", docProps); @@ -104,6 +100,11 @@ export const other_pdf = ({ docProps }) => { return dd + "/" + mm + "/" + yyyy; } let values = docProps; + + let datestr = values.pinswg_name.split("-"); + let signedDate = datestr[2] + "/" + datestr[1] + "/" + datestr[0]; + let appealTypeValue = getFormCollectionByID(values.appealType); + return ( @@ -164,8 +165,29 @@ export const other_pdf = ({ docProps }) => { {values.caseRef} - - {/* + + 3. + + Site address/grid ref: + + + {values.siteAddress} + + + { Case Type: - Planning applicaiton (s78) + {appealTypeValue.value} - */} + @@ -198,6 +220,20 @@ export const other_pdf = ({ docProps }) => { marginBottom: 10, }} > + + + 5. + + + Other Comments + + {values.representationComments} @@ -206,7 +242,7 @@ export const other_pdf = ({ docProps }) => { - {/* + { List of attached files - - - {values.LPAcaseFileAndReps} - + + {values.filesList.map(function (p) { + return ( + + + {p.name} - {p.size} + + + ); + })} @@ -267,7 +323,7 @@ export const other_pdf = ({ docProps }) => { Signed: - {values.caseOfficer} + {values.firstname} {values.lastname} { Date: - {formatDates(values.signedDate)} + {signedDate} @@ -296,29 +352,11 @@ export const other_pdf = ({ docProps }) => { On behalf of: - {values.onBehalfOfLPA} + {values.representationCapacity} - - - * Article 11 of The Town and Country Planning - (Development Management Procedure) (Wales) Order - 2012; Regulation 7 of The Town and Country - Planning (Listed Buildings and Conservation - Areas) (Wales) Regulations 2012 - - - ** Article 12 of The Town and Country Planning - (Development Management Procedure) (Wales) Order - 2012; Section 67/73 of The Town and Country - Planning (Listed Buildings and Conservation - Areas) Act 1990; Regulation 10 of The Town and - Country Planning (Listed Buildings and - Conservation Areas) (Wales) Regulations 2012 - - - */} + -// createElement(renderer_1.View, { style: style }, children), -// }; export const statement_pdf = ({ docProps }) => { //console.log("----", docProps); @@ -104,6 +100,11 @@ export const statement_pdf = ({ docProps }) => { return dd + "/" + mm + "/" + yyyy; } let values = docProps; + + let datestr = values.pinswg_name.split("-"); + let signedDate = datestr[2] + "/" + datestr[1] + "/" + datestr[0]; + let appealTypeValue = getFormCollectionByID(values.appealType); + return ( @@ -170,15 +171,7 @@ export const statement_pdf = ({ docProps }) => { flexDirection: "row", marginBottom: 10, }} - > - 2. - - LPA reference: - - - {values.lpaRef} - - + > { Site address/grid ref: - 123 Big Street, Small Town, Little County, - XD23 54X + {values.siteAddress} { Case Type: - Planning applicaiton (s78) + {appealTypeValue.value} @@ -239,12 +231,14 @@ export const statement_pdf = ({ docProps }) => { 5. - Stament - - - {values.representationComment} + Statement + + + {values.representationComments} + + @@ -271,10 +265,30 @@ export const statement_pdf = ({ docProps }) => { List of attached files - - - {values.LPAcaseFileAndReps} - + + {values.filesList.map(function (p) { + return ( + + + {p.name} - {p.size} + + + ); + })} @@ -309,7 +323,7 @@ export const statement_pdf = ({ docProps }) => { Signed: - {values.caseOfficer} + {values.firstname} {values.lastname} { Date: - {formatDates(values.signedDate)} + {signedDate} @@ -338,28 +352,10 @@ export const statement_pdf = ({ docProps }) => { On behalf of: - {values.onBehalfOfLPA} + {values.representationCapacity} - - - * Article 11 of The Town and Country Planning - (Development Management Procedure) (Wales) Order - 2012; Regulation 7 of The Town and Country - Planning (Listed Buildings and Conservation - Areas) (Wales) Regulations 2012 - - - ** Article 12 of The Town and Country Planning - (Development Management Procedure) (Wales) Order - 2012; Section 67/73 of The Town and Country - Planning (Listed Buildings and Conservation - Areas) Act 1990; Regulation 10 of The Town and - Country Planning (Listed Buildings and - Conservation Areas) (Wales) Regulations 2012 - - -// createElement(renderer_1.View, { style: style }, children), -// }; export const writtenStatement_pdf = ({ docProps }) => { //console.log("----", docProps); @@ -104,6 +100,11 @@ export const writtenStatement_pdf = ({ docProps }) => { return dd + "/" + mm + "/" + yyyy; } let values = docProps; + + let datestr = values.pinswg_name.split("-"); + let signedDate = datestr[2] + "/" + datestr[1] + "/" + datestr[0]; + let appealTypeValue = getFormCollectionByID(values.appealType); + return ( @@ -170,15 +171,7 @@ export const writtenStatement_pdf = ({ docProps }) => { flexDirection: "row", marginBottom: 10, }} - > - 2. - - LPA reference: - - - {values.lpaRef} - - + > { Site address/grid ref: - 123 Big Street, Small Town, Little County, - XD23 54X + {values.siteAddress} { Case Type: - Planning applicaiton (s78) + {appealTypeValue.value} @@ -239,12 +231,14 @@ export const writtenStatement_pdf = ({ docProps }) => { 5. - Stament - - - {values.representationComment} + Statement + + + {values.representationComments} + + @@ -271,10 +265,30 @@ export const writtenStatement_pdf = ({ docProps }) => { List of attached files - - - {values.LPAcaseFileAndReps} - + + {values.filesList.map(function (p) { + return ( + + + {p.name} - {p.size} + + + ); + })} @@ -309,7 +323,7 @@ export const writtenStatement_pdf = ({ docProps }) => { Signed: - {values.caseOfficer} + {values.firstname} {values.lastname} { Date: - {formatDates(values.signedDate)} + {signedDate} @@ -338,28 +352,10 @@ export const writtenStatement_pdf = ({ docProps }) => { On behalf of: - {values.onBehalfOfLPA} + {values.representationCapacity} - - - * Article 11 of The Town and Country Planning - (Development Management Procedure) (Wales) Order - 2012; Regulation 7 of The Town and Country - Planning (Listed Buildings and Conservation - Areas) (Wales) Regulations 2012 - - - ** Article 12 of The Town and Country Planning - (Development Management Procedure) (Wales) Order - 2012; Section 67/73 of The Town and Country - Planning (Listed Buildings and Conservation - Areas) Act 1990; Regulation 10 of The Town and - Country Planning (Listed Buildings and - Conservation Areas) (Wales) Regulations 2012 - -