feat: send remark to flowaccount
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 5s

This commit is contained in:
Methapon2001 2025-09-11 17:23:21 +07:00
parent 86db927efe
commit eda0edbd29

View file

@ -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,