Skip to content

Commit

Permalink
Merge pull request #1170 from ShivankShuklaa/Dev-2.0
Browse files Browse the repository at this point in the history
Architect and citizen consent format corrected, Dropdowns are started coming from MDMS instead of locally
  • Loading branch information
deepikaarora88 authored Jul 1, 2024
2 parents 35e27f7 + d40f8d9 commit 88fb28e
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 283 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@
}, [files]);





const approvedcolonyStatus = [
{
code: "YES",
Expand All @@ -110,20 +107,7 @@
i18nKey: "LAL LAKEER"
}
]
const ratingvalue = [
{
code: "PLATINUM",
i18nKey: "PLATINUM"
},
{
code: "GOLD",
i18nKey: "GOLD"
},
{
code: "BRONZE",
i18nKey: "BRONZE"
}
]


const common = [
{
Expand All @@ -143,95 +127,112 @@
}
]

const schemesselectiontype = [
{
code: "SCHEME",
i18nKey: "SCHEME"
},
{
code: "NON_SCHEME",
i18nKey: "NON SCHEME"
},
]

const forschemes = [
{
code: "TP_SCHEMES",
i18nKey: "TP SCHEMES"
},
{
code: "DEVELOPMENT_SCHEMES",
i18nKey: "DEVELOPMENT SCHEMES"
},
{
code: "AFFORDABLE",
i18nKey: "AFFORDABLE"
}
]

const status = [
{
code: "AUTHORIZED",
i18nKey: "Authorized"
},
{
code: "REGULARIZED",
i18nKey: "Regularized"
}
]

const masterdropfields = [
{
code: "RESIDENT",
i18nKey: "Resident"
},
{
code: "COMMERCIAL",
i18nKey: "Commercial"
},
{
code: "INDUSTRIAL",
i18nKey: "Industrial"
}
]

const tenantId = Digit.ULBService.getCurrentTenantId();
const stateId = Digit.ULBService.getStateId();

const { data: ULBLIST } = Digit.Hooks.obps.useUlbType(stateId, "BPA", "UlbType");
const { data: ulbList } = Digit.Hooks.obps.useUlbType(stateId, "BPA", "UlbType");

const { data: Menu } = Digit.Hooks.obps.useDistricts(stateId, "BPA", "Districts");
const { data: districtMenu } = Digit.Hooks.obps.useDistricts(stateId, "BPA", "Districts");
const { data: ULB } = Digit.Hooks.obps.useULBList(stateId, "BPA", "Ulb");

let ulblists = [];

let menu = [];
let ulb = [];

ULBLIST &&
ULBLIST.map((ulbtypelist) => {
ulbList &&
ulbList.map((ulbtypelist) => {
if(ulbtypelist?.Districts === UlbName?.code)
ulblists.push({ i18nKey: `${ulbtypelist.code}`, code: `${ulbtypelist.code}`, value: `${ulbtypelist.name}` });
ulblists.push({ i18nKey: `${ulbtypelist.name}`, code: `${ulbtypelist.code}`, value: `${ulbtypelist.name}` });
});

Menu &&
Menu.map((districts) => {
districtMenu &&
districtMenu.map((districts) => {
// if(districts.UlbType == Ulblisttype?.code)
menu.push({ i18nKey: `${districts.code}`, code: `${districts.code}`, value: `${districts.name}` });
menu.push({ i18nKey: `${districts.name}`, code: `${districts.code}`, value: `${districts.name}` });
});

ULB &&
ULB.map((ulblist) => {
if (ulblist.Districts == UlbName?.code) {
ulb.push({
i18nKey: `${ulblist.code}`,
i18nKey: `${ulblist.name}`,
code: `${ulblist.code}`,
value: `${ulblist.name}`
});
}

});


// Custom hooks to get the Data directly from MDMS, No need to make file inside Libraries --> Hooks Folder

const { data: commonBuilding } = Digit.Hooks.useCustomMDMS(Digit.ULBService.getStateId(), "BPA", [{ name: "BuildingStatus" }],
{
select: (data) => {
const formattedData = data?.["BPA"]?.["BuildingStatus"]
return formattedData;
},
});
let building_status = [];

commonBuilding && commonBuilding.map((selectBuilding) => {
building_status.push({i18nKey: `BPA_${selectBuilding.code}`, code: `${selectBuilding.code}`, value: `${selectBuilding.name}`})
})

const { data: commonrating } = Digit.Hooks.useCustomMDMS(Digit.ULBService.getStateId(), "BPA", [{ name: "RatingValue" }],
{
select: (data) => {
const formattedData = data?.["BPA"]?.["RatingValue"]
return formattedData;
},
});
let selectRating = [];

commonrating && commonrating.map((selectRatings) => {
selectRating.push({i18nKey: `BPA_${selectRatings.code}`, code: `${selectRatings.code}`, value: `${selectRatings.name}`})
})

const { data: commonmasterFields } = Digit.Hooks.useCustomMDMS(Digit.ULBService.getStateId(), "BPA", [{ name: "MasterFields" }],
{
select: (data) => {
const formattedData = data?.["BPA"]?.["MasterFields"]
return formattedData;
},
});
let selectmasterDrop = [];

commonmasterFields && commonmasterFields.map((selectMaster) => {
selectmasterDrop.push({i18nKey: `BPA_${selectMaster.code}`, code: `${selectMaster.code}`, value: `${selectMaster.name}`})
})

const { data: commonScheme } = Digit.Hooks.useCustomMDMS(Digit.ULBService.getStateId(), "BPA", [{ name: "Scheme" }],
{
select: (data) => {
const formattedData = data?.["BPA"]?.["Scheme"]
return formattedData;
},
});
let selectscheme = [];

commonScheme && commonScheme.map((selectScheme) => {
selectscheme.push({i18nKey: `BPA_${selectScheme.code}`, code: `${selectScheme.code}`, value: `${selectScheme.name}`})
})

const { data: commonSchemeType } = Digit.Hooks.useCustomMDMS(Digit.ULBService.getStateId(), "BPA", [{ name: "SchemeType" }],
{
select: (data) => {
const formattedData = data?.["BPA"]?.["SchemeType"]
return formattedData;
},
});
let selectschemetypes = [];

commonSchemeType && commonSchemeType.map((selectscheme) => {
selectschemetypes.push({i18nKey: `BPA_${selectscheme.code}`, code: `${selectscheme.code}`, value: `${selectscheme.name}`})
})



const { control } = useForm();

Expand Down Expand Up @@ -464,7 +465,7 @@
className="form-field"
selected={rating}
select={setrating}
option={ratingvalue}
option={selectRating}
optionKey="i18nKey"
t={t}
/>
Expand Down Expand Up @@ -497,7 +498,7 @@
className="form-field"
selected={use}
select={setUse}
option={masterdropfields}
option={selectmasterDrop}
optionKey="i18nKey"
t={t}
/>
Expand Down Expand Up @@ -531,7 +532,7 @@
className="form-field"
selected={schemesselection}
select={setSchemeselection}
option={forschemes}
option={selectschemetypes}
optionKey="i18nKey"
t={t}
/>
Expand Down Expand Up @@ -732,7 +733,7 @@
className="form-field"
selected={buildingStatus}
select={setbuildingStatus}
option={status}
option={building_status}
optionKey="i18nKey"
t={t}
/>
Expand All @@ -750,7 +751,7 @@
className="form-field"
selected={schemes}
select={setschemes}
option={schemesselectiontype}
option={selectscheme}
optionKey="i18nKey"
t={t}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const OwnerDetails = ({ t, config, onSelect, userType, formData }) => {
(formData?.owners && formData?.owners?.owners) || [{ name: "", gender: "", mobileNumber: null, isPrimaryOwner: true }]
);

const user = Digit.UserService.getUser();
console.log("userrrr",user);

useEffect(() => {
var flag=0;
fields.map((ob) => {
Expand Down Expand Up @@ -387,6 +390,9 @@ const OwnerDetails = ({ t, config, onSelect, userType, formData }) => {
if (formData?.owners?.greenuploadedFile) payload.additionalDetails.uploadedFileGreenBuilding = formData?.owners?.greenuploadedFile;
if (formData?.owners?.use?.code) payload.additionalDetails.use = formData?.owners?.use?.code;

//adding Architect name and his mobilenumber so that i can use it in Consent form
if (user?.info?.name) payload.additionalDetails.architectName = user?.info?.name;
if (user?.info?.mobileNumber) payload.additionalDetails.architectMobileNumber = user?.info?.mobileNumber;

//For LandInfo
payload.landInfo = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,104 +119,25 @@
const uploadSelfDeclaration = async () => {
try {
setIsUploading(true); // Set isUploading to true before starting the upload
const doc = new jsPDF();
const leftMargin = 15;
const topMargin = 10;
const lineSpacing = 5;
const pageWidth = doc.internal.pageSize.getWidth();
const maxLineWidth = pageWidth - 2 * leftMargin;

let currentY = topMargin;

doc.setFont("Times-Roman");
doc.setFontSize(12);

// Split and write text into the PDF
const lines = selfdeclarationform.split("\n");
// lines.forEach((line) => {
// const wrappedLines = doc.splitTextToSize(line, maxLineWidth);
// wrappedLines.forEach((wrappedLine) => {
// if (currentY + lineSpacing > doc.internal.pageSize.getHeight() - topMargin) {
// doc.addPage();
// currentY = topMargin;
// }
// doc.text(leftMargin, currentY, wrappedLine);
// currentY += lineSpacing;
// });
// });
lines.forEach((line) => {
const segments = line.split(/(<b>|<\/b>)/g); // Split line by <b> and </b> tags
let isBold = false;
let currentX = leftMargin;

segments.forEach((segment) => {
if (segment === "<b>") {
isBold = true;
} else if (segment === "</b>") {
isBold = false;
} else {
const words = segment.split(' ');
words.forEach((word, index) => {
const wordWithSpace = index < words.length - 1 ? `${word} ` : word;
const textWidth = doc.getTextWidth(wordWithSpace);

if (currentX + textWidth > maxLineWidth) {
currentY += lineSpacing;
currentX = leftMargin;
if (currentY + lineSpacing > doc.internal.pageSize.getHeight() - topMargin) {
doc.addPage();
currentY = topMargin;
}
}

doc.setFont(isBold ? "Times-Bold" : "Times-Roman");
doc.text(currentX, currentY, wordWithSpace);
currentX += textWidth;
});
}
});

currentY += lineSpacing;
if (currentY + lineSpacing > doc.internal.pageSize.getHeight() - topMargin) {
doc.addPage();
currentY = topMargin;

let result = await Digit.PaymentService.generatePdf(Digit.ULBService.getStateId(), { Bpa: [data] }, "ownerconsent");

if (result?.filestoreIds[0]?.length > 0) {
alert("File Uploaded Successfully");
sessionStorage.setItem("CitizenConsentdocFilestoreid",result?.filestoreIds[0]);
setIsFileUploaded(true); // Set isFileUploaded to true on successful upload
} else {
alert("File Upload Failed");
}
});


// Convert the PDF to a Blob

const pdfBlob = doc.output("blob", "declaration.pdf");

// Prepare FormData for the upload
const formData = new FormData();
formData.append("file", pdfBlob, "declaration.pdf");
formData.append("tenantId", "pg");
formData.append("module", "BPA");
} catch (error) {
alert("Error Uploading PDF:", error); // Error handling
}
finally {
setIsUploading(false); // Set isUploading to false after the upload is complete
}
};


const response = await Axios({
method: "post",
url: `${Urls.FileStore}`,
data: formData,
headers: { "auth-token": Digit.UserService.getUser()?.access_token },
});

if (response?.data?.files?.length > 0) {
alert("File Uploaded Successfully");
sessionStorage.setItem("CitizenConsentdocFilestoreid",response?.data?.files[0]?.fileStoreId);
setIsFileUploaded(true); // Set isFileUploaded to true on successful upload
} else {
alert("File Upload Failed");
}
} catch (error) {
alert("Error Uploading PDF:", error); // Error handling
}
finally {
setIsUploading(false); // Set isUploading to false after the upload is complete
}
};



const modalStyles = {
Expand Down
Loading

0 comments on commit 88fb28e

Please sign in to comment.