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
@@ -0,0 +1,372 @@
<!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: 10px;
}
.sheet {
width: 100%;
margin: 0 auto;
background: white;
border: 1px solid #222;
}
.company-band {
display: grid;
grid-template-columns: 1fr 1.35fr 0.95fr;
min-height: 112px;
border-bottom: 1px solid #444;
}
.company-left,
.company-middle,
.company-right {
padding: 4px 6px;
font-size: 10px;
}
.company-left {
line-height: 1.35;
}
.company-middle {
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
.logo-placeholder {
font-size: 28px;
font-weight: 700;
letter-spacing: 6px;
color: #1c5c9d;
}
.company-middle .tagline {
margin-top: 4px;
font-size: 10px;
color: #555;
}
.company-right {
display: flex;
align-items: flex-start;
justify-content: flex-end;
text-align: right;
line-height: 1.25;
}
.company-right .stack {
max-width: 100%;
}
.title-row {
border-bottom: 1px solid #444;
text-align: center;
padding: 5px 0 4px;
color: #7da3de;
font-size: 22px;
font-weight: 700;
}
.bill-row {
display: grid;
grid-template-columns: 1.55fr 1fr;
border-bottom: 1px solid #444;
min-height: 72px;
}
.bill-left,
.bill-right {
padding: 4px 6px;
font-size: 10px;
}
.bill-left {
border-right: 1px solid #444;
line-height: 1.25;
}
.bill-right {
display: flex;
flex-direction: column;
justify-content: center;
gap: 2px;
line-height: 1.2;
}
.bill-line {
display: flex;
justify-content: space-between;
gap: 6px;
}
.meta-row {
display: grid;
grid-template-columns: 1fr 1fr;
border-bottom: 1px solid #444;
}
.meta-col {
padding: 4px 6px;
font-size: 10px;
line-height: 1.25;
}
.meta-col:first-child {
border-right: 1px solid #444;
}
.meta-line {
display: flex;
justify-content: space-between;
gap: 8px;
}
.meta-label {
font-weight: 700;
min-width: 112px;
}
.items-table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
.items-table th,
.items-table td {
border: 1px solid #444;
font-size: 10px;
padding: 2px 3px;
vertical-align: middle;
}
.items-table th {
text-align: center;
font-weight: 700;
background: #b7d2ea;
}
.no-col { width: 5%; }
.desc-col { width: 37%; }
.remarks-col { width: 33%; }
.amount-col { width: 12%; }
.confirm-col { width: 13%; }
.center {
text-align: center;
}
.right {
text-align: right;
}
.spacer-row td {
height: 26px;
}
.total-row td {
font-weight: 700;
background: #f5f5f5;
}
.approval-area {
height: 94px;
border-top: 1px solid #444;
display: flex;
align-items: flex-end;
justify-content: flex-end;
padding: 10px 12px 14px;
}
.approval-box {
text-align: center;
min-width: 230px;
}
.signature-line {
margin-top: 18px;
border-top: 1px solid #222;
width: 100%;
}
.footer-row {
border-top: 1px solid #444;
text-align: center;
padding: 4px 0 5px;
font-size: 10px;
}
.watermark-line {
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
font-size: 10px;
}
.line-dots {
letter-spacing: 3px;
text-align: right;
}
.company-logo-text {
text-align: center;
color: #1c5c9d;
font-size: 14px;
line-height: 1.1;
font-weight: 700;
}
.company-logo-small {
font-size: 10px;
font-weight: 400;
color: #333;
}
.header-stack {
line-height: 1.15;
}
.small-note {
font-size: 9px;
color: #444;
}
.highlight {
background: #ffeb3b;
padding: 0 2px;
}
.multi-line {
white-space: pre-line;
}
</style>
</head>
<body>
<%
const creditCompany = typeof company !== 'undefined' && company ? company : {};
const creditHeader = typeof header !== 'undefined' && header ? header : {};
const creditBillTo = typeof billTo !== 'undefined' && billTo ? billTo : {};
const creditMeta = typeof meta !== 'undefined' && meta ? meta : {};
const creditVessel = typeof vessel !== 'undefined' && vessel ? vessel : {};
const creditOrderMeta = typeof orderMeta !== 'undefined' && orderMeta ? orderMeta : {};
const creditItems = typeof items !== 'undefined' && Array.isArray(items) ? items : [];
const creditApprovedByLabel = typeof approvedByLabel !== 'undefined' && approvedByLabel ? approvedByLabel : 'Approved by GLMS Finance Dept.';
const creditDepartmentLabel = typeof departmentLabel !== 'undefined' && departmentLabel ? departmentLabel : 'GLMS - Accounts Department';
%>
<div class="sheet">
<div class="company-band">
<div class="company-left">
<div><strong><%= creditCompany.name || 'GREEK-LANKA MARITIME SERVICES (PVT) LTD' %></strong></div>
<div><%= creditCompany.addressLine1 || '' %></div>
<div><%= creditCompany.addressLine2 || '' %></div>
<div><%= creditCompany.addressLine3 || '' %></div>
<div><%= creditCompany.postal || '' %></div>
<div><%= creditCompany.contact || '' %></div>
<div><%= creditCompany.br || '' %></div>
<div><%= creditCompany.license || '' %></div>
</div>
<div class="company-middle">
<div>
<div class="company-logo-text">GREEK<br/>LANKA</div>
<div class="company-logo-small">We Serve the Ocean</div>
</div>
</div>
<div class="company-right">
<div class="stack">
<div class="header-stack">
<div style="font-size: 14px; font-weight:700; color:#7da3de; letter-spacing:0.5px;">CREDIT NOTE</div>
</div>
</div>
</div>
</div>
<div class="title-row"><%= creditHeader.title || 'CREDIT NOTE' %></div>
<div class="bill-row">
<div class="bill-left">
<div><strong>Bill To :</strong> <%= creditBillTo.name || 'Master & Owner of MV TEAM VENTURES' %></div>
<div class="multi-line"><%- (creditBillTo.details || '').replace(/\n/g, '<br/>') || 'VRIDHI MARITIME SHIP MANAGEMENT & OPERATION LLC<br/>Office No: 2004, The Prism Tower, Dubai' %></div>
</div>
<div class="bill-right">
<div class="bill-line"><span><strong>CRN NO :</strong></span><span><%= creditMeta.crnNo || 'N/A' %></span></div>
<div class="bill-line"><span><strong>DATE :</strong></span><span><%= creditMeta.date || 'N/A' %></span></div>
</div>
</div>
<div class="meta-row">
<div class="meta-col">
<div class="meta-line"><span class="meta-label">Vessel Name :</span> <span><%= creditVessel.name || 'N/A' %></span></div>
<div class="meta-line"><span class="meta-label">Port :</span> <span><%= creditVessel.port || 'N/A' %></span></div>
<div class="meta-line"><span class="meta-label">Name of Agent :</span> <span><%= creditVessel.agent || 'N/A' %></span></div>
</div>
<div class="meta-col">
<div class="meta-line"><span class="meta-label">GRT :</span> <span><%= creditVessel.grt || 'N/A' %></span></div>
<div class="meta-line"><span class="meta-label">IMO Number :</span> <span><%= creditVessel.imo || 'N/A' %></span></div>
<div class="meta-line"><span class="meta-label">Port/Country :</span> <span><%= creditVessel.portCountry || 'N/A' %></span></div>
</div>
</div>
<div style="overflow-x:auto;">
<table class="items-table">
<thead>
<tr>
<th class="no-col">DESCRIPTION</th>
<th class="amount-col">AMOUNT</th>
</tr>
</thead>
<tbody>
<% if (creditItems.length > 0) { %>
<% creditItems.forEach((item, index) => { %>
<tr class="spacer-row">
<td>
<%= item.description || item.desc || '' %>
<% if (item.note) { %>
<div class="small-note"><%= item.note %></div>
<% } %>
</td>
<td class="right"><%= (typeof item.amount !== 'undefined') ? item.amount : '' %></td>
</tr>
<% }); %>
<% } %>
<tr class="total-row">
<td class="right">Total Amount</td>
<td class="right"><%= total || totalAmount || 0 %></td>
</tr>
</tbody>
</table>
</div>
<div class="approval-area">
<div class="approval-box">
<div style="height: 42px;"></div>
<div class="signature-line"></div>
<div style="margin-top: 4px;"><%= creditApprovedByLabel %></div>
</div>
</div>
<div class="footer-row">
<%= creditDepartmentLabel %>
</div>
</div>
</body>
</html>
@@ -0,0 +1,131 @@
/**
* 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/creditNote/creditNote.template.js
const { log } = require("../../../utils/consoleLog.utill");
module.exports = async (data) => {
log("📋 Preparing Credit Note 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 "";
};
// Normalize incoming fields and provide defaults matching the screenshot
const company = {
name: pick("companyName", "company_name") || "GREEK-LANKA MARITIME SERVICES (PVT) LTD",
addressLine1: pick("companyAddressLine1", "company_address_line1") || "No. 56/2, Dharmapala Mw, Kotte",
addressLine2: pick("companyAddressLine2", "company_address_line2") || "Sri Jayewardenepura",
addressLine3: pick("companyAddressLine3", "company_address_line3") || "Sri Lanka",
postal: pick("companyPostal", "company_postal") || "Postal Code : 10100",
contact: pick("companyContact", "company_contact") || "Tel:+94 11 2083206 / Mobile (24/7) : +94 777 232 271",
br: pick("companyBR", "company_br") || "BR No : PV 0022630",
license: pick("companyLicense", "company_license") || "License No : SA00317-2024",
logoUrl: pick("logoUrl", "logo_url") ||
"https://res.cloudinary.com/dtthuvvir/image/upload/v1780748661/company_logo_transperent_bg_uullzw.png",
};
const header = {
title: pick("title") || "CREDIT NOTE",
};
const billTo = {
name: pick("billToName", "bill_to_name") || "Master & Owner of MV TEAM VENTURES",
details: pick("billToDetails", "bill_to_details") || "VRIDHI MARITIME SHIP MANAGEMENT & OPERATION LLC\nOffice No: 2004, The Prism Tower, Dubai",
};
const meta = {
crnNo: pick("crnNo", "crn_no", "creditNoteNumber", "credit_note_number", "reference_no") || "GLMS/COLOMBO/474/CRN01",
date: pick("date") || new Date().toLocaleDateString(),
};
const vessel = {
name: pick("vesselName", "vessel_name") || 'MV "TEAM VENTURES"',
grt: pick("grt", "GRT") || "25,543 MT",
port: pick("port", "port_name") || "REPAIRS AT COLOMBO DOCK YARD",
imo: pick("imo", "imo_number", "imoNumber") || "9339765",
agent: pick("nameOfAgent", "name_of_agent", "agent") || "",
portCountry: pick("portCountry", "port_country") || "COLOMBO / SRI LANKA",
};
const orderMeta = {
orderDate: pick("orderDate", "order_date") || meta.date,
orderNo: pick("orderNo", "order_no") || "",
portReference: pick("portReference", "port_reference") || "",
};
// Items: array of { description, amount }
const items = (Array.isArray(source.items) ? source.items : []).map((it) => ({
description: it.description || it.desc || it.item_name || '',
amount: Number(it.amount || it.value || it.total || it.totalAmount || 0),
quantity: it.quantity ?? it.qty ?? '',
note: it.note || it.notes || '',
}));
const computedTotal = items.reduce((s, i) => s + (i.amount || 0), 0);
const templateData = {
company,
header,
billTo,
meta,
vessel,
orderMeta,
items,
totalAmount: Number(pick("totalAmount", "total") || computedTotal),
approvedBy: pick("approvedBy", "approved_by") || 'GLMS Finance Dept.',
approvedByLabel: pick("approvedByLabel", "approved_by_label") || 'Approved by GLMS Finance Dept.',
departmentLabel: pick("departmentLabel", "department_label") || 'GLMS - Accounts Department',
};
// Top-level conveniences for templates and pdfRenderer
templateData.logoUrl = company.logoUrl;
templateData.creditNoteNumber = templateData.meta.crnNo;
templateData.date = templateData.meta.date;
templateData.billToName = templateData.billTo.name;
templateData.billToDetails = templateData.billTo.details;
templateData.vessel = templateData.vessel;
// Provide invoiceNumber if present
templateData.invoiceNumber = pick("invoiceNumber", "invoice_number", "invoice_no") || '';
// Provide subtotal/tax/discount/total for EJS summary table compatibility
templateData.subtotal = Number(pick("subtotal", "sub_total") || computedTotal);
templateData.tax = Number(pick("tax") || 0);
templateData.discount = Number(pick("discount") || 0);
templateData.total = Number(pick("totalAmount", "total") || templateData.subtotal + templateData.tax - templateData.discount);
// Provide reason / notes
templateData.reason = pick("reason", "remarks", "notes") || '';
// Provide paymentTerms and notes for EJS
templateData.paymentTerms = pick("paymentTerms", "payment_terms") || '';
templateData.notes = pick("notes", "note") || '';
log("✅ Credit Note data prepared", JSON.stringify(templateData));
return templateData;
};