next slice
This commit is contained in:
@@ -3,6 +3,8 @@ import { Router } from "express";
|
||||
|
||||
import { renderPdf } from "../../lib/pdf.js";
|
||||
import { requirePermissions } from "../../lib/rbac.js";
|
||||
import { getPurchaseOrderPdfData } from "../purchasing/service.js";
|
||||
import { getSalesDocumentPdfData } from "../sales/service.js";
|
||||
import { getShipmentPackingSlipData } from "../shipping/service.js";
|
||||
import { getActiveCompanyProfile } from "../settings/service.js";
|
||||
|
||||
@@ -17,6 +19,123 @@ function escapeHtml(value: string) {
|
||||
.replaceAll("'", "'");
|
||||
}
|
||||
|
||||
function formatDate(value: string | null | undefined) {
|
||||
return value ? new Date(value).toLocaleDateString() : "N/A";
|
||||
}
|
||||
|
||||
function buildAddressLines(record: {
|
||||
name: string;
|
||||
addressLine1: string;
|
||||
addressLine2: string;
|
||||
city: string;
|
||||
state: string;
|
||||
postalCode: string;
|
||||
country: string;
|
||||
}) {
|
||||
return [
|
||||
record.name,
|
||||
record.addressLine1,
|
||||
record.addressLine2,
|
||||
`${record.city}, ${record.state} ${record.postalCode}`.trim(),
|
||||
record.country,
|
||||
].filter((line) => line.trim().length > 0);
|
||||
}
|
||||
|
||||
function renderCommercialDocumentPdf(options: {
|
||||
company: Awaited<ReturnType<typeof getActiveCompanyProfile>>;
|
||||
title: string;
|
||||
documentNumber: string;
|
||||
issueDate: string;
|
||||
status: string;
|
||||
partyTitle: string;
|
||||
partyLines: string[];
|
||||
partyMeta: Array<{ label: string; value: string }>;
|
||||
documentMeta: Array<{ label: string; value: string }>;
|
||||
rows: string;
|
||||
totalsRows: string;
|
||||
notes: string;
|
||||
}) {
|
||||
const { company } = options;
|
||||
|
||||
return renderPdf(`
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
@page { margin: 16mm; }
|
||||
body { font-family: ${company.theme.fontFamily}, Arial, sans-serif; color: #1b1f29; font-size: 12px; }
|
||||
.page { display: flex; flex-direction: column; gap: 16px; }
|
||||
.header { display: flex; justify-content: space-between; gap: 24px; border-bottom: 2px solid ${company.theme.primaryColor}; padding-bottom: 16px; }
|
||||
.brand h1 { margin: 0; font-size: 24px; color: ${company.theme.primaryColor}; }
|
||||
.brand p { margin: 6px 0 0; color: #5a6a85; line-height: 1.45; }
|
||||
.document-meta { min-width: 280px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }
|
||||
.label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: #5a6a85; }
|
||||
.value { margin-top: 4px; font-size: 13px; font-weight: 600; }
|
||||
.grid { display: grid; grid-template-columns: 1.05fr 0.95fr; gap: 16px; }
|
||||
.card { border: 1px solid #d7deeb; border-radius: 14px; padding: 14px 16px; }
|
||||
.card-title { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: #5a6a85; margin-bottom: 8px; }
|
||||
.stack { display: flex; flex-direction: column; gap: 4px; }
|
||||
table { width: 100%; border-collapse: collapse; }
|
||||
thead th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: #5a6a85; background: #f4f7fb; padding: 10px 12px; border-bottom: 1px solid #d7deeb; }
|
||||
tbody td { padding: 12px; border-bottom: 1px solid #e6ebf3; vertical-align: top; }
|
||||
.number { text-align: right; white-space: nowrap; }
|
||||
.item-name { font-weight: 600; }
|
||||
.item-desc { margin-top: 4px; color: #5a6a85; font-size: 11px; }
|
||||
.summary { margin-left: auto; width: 320px; border: 1px solid #d7deeb; border-radius: 14px; overflow: hidden; }
|
||||
.summary table tbody td { padding: 10px 12px; }
|
||||
.summary table tbody tr:last-child td { font-size: 14px; font-weight: 700; background: #f4f7fb; }
|
||||
.notes { border: 1px solid #d7deeb; border-radius: 14px; padding: 14px 16px; min-height: 72px; white-space: pre-line; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="page">
|
||||
<div class="header">
|
||||
<div class="brand">
|
||||
<h1>${escapeHtml(company.companyName)}</h1>
|
||||
<p>${escapeHtml(company.addressLine1)}${company.addressLine2 ? `<br/>${escapeHtml(company.addressLine2)}` : ""}<br/>${escapeHtml(company.city)}, ${escapeHtml(company.state)} ${escapeHtml(company.postalCode)}<br/>${escapeHtml(company.country)}</p>
|
||||
</div>
|
||||
<div class="document-meta">
|
||||
<div><div class="label">Document</div><div class="value">${escapeHtml(options.title)}</div></div>
|
||||
<div><div class="label">Number</div><div class="value">${escapeHtml(options.documentNumber)}</div></div>
|
||||
<div><div class="label">Issue Date</div><div class="value">${escapeHtml(formatDate(options.issueDate))}</div></div>
|
||||
<div><div class="label">Status</div><div class="value">${escapeHtml(options.status)}</div></div>
|
||||
${options.documentMeta.map((entry) => `<div><div class="label">${escapeHtml(entry.label)}</div><div class="value">${escapeHtml(entry.value)}</div></div>`).join("")}
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid">
|
||||
<div class="card">
|
||||
<div class="card-title">${escapeHtml(options.partyTitle)}</div>
|
||||
<div class="stack">${options.partyLines.map((line) => `<div>${escapeHtml(line)}</div>`).join("")}</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-title">Contact</div>
|
||||
<div class="stack">${options.partyMeta.map((entry) => `<div><strong>${escapeHtml(entry.label)}:</strong> ${escapeHtml(entry.value)}</div>`).join("")}</div>
|
||||
</div>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 16%;">SKU</th>
|
||||
<th>Description</th>
|
||||
<th style="width: 9%;" class="number">Qty</th>
|
||||
<th style="width: 9%;" class="number">UOM</th>
|
||||
<th style="width: 13%;" class="number">Unit</th>
|
||||
<th style="width: 14%;" class="number">Line Total</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>${options.rows}</tbody>
|
||||
</table>
|
||||
<div class="summary">
|
||||
<table>
|
||||
<tbody>${options.totalsRows}</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="notes"><div class="card-title">Notes</div>${escapeHtml(options.notes || "No notes recorded for this document.")}</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`);
|
||||
}
|
||||
|
||||
documentsRouter.get("/company-profile-preview.pdf", requirePermissions([permissions.companyRead]), async (_request, response) => {
|
||||
const profile = await getActiveCompanyProfile();
|
||||
const pdf = await renderPdf(`
|
||||
@@ -58,6 +177,180 @@ documentsRouter.get("/company-profile-preview.pdf", requirePermissions([permissi
|
||||
return response.send(pdf);
|
||||
});
|
||||
|
||||
documentsRouter.get(
|
||||
"/sales/quotes/:quoteId/document.pdf",
|
||||
requirePermissions([permissions.salesRead]),
|
||||
async (request, response) => {
|
||||
const quoteId = typeof request.params.quoteId === "string" ? request.params.quoteId : null;
|
||||
if (!quoteId) {
|
||||
response.status(400);
|
||||
return response.send("Invalid quote id.");
|
||||
}
|
||||
|
||||
const [profile, quote] = await Promise.all([getActiveCompanyProfile(), getSalesDocumentPdfData("QUOTE", quoteId)]);
|
||||
if (!quote) {
|
||||
response.status(404);
|
||||
return response.send("Quote was not found.");
|
||||
}
|
||||
|
||||
const rows = quote.lines.map((line) => `
|
||||
<tr>
|
||||
<td>${escapeHtml(line.itemSku)}</td>
|
||||
<td><div class="item-name">${escapeHtml(line.itemName)}</div><div class="item-desc">${escapeHtml(line.description || "")}</div></td>
|
||||
<td class="number">${line.quantity}</td>
|
||||
<td class="number">${escapeHtml(line.unitOfMeasure)}</td>
|
||||
<td class="number">$${line.unitPrice.toFixed(2)}</td>
|
||||
<td class="number">$${line.lineTotal.toFixed(2)}</td>
|
||||
</tr>
|
||||
`).join("");
|
||||
|
||||
const pdf = await renderCommercialDocumentPdf({
|
||||
company: profile,
|
||||
title: "Sales Quote",
|
||||
documentNumber: quote.documentNumber,
|
||||
issueDate: quote.issueDate,
|
||||
status: quote.status,
|
||||
partyTitle: "Bill To",
|
||||
partyLines: buildAddressLines(quote.customer),
|
||||
partyMeta: [
|
||||
{ label: "Email", value: quote.customer.email || "Not set" },
|
||||
{ label: "Phone", value: quote.customer.phone || "Not set" },
|
||||
],
|
||||
documentMeta: [
|
||||
{ label: "Expires", value: formatDate(quote.expiresAt) },
|
||||
],
|
||||
rows,
|
||||
totalsRows: `
|
||||
<tr><td>Subtotal</td><td class="number">$${quote.subtotal.toFixed(2)}</td></tr>
|
||||
<tr><td>Discount (${quote.discountPercent.toFixed(2)}%)</td><td class="number">-$${quote.discountAmount.toFixed(2)}</td></tr>
|
||||
<tr><td>Tax (${quote.taxPercent.toFixed(2)}%)</td><td class="number">$${quote.taxAmount.toFixed(2)}</td></tr>
|
||||
<tr><td>Freight</td><td class="number">$${quote.freightAmount.toFixed(2)}</td></tr>
|
||||
<tr><td>Total</td><td class="number">$${quote.total.toFixed(2)}</td></tr>
|
||||
`,
|
||||
notes: quote.notes,
|
||||
});
|
||||
|
||||
response.setHeader("Content-Type", "application/pdf");
|
||||
response.setHeader("Content-Disposition", `inline; filename=${quote.documentNumber.toLowerCase()}-quote.pdf`);
|
||||
return response.send(pdf);
|
||||
}
|
||||
);
|
||||
|
||||
documentsRouter.get(
|
||||
"/sales/orders/:orderId/document.pdf",
|
||||
requirePermissions([permissions.salesRead]),
|
||||
async (request, response) => {
|
||||
const orderId = typeof request.params.orderId === "string" ? request.params.orderId : null;
|
||||
if (!orderId) {
|
||||
response.status(400);
|
||||
return response.send("Invalid sales order id.");
|
||||
}
|
||||
|
||||
const [profile, order] = await Promise.all([getActiveCompanyProfile(), getSalesDocumentPdfData("ORDER", orderId)]);
|
||||
if (!order) {
|
||||
response.status(404);
|
||||
return response.send("Sales order was not found.");
|
||||
}
|
||||
|
||||
const rows = order.lines.map((line) => `
|
||||
<tr>
|
||||
<td>${escapeHtml(line.itemSku)}</td>
|
||||
<td><div class="item-name">${escapeHtml(line.itemName)}</div><div class="item-desc">${escapeHtml(line.description || "")}</div></td>
|
||||
<td class="number">${line.quantity}</td>
|
||||
<td class="number">${escapeHtml(line.unitOfMeasure)}</td>
|
||||
<td class="number">$${line.unitPrice.toFixed(2)}</td>
|
||||
<td class="number">$${line.lineTotal.toFixed(2)}</td>
|
||||
</tr>
|
||||
`).join("");
|
||||
|
||||
const pdf = await renderCommercialDocumentPdf({
|
||||
company: profile,
|
||||
title: "Sales Order",
|
||||
documentNumber: order.documentNumber,
|
||||
issueDate: order.issueDate,
|
||||
status: order.status,
|
||||
partyTitle: "Bill To",
|
||||
partyLines: buildAddressLines(order.customer),
|
||||
partyMeta: [
|
||||
{ label: "Email", value: order.customer.email || "Not set" },
|
||||
{ label: "Phone", value: order.customer.phone || "Not set" },
|
||||
],
|
||||
documentMeta: [],
|
||||
rows,
|
||||
totalsRows: `
|
||||
<tr><td>Subtotal</td><td class="number">$${order.subtotal.toFixed(2)}</td></tr>
|
||||
<tr><td>Discount (${order.discountPercent.toFixed(2)}%)</td><td class="number">-$${order.discountAmount.toFixed(2)}</td></tr>
|
||||
<tr><td>Tax (${order.taxPercent.toFixed(2)}%)</td><td class="number">$${order.taxAmount.toFixed(2)}</td></tr>
|
||||
<tr><td>Freight</td><td class="number">$${order.freightAmount.toFixed(2)}</td></tr>
|
||||
<tr><td>Total</td><td class="number">$${order.total.toFixed(2)}</td></tr>
|
||||
`,
|
||||
notes: order.notes,
|
||||
});
|
||||
|
||||
response.setHeader("Content-Type", "application/pdf");
|
||||
response.setHeader("Content-Disposition", `inline; filename=${order.documentNumber.toLowerCase()}-sales-order.pdf`);
|
||||
return response.send(pdf);
|
||||
}
|
||||
);
|
||||
|
||||
documentsRouter.get(
|
||||
"/purchasing/orders/:orderId/document.pdf",
|
||||
requirePermissions([permissions.purchasingRead]),
|
||||
async (request, response) => {
|
||||
const orderId = typeof request.params.orderId === "string" ? request.params.orderId : null;
|
||||
if (!orderId) {
|
||||
response.status(400);
|
||||
return response.send("Invalid purchase order id.");
|
||||
}
|
||||
|
||||
const [profile, order] = await Promise.all([getActiveCompanyProfile(), getPurchaseOrderPdfData(orderId)]);
|
||||
if (!order) {
|
||||
response.status(404);
|
||||
return response.send("Purchase order was not found.");
|
||||
}
|
||||
|
||||
const rows = order.lines.map((line) => `
|
||||
<tr>
|
||||
<td>${escapeHtml(line.itemSku)}</td>
|
||||
<td><div class="item-name">${escapeHtml(line.itemName)}</div><div class="item-desc">${escapeHtml(line.description || "")}</div></td>
|
||||
<td class="number">${line.quantity}</td>
|
||||
<td class="number">${escapeHtml(line.unitOfMeasure)}</td>
|
||||
<td class="number">$${line.unitCost.toFixed(2)}</td>
|
||||
<td class="number">$${line.lineTotal.toFixed(2)}</td>
|
||||
</tr>
|
||||
`).join("");
|
||||
|
||||
const pdf = await renderCommercialDocumentPdf({
|
||||
company: profile,
|
||||
title: "Purchase Order",
|
||||
documentNumber: order.documentNumber,
|
||||
issueDate: order.issueDate,
|
||||
status: order.status,
|
||||
partyTitle: "Vendor",
|
||||
partyLines: buildAddressLines(order.vendor),
|
||||
partyMeta: [
|
||||
{ label: "Email", value: order.vendor.email || "Not set" },
|
||||
{ label: "Phone", value: order.vendor.phone || "Not set" },
|
||||
{ label: "Terms", value: order.vendor.paymentTerms || "Not set" },
|
||||
{ label: "Currency", value: order.vendor.currencyCode || "USD" },
|
||||
],
|
||||
documentMeta: [],
|
||||
rows,
|
||||
totalsRows: `
|
||||
<tr><td>Subtotal</td><td class="number">$${order.subtotal.toFixed(2)}</td></tr>
|
||||
<tr><td>Tax (${order.taxPercent.toFixed(2)}%)</td><td class="number">$${order.taxAmount.toFixed(2)}</td></tr>
|
||||
<tr><td>Freight</td><td class="number">$${order.freightAmount.toFixed(2)}</td></tr>
|
||||
<tr><td>Total</td><td class="number">$${order.total.toFixed(2)}</td></tr>
|
||||
`,
|
||||
notes: order.notes,
|
||||
});
|
||||
|
||||
response.setHeader("Content-Type", "application/pdf");
|
||||
response.setHeader("Content-Disposition", `inline; filename=${order.documentNumber.toLowerCase()}-purchase-order.pdf`);
|
||||
return response.send(pdf);
|
||||
}
|
||||
);
|
||||
|
||||
documentsRouter.get(
|
||||
"/shipping/shipments/:shipmentId/packing-slip.pdf",
|
||||
requirePermissions([permissions.shippingRead]),
|
||||
|
||||
@@ -6,6 +6,42 @@ import { prisma } from "../../lib/prisma.js";
|
||||
|
||||
const purchaseOrderModel = prisma.purchaseOrder;
|
||||
|
||||
export interface PurchaseOrderPdfData {
|
||||
documentNumber: string;
|
||||
status: PurchaseOrderStatus;
|
||||
issueDate: string;
|
||||
vendor: {
|
||||
name: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
addressLine1: string;
|
||||
addressLine2: string;
|
||||
city: string;
|
||||
state: string;
|
||||
postalCode: string;
|
||||
country: string;
|
||||
paymentTerms: string | null;
|
||||
currencyCode: string | null;
|
||||
};
|
||||
notes: string;
|
||||
subtotal: number;
|
||||
taxPercent: number;
|
||||
taxAmount: number;
|
||||
freightAmount: number;
|
||||
total: number;
|
||||
lines: Array<{
|
||||
itemSku: string;
|
||||
itemName: string;
|
||||
description: string;
|
||||
quantity: number;
|
||||
receivedQuantity: number;
|
||||
remainingQuantity: number;
|
||||
unitOfMeasure: string;
|
||||
unitCost: number;
|
||||
lineTotal: number;
|
||||
}>;
|
||||
}
|
||||
|
||||
type PurchaseLineRecord = {
|
||||
id: string;
|
||||
description: string;
|
||||
@@ -642,3 +678,80 @@ export async function createPurchaseReceipt(orderId: string, payload: PurchaseRe
|
||||
const detail = await getPurchaseOrderById(orderId);
|
||||
return detail ? { ok: true as const, document: detail } : { ok: false as const, reason: "Unable to load updated purchase order." };
|
||||
}
|
||||
|
||||
export async function getPurchaseOrderPdfData(orderId: string): Promise<PurchaseOrderPdfData | null> {
|
||||
const order = await prisma.purchaseOrder.findUnique({
|
||||
where: { id: orderId },
|
||||
include: {
|
||||
vendor: {
|
||||
select: {
|
||||
name: true,
|
||||
email: true,
|
||||
phone: true,
|
||||
addressLine1: true,
|
||||
addressLine2: true,
|
||||
city: true,
|
||||
state: true,
|
||||
postalCode: true,
|
||||
country: true,
|
||||
paymentTerms: true,
|
||||
currencyCode: true,
|
||||
},
|
||||
},
|
||||
lines: {
|
||||
include: {
|
||||
item: {
|
||||
select: {
|
||||
sku: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
receiptLines: {
|
||||
select: {
|
||||
quantity: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: [{ position: "asc" }, { createdAt: "asc" }],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!order) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const lines = order.lines.map((line) => {
|
||||
const receivedQuantity = line.receiptLines.reduce((sum, receiptLine) => sum + receiptLine.quantity, 0);
|
||||
return {
|
||||
itemSku: line.item.sku,
|
||||
itemName: line.item.name,
|
||||
description: line.description,
|
||||
quantity: line.quantity,
|
||||
receivedQuantity,
|
||||
remainingQuantity: Math.max(0, line.quantity - receivedQuantity),
|
||||
unitOfMeasure: line.unitOfMeasure,
|
||||
unitCost: line.unitCost,
|
||||
lineTotal: line.quantity * line.unitCost,
|
||||
};
|
||||
});
|
||||
const totals = calculateTotals(
|
||||
lines.reduce((sum, line) => sum + line.lineTotal, 0),
|
||||
order.taxPercent,
|
||||
order.freightAmount
|
||||
);
|
||||
|
||||
return {
|
||||
documentNumber: order.documentNumber,
|
||||
status: order.status as PurchaseOrderStatus,
|
||||
issueDate: order.issueDate.toISOString(),
|
||||
vendor: order.vendor,
|
||||
notes: order.notes,
|
||||
subtotal: totals.subtotal,
|
||||
taxPercent: totals.taxPercent,
|
||||
taxAmount: totals.taxAmount,
|
||||
freightAmount: totals.freightAmount,
|
||||
total: totals.total,
|
||||
lines,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,6 +10,42 @@ import type {
|
||||
|
||||
import { prisma } from "../../lib/prisma.js";
|
||||
|
||||
export interface SalesDocumentPdfData {
|
||||
type: SalesDocumentType;
|
||||
documentNumber: string;
|
||||
status: SalesDocumentStatus;
|
||||
issueDate: string;
|
||||
expiresAt: string | null;
|
||||
customer: {
|
||||
name: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
addressLine1: string;
|
||||
addressLine2: string;
|
||||
city: string;
|
||||
state: string;
|
||||
postalCode: string;
|
||||
country: string;
|
||||
};
|
||||
notes: string;
|
||||
subtotal: number;
|
||||
discountPercent: number;
|
||||
discountAmount: number;
|
||||
taxPercent: number;
|
||||
taxAmount: number;
|
||||
freightAmount: number;
|
||||
total: number;
|
||||
lines: Array<{
|
||||
itemSku: string;
|
||||
itemName: string;
|
||||
description: string;
|
||||
quantity: number;
|
||||
unitOfMeasure: string;
|
||||
unitPrice: number;
|
||||
lineTotal: number;
|
||||
}>;
|
||||
}
|
||||
|
||||
type SalesLineRecord = {
|
||||
id: string;
|
||||
description: string;
|
||||
@@ -475,3 +511,80 @@ export async function convertQuoteToSalesOrder(quoteId: string) {
|
||||
const order = await getSalesDocumentById("ORDER", created.id);
|
||||
return order ? { ok: true as const, document: order } : { ok: false as const, reason: "Unable to load converted sales order." };
|
||||
}
|
||||
|
||||
export async function getSalesDocumentPdfData(type: SalesDocumentType, documentId: string): Promise<SalesDocumentPdfData | null> {
|
||||
const include = {
|
||||
customer: {
|
||||
select: {
|
||||
name: true,
|
||||
email: true,
|
||||
phone: true,
|
||||
addressLine1: true,
|
||||
addressLine2: true,
|
||||
city: true,
|
||||
state: true,
|
||||
postalCode: true,
|
||||
country: true,
|
||||
},
|
||||
},
|
||||
lines: {
|
||||
include: {
|
||||
item: {
|
||||
select: {
|
||||
sku: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: [{ position: "asc" as const }, { createdAt: "asc" as const }],
|
||||
},
|
||||
};
|
||||
const record =
|
||||
type === "QUOTE"
|
||||
? await prisma.salesQuote.findUnique({
|
||||
where: { id: documentId },
|
||||
include,
|
||||
})
|
||||
: await prisma.salesOrder.findUnique({
|
||||
where: { id: documentId },
|
||||
include,
|
||||
});
|
||||
|
||||
if (!record) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const lines = record.lines.map((line: { item: { sku: string; name: string }; description: string; quantity: number; unitOfMeasure: string; unitPrice: number }) => ({
|
||||
itemSku: line.item.sku,
|
||||
itemName: line.item.name,
|
||||
description: line.description,
|
||||
quantity: line.quantity,
|
||||
unitOfMeasure: line.unitOfMeasure,
|
||||
unitPrice: line.unitPrice,
|
||||
lineTotal: line.quantity * line.unitPrice,
|
||||
}));
|
||||
const totals = calculateTotals(
|
||||
lines.reduce((sum: number, line: SalesDocumentPdfData["lines"][number]) => sum + line.lineTotal, 0),
|
||||
record.discountPercent,
|
||||
record.taxPercent,
|
||||
record.freightAmount
|
||||
);
|
||||
|
||||
return {
|
||||
type,
|
||||
documentNumber: record.documentNumber,
|
||||
status: record.status as SalesDocumentStatus,
|
||||
issueDate: record.issueDate.toISOString(),
|
||||
expiresAt: "expiresAt" in record && record.expiresAt ? record.expiresAt.toISOString() : null,
|
||||
customer: record.customer,
|
||||
notes: record.notes,
|
||||
subtotal: totals.subtotal,
|
||||
discountPercent: totals.discountPercent,
|
||||
discountAmount: totals.discountAmount,
|
||||
taxPercent: totals.taxPercent,
|
||||
taxAmount: totals.taxAmount,
|
||||
freightAmount: totals.freightAmount,
|
||||
total: totals.total,
|
||||
lines,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user