fix: template error when no items

This commit is contained in:
Methapon2001 2025-01-24 11:16:05 +07:00
parent f08c45379d
commit a75e0fff3f

View file

@ -44,7 +44,7 @@ const templates = {
'order-detail': { 'order-detail': {
converter: (context?: { converter: (context?: {
items: { items?: {
product: RequestWork['productService']['product']; product: RequestWork['productService']['product'];
list: RequestWork[]; list: RequestWork[];
}[]; }[];
@ -53,11 +53,13 @@ const templates = {
discount?: number; discount?: number;
}[]; }[];
}) => { }) => {
return context?.items.flatMap((item) => { return (
context?.items?.flatMap((item) => {
const price = formatNumberDecimal( const price = formatNumberDecimal(
item.product.serviceCharge - item.product.serviceCharge -
(context.itemsDiscount?.find((v) => v.productId === item.product.id) (context.itemsDiscount?.find(
?.discount || 0), (v) => v.productId === item.product.id,
)?.discount || 0),
); );
const list = item.list.map((v, i) => { const list = item.list.map((v, i) => {
@ -69,10 +71,14 @@ const templates = {
`(${branch.customer.customerType === 'PERS' ? `นายจ้าง ${branch.namePrefix}. ${branch.firstNameEN} ${branch.lastNameEN} `.toUpperCase() : branch.registerName})` `(${branch.customer.customerType === 'PERS' ? `นายจ้าง ${branch.namePrefix}. ${branch.firstNameEN} ${branch.lastNameEN} `.toUpperCase() : branch.registerName})`
); );
}); });
return [`- ${item.product.name} ราคา ${price} บาท`, '', ...list].join( return [
'<br />', `- ${item.product.name} ราคา ${price} บาท`,
); '',
}); ...list,
'',
].join('<br />');
}) || []
).join('<br />');
}, },
}, },
} as const; } as const;