Skip to content

Commit ca8590b

Browse files
committed
fix: use withholding tax amount directly from eventpop
1 parent 1ce8589 commit ca8590b

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

Diff for: app.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { parse } from "csv-parse/sync";
44
import fs from "fs";
55
import { DateTime } from "luxon";
66
import { execSync } from 'child_process';
7+
import { isEmpty } from 'lodash'
78

89
import { createInvoice } from "./createInvoice";
910
import { createPayment } from "./createPayment";
@@ -46,10 +47,10 @@ const processedData: ProcessedData[] = (orders as Order[])
4647
return {
4748
eventpopId: item['Order #'],
4849
customer: {
49-
name: item["Buyer Name"],
50+
name: taxInfo?.["Billing Name"] ?? item["Buyer Name"],
5051
taxId: taxInfo?.["Billing Tax ID"] ?? null,
5152
address: taxInfo?.["Billing Address"] ?? null,
52-
branch: 'สำนักงานใหญ่',
53+
branch: taxInfo?.["Billing Branch"] ?? 'สำนักงานใหญ่',
5354
email: orderWithEmail[item['Order #']]
5455
},
5556
ticket: {
@@ -66,9 +67,9 @@ const processedData: ProcessedData[] = (orders as Order[])
6667
zone: 'Asia/Bangkok',
6768
setZone: true,
6869
}
69-
).toISO()!).toISOString()
70+
).toISO()!).toISOString(),
71+
witholdingTax: Number(item["Withholding Tax"]) > 0 ? Number(item["Withholding Tax"]) : null
7072
},
71-
isWitholdingTax: Number(item["Withholding Tax"]) > 0
7273
} satisfies ProcessedData
7374
})
7475

@@ -85,13 +86,13 @@ const pickedData = processedData
8586
"#38704-3267295", // bank, tax
8687
"#38704-3225968", // credit
8788
"#38704-3215101", // bank,
88-
"#38704-3288940", // out of scope
89+
"#38704-3288940", // out of scope,
90+
"#38704-3251019", // company
91+
"#38704-3215560" // company
8992

9093
].includes(o.eventpopId)
9194
)
9295

93-
console.log(pickedData)
94-
9596
;(async () => {
9697
let index = 1
9798
for await (const item of pickedData) {

Diff for: createPayment.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ export const createPayment = (data: ProcessedData, recordId: number) => {
1313
}
1414

1515
const totalPrice = data.ticket.price * data.ticket.amount
16-
const withheldAmount = Number(((data.isWitholdingTax ? 0.0279 : 0) * totalPrice).toFixed(2))
16+
const withheldAmount = data.payment.witholdingTax !== null ? data.payment.witholdingTax : 0
1717
const actualPriceAfterDeductWithheld = totalPrice - withheldAmount
1818

1919
let payload = {
2020
"dateNow": data.payment.method === 'bank' ? dayjs(data.payment.when).add(7, 'h').toISOString() : creditCardBilledDate,
2121
"chequeDate": data.payment.method === 'bank' ? dayjs(data.payment.when).add(7, 'h').toISOString() : creditCardBilledDate,
22-
"withholdingTax": data.isWitholdingTax ? 3 : null,
22+
"withholdingTax": data.payment.witholdingTax !== null ? 3 : null,
2323
"amountWithheld": withheldAmount,
2424
"charge": 0,
2525
"paymentMethod": data.payment.method === "bank" ? 5 : 13,

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
"csv-parse": "5.5.6",
1515
"dayjs": "1.11.13",
1616
"dotenv": "16.4.5",
17+
"lodash": "^4.17.21",
1718
"luxon": "3.5.0"
1819
},
1920
"devDependencies": {
21+
"@types/lodash": "^4.17.7",
2022
"@types/luxon": "3.4.2",
2123
"@types/node": "22.5.4",
2224
"tsx": "^4.19.0",

Diff for: pnpm-lock.yaml

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export interface Order {
4848
payment: {
4949
method: 'bank' | 'credit'
5050
when: string // ISO timestamp
51+
witholdingTax: number | null
5152
}
5253
customer: {
5354
name: string
@@ -56,5 +57,4 @@ export interface Order {
5657
branch: string
5758
email: string
5859
}
59-
isWitholdingTax: boolean
6060
}

0 commit comments

Comments
 (0)