From 4e71343af7cae29af0f4d9496ec004364e046cbd Mon Sep 17 00:00:00 2001 From: HAM Date: Tue, 16 Sep 2025 09:53:03 +0700 Subject: [PATCH] refactor: use function for correct decimal number --- src/services/flowaccount.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/services/flowaccount.ts b/src/services/flowaccount.ts index fde345d..ec934ca 100644 --- a/src/services/flowaccount.ts +++ b/src/services/flowaccount.ts @@ -4,6 +4,7 @@ import { CustomerType, PayCondition } from "@prisma/client"; import { convertTemplate } from "../utils/string-template"; import { htmlToText } from "html-to-text"; import { JsonObject } from "@prisma/client/runtime/library"; +import { precisionRound } from "../utils/arithmetic"; 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"); @@ -185,6 +186,8 @@ const flowAccountAPI = { data.paymentDate = `${year}-${String(month).padStart(2, "0")}-${String(date).padStart(2, "0")}`; } */ + console.log(JSON.stringify(data, null, 2)); + const res = await fetch( api + "/upgrade/receipts/inline" + (withPayment ? "/with-payment" : ""), { @@ -327,7 +330,6 @@ const flowAccount = { dueDate: quotation.dueDate, salesName: [quotation.createdBy?.firstName, quotation.createdBy?.lastName].join(" "), - useInlineVat: true, isVatInclusive: true, isVat: true, @@ -372,7 +374,7 @@ const flowAccount = { items: product.map((v) => ({ type: ProductAndServiceType.ProductNonInv, name: v.product.name, - pricePerUnit: Math.round(v.pricePerUnit * 100) / 100, + pricePerUnit: precisionRound(v.pricePerUnit), quantity: v.amount, discountAmount: v.discount, total: (v.pricePerUnit - (v.discount || 0)) * v.amount + v.vat,