fix: template error when no items
This commit is contained in:
parent
f08c45379d
commit
a75e0fff3f
1 changed files with 26 additions and 20 deletions
|
|
@ -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,26 +53,32 @@ const templates = {
|
||||||
discount?: number;
|
discount?: number;
|
||||||
}[];
|
}[];
|
||||||
}) => {
|
}) => {
|
||||||
return context?.items.flatMap((item) => {
|
return (
|
||||||
const price = formatNumberDecimal(
|
context?.items?.flatMap((item) => {
|
||||||
item.product.serviceCharge -
|
const price = formatNumberDecimal(
|
||||||
(context.itemsDiscount?.find((v) => v.productId === item.product.id)
|
item.product.serviceCharge -
|
||||||
?.discount || 0),
|
(context.itemsDiscount?.find(
|
||||||
);
|
(v) => v.productId === item.product.id,
|
||||||
|
)?.discount || 0),
|
||||||
const list = item.list.map((v, i) => {
|
|
||||||
const employee = v.request.employee;
|
|
||||||
const branch = v.request.quotation.customerBranch;
|
|
||||||
return (
|
|
||||||
`${i + 1}. ` +
|
|
||||||
`${employee.namePrefix}. ${employee.firstNameEN} ${employee.lastNameEN} `.toUpperCase() +
|
|
||||||
`(${branch.customer.customerType === 'PERS' ? `นายจ้าง ${branch.namePrefix}. ${branch.firstNameEN} ${branch.lastNameEN} `.toUpperCase() : branch.registerName})`
|
|
||||||
);
|
);
|
||||||
});
|
|
||||||
return [`- ${item.product.name} ราคา ${price} บาท`, '', ...list].join(
|
const list = item.list.map((v, i) => {
|
||||||
'<br />',
|
const employee = v.request.employee;
|
||||||
);
|
const branch = v.request.quotation.customerBranch;
|
||||||
});
|
return (
|
||||||
|
`${i + 1}. ` +
|
||||||
|
`${employee.namePrefix}. ${employee.firstNameEN} ${employee.lastNameEN} `.toUpperCase() +
|
||||||
|
`(${branch.customer.customerType === 'PERS' ? `นายจ้าง ${branch.namePrefix}. ${branch.firstNameEN} ${branch.lastNameEN} `.toUpperCase() : branch.registerName})`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
return [
|
||||||
|
`- ${item.product.name} ราคา ${price} บาท`,
|
||||||
|
'',
|
||||||
|
...list,
|
||||||
|
'',
|
||||||
|
].join('<br />');
|
||||||
|
}) || []
|
||||||
|
).join('<br />');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue