diff --git a/src/services/flowaccount.ts b/src/services/flowaccount.ts index 730482d..80c0ca0 100644 --- a/src/services/flowaccount.ts +++ b/src/services/flowaccount.ts @@ -1,6 +1,8 @@ import prisma from "../db"; import config from "../config.json"; import { CustomerType, PayCondition } from "@prisma/client"; +import { convertTemplate } from "../utils/string-template"; +import { htmlToText } from "html-to-text"; if (!process.env.FLOW_ACCOUNT_URL) throw new Error("Require FLOW_ACCOUNT_URL"); if (!process.env.FLOW_ACCOUNT_CLIENT_ID) throw new Error("Require FLOW_ACCOUNT_CLIENT_ID"); @@ -232,6 +234,29 @@ const flowAccount = { installments: true, quotation: { include: { + paySplit: true, + worker: { + select: { + employee: { + select: { + employeePassport: { + select: { + number: true, + }, + orderBy: { + expireDate: "desc", + }, + take: 1, + }, + namePrefix: true, + firstName: true, + lastName: true, + firstNameEN: true, + lastNameEN: true, + }, + }, + }, + }, registeredBranch: { include: { province: true, @@ -326,6 +351,22 @@ const flowAccount = { ? data.installments.reduce((a, c) => a + c.amount, 0) : quotation.finalPrice, + remarks: htmlToText( + convertTemplate(quotation.remark ?? "", { + "quotation-payment": { + paymentType: quotation?.payCondition || "Full", + amount: quotation.finalPrice, + installments: quotation?.paySplit, + }, + "quotation-labor": { + name: quotation.worker.map( + (v, i) => + `${i + 1}. ` + + `${v.employee.employeePassport.length !== 0 ? v.employee.employeePassport[0].number + "_" : ""}${v.employee.namePrefix}. ${v.employee.firstNameEN ? `${v.employee.firstNameEN} ${v.employee.lastNameEN}` : `${v.employee.firstName} ${v.employee.lastName}`} `.toUpperCase(), + ), + }, + }), + ), items: product.map((v) => ({ type: ProductAndServiceType.ProductNonInv, name: v.product.name,