From f53faf47e2277ec184002e79387c284c152dbc59 Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Wed, 11 Oct 2023 13:51:35 +0100 Subject: [PATCH] create rep pdf tweaks prior to multi types matrix --- actions/azurestorage.js | 48 +- components/case/representation/index.js | 86 +- .../case/representation/representationLPA.js | 1487 +++++++++-------- components/pdftemplates/appealRow_pdf.js | 348 ++++ .../pdftemplates/lpaQuestionnaire_pdf.js | 2 + components/pdftemplates/other_pdf.js | 49 +- .../pdftemplates/planningappeals78_pdf.js | 362 ++++ package.json | 3 +- pages/api/file/generateappealpdf.js | 211 +++ pages/api/file/generatepdf.js | 27 +- 10 files changed, 1824 insertions(+), 799 deletions(-) create mode 100644 components/pdftemplates/appealRow_pdf.js create mode 100644 components/pdftemplates/planningappeals78_pdf.js create mode 100644 pages/api/file/generateappealpdf.js diff --git a/actions/azurestorage.js b/actions/azurestorage.js index 277fdcfd..c4855bb6 100644 --- a/actions/azurestorage.js +++ b/actions/azurestorage.js @@ -428,6 +428,52 @@ export const uploadRepFiles = async ( ); }; +export const uploadPDFRepFiles = async ( + formContent, + containerName, + foldername, + repType +) => { + const containerToken = await createContainerSas(containerName); + const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`; + const containerClient = new ContainerClient(sasUrl); + + const files = formContent; + + console.log(formContent, containerName, foldername); + console.log( + "rep pdf files...", + files, + Object.keys(files).length, + foldername + ); + + // console.log(`files[${prop}] = ${files[prop][0].size}`); + console.log(foldername + "/files/" + formContent.split("tmp/")[1]); + + const blobName = foldername + "/" + formContent.split("tmp/")[1]; + console.log(blobName); + + const blockBlobClient = containerClient.getBlockBlobClient(blobName); + const uploadBlobResponse = await blockBlobClient.uploadFile(formContent); + + const tags = { + containerid: containerName, + caseID: foldername.split("/")[0], + documentType: repType, + blobType: "RepresentationPDF", + }; + + console.log("the tags:", tags); + const withTags = await blockBlobClient.setTags(tags); + const withMeta = await blockBlobClient.setMetadata(tags); + + console.log( + `Uploaded block blob ${files} successfully`, + uploadBlobResponse.requestId + ); +}; + export const uploadPDFCaseFiles = async ( formContent, containerName, @@ -821,7 +867,7 @@ export const getRepsBlobs = async (containerName) => { listOptions )) { const blobClient = await containerClient.getBlobClient(blob.name); - console.log(blob); + console.log("getreps blob blob", blob); blob.name.split("/")[2].indexOf("_rep.json") > 0 && blob.name.split("/")[2].indexOf("undefined") < 0 && blobObj.push({ diff --git a/components/case/representation/index.js b/components/case/representation/index.js index ab9debcb..96b1ef35 100644 --- a/components/case/representation/index.js +++ b/components/case/representation/index.js @@ -432,40 +432,56 @@ let MakeRepresentation = (props) => { detailsObj = detailsObj[0]; - Object.assign(values, { - "containerID": props.props.accountDetails.containerID, - "appealType": props.props.currentView.caseReference.appealType, - "incidentID": props.props.currentView.caseReference.incidentid, - "caseRef": props.props.currentView.caseReference.currentReference, - "pinswg_name": - props.props.currentView.caseReference.currentReference, - "firstname": props.props.accountDetails.accountDetails.firstname, - "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, - "pinswg_siteaddressline1": detailsObj.pinswg_siteaddressline1, - "pinswg_siteaddressline2": detailsObj.pinswg_siteaddressline2, - "pinswg_siteaddresstown": detailsObj.pinswg_siteaddresstown, - "pinswg_siteaddresspostcode": detailsObj.pinswg_siteaddresspostcode, - "_pinswg_appellant_value": detailsObj["_pinswg_appellant_value"], - "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue": - detailsObj[ - "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue" - ], - "representationCapacity": router.query.hasOwnProperty("state") - ? router.query.state == "edit" - ? props.props.currentView.representationCapacity - : values.representationCapacity - : values.representationCapacity, - }); + console.log( + "Has data from form:", + formObj.hasOwnProperty("representationForm") && + formObj.representationForm.hasOwnProperty("values") + ); + + formObj.hasOwnProperty("representationForm") && + !router.query.hasOwnProperty("state") && + formObj.representationForm.hasOwnProperty("values") && + (Object.assign(values, formObj.representationForm.values), + Object.assign(values, { + "containerID": props.props.accountDetails.containerID, + "appealType": props.props.currentView.caseReference.appealType, + "incidentID": props.props.currentView.caseReference.incidentid, + "caseRef": + props.props.currentView.caseReference.currentReference, + "pinswg_name": + props.props.currentView.caseReference.currentReference, + "firstname": + props.props.accountDetails.accountDetails.firstname, + "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, + "pinswg_siteaddressline1": detailsObj.pinswg_siteaddressline1, + "pinswg_siteaddressline2": detailsObj.pinswg_siteaddressline2, + "pinswg_siteaddresstown": detailsObj.pinswg_siteaddresstown, + "pinswg_siteaddresspostcode": + detailsObj.pinswg_siteaddresspostcode, + "_pinswg_appellant_value": + detailsObj["_pinswg_appellant_value"], + "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue": + detailsObj[ + "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue" + ], + "representationCapacity": router.query.hasOwnProperty("state") + ? router.query.state == "edit" + ? props.props.currentView.representationCapacity + : values.representationCapacity + : isLPA + ? "lpa" + : values.representationCapacity, + })); console.log(values); currentView.representationSubmit != true ? _.isEmpty(currentView.representationCapacity) @@ -610,7 +626,7 @@ let MakeRepresentation = (props) => { }; const mapStateToProps = (state) => { - console.log("\\\\\\\\\\\\\\\\\\\\\\\\\\\\/nin map state", state); + console.log("\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \n in map state", state); return { search: state.search, diff --git a/components/case/representation/representationLPA.js b/components/case/representation/representationLPA.js index 92e1fad9..197cc4a0 100644 --- a/components/case/representation/representationLPA.js +++ b/components/case/representation/representationLPA.js @@ -48,7 +48,7 @@ let RepLPA = (props) => {

- Questionnaire from an LPA + Representation from an LPA

@@ -59,6 +59,7 @@ let RepLPA = (props) => { What kind of representation are you making? {
- {props.representationTypeValue != "Questionnaire" ? ( - <> -

- You can enter your comments in the space - provided or attach a separate document. -

-
-
+

+ You can enter your comments in the space + provided or attach a separate document. +

+
- My comments are set out in: -
-
- -
-
- - ) : ( - <> -
-

- Appeal procedure and site visit{" "} -

-
- - {(procedureTypeValue == "Hearing" || - procedureTypeValue == - "Inquiry") && ( +
+ My comments are set out in: +
+
+
+
+
+ {" "} +
+ +
+
+ + ) : ( + <> +
+

+ Appeal procedure and site visit{" "} +

+
+ + {(procedureTypeValue == "Hearing" || + procedureTypeValue == + "Inquiry") && ( + + )} + + + +
+ +
+
+ +
+
+ +
+ +
+ +
+
+
+
+

+ Supporting documents{" "} +

+
+ { props.name + "-hint" } richText="false" + hint="Insert weblink(s) to case file and representations on the LPA’s public portal. This must include all documents which were before the LPA at the time of its decision or when the appeal was made. Ensure that you link directly to the case documents list, not to a generic page on the LPA’s portal. If web-based comments were also made, insert a second link to that page. Alternatively, state here if you are sending relevant case file documents under separate cover." /> - )} - +
+
+ +
+
+ +
+
+ +
+

+ Statutory considerations +

+ {
{ } validate={[required]} legend={ - "7. Do you consider that the Inspector needs to enter neighbouring private land/property to view the site?" + "16. Does the site include any public rights of way?" } conditionalLabel={ - "If Yes, give reasons and provide the neighbouring site address. If you have them, provide the contact details of the landowner in an attachment." + "If Yes, attach or insert a link to the definitive map and statement for the local area" } optionSelect={"Yes"} />
{ } validate={[required]} legend={ - "8. If access to private land/buildings is required, are you content for the Inspector to visit the site on an ‘access required’ basis, with only the landowner or their representative present?" + "17. Is all or part of the site within a Conservation Area?" } conditionalLabel={ - "If No, give reasons for why you consider an Accompanied Site Visit to be necessary" + "If Yes, attach or insert links to a plan showing the Conservation Area boundary" + } + optionSelect={"Yes"} + /> +
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+ +
+
+
+

+ Suggested conditions +

+
+ 24. Review the following standard + conditions and advise whether they + would be necessary if + permission/consent is granted (not + applicable to Advertisement consent + proposals): +
+ + + +
+ +
+ + + +
+ +
+
+
+

+ Before sending, have you attached or + provided a web link to: +

+ +
+
{ } validate={[required]} legend={ - "9. Are you aware of any health and safety issues which would need to be considered when the Inspector visits the site?" + "27. Evidence of any publicity given to the application, including site notices and local advertisement?**" } conditionalLabel={ - "If Yes, describe the health and safety issues to be considered" + "Insert weblink here if available online. If No, give reasons" + } + optionSelect={"No"} + /> +
+
+ +
+
+
-
+
+
+ +
+
+ +
+
+ +
+
+
+

+ Declaration +

+
+
-
- -
-

- Supporting documents{" "} -

-
- -
-
- -
-
- -
- -
-
-

- Statutory considerations -

- +
+ {onBehalfOfLPA} seww + +
+ +
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
- -
- -
- -
-

- Suggested conditions -

-
- 24. Review the following standard - conditions and advise whether they would - be necessary if permission/consent is - granted (not applicable to Advertisement - consent proposals): -
- - - -
- -
- - - -
- -
-
-
-

- Before sending, have you attached or - provided a web link to: -

- -
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
-

- Declaration -

-
- -
- -
- {onBehalfOfLPA} seww - -
- -
- -
- {" "} -
- -
-
- - )} +
+ {" "} +
+ +
+
+ + ))}
{" "}
@@ -929,7 +970,17 @@ RepLPA = connect((state) => { })(RepLPA); const mapStateToProps = (state, props) => { - console.log(); + let initialValuesTemp = Object.assign( + state.currentView.caseReference.hasOwnProperty("repDetails") + ? state.currentView.caseReference.repDetails + : state.currentView.caseReference, + { + "onBehalfOfLPA": + props.props.props.accountDetails.accountDetails[ + "pinswg_contact_associatedlpa@OData.Community.Display.V1.FormattedValue" + ], + } + ); return { search: state.search, searchResultsObj: state.searchResultsObj, @@ -937,7 +988,7 @@ const mapStateToProps = (state, props) => { appealType: state.appealType, currentView: state.currentView, myRepresentations: state.myRepresentations, - initialValues: state.currentView.caseReference.repDetails, + initialValues: initialValuesTemp, }; }; diff --git a/components/pdftemplates/appealRow_pdf.js b/components/pdftemplates/appealRow_pdf.js new file mode 100644 index 00000000..80b3019b --- /dev/null +++ b/components/pdftemplates/appealRow_pdf.js @@ -0,0 +1,348 @@ +import Link from "next/link"; +import { useRouter } from "next/router"; +import useTranslation from "next-translate/useTranslation"; +import xpath from "xpath"; +import jsonpath from "jsonpath"; +import { useSelector, shallowEqual, connect } from "react-redux"; +import fieldLookup from "../../data/crmfieldlookuptranslations.json"; +import { + getFormCollectionByID, + getPickListLabel, + getRadioLabel, +} from "../../components/utils"; + +import ReactPDF, { + Document, + Page, + Text, + View, + Image, + StyleSheet, + PDFViewer, + Font, +} from "@react-pdf/renderer"; +import _ from "lodash"; + +import { DOMParser, XMLSerializer } from "@xmldom/xmldom"; + +export const AppealRow_pdf = (props) => { + let { t } = useTranslation(); + + // const router = useRouter(); + // console.log(router); + // const { locale } = router; + + const { + formXML, + whichSection, + sectionCount, + onSubmit, + updateCurrentSection, + mandatoryFieldsData, + } = props; + + const styles = StyleSheet.create({ + page: { + backgroundColor: "white", + padding: 20, + fontSize: 16, + paddingBottom: 50, + }, + header: { + fontSize: 25, + fontFamily: "Helvetica", + flexDirection: "row", + justifyContent: "space-between", + }, + subHeader: { + fontSize: 20, + }, + logoImage: { width: "200pt" }, + questionBullet: { width: "5%", fontSize: 12 }, + questionText: { width: "30%", fontSize: 12 }, + questionTextMid: { width: "80%", fontSize: 12 }, + questionTextWide: { width: "95%", fontSize: 12, marginBottom: 5 }, + questionAnswer: { + color: "#757575", + width: "65%", + fontSize: 12, + padding: 5, + border: 1, + borderColor: "#eee", + paddingLeft: 10, + backgroundColor: "white", + }, + questionAnswerMid: { + color: "#757575", + width: "20%", + fontSize: 12, + padding: 5, + border: 1, + borderColor: "#eee", + paddingLeft: 10, + backgroundColor: "white", + }, + questionAnswerWide: { + color: "#757575", + width: "95%", + fontSize: 12, + marginLeft: "5%", + border: 1, + borderColor: "#eee", + backgroundColor: "white", + padding: 5, + }, + + sectionContainer: { + backgroundColor: "#F8F8F8", + padding: 10, + marginTop: 20, + fontSize: 15, + }, + pageNumber: { + position: "absolute", + fontSize: 12, + bottom: 20, + left: 0, + right: 0, + textAlign: "center", + color: "grey", + }, + + richArea: { + fontSize: 12, + color: "red", + flexDirection: "column", + }, + }); + + const parser = new DOMParser(); + var doc = parser.parseFromString(formXML, "text/xml"); + + var rowXML = xpath.select( + "/form/tabs/tab[" + + whichSection + + "]/columns//sections/section/rows/row", + doc + ); + + //console.log(rowXML); + + function formatDate(dateObj) { + var m = new Date(dateObj); + var dateString; + dateObj != null + ? (dateString = + ("0" + m.getDate()).slice(-2) + + "/" + + ("0" + (m.getMonth() + 1)).slice(-2) + + "/" + + m.getFullYear()) + : (dateString = ""); + + return dateString; + } + + const FieldsTranslations = (label) => { + // const router = useRouter(); + // const { locale } = router; + const { appealtypes } = router.query; + + let formObj = jsonpath.query(fieldLookup, "$['" + appealtypes + "']"); + + // let labelTrans = + // router.locale == "cy" + // ? jsonpath.query( + // formObj, + // "$..[?(@.value=='" + label + "')].value_cy" + // ) + // : label; + + let labelTrans = label; + return labelTrans; + }; + + return ( + <> + {Object.keys(rowXML).map((key, index) => { + var newRowXML = new XMLSerializer().serializeToString( + rowXML[key] + ); + //console.log(newRowXML); + var doc = parser.parseFromString(newRowXML, "text/xml"); + + var rows = xpath.select("//label/@description", doc); + var fieldtype = xpath.select("//@classid", doc); + var datafieldname = xpath.select("//@datafieldname", doc); + + return ( + <> + {(() => { + switch (fieldtype[0].value) { + case "{5B773807-9FB2-42db-97C3-7A91EFF8ADFF}": + return ( + + + {/* {FieldsTranslations(rows[0].value)} */} + {rows[0].value} + + + + {formatDate( + props.props[ + datafieldname[0].value + ] + )}{" "} + + + ); + break; + case "{E0DECE4B-6FC8-4a8f-A065-082708572369}": + return ( + + + + {rows[0].value} + + + + + { + props.props[ + datafieldname[0] + .value + ] + } + + + + ); + break; + case "{07FAC785-CD58-4f9f-ABB3-4B7DDC6ED5ED}": + return ( + + + + {rows[0].value} + + + + + { + props.props[ + datafieldname[0] + .value + ] + } + + + + ); + break; + + default: + return ( + + + {/* {FieldsTranslations(rows[0].value)} */} + {rows[0].value} + + + + { + props.props[ + datafieldname[0].value + ] + } + + + ); + break; + } + })()} + + {/* + {fieldtype[0].value == + "{5B773807-9FB2-42db-97C3-7A91EFF8ADFF}" + ? formatDate( + props.props.values[datafieldname[0].value] + ) + : fieldtype[0].value == + "{3EF39988-22BB-4f0b-BBBE-64B5A3748AEE}" + ? getPickListLabel( + props.props.formData.pickListData, + datafieldname[0].value, + props.props.values[datafieldname[0].value] + ) + : fieldtype[0].value == + "{07FAC785-CD58-4f9f-ABB3-4B7DDC6ED5ED}" + ? getRadioLabel( + props.props.formData.pickListData, + datafieldname[0].value, + props.props.values[datafieldname[0].value] + ) + : fieldtype[0].value == + "{16D63FD6-119B-4353-BDCA-18358721C3FE}" + ? "ssss" + : props.props.values[datafieldname[0].value]} + */} + + ); + })} + + ); +}; diff --git a/components/pdftemplates/lpaQuestionnaire_pdf.js b/components/pdftemplates/lpaQuestionnaire_pdf.js index fd50ad3b..08afcbc7 100644 --- a/components/pdftemplates/lpaQuestionnaire_pdf.js +++ b/components/pdftemplates/lpaQuestionnaire_pdf.js @@ -9,6 +9,7 @@ import ReactPDF, { Font, } from "@react-pdf/renderer"; import Html from "react-pdf-html"; +import { getFormCollectionByID } from "../../components/utils"; const styles = StyleSheet.create({ page: { @@ -96,6 +97,7 @@ export const lpaQuestionnaire_pdf = ({ docProps }) => { return dd + "/" + mm + "/" + yyyy; } let values = docProps; + let appealTypeValue = getFormCollectionByID(values.appealType); console.log("sdffhjdhjdjdgkj: ", values.procedureType); return ( diff --git a/components/pdftemplates/other_pdf.js b/components/pdftemplates/other_pdf.js index 93fd7793..59c74208 100644 --- a/components/pdftemplates/other_pdf.js +++ b/components/pdftemplates/other_pdf.js @@ -103,7 +103,7 @@ export const other_pdf = ({ docProps }) => { let datestr = values.pinswg_name.split("-"); let signedDate = datestr[2] + "/" + datestr[1] + "/" + datestr[0]; - let appealTypeValue = getFormCollectionByID(values.appealType); + const isLPA = values.representationCapacity == "lpa" ? true : false; return ( @@ -128,9 +128,13 @@ export const other_pdf = ({ docProps }) => { fontFamily: "Helvetica-Bold", }} > - For Planning, Conservation area, Listed - Building and Advertisement - applications/appeals + For Planning Appeal, Planning Conditions, + Listed Building and Conservation Area + Appeal, Lawful Development Appeal, Planning + Obligations, Community Infrastructure Levy, + Enforcement Notice appeal, Enforcement + Listed Building Appeal, Maintenance of land, + Called in Application applications/appeals @@ -199,7 +203,10 @@ export const other_pdf = ({ docProps }) => { Case Type: - {appealTypeValue.value} + { + getFormCollectionByID(values.appealType) + .value + } @@ -342,20 +349,24 @@ export const other_pdf = ({ docProps }) => { - - - On behalf of: - - - {values.representationCapacity} - - + {isLPA && ( + + + On behalf of: + + + {values.representationCapacity} + + + )} diff --git a/components/pdftemplates/planningappeals78_pdf.js b/components/pdftemplates/planningappeals78_pdf.js new file mode 100644 index 00000000..92d1c57a --- /dev/null +++ b/components/pdftemplates/planningappeals78_pdf.js @@ -0,0 +1,362 @@ +import ReactPDF, { + Document, + Page, + Text, + View, + Image, + StyleSheet, + PDFViewer, + Font, +} from "@react-pdf/renderer"; +import { createElement } from "react"; +import Html from "react-pdf-html"; +import { getFormCollectionByID } from "../utils"; +import fs from "fs"; +import xpath from "xpath"; +import renderers, { renderBlock } from "react-pdf-html/dist/renderers"; +import _ from "lodash"; +import { DOMParser, XMLSerializer } from "@xmldom/xmldom"; +import { AppealRow_pdf } from "./appealRow_pdf"; + +const styles = StyleSheet.create({ + page: { + backgroundColor: "white", + padding: 20, + fontSize: 16, + paddingBottom: 50, + }, + header: { + fontSize: 25, + fontFamily: "Helvetica", + flexDirection: "row", + justifyContent: "space-between", + }, + subHeader: { + fontSize: 20, + }, + logoImage: { width: "200pt" }, + questionBullet: { width: "5%", fontSize: 12 }, + questionText: { width: "30%", fontSize: 12 }, + questionTextMid: { width: "80%", fontSize: 12 }, + questionTextWide: { width: "95%", fontSize: 12, marginBottom: 5 }, + questionAnswer: { + color: "#757575", + width: "65%", + fontSize: 12, + padding: 5, + border: 1, + borderColor: "#eee", + paddingLeft: 10, + backgroundColor: "white", + }, + questionAnswerMid: { + color: "#757575", + width: "20%", + fontSize: 12, + padding: 5, + border: 1, + borderColor: "#eee", + paddingLeft: 10, + backgroundColor: "white", + }, + questionAnswerWide: { + color: "#757575", + width: "95%", + fontSize: 12, + marginLeft: "5%", + border: 1, + borderColor: "#eee", + backgroundColor: "white", + padding: 5, + }, + + sectionContainer: { + backgroundColor: "#F8F8F8", + padding: 10, + marginTop: 20, + fontSize: 15, + }, + pageNumber: { + position: "absolute", + fontSize: 12, + bottom: 20, + left: 0, + right: 0, + textAlign: "center", + color: "grey", + }, + + richArea: { + fontSize: 12, + color: "red", + flexDirection: "column", + }, +}); + +export const planningappeals78_pdf = ({ docProps }) => { + //console.log("----", docProps); + function formatDates(dateObj) { + var dateObj = new Date(dateObj); + var dd = String(dateObj.getDate()).padStart(2, "0"); + var mm = String(dateObj.getMonth() + 1).padStart(2, "0"); //January is 0! + var yyyy = dateObj.getFullYear(); + + 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.pinswg_appealcasetype); + + var path = require("path"); + const configDirectory = path.resolve(process.cwd(), "data/formsxml"); + var xmlStr = fs.readFileSync( + path.join(configDirectory, "planningappeals78" + ".xml"), + "utf8" + ); + + xmlStr = xmlStr.replace(/\t/g, ""); + xmlStr = xmlStr.replace(/\n/g, ""); + xmlStr = xmlStr.replace(/> <"/g, "><"); + xmlStr = xmlStr.toString(); + + console.log(xmlStr); + + const parser = new DOMParser(); + var doc = parser.parseFromString(xmlStr, "text/xml"); + var titles = xpath.select( + "//form/tabs/tab[*]/labels/label/@description", + doc + ); + var rowXML = xpath.select( + "/form/tabs/tab[*]/columns//sections/section/rows/row", + doc + ); + + var titleList = xpath.select( + "//form/tabs/tab[*]/labels/label/@description", + doc + ); + + //console.log(titles); + + return ( + + + + + + + Planning Appeals s78 + + + + For Planning, Conservation area, Listed + Building and Advertisement + applications/appeals + + + + + + + + + Case details + + + + 1. + + PEDW reference: + + + {values.caseRef} + + + + + 3. + + Site address/grid ref: + + + {values.siteAddress} + + + + 4. + + Case Type: + + + {appealTypeValue.value} + + + + + + {Object.keys(titles).map((key) => ( + + + + {parseInt(key) + 1} {titles[key].value} + + + + + + + + + + + ))} + + + + + Supporting documents + + + + + 11. + + List of attached files + + + {values.hasOwnProperty("filesList") && + values.filesList.map(function (p) { + return ( + + + {p.name} - {p.size} + + + ); + })} + + + + + + + `${pageNumber} / ${totalPages}` + } + fixed + /> + + + + ); +}; diff --git a/package.json b/package.json index 4257786f..3f5f261e 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "@prisma/client": "^5.0.0", "@react-pdf/renderer": "^3.1.12", "@redux-devtools/extension": "^3.2.5", + "@xmldom/xmldom": "^0.8.10", "applicationinsights": "^2.2.0", "axios": "^0.24.0", "compression": "^1.7.4", @@ -86,4 +87,4 @@ "eslint-plugin-jsdoc": "^40.0.1", "prisma": "^5.0.0" } -} \ No newline at end of file +} diff --git a/pages/api/file/generateappealpdf.js b/pages/api/file/generateappealpdf.js new file mode 100644 index 00000000..d17bf538 --- /dev/null +++ b/pages/api/file/generateappealpdf.js @@ -0,0 +1,211 @@ +/** + * @swagger + * /api/file/generateappealpdf: + * post: + * tags: [Azure Storage] + * summary: Phase 2 + * description: Create reps pdf from text field + * consumes: + * - application/json + * requestBody: + * name: PDF + * description: PDF content body + * required: true + * content: + * 'application/json': + * schema: + * type: object + * properties: + * representationType: + * type: string + * example: "Questionnaire" + * representationQuestion1: + * type: string + * example: "question 111111" + * representationQuestion2: + * type: string + * example: "question 232222" + * representationCapacity: + * type: string + * example: "yes" + * representationDocuments: + * type: array + * example: [{}] + * pinswg_name: + * type: string + * example: "2023-8-24-1692882853853--REP_Bond" + * containerID: + * type: string + * example: "cljzkgyev0006f9tl4pk6u171" + * appealType: + * type: integer + * example: 846040000 + * incidentID: + * type: string + * example: "50b533aa-43f1-ec11-aade-00224800be9c" + * caseRef: + * type: string + * example: "CAS-00764-L0Q9W2" + * parameters: + * - name: container + * in: query + * required: true + * example: cljzkgyev0006f9tl4pk6u171 + * schema: + * type: string + * - name: casefolderID + * in: query + * required: true + * example: CAS-00764-L0Q9W2 + * schema: + * type: string + * - name: hash + * in: query + * required: true + * example: 530b67db992ea277a236790be05b2e49bdd9dd02e6d790cc1c25f96cf39687cb + * schema: + * type: string + + * + * responses: + * 200: + * description: Success + */ + +import { + createContainer, + getContainers, + getBlobs, + createRepBlob, + uploadFile, + uploadPDFAppealFiles, + downloadProgressFile, + getProgressBlobs, +} from "../../../actions/azurestorage"; +import { hashAPIPath } from "../../../actions"; + +import ReactPDF, { + Document, + Page, + Text, + View, + StyleSheet, + PDFViewer, +} from "@react-pdf/renderer"; +import middleware from "../middleware/middleware"; +import nextConnect from "next-connect"; +import fs from "fs"; +import { planningappeals78_pdf } from "../../../components/pdftemplates/planningappeals78_pdf"; +import { finalComments_pdf } from "../../../components/pdftemplates/finalComments_pdf"; +import { statement_pdf } from "../../../components/pdftemplates/statement_pdf"; +import { writtenStatement_pdf } from "../../../components/pdftemplates/writtenStatement_pdf"; +import { other_pdf } from "../../../components/pdftemplates/other_pdf"; + +// const ApiProxy = nextConnect(); +// ApiProxy.use(middleware); + +// ApiProxy.post(async (req, res) => { + +export default async function handler(req, res) { + var checkHash = req.query.hash; + + let appealBodyObj = req.body; //JSON.parse(req.body); + + console.log( + "//////////////////////\nappealBodyObj" + + req + + "\n//////////////////////\n" + ); + console.log( + "//////////////////////\nappealBodyObj" + + req.body + + "\n//////////////////////\n" + ); + + var containerID = req.query.containerID; + var casefolderID = req.query.casefolderID; + var caseRef = req.query.caseRef; + + //console.log("there are files:", Object.keys(req.files).length); + + var checkquerypath = "/api/file/generateappealpdf"; + + //console.log("-------", checkHash); + // console.log(hashAPIPath(checkquerypath) == "?hash=" + checkHash); + console.log(casefolderID, caseRef); + // Create Document Component + + const MyDocument = (values) => { + switch (values.docProps.pinswg_appealcasetype) { + case "846040000": + return planningappeals78_pdf(values); + break; + case "846040025": + return listedbuildingandconservationareaconsen_pdf(values); + break; + case "846040004": + return householderappealhas_pdf(values); + break; + case "846040018": + return adverts_pdf(values); + break; + case "846040024": + return nonvalidation_pdf(values); + break; + case "846040005": + return enforcement_pdf(values); + break; + case "846040017": + return highhedgestpo_pdf(values); + break; + default: + return other_pdf(values); + } + }; + + const blobProgress = await getProgressBlobs(containerID, casefolderID).then( + (data) => { + console.log("Progress blob path:", data); + return downloadProgressFile(containerID, data.path, casefolderID); + } + ); + + console.log(blobProgress); + //if (hashAPIPath(checkquerypath) == "?hash=" + checkHash) { + // //createContainer(containerID).then((containerName) => { + + // console.log("does this get folder name:", containerID, casefolderID); + + console.log( + "///////////////////////////////////\n file created: \n" + + `tmp/${blobProgress.pinswg_name}.pdf` + + "\n/////////////////////////" + ); + + // createRepBlob(req.body, containerID, caseRef); + + ReactPDF.render( + , + `tmp/${blobProgress.pinswg_name}.pdf` + ); + + // uploadPDFAppealFiles( + // `tmp/${appealBodyObj.repfile_name}.pdf`, + // containerID, + // caseRef + "/" + appealBodyObj.pinswg_name + // ); + + // to do upload file to storage account + + // then remove from local folder + + // fs.unlinkSync( `tmp/${appealBodyObj.repfile_name}.pdf`,); + + return res.status(200).json({ + data: "success", + path: `tmp/${blobProgress.pinswg_name}.pdf`, + }); + // } else { + // return res.status(400).json(); + // } +} diff --git a/pages/api/file/generatepdf.js b/pages/api/file/generatepdf.js index 03e826dd..a48d15a0 100644 --- a/pages/api/file/generatepdf.js +++ b/pages/api/file/generatepdf.js @@ -207,38 +207,18 @@ export default function handler(req, res) { // code block } - // const repDate = new Date(); - - // let day = ("0" + repDate.getDate()).slice(-2); - // let month = ("0" + (repDate.getMonth() + 1)).slice(-2); - // let year = repDate.getFullYear(); - // let time = - // ("0" + repDate.getHours()).slice(-2) + - // "" + - // ("0" + repDate.getMinutes()).slice(-2); - - // let repDateStamp = ""; - // repDateStamp = year + "" + month + day; //+ "-" + time; - - //console.log(reqBodyobj); - //if (hashAPIPath(checkquerypath) == "?hash=" + checkHash) { - // //createContainer(containerID).then((containerName) => { - - // console.log("does this get folder name:", containerID, casefolderID); - console.log( "///////////////////////////////////\n file created: \n" + `tmp/${reqBodyobj.repfile_name}.pdf` + "\n/////////////////////////" ); - // createRepBlob(req.body, containerID, caseRef); - ReactPDF.render( , `tmp/${reqBodyobj.repfile_name}.pdf` ); + // upload file to storage account uploadPDFRepFiles( `tmp/${reqBodyobj.repfile_name}.pdf`, containerID, @@ -246,10 +226,7 @@ export default function handler(req, res) { repType ); - // to do upload file to storage account - - // then remove from local folder - + // remove from local folder // fs.unlinkSync( `tmp/${reqBodyobj.repfile_name}.pdf`,); return res.status(200).json({