Skip to content

Commit

Permalink
Merge pull request #476 from bcgov/mals2-26-deploy
Browse files Browse the repository at this point in the history
Revert some changes
  • Loading branch information
mgtennant authored Oct 16, 2024
2 parents a1e6142 + ec78b68 commit fbe1335
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 93 deletions.
2 changes: 1 addition & 1 deletion app/client/src/features/licences/LicenceDetailsEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default function LicenceDetailsEdit({
};

const editPhone = () => {
// The watch doesnt seem to be updated when adding the initial entry to phone numbers
// The watch doesn't seem to be updated when adding the initial entry to phone numbers
// So manually set the key here
let selectedKey = watchPhoneKey;
if (!selectedKey || selectedKey.length === 0) {
Expand Down
185 changes: 93 additions & 92 deletions app/server/routes/v1/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,98 +291,99 @@ async function generateCertificate(documentId) {
const template = templateBuffers.find(
(x) => x.templateFileName === templateFileName
);
// check if certificate is CARD (3 templates), if so, split into two arrays
if (
document.document_type === "CARD" &&
(document.licence_type === "BULK TANK MILK GRADER" ||
document.licence_type === "LIVESTOCK DEALER" ||
document.licence_type === "LIVESTOCK DEALER AGENT")
) {
/**
* The Card templates have a table that is 2 columns by N rows, this function effectively combines
* those two columns into one so that we don't have to deal with bi-directional looping
* (which cdogs doesn't support yet) */

function combineEntries(licenceType, documentJson) {
let combinedJson = [];
switch (licenceType) {
case "BULK TANK MILK GRADER":
for (let i = 0; i < documentJson.length; i += 2) {
let combinedEntry = { ...documentJson[i] };
if (documentJson[i + 1]) {
combinedEntry.LicenceHolderName2 =
documentJson[i + 1].LicenceHolderName;
combinedEntry.LicenceHolderCompany2 =
documentJson[i + 1].LicenceHolderCompany;
combinedEntry.LicenceNumber2 = documentJson[i + 1].LicenceNumber;
combinedEntry.ExpiryDate2 = documentJson[i + 1].ExpiryDate;
combinedEntry.CardLabel2 = documentJson[i + 1].CardLabel;
} else {
combinedEntry.LicenceHolderName2 = null;
combinedEntry.LicenceHolderCompany2 = null;
combinedEntry.LicenceNumber2 = null;
combinedEntry.ExpiryDate2 = null;
combinedEntry.CardLabel2 = null;
}
combinedJson.push(combinedEntry);
}
return combinedJson;
case "LIVESTOCK DEALER AGENT":
for (let i = 0; i < documentJson.length; i += 2) {
let combinedEntry = { ...documentJson[i] };
if (documentJson[i + 1]) {
combinedEntry.CardType2 = documentJson[i + 1].CardType;
combinedEntry.LicenceHolderName2 =
documentJson[i + 1].LicenceHolderName;
combinedEntry.LastFirstName2 = documentJson[i + 1].LastFirstName;
combinedEntry.AgentFor2 = documentJson[i + 1].AgentFor;
combinedEntry.LicenceNumber2 = documentJson[i + 1].LicenceNumber;
combinedEntry.StartDate2 = documentJson[i + 1].StartDate;
combinedEntry.ExpiryDate2 = documentJson[i + 1].ExpiryDate;
} else {
combinedEntry.CardType2 = null;
combinedEntry.LicenceHolderName2 = null;
combinedEntry.LastFirstName2 = null;
combinedEntry.AgentFor2 = null;
combinedEntry.LicenceNumber2 = null;
combinedEntry.StartDate2 = null;
combinedEntry.ExpiryDate2 = null;
}
combinedJson.push(combinedEntry);
}
return combinedJson;
case "LIVESTOCK DEALER":
for (let i = 0; i < documentJson.length; i += 2) {
let combinedEntry = { ...documentJson[i] };
if (documentJson[i + 1]) {
combinedEntry.CardType2 = documentJson[i + 1].CardType;
combinedEntry.LicenceHolderCompany2 =
documentJson[i + 1].LicenceHolderCompany;
combinedEntry.LicenceNumber2 = documentJson[i + 1].LicenceNumber;
combinedEntry.StartDate2 = documentJson[i + 1].StartDate;
combinedEntry.ExpiryDate2 = documentJson[i + 1].ExpiryDate;
} else {
combinedEntry.CardType2 = null;
combinedEntry.LicenceHolderCompany2 = null;
combinedEntry.LicenceNumber2 = null;
combinedEntry.StartDate2 = null;
combinedEntry.ExpiryDate2 = null;
}
combinedJson.push(combinedEntry);
}
return combinedJson;
default:
return null;
}
}

let updatedJson = combineEntries(
document.licence_type,
document.document_json
);

document.document_json = updatedJson;
}
// MALS2-6 to re-apply this, uncomment this code and use the 3 updated templates
// // check if certificate is CARD (3 templates), if so, split into two arrays
// if (
// document.document_type === "CARD" &&
// (document.licence_type === "BULK TANK MILK GRADER" ||
// document.licence_type === "LIVESTOCK DEALER" ||
// document.licence_type === "LIVESTOCK DEALER AGENT")
// ) {
// /**
// * The Card templates have a table that is 2 columns by N rows, this function effectively combines
// * those two columns into one so that we don't have to deal with bi-directional looping
// * (which cdogs doesn't support yet) */

// function combineEntries(licenceType, documentJson) {
// let combinedJson = [];
// switch (licenceType) {
// case "BULK TANK MILK GRADER":
// for (let i = 0; i < documentJson.length; i += 2) {
// let combinedEntry = { ...documentJson[i] };
// if (documentJson[i + 1]) {
// combinedEntry.LicenceHolderName2 =
// documentJson[i + 1].LicenceHolderName;
// combinedEntry.LicenceHolderCompany2 =
// documentJson[i + 1].LicenceHolderCompany;
// combinedEntry.LicenceNumber2 = documentJson[i + 1].LicenceNumber;
// combinedEntry.ExpiryDate2 = documentJson[i + 1].ExpiryDate;
// combinedEntry.CardLabel2 = documentJson[i + 1].CardLabel;
// } else {
// combinedEntry.LicenceHolderName2 = null;
// combinedEntry.LicenceHolderCompany2 = null;
// combinedEntry.LicenceNumber2 = null;
// combinedEntry.ExpiryDate2 = null;
// combinedEntry.CardLabel2 = null;
// }
// combinedJson.push(combinedEntry);
// }
// return combinedJson;
// case "LIVESTOCK DEALER AGENT":
// for (let i = 0; i < documentJson.length; i += 2) {
// let combinedEntry = { ...documentJson[i] };
// if (documentJson[i + 1]) {
// combinedEntry.CardType2 = documentJson[i + 1].CardType;
// combinedEntry.LicenceHolderName2 =
// documentJson[i + 1].LicenceHolderName;
// combinedEntry.LastFirstName2 = documentJson[i + 1].LastFirstName;
// combinedEntry.AgentFor2 = documentJson[i + 1].AgentFor;
// combinedEntry.LicenceNumber2 = documentJson[i + 1].LicenceNumber;
// combinedEntry.StartDate2 = documentJson[i + 1].StartDate;
// combinedEntry.ExpiryDate2 = documentJson[i + 1].ExpiryDate;
// } else {
// combinedEntry.CardType2 = null;
// combinedEntry.LicenceHolderName2 = null;
// combinedEntry.LastFirstName2 = null;
// combinedEntry.AgentFor2 = null;
// combinedEntry.LicenceNumber2 = null;
// combinedEntry.StartDate2 = null;
// combinedEntry.ExpiryDate2 = null;
// }
// combinedJson.push(combinedEntry);
// }
// return combinedJson;
// case "LIVESTOCK DEALER":
// for (let i = 0; i < documentJson.length; i += 2) {
// let combinedEntry = { ...documentJson[i] };
// if (documentJson[i + 1]) {
// combinedEntry.CardType2 = documentJson[i + 1].CardType;
// combinedEntry.LicenceHolderCompany2 =
// documentJson[i + 1].LicenceHolderCompany;
// combinedEntry.LicenceNumber2 = documentJson[i + 1].LicenceNumber;
// combinedEntry.StartDate2 = documentJson[i + 1].StartDate;
// combinedEntry.ExpiryDate2 = documentJson[i + 1].ExpiryDate;
// } else {
// combinedEntry.CardType2 = null;
// combinedEntry.LicenceHolderCompany2 = null;
// combinedEntry.LicenceNumber2 = null;
// combinedEntry.StartDate2 = null;
// combinedEntry.ExpiryDate2 = null;
// }
// combinedJson.push(combinedEntry);
// }
// return combinedJson;
// default:
// return null;
// }
// }

// let updatedJson = combineEntries(
// document.licence_type,
// document.document_json
// );

// document.document_json = updatedJson;
// }

const generate = async () => {
const { data, status } = await cdogs.post(
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit fbe1335

Please sign in to comment.