feat: template string

This commit is contained in:
Methapon2001 2025-01-23 15:18:15 +07:00
parent 8d9ae538cf
commit b022ff490b

View file

@ -1,3 +1,4 @@
import { RequestWork } from 'src/stores/request-list';
import { formatNumberDecimal } from 'src/stores/utils';
const templates = {
@ -40,6 +41,40 @@ const templates = {
}
},
},
'order-detail': {
converter: (context?: {
items: {
product: RequestWork['productService']['product'];
list: RequestWork[];
}[];
itemsDiscount?: {
productId: string;
discount?: number;
}[];
}) => {
return context?.items.flatMap((item) => {
const price = formatNumberDecimal(
item.product.serviceCharge -
(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(
'<br />',
);
});
},
},
} as const;
type Template = typeof templates;