-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecon.ts
98 lines (90 loc) · 2.58 KB
/
recon.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import XLSX from "xlsx";
interface BankRecord {
transactionName: string;
date: string;
amount: number;
}
interface BankRecordWithStatus extends BankRecord {
status: string;
}
interface InternalRecord {
vaNumber: string;
schoolCode: string;
schoolName: string;
studentName: string;
amount: number;
}
const readInternalRecord = async (file: File): Promise<InternalRecord[]> => {
const buffer = await file.arrayBuffer();
const data = new Uint8Array(buffer);
const workbook = XLSX.read(data, { type: "array" });
const worksheet = workbook.Sheets[workbook.SheetNames[0] || 0];
return [];
};
const readBankRecord = async (file: File): Promise<BankRecord[]> => {
const buffer = await file.arrayBuffer();
const data = new Uint8Array(buffer);
const workbook = XLSX.read(data, { type: "array" });
const worksheet = workbook.Sheets[workbook.SheetNames[0] || 0];
return [];
};
const markRowStatus = (
internalRecords: InternalRecord[],
bankRecords: BankRecord[]
): BankRecordWithStatus[] => {
// bad time:
const result = bankRecords.map((bankRecord) => {
const bankRecordVaNumber = getVaNumberFromTrx(bankRecord.transactionName);
let status = "";
internalRecords.forEach((internalRecord) => {
if (bankRecordVaNumber === internalRecord.vaNumber) {
if (internalRecord.amount === bankRecord.amount) {
status = "AMAN";
}
}
});
return { ...bankRecord, status };
});
return result;
};
const getVaNumberFromTrx = (input: string): string => {
const startIndex = input.indexOf("127");
const vaNumber = input.slice(startIndex, startIndex + 18);
return vaNumber;
};
const splitVaNumber = (vaNumber: string): { left: string; right: string } => {
const a = vaNumber.split("0");
return { left: a[0], right: a[1] };
};
// const pipe = (...fns) => fns.reduce((fn, cur) => fn(cur));
// Test case
console.log(
getVaNumberFromTrx(
"BRIVA127060000000267170NBMBIQLIMA ARSYA ESB:NBMB:0200200P:493496516597"
)
);
console.log(
getVaNumberFromTrx(
"BRIVA127060000000272563NBMBMUHAMAD FAHRE ESB:NBMB:0200200P:493502002745"
)
);
console.log(
getVaNumberFromTrx(
"BRIVA127060000000317526NBMBMutiara Mauli ESB:NBMB:0200200P:493503967703"
)
);
console.log(
getVaNumberFromTrx(
"BRIVA127060000000183612NBMBRamzi Fairuz ESB:NBMB:0200200P:493505973029"
)
);
console.log(
getVaNumberFromTrx(
"BRIVA127060000000295840NBMBRARA PUTRI MA ESB:NBMB:0200200P:493506557999"
)
);
console.log(
getVaNumberFromTrx(
"127060000000959095#004138255402#ATM #TRF TRF LINK FROM SOBIRIN LN127060000000959095ATM 4215701500340776"
)
);