Skip to content

Commit 7fdbb27

Browse files
committed
fix: use fallback value if name in tax order is empty
1 parent ca8590b commit 7fdbb27

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

Diff for: app.ts

+19-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +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'
7+
import isEmpty from 'lodash/isEmpty'
88

99
import { createInvoice } from "./createInvoice";
1010
import { createPayment } from "./createPayment";
@@ -40,17 +40,19 @@ const orderWithEmail: Record<string, string> = parse(fs.readFileSync("input/even
4040
const processedData: ProcessedData[] = (orders as Order[])
4141
// filter subtotal 0 away
4242
.filter(o => Number(o['Subtotal']) > 0)
43+
.filter(o => o["Order #"] === '#38704-3215128')
4344
// beautify data
4445
.map(item => {
4546
const taxInfo = ordersWithTaxMap[item["Order #"]]
47+
console.log(taxInfo)
4648

4749
return {
4850
eventpopId: item['Order #'],
4951
customer: {
50-
name: taxInfo?.["Billing Name"] ?? item["Buyer Name"],
52+
name: !isEmpty(taxInfo?.["Billing Name"]) ? taxInfo?.["Billing Name"] : item["Buyer Name"],
5153
taxId: taxInfo?.["Billing Tax ID"] ?? null,
5254
address: taxInfo?.["Billing Address"] ?? null,
53-
branch: taxInfo?.["Billing Branch"] ?? 'สำนักงานใหญ่',
55+
branch: taxInfo?.["Billing Branch"] ?? '',
5456
email: orderWithEmail[item['Order #']]
5557
},
5658
ticket: {
@@ -78,20 +80,20 @@ fs.writeFileSync("output/processedData.json", JSON.stringify(processedData, null
7880
// const pickedData = [processedData[0]]
7981
// const pickedData = processedData
8082
const pickedData = processedData
81-
.filter(o =>
82-
[
83-
"#38704-3216014", // credit, tax, withholding
84-
"#38704-3215164", // bank, tax, withholding
85-
"#38704-3215100", // credit, tax
86-
"#38704-3267295", // bank, tax
87-
"#38704-3225968", // credit
88-
"#38704-3215101", // bank,
89-
"#38704-3288940", // out of scope,
90-
"#38704-3251019", // company
91-
"#38704-3215560" // company
92-
93-
].includes(o.eventpopId)
94-
)
83+
// .filter(o =>
84+
// [
85+
// "#38704-3216014", // credit, tax, withholding
86+
// "#38704-3215164", // bank, tax, withholding
87+
// "#38704-3215100", // credit, tax
88+
// "#38704-3267295", // bank, tax
89+
// "#38704-3225968", // credit
90+
// "#38704-3215101", // bank,
91+
// "#38704-3288940", // out of scope,
92+
// "#38704-3251019", // company
93+
// "#38704-3215560" // company
94+
//
95+
// ].includes(o.eventpopId)
96+
// )
9597

9698
;(async () => {
9799
let index = 1

Diff for: createInvoice.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export const createInvoice = async (data: ProcessedData, index: number): Promise
3434
// const vat = Number((total * 0.07).toFixed(2));
3535
// const grandTotal = Number((total + vat).toFixed(2));
3636

37+
console.log(data)
38+
3739
const raw = JSON.stringify({
3840
"isComplieAccountingRule": false,
3941
"documentContactCompanyChangeType": 7,
@@ -54,8 +56,8 @@ export const createInvoice = async (data: ProcessedData, index: number): Promise
5456
"isReverseAccrual": false,
5557
"contactStateChange": false,
5658
"companyStateChange": false,
57-
"publishedOn": data.payment.method === 'bank' ? dayjs(data.payment.when).add(7, 'h').toISOString() : creditCardBilledDate,
58-
"dueDate": data.payment.method === 'bank' ? dayjs(data.payment.when).add(7, 'h').toISOString() : creditCardBilledDate,
59+
"publishedOn": dayjs(data.payment.when).add(7, 'h').toISOString(),
60+
"dueDate": dayjs(data.payment.when).add(7, 'h').toISOString(),
5961
"discount": 0,
6062
"discountPercentage": 0,
6163
"creditDays": 0,
@@ -189,6 +191,8 @@ export const createInvoice = async (data: ProcessedData, index: number): Promise
189191
return result as PartialResponse
190192
})
191193

194+
console.log(invoice)
195+
192196
console.log('invoice:done: ', data.eventpopId)
193197
execSync(`echo "${data.eventpopId} ${invoice.data.recordId} ${invoice.data.documentSerial}" >> output/invoice.txt`, {
194198
cwd: process.cwd()

0 commit comments

Comments
 (0)