From b022ff490b77c76e6cf902d4f6049e1bb7f840a7 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 23 Jan 2025 15:18:15 +0700 Subject: [PATCH] feat: template string --- src/utils/string-template.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/utils/string-template.ts b/src/utils/string-template.ts index 4d33ab3e..94ae0d2f 100644 --- a/src/utils/string-template.ts +++ b/src/utils/string-template.ts @@ -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( + '
', + ); + }); + }, + }, } as const; type Template = typeof templates;