first commit

This commit is contained in:
Isuru Bimsara
2026-08-14 22:46:02 +05:30
commit 81d0e65686
132 changed files with 24398 additions and 0 deletions
+308
View File
@@ -0,0 +1,308 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
@page {
size: A4;
margin: 0;
}
body {
background: white;
font-family: Arial, Helvetica, sans-serif;
padding: 12px;
}
.page {
width: 100%;
margin: 0 auto;
background: white;
border: 1px solid #333;
}
.logo-section {
height: 72px;
display: flex;
align-items: center;
justify-content: center;
border-bottom: 1px solid #c9c9c9;
}
.logo-section img {
max-height: 52px;
object-fit: contain;
}
.title-section {
text-align: center;
padding: 5px 0 4px;
border-bottom: 1px solid #333;
font-size: 22px;
font-weight: 700;
color: #2d5c96;
letter-spacing: 0.4px;
}
.top-grid {
display: grid;
grid-template-columns: 1.6fr 1fr;
min-height: 70px;
border-bottom: 1px solid #c9c9c9;
}
.top-left,
.top-right,
.mid-left,
.mid-right {
padding: 4px 6px;
font-size: 10px;
color: #111;
}
.top-left {
border-right: 1px solid #e2e2e2;
display: flex;
align-items: flex-start;
}
.bill-to-label {
font-weight: 700;
min-width: 48px;
}
.bill-to-name {
font-weight: 700;
}
.bill-to-address {
margin-top: 2px;
line-height: 1.25;
}
.top-right {
display: flex;
flex-direction: column;
justify-content: flex-start;
gap: 2px;
text-align: right;
font-weight: 700;
}
.top-right-row {
display: flex;
justify-content: flex-end;
gap: 6px;
}
.top-right-row .value {
font-weight: 400;
min-width: 110px;
text-align: left;
}
.info-grid {
display: grid;
grid-template-columns: 1.4fr 1fr;
border-bottom: 1px solid #c9c9c9;
}
.mid-left {
border-right: 1px solid #e2e2e2;
}
.mid-row {
display: flex;
justify-content: space-between;
gap: 10px;
margin-bottom: 2px;
}
.info-label {
font-weight: 700;
}
.info-value {
text-align: right;
min-width: 90px;
}
.items-wrap {
overflow-x: auto;
}
.items-table {
width: 100%;
border-collapse: collapse;
}
.items-table thead th {
background: #a8d9de;
color: #111;
font-weight: bold;
font-size: 10px;
text-align: center;
padding: 5px 4px;
border: 1px solid #4b4b4b;
}
.items-table td {
border: 1px solid #5d5d5d;
font-size: 10px;
height: 15px;
padding: 2px 4px;
vertical-align: middle;
}
.center {
text-align: center;
}
.right {
text-align: right;
}
.col-no { width: 8%; }
.col-desc { width: 30%; }
.col-remarks { width: 24%; }
.col-qty { width: 9%; }
.col-unit { width: 9%; }
.col-price { width: 10%; }
.col-total { width: 10%; }
.spacer-row td {
height: 18px;
}
.bottom-table {
display: grid;
grid-template-columns: 1.4fr 1fr;
border-top: 1px solid #c9c9c9;
}
.bottom-left,
.bottom-right {
padding: 4px 6px;
font-size: 10px;
}
.bottom-left {
border-right: 1px solid #e2e2e2;
}
.bottom-row {
display: flex;
flex-direction: column;
gap: 2px;
}
.bottom-line {
display: flex;
justify-content: space-between;
gap: 8px;
}
.footer-row {
border-top: 1px solid #333;
text-align: right;
padding: 4px 6px;
font-size: 9px;
color: #555;
}
</style>
</head>
<body>
<%
const invoiceTitle = typeof title !== 'undefined' && title ? title : 'INVOICE';
const invoiceJobReference = typeof jobReference !== 'undefined' && jobReference ? jobReference : 'N/A';
const invoicePoNumber = typeof poNumber !== 'undefined' && poNumber ? poNumber : 'N/A';
const invoiceDate = typeof date !== 'undefined' && date ? date : 'N/A';
const invoicePageLabel = typeof pageLabel !== 'undefined' && pageLabel ? pageLabel : 'Page 01 of 02';
const invoiceBillToName = typeof billToName !== 'undefined' && billToName ? billToName : 'Client Name';
const invoiceBillToAddress = typeof billToAddress !== 'undefined' && billToAddress ? billToAddress : 'Address';
const invoiceVesselName = typeof vesselName !== 'undefined' && vesselName ? vesselName : 'N/A';
const invoicePurposeOfCall = typeof purposeOfCall !== 'undefined' && purposeOfCall ? purposeOfCall : 'N/A';
const invoiceSupplyDate = typeof supplyDate !== 'undefined' && supplyDate ? supplyDate : 'N/A';
const invoiceGrt = typeof grt !== 'undefined' && grt ? grt : 'N/A';
const invoiceImoNumber = typeof imoNumber !== 'undefined' && imoNumber ? imoNumber : 'N/A';
const invoicePortCountry = typeof portCountry !== 'undefined' && portCountry ? portCountry : 'N/A';
const invoiceItems = typeof items !== 'undefined' && Array.isArray(items) ? items : [];
%>
<div class="page">
<div class="logo-section">
<% if (logoBase64) { %>
<img src="<%= logoBase64 %>" alt="Company Logo" />
<% } %>
</div>
<div class="title-section"><%= invoiceTitle %></div>
<div class="top-grid">
<div class="top-left">
<div>
<div><span class="bill-to-label">Bill To:</span> <span class="bill-to-name"><%= invoiceBillToName %></span></div>
<div class="bill-to-address"><%= invoiceBillToAddress %></div>
</div>
</div>
<div class="top-right">
<div class="top-right-row"><span>Job Reference :</span> <span class="value"><%= invoiceJobReference %></span></div>
<div class="top-right-row"><span>PO Number :</span> <span class="value"><%= invoicePoNumber %></span></div>
<div class="top-right-row"><span>Date :</span> <span class="value"><%= invoiceDate %></span></div>
<div class="top-right-row"><span></span> <span class="value"><%= invoicePageLabel %></span></div>
</div>
</div>
<div class="info-grid">
<div class="mid-left">
<div class="mid-row"><span class="info-label">Vessel Name :</span> <span class="info-value"><%= invoiceVesselName %></span></div>
<div class="mid-row"><span class="info-label">Purpose of Call :</span> <span class="info-value"><%= invoicePurposeOfCall %></span></div>
<div class="mid-row"><span class="info-label">Supply Date :</span> <span class="info-value"><%= invoiceSupplyDate %></span></div>
</div>
<div class="mid-right">
<div class="mid-row"><span class="info-label">GRT :</span> <span class="info-value"><%= invoiceGrt %></span></div>
<div class="mid-row"><span class="info-label">IMO Number :</span> <span class="info-value"><%= invoiceImoNumber %></span></div>
<div class="mid-row"><span class="info-label">Port/Country :</span> <span class="info-value"><%= invoicePortCountry %></span></div>
</div>
</div>
<div class="items-wrap">
<table class="items-table">
<thead>
<tr>
<th class="col-no">No.</th>
<th class="col-desc">Description</th>
<th class="col-remarks">Remarks</th>
<th class="col-qty">Qty</th>
<th class="col-unit">Unit</th>
<th class="col-price">Unit Price (USD)</th>
<th class="col-total">Final Amount (USD)</th>
</tr>
</thead>
<tbody>
<% const rows = Math.max(10, invoiceItems.length); %>
<% for (let index = 0; index < rows; index++) { %>
<% const item = invoiceItems[index] || {}; %>
<% const quantity = Number(item.quantity || item.qty || 0); %>
<% const unitPrice = Number(item.unit_price || item.unitPrice || 0); %>
<tr class="spacer-row">
<td class="center"><%= index + 1 %></td>
<td><%= item.description || item.item_name || item.name || '' %></td>
<td><%= item.remarks || '' %></td>
<td class="center"><%= item.quantity || item.qty || '' %></td>
<td class="center"><%= item.unit || '' %></td>
<td class="right"><%= item.unit_price || item.unitPrice || '' %></td>
<td class="right"><%= quantity && unitPrice ? quantity * unitPrice : (item.total || item.amount || '') %></td>
</tr>
<% } %>
</tbody>
</table>
</div>
</div>
</body>
</html>
@@ -0,0 +1,111 @@
/**
* 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/invoice/invoice.template.js
const { log } = require("../../../utils/consoleLog.utill");
module.exports = async (data) => {
log("📋 Preparing Invoice 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 deepFind = (node, keys, visited = new Set()) => {
if (!node || typeof node !== "object" || visited.has(node)) {
return "";
}
visited.add(node);
for (const key of keys) {
const value = node[key];
if (value !== undefined && value !== null && value !== "") {
return value;
}
}
for (const child of Object.values(node)) {
const found = deepFind(child, keys, visited);
if (found !== "") {
return found;
}
}
return "";
};
const pick = (...keys) => {
const direct = deepFind(source, keys);
if (direct !== "") {
return direct;
}
return deepFind(payload, keys);
};
const templateData = {
logoUrl:
pick("logoUrl", "logo_url") ||
"https://res.cloudinary.com/dtthuvvir/image/upload/v1780748661/company_logo_transperent_bg_uullzw.png",
title: pick("title") || "INVOICE",
jobReference:
pick(
"jobReference",
"job_reference",
"referenceNumber",
"reference_no",
"jobRef",
"job_ref",
) || "",
poNumber: pick("poNumber", "po_number", "poNo", "po_no") || "",
date: pick("date") || new Date().toLocaleDateString(),
pageLabel: pick("pageLabel", "page_label") || "Page 01 of 02",
billToName: pick("billToName", "bill_to_name") || "Client Name",
billToAddress: pick("billToAddress", "bill_to_address") || "Address",
vesselName: pick("vesselName", "vessel_name") || "",
purposeOfCall: pick("purposeOfCall", "purpose_of_call") || "",
supplyDate: pick("supplyDate", "supply_date") || "",
grt: pick("grt", "GRT") || "",
imoNumber: pick("imoNumber", "imo_number", "imo") || "",
portCountry: pick("portCountry", "port_country") || "",
items: Array.isArray(source.items) ? source.items : [],
subtotal: Number(pick("subtotal", "sub_total") || 0),
tax: Number(pick("tax") || 0),
discount: Number(pick("discount") || 0),
total: Number(pick("total") || 0),
paymentTerms: pick("paymentTerms", "payment_terms") || "",
notes: pick("notes") || "",
};
log("✅ Invoice data prepared");
return templateData;
};
+23
View File
@@ -0,0 +1,23 @@
body {
font-family: Arial;
padding: 20px;
}
h1 {
text-align: center;
}
table {
width: 100%;
border-collapse: collapse;
}
td,
th {
border: 1px solid #ddd;
padding: 8px;
}
th {
background: #f4f4f4;
}
@@ -0,0 +1,24 @@
<html>
<head>
<style>
{{styles}}
</style>
</head>
<body>
<h1>PreCost Estimate</h1>
<p>Customer: {{customerName}}</p>
<table>
<tr>
<th>Item</th>
<th>Description</th>
<th>Qty</th>
<th>Unit Price</th>
<th>Total</th>
</tr>
{{items}}
</table>
</body>
</html>