82 lines
2.8 KiB
JavaScript
82 lines
2.8 KiB
JavaScript
/**
|
|
* Copyright (c) 2026 Niolla
|
|
* All rights reserved.
|
|
*
|
|
* This source code is proprietary and confidential.
|
|
* Unauthorized copying, modification, distribution, or use
|
|
* of this file, via any medium, is strictly prohibited.
|
|
*/
|
|
|
|
// app/templates/documents/customDocument/customDocument.template.js
|
|
|
|
const { log } = require("../../../utils/consoleLog.utill");
|
|
|
|
module.exports = async (data) => {
|
|
log("📋 Preparing Custom Document data for PDF...");
|
|
|
|
let payload = data;
|
|
|
|
if (typeof payload === "string") {
|
|
try {
|
|
payload = JSON.parse(payload);
|
|
} catch (error) {
|
|
payload = {};
|
|
}
|
|
}
|
|
|
|
const source = payload.documentData || payload.document_data || payload.data || payload;
|
|
|
|
const pick = (...keys) => {
|
|
for (const key of keys) {
|
|
const value = source?.[key];
|
|
if (value !== undefined && value !== null && value !== "") {
|
|
return value;
|
|
}
|
|
}
|
|
|
|
return "";
|
|
};
|
|
|
|
const templateData = {
|
|
logoUrl:
|
|
pick("logoUrl", "logo_url") ||
|
|
"https://res.cloudinary.com/dtthuvvir/image/upload/v1780748661/company_logo_transperent_bg_uullzw.png",
|
|
|
|
title: pick("title") || "CUSTOM DOCUMENT",
|
|
documentNumber: pick("documentNumber", "document_number") || "",
|
|
date: pick("date") || new Date().toLocaleDateString(),
|
|
|
|
telePhone: pick("telePhone", "telephone", "phone", "tel") || "",
|
|
emailAddress: pick("emailAddress", "email", "e_mail") || "",
|
|
|
|
officeAddressLine1: pick("officeAddressLine1", "office_address_line1") || "",
|
|
officeAddressLine2: pick("officeAddressLine2", "office_address_line2") || "",
|
|
officeAddressLine3: pick("officeAddressLine3", "office_address_line3") || "",
|
|
|
|
directorOfCustoms: pick("directorOfCustoms", "director_of_customs") || "",
|
|
vehicleNo: pick("vehicleNo", "vehicle_no") || "",
|
|
permitNo: pick("permitNo", "permit_no") || "",
|
|
chiefSecurityOfficer: pick("chiefSecurityOfficer", "chief_security_officer") || "",
|
|
exportGate: pick("exportGate", "export_gate") || "",
|
|
slpa: pick("slpa") || "",
|
|
gateNo: pick("gateNo", "gate_no") || "",
|
|
permissionText: pick("permissionText", "permission_text") || "Please grant permission to pass these Customs entry papers to supply goods to the vessel",
|
|
|
|
companyName: pick("companyName", "company_name") || "Oceanic Maritime Solutions (Pvt) Ltd",
|
|
subtitle: pick("subtitle") || "LICENSED SHIPCHANDLERS",
|
|
sectionCode: pick("sectionCode", "section_code") || "SC/FORM/06",
|
|
dateLabel: pick("dateLabel", "date_label") || "DATE :",
|
|
|
|
items: Array.isArray(source.items) ? source.items : [],
|
|
itemHeaders:
|
|
pick("itemHeaders", "item_headers") ||
|
|
["NO", "QTY", "UNIT", "DESCRIPTION", "RATE", "TOTAL", "Confirm Order Rate"],
|
|
|
|
footerText: pick("footerText", "footer_text") || "",
|
|
};
|
|
|
|
log("✅ Custom Document data prepared");
|
|
|
|
return templateData;
|
|
};
|