@tomei/finance 0.6.99 → 0.6.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/commit-msg +12 -3
- package/.husky/pre-commit +4 -4
- package/configs/config.js +1 -1
- package/dist/account/account.d.ts +37 -37
- package/dist/account/account.js +251 -263
- package/dist/account/account.js.map +1 -1
- package/dist/account/account.repository.d.ts +5 -5
- package/dist/account/account.repository.js +11 -11
- package/dist/account/interfaces/account-attr.interface.d.ts +29 -29
- package/dist/account/interfaces/account-attr.interface.js +2 -2
- package/dist/account-system-entity/account-system-entity.d.ts +12 -12
- package/dist/account-system-entity/account-system-entity.js +55 -66
- package/dist/account-system-entity/account-system-entity.js.map +1 -1
- package/dist/account-system-entity/post-history.repository.d.ts +5 -5
- package/dist/account-system-entity/post-history.repository.js +11 -11
- package/dist/config.d.ts +1888 -1888
- package/dist/config.js +331 -331
- package/dist/config.js.map +1 -1
- package/dist/customer/customer.d.ts +44 -44
- package/dist/customer/customer.js +212 -234
- package/dist/customer/customer.js.map +1 -1
- package/dist/customer/finance-customer.repository.d.ts +5 -5
- package/dist/customer/finance-customer.repository.js +25 -25
- package/dist/customer/finance-customer.repository.js.map +1 -1
- package/dist/customer/interfaces/customer.repository.interface.d.ts +3 -3
- package/dist/customer/interfaces/customer.repository.interface.js +2 -2
- package/dist/customer/interfaces/finance-customer-attr.interface.d.ts +10 -10
- package/dist/customer/interfaces/finance-customer-attr.interface.js +2 -2
- package/dist/customer/interfaces/finance-customer.repository.interface.d.ts +3 -3
- package/dist/customer/interfaces/finance-customer.repository.interface.js +2 -2
- package/dist/database.d.ts +4 -4
- package/dist/database.js +46 -47
- package/dist/database.js.map +1 -1
- package/dist/document/document-item.d.ts +46 -46
- package/dist/document/document-item.js +122 -132
- package/dist/document/document-item.js.map +1 -1
- package/dist/document/document-item.repository.d.ts +5 -5
- package/dist/document/document-item.repository.js +11 -11
- package/dist/document/document.d.ts +87 -88
- package/dist/document/document.js +735 -766
- package/dist/document/document.js.map +1 -1
- package/dist/document/document.repository.d.ts +5 -5
- package/dist/document/document.repository.js +11 -11
- package/dist/document/interfaces/document-attr.interface.d.ts +27 -27
- package/dist/document/interfaces/document-attr.interface.js +6 -6
- package/dist/document/interfaces/document-find-all.interface.d.ts +13 -13
- package/dist/document/interfaces/document-find-all.interface.js +2 -2
- package/dist/document/interfaces/document-item-attr.interface.d.ts +26 -26
- package/dist/document/interfaces/document-item-attr.interface.js +6 -6
- package/dist/document/interfaces/document-item.repository.interface.d.ts +3 -3
- package/dist/document/interfaces/document-item.repository.interface.js +2 -2
- package/dist/enum/collect-payment-type.d.ts +4 -4
- package/dist/enum/collect-payment-type.js +8 -8
- package/dist/enum/collect-payment-type.js.map +1 -1
- package/dist/enum/doc-type.enum.d.ts +8 -8
- package/dist/enum/doc-type.enum.js +12 -12
- package/dist/enum/doc-type.enum.js.map +1 -1
- package/dist/enum/document-status.enum.d.ts +6 -6
- package/dist/enum/document-status.enum.js +10 -10
- package/dist/enum/document-status.enum.js.map +1 -1
- package/dist/enum/index.d.ts +9 -9
- package/dist/enum/index.js +19 -19
- package/dist/enum/payment-method.enum.d.ts +3 -3
- package/dist/enum/payment-method.enum.js +7 -7
- package/dist/enum/payment-method.enum.js.map +1 -1
- package/dist/enum/payment-status.enum.d.ts +10 -10
- package/dist/enum/payment-status.enum.js +15 -16
- package/dist/enum/payment-status.enum.js.map +1 -1
- package/dist/enum/payment-type.enum.d.ts +4 -4
- package/dist/enum/payment-type.enum.js +8 -8
- package/dist/enum/payment-type.enum.js.map +1 -1
- package/dist/enum/quick-book-client-scopes.enum.d.ts +13 -13
- package/dist/enum/quick-book-client-scopes.enum.js +18 -18
- package/dist/enum/quick-book-client-scopes.enum.js.map +1 -1
- package/dist/enum/transaction-type.enum.d.ts +4 -4
- package/dist/enum/transaction-type.enum.js +8 -8
- package/dist/enum/transaction-type.enum.js.map +1 -1
- package/dist/finance-company/finance-company.d.ts +88 -88
- package/dist/finance-company/finance-company.js +1533 -1576
- package/dist/finance-company/finance-company.js.map +1 -1
- package/dist/finance-company/finance-company.repository.d.ts +5 -5
- package/dist/finance-company/finance-company.repository.js +11 -11
- package/dist/helpers/login-user.d.ts +13 -13
- package/dist/helpers/login-user.js +28 -28
- package/dist/helpers/login-user.js.map +1 -1
- package/dist/helpers/typeof.d.ts +1 -1
- package/dist/helpers/typeof.js +28 -29
- package/dist/helpers/typeof.js.map +1 -1
- package/dist/index.d.ts +17 -17
- package/dist/index.js +32 -32
- package/dist/interfaces/account-system.interface.d.ts +30 -30
- package/dist/interfaces/account-system.interface.js +2 -2
- package/dist/interfaces/index.d.ts +2 -2
- package/dist/interfaces/index.js +2 -2
- package/dist/journal-entry/interfaces/journal-entry-attr.interface.d.ts +12 -12
- package/dist/journal-entry/interfaces/journal-entry-attr.interface.js +2 -2
- package/dist/journal-entry/journal-entry.d.ts +42 -42
- package/dist/journal-entry/journal-entry.js +216 -233
- package/dist/journal-entry/journal-entry.js.map +1 -1
- package/dist/journal-entry/journal-entry.repository.d.ts +6 -6
- package/dist/journal-entry/journal-entry.repository.js +16 -27
- package/dist/journal-entry/journal-entry.repository.js.map +1 -1
- package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.d.ts +17 -17
- package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.js +2 -2
- package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.d.ts +5 -5
- package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.js +2 -2
- package/dist/ledger-transaction/ledger-transaction.d.ts +54 -54
- package/dist/ledger-transaction/ledger-transaction.js +143 -164
- package/dist/ledger-transaction/ledger-transaction.js.map +1 -1
- package/dist/ledger-transaction/ledger-transaction.repository.d.ts +6 -6
- package/dist/ledger-transaction/ledger-transaction.repository.js +16 -27
- package/dist/ledger-transaction/ledger-transaction.repository.js.map +1 -1
- package/dist/models/account.entity.d.ts +30 -30
- package/dist/models/account.entity.js +232 -232
- package/dist/models/account.entity.js.map +1 -1
- package/dist/models/customer.entity.d.ts +13 -13
- package/dist/models/customer.entity.js +109 -109
- package/dist/models/customer.entity.js.map +1 -1
- package/dist/models/document-item.entity.d.ts +31 -31
- package/dist/models/document-item.entity.js +200 -200
- package/dist/models/document-item.entity.js.map +1 -1
- package/dist/models/document.entity.d.ts +36 -36
- package/dist/models/document.entity.js +242 -242
- package/dist/models/document.entity.js.map +1 -1
- package/dist/models/finance-company.entity.d.ts +15 -15
- package/dist/models/finance-company.entity.js +93 -93
- package/dist/models/finance-company.entity.js.map +1 -1
- package/dist/models/journal-entry.entity.d.ts +16 -16
- package/dist/models/journal-entry.entity.js +127 -127
- package/dist/models/journal-entry.entity.js.map +1 -1
- package/dist/models/ledger-transaction.entity.d.ts +24 -24
- package/dist/models/ledger-transaction.entity.js +172 -172
- package/dist/models/ledger-transaction.entity.js.map +1 -1
- package/dist/models/payment-item.entity.d.ts +12 -12
- package/dist/models/payment-item.entity.js +75 -75
- package/dist/models/payment-item.entity.js.map +1 -1
- package/dist/models/payment-method-type.entity.d.ts +13 -13
- package/dist/models/payment-method-type.entity.js +85 -85
- package/dist/models/payment-method-type.entity.js.map +1 -1
- package/dist/models/payment-method.entity.d.ts +10 -10
- package/dist/models/payment-method.entity.js +62 -62
- package/dist/models/payment-method.entity.js.map +1 -1
- package/dist/models/payment-paid-with.entity.d.ts +24 -24
- package/dist/models/payment-paid-with.entity.js +158 -158
- package/dist/models/payment-paid-with.entity.js.map +1 -1
- package/dist/models/payment.entity.d.ts +29 -29
- package/dist/models/payment.entity.js +193 -193
- package/dist/models/payment.entity.js.map +1 -1
- package/dist/models/post-history.entity.d.ts +11 -11
- package/dist/models/post-history.entity.js +63 -63
- package/dist/models/post-history.entity.js.map +1 -1
- package/dist/models/tax.entity.d.ts +13 -13
- package/dist/models/tax.entity.js +89 -89
- package/dist/models/tax.entity.js.map +1 -1
- package/dist/payment/interfaces/payment-attr.interface.d.ts +22 -22
- package/dist/payment/interfaces/payment-attr.interface.js +6 -6
- package/dist/payment/interfaces/payment-params.interface.d.ts +7 -7
- package/dist/payment/interfaces/payment-params.interface.js +2 -2
- package/dist/payment/payment.d.ts +53 -53
- package/dist/payment/payment.js +186 -201
- package/dist/payment/payment.js.map +1 -1
- package/dist/payment/payment.repository.d.ts +5 -5
- package/dist/payment/payment.repository.js +11 -11
- package/dist/payment-item/interfaces/payment-item-attr.interface.d.ts +10 -10
- package/dist/payment-item/interfaces/payment-item-attr.interface.js +6 -6
- package/dist/payment-item/payment-item.d.ts +25 -25
- package/dist/payment-item/payment-item.js +111 -122
- package/dist/payment-item/payment-item.js.map +1 -1
- package/dist/payment-item/payment-item.repository.d.ts +5 -5
- package/dist/payment-item/payment-item.repository.js +11 -11
- package/dist/payment-method/interfaces/payment-method-attr.interface.d.ts +5 -5
- package/dist/payment-method/interfaces/payment-method-attr.interface.js +2 -2
- package/dist/payment-method/payment-method.d.ts +21 -21
- package/dist/payment-method/payment-method.js +104 -117
- package/dist/payment-method/payment-method.js.map +1 -1
- package/dist/payment-method/payment-method.repository.d.ts +5 -5
- package/dist/payment-method/payment-method.repository.js +11 -11
- package/dist/payment-method-type/interfaces/payment-method-type-attr.interface.d.ts +8 -8
- package/dist/payment-method-type/interfaces/payment-method-type-attr.interface.js +2 -2
- package/dist/payment-method-type/payment-method-type.d.ts +18 -18
- package/dist/payment-method-type/payment-method-type.js +65 -76
- package/dist/payment-method-type/payment-method-type.js.map +1 -1
- package/dist/payment-method-type/payment-method-type.repository.d.ts +5 -5
- package/dist/payment-method-type/payment-method-type.repository.js +11 -11
- package/dist/payment-paid-with/interfaces/payment-paid-with.interface.d.ts +19 -19
- package/dist/payment-paid-with/interfaces/payment-paid-with.interface.js +6 -6
- package/dist/payment-paid-with/payment-paid-with.d.ts +33 -33
- package/dist/payment-paid-with/payment-paid-with.js +56 -56
- package/dist/payment-paid-with/payment-paid-with.js.map +1 -1
- package/dist/payment-paid-with/payment-paid-with.repository.d.ts +5 -5
- package/dist/payment-paid-with/payment-paid-with.repository.js +11 -11
- package/dist/tax/interfaces/tax-attr.interface.d.ts +10 -10
- package/dist/tax/interfaces/tax-attr.interface.js +2 -2
- package/dist/tax/tax.d.ts +26 -26
- package/dist/tax/tax.js +51 -51
- package/dist/tax/tax.js.map +1 -1
- package/dist/tax/tax.repository.d.ts +5 -5
- package/dist/tax/tax.repository.js +11 -11
- package/dist/test-document.d.ts +3 -3
- package/dist/test-document.js +18 -18
- package/dist/test.d.ts +1 -1
- package/dist/test.js +6 -7
- package/dist/test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eslint.config.mjs +58 -0
- package/invoice-template/assets/js/html2canvas.min.js +16 -16
- package/package.json +35 -41
- package/src/account/account.ts +2 -1
- package/src/customer/customer.ts +8 -7
- package/src/document/document-item.ts +3 -2
- package/src/document/document.ts +20 -13
- package/src/enum/collect-payment-type.ts +3 -3
- package/src/enum/payment-status.enum.ts +1 -1
- package/src/finance-company/finance-company.ts +5 -7
- package/src/journal-entry/journal-entry.ts +0 -1
- package/src/ledger-transaction/ledger-transaction.ts +4 -4
- package/src/payment-method-type/payment-method-type.ts +1 -1
- package/src/tax/tax.ts +0 -1
- package/tsconfig.json +4 -3
- package/.eslintrc.js +0 -72
- package/img.png +0 -0
- package/img_1.png +0 -0
- package/tslint.json +0 -18
|
@@ -1,1577 +1,1534 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
get
|
|
40
|
-
return this.
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
this.
|
|
47
|
-
}
|
|
48
|
-
get
|
|
49
|
-
return this.
|
|
50
|
-
}
|
|
51
|
-
set
|
|
52
|
-
this.
|
|
53
|
-
}
|
|
54
|
-
get
|
|
55
|
-
return this.
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
this.
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
this.
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
set
|
|
73
|
-
this.
|
|
74
|
-
}
|
|
75
|
-
get
|
|
76
|
-
return this.
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
this.
|
|
80
|
-
}
|
|
81
|
-
set
|
|
82
|
-
this.
|
|
83
|
-
}
|
|
84
|
-
get
|
|
85
|
-
return this.
|
|
86
|
-
}
|
|
87
|
-
get
|
|
88
|
-
return
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
this.
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
this.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
this.
|
|
108
|
-
this.
|
|
109
|
-
this.
|
|
110
|
-
this.
|
|
111
|
-
this.
|
|
112
|
-
this.
|
|
113
|
-
this.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
financeCompany.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
throw
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
invoiceMedia
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
const
|
|
489
|
-
const
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
invoice.
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
creditTransaction.
|
|
828
|
-
creditTransaction.
|
|
829
|
-
creditTransaction.
|
|
830
|
-
creditTransaction.
|
|
831
|
-
creditTransaction.
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
.
|
|
1118
|
-
|
|
1119
|
-
})
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
}
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
receipt.
|
|
1413
|
-
receipt.
|
|
1414
|
-
receipt.
|
|
1415
|
-
|
|
1416
|
-
receipt.
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
receipt.
|
|
1421
|
-
receipt.
|
|
1422
|
-
receipt.
|
|
1423
|
-
|
|
1424
|
-
receipt.
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
receiptItem.
|
|
1434
|
-
|
|
1435
|
-
receiptItem.
|
|
1436
|
-
receiptItem.
|
|
1437
|
-
receiptItem.
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
});
|
|
1470
|
-
const
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
creditLT.Name = paymentMethodType.Name;
|
|
1535
|
-
creditLT.RelatedObjectId = payment.PaymentId;
|
|
1536
|
-
creditLT.RelatedObjectType = (0, typeof_1.type)(payment);
|
|
1537
|
-
creditLT.RelatedPaymentId = payment.PaymentId;
|
|
1538
|
-
yield this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
1539
|
-
}
|
|
1540
|
-
break;
|
|
1541
|
-
default:
|
|
1542
|
-
throw new general_1.ClassError('FinanceCompany', 'FinanceCompanyConfirmPaymentErrMsg03', `Invalid status.`);
|
|
1543
|
-
}
|
|
1544
|
-
yield FinanceCompany._PaymentRepository.update({
|
|
1545
|
-
ReceiptDocNo: receiptDocNo,
|
|
1546
|
-
Status: payment.Status,
|
|
1547
|
-
UpdatedAt: new Date(),
|
|
1548
|
-
UpdatedBy: loginUser.ObjectId,
|
|
1549
|
-
}, {
|
|
1550
|
-
where: {
|
|
1551
|
-
PaymentId: payment.PaymentId,
|
|
1552
|
-
},
|
|
1553
|
-
transaction: dbTransaction,
|
|
1554
|
-
});
|
|
1555
|
-
}
|
|
1556
|
-
catch (error) {
|
|
1557
|
-
throw error;
|
|
1558
|
-
}
|
|
1559
|
-
});
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
exports.default = FinanceCompany;
|
|
1563
|
-
FinanceCompany._htFinanceCompanyIds = new general_1.HashTable();
|
|
1564
|
-
FinanceCompany._htFinanceCompanies = new general_1.HashTable();
|
|
1565
|
-
FinanceCompany._financeCompanyRepository = new finance_company_repository_1.FinanceCompanyRepository();
|
|
1566
|
-
FinanceCompany._PaymentRepository = new payment_repository_1.PaymentRepository();
|
|
1567
|
-
FinanceCompany._PaymentItemRepository = new payment_item_repository_1.PaymentItemRepository();
|
|
1568
|
-
FinanceCompany._PaymentPaidWithRepository = new payment_paid_with_repository_1.PaymentPaidWithRepository();
|
|
1569
|
-
FinanceCompany._PaymentMethodRepository = new payment_method_repository_1.PaymentMethodRepository();
|
|
1570
|
-
FinanceCompany._PaymentMethodTypeRepository = new payment_method_type_repository_1.PaymentMethodTypeRepository();
|
|
1571
|
-
FinanceCompany._DocumentRepository = new document_repository_1.DocumentRepository();
|
|
1572
|
-
FinanceCompany._DocumentItemRepository = new document_item_repository_1.DocumentItemRepository();
|
|
1573
|
-
FinanceCompany._FinanceCustomerRepository = new finance_customer_repository_1.FinanceCustomerRepository();
|
|
1574
|
-
FinanceCompany._LedgerTransactionRepository = new ledger_transaction_repository_1.LedgerTransactionRepository();
|
|
1575
|
-
FinanceCompany._AccountRepository = new account_repository_1.AccountRepository();
|
|
1576
|
-
FinanceCompany._TaxRepository = new tax_repository_1.TaxRepository();
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const axios_1 = require("axios");
|
|
4
|
+
const general_1 = require("@tomei/general");
|
|
5
|
+
const account_1 = require("../account/account");
|
|
6
|
+
const journal_entry_1 = require("../journal-entry/journal-entry");
|
|
7
|
+
const document_1 = require("../document/document");
|
|
8
|
+
const finance_company_repository_1 = require("./finance-company.repository");
|
|
9
|
+
const finance_customer_repository_1 = require("../customer/finance-customer.repository");
|
|
10
|
+
const ledger_transaction_repository_1 = require("../ledger-transaction/ledger-transaction.repository");
|
|
11
|
+
const enum_1 = require("../enum");
|
|
12
|
+
const payment_method_type_1 = require("../payment-method-type/payment-method-type");
|
|
13
|
+
const payment_repository_1 = require("../payment/payment.repository");
|
|
14
|
+
const payment_item_repository_1 = require("../payment-item/payment-item.repository");
|
|
15
|
+
const document_repository_1 = require("../document/document.repository");
|
|
16
|
+
const document_item_repository_1 = require("../document/document-item.repository");
|
|
17
|
+
const payment_method_repository_1 = require("../payment-method/payment-method.repository");
|
|
18
|
+
const payment_method_type_repository_1 = require("../payment-method-type/payment-method-type.repository");
|
|
19
|
+
const payment_method_1 = require("../payment-method/payment-method");
|
|
20
|
+
const account_repository_1 = require("../account/account.repository");
|
|
21
|
+
const payment_paid_with_repository_1 = require("../payment-paid-with/payment-paid-with.repository");
|
|
22
|
+
const document_item_1 = require("../document/document-item");
|
|
23
|
+
const typeof_1 = require("../helpers/typeof");
|
|
24
|
+
const activity_history_1 = require("@tomei/activity-history");
|
|
25
|
+
const config_1 = require("@tomei/config");
|
|
26
|
+
const tax_repository_1 = require("../tax/tax.repository");
|
|
27
|
+
const tax_1 = require("../tax/tax");
|
|
28
|
+
const collect_payment_type_1 = require("../enum/collect-payment-type");
|
|
29
|
+
class FinanceCompany extends general_1.ObjectBase {
|
|
30
|
+
get ObjectType() {
|
|
31
|
+
return this._ObjectType;
|
|
32
|
+
}
|
|
33
|
+
get CompSystemCode() {
|
|
34
|
+
return this._CompSystemCode;
|
|
35
|
+
}
|
|
36
|
+
set CompSystemCode(code) {
|
|
37
|
+
this._CompSystemCode = code;
|
|
38
|
+
}
|
|
39
|
+
get CompSystemRefId() {
|
|
40
|
+
return this._CompSystemRefId;
|
|
41
|
+
}
|
|
42
|
+
set CompSystemRefId(id) {
|
|
43
|
+
this._CompSystemRefId = id;
|
|
44
|
+
}
|
|
45
|
+
get AccSystemCode() {
|
|
46
|
+
return this._AccSystemCode;
|
|
47
|
+
}
|
|
48
|
+
get AccSystemRefId() {
|
|
49
|
+
return this._AccSystemRefId;
|
|
50
|
+
}
|
|
51
|
+
set AccSystemRefId(id) {
|
|
52
|
+
this._AccSystemRefId = id;
|
|
53
|
+
}
|
|
54
|
+
get PostedToAccSystemYN() {
|
|
55
|
+
return this._PostedToAccSystemYN;
|
|
56
|
+
}
|
|
57
|
+
set PostedToAccSystemYN(value) {
|
|
58
|
+
this._PostedToAccSystemYN = value;
|
|
59
|
+
}
|
|
60
|
+
get PostedById() {
|
|
61
|
+
return this._PostedById;
|
|
62
|
+
}
|
|
63
|
+
set PostedById(id) {
|
|
64
|
+
this._PostedById = id;
|
|
65
|
+
}
|
|
66
|
+
get PostedDateTime() {
|
|
67
|
+
return this._PostedDateTime;
|
|
68
|
+
}
|
|
69
|
+
set PostedDateTime(date) {
|
|
70
|
+
this._PostedDateTime = date;
|
|
71
|
+
}
|
|
72
|
+
set AccSystemCode(code) {
|
|
73
|
+
this._AccSystemCode = code;
|
|
74
|
+
}
|
|
75
|
+
get CompanyId() {
|
|
76
|
+
return this._CompanyId;
|
|
77
|
+
}
|
|
78
|
+
get ObjectId() {
|
|
79
|
+
return this._CompanyId;
|
|
80
|
+
}
|
|
81
|
+
set ObjectId(id) {
|
|
82
|
+
this._CompanyId = id;
|
|
83
|
+
}
|
|
84
|
+
get ObjectName() {
|
|
85
|
+
return `${this.CompSystemCode}-${this.CompSystemRefId}-${this.AccSystemCode}`;
|
|
86
|
+
}
|
|
87
|
+
get TableName() {
|
|
88
|
+
return 'finance_Company';
|
|
89
|
+
}
|
|
90
|
+
get AccountingSystem() {
|
|
91
|
+
return this._AccountingSystem;
|
|
92
|
+
}
|
|
93
|
+
set AccountingSystem(system) {
|
|
94
|
+
this._AccountingSystem = system;
|
|
95
|
+
}
|
|
96
|
+
constructor(compSystemCode, compSystemRefId, accSystemCode) {
|
|
97
|
+
super();
|
|
98
|
+
this._CompanyId = 'New';
|
|
99
|
+
this._CompSystemCode = '';
|
|
100
|
+
this._CompSystemRefId = '';
|
|
101
|
+
this._AccSystemCode = '';
|
|
102
|
+
this._AccSystemRefId = 'REF';
|
|
103
|
+
this._PostedToAccSystemYN = 'N';
|
|
104
|
+
this._PostedById = null;
|
|
105
|
+
this._PostedDateTime = null;
|
|
106
|
+
this._ObjectType = 'FinanceCompany';
|
|
107
|
+
this._PaymentMethods = [];
|
|
108
|
+
this._Taxes = [];
|
|
109
|
+
this.CompSystemCode = compSystemCode;
|
|
110
|
+
this.CompSystemRefId = compSystemRefId;
|
|
111
|
+
this.AccSystemCode = accSystemCode;
|
|
112
|
+
this.AccSystemRefId = 'REF';
|
|
113
|
+
this.PostedToAccSystemYN = 'N';
|
|
114
|
+
}
|
|
115
|
+
static async getFinanceCompanyId(compSystemCode, compSystemRefId, accSystemCode) {
|
|
116
|
+
let sCompanyId = '';
|
|
117
|
+
const sKey = `${compSystemCode}-${compSystemRefId}-${accSystemCode}`;
|
|
118
|
+
if (!FinanceCompany._htFinanceCompanyIds.get(sKey)) {
|
|
119
|
+
const financeCompany = new FinanceCompany(compSystemCode, compSystemRefId, accSystemCode);
|
|
120
|
+
const company = await FinanceCompany._financeCompanyRepository.findOne({
|
|
121
|
+
where: {
|
|
122
|
+
CompSystemCode: compSystemCode,
|
|
123
|
+
CompSystemRefId: compSystemRefId,
|
|
124
|
+
AccSystemCode: accSystemCode,
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
financeCompany.ObjectId = company.CompanyId;
|
|
128
|
+
sCompanyId = financeCompany.ObjectId;
|
|
129
|
+
FinanceCompany._htFinanceCompanyIds.add(sKey, financeCompany.ObjectId);
|
|
130
|
+
FinanceCompany._htFinanceCompanies.add(sCompanyId, financeCompany);
|
|
131
|
+
}
|
|
132
|
+
if (typeof FinanceCompany._htFinanceCompanyIds.get(sKey) === 'string') {
|
|
133
|
+
sCompanyId = FinanceCompany._htFinanceCompanyIds.get(sKey);
|
|
134
|
+
}
|
|
135
|
+
return sCompanyId;
|
|
136
|
+
}
|
|
137
|
+
static async getFinanceCompany(companyId) {
|
|
138
|
+
if (!FinanceCompany._htFinanceCompanies.get(companyId)) {
|
|
139
|
+
const company = await FinanceCompany._financeCompanyRepository.findOne({
|
|
140
|
+
where: { CompanyId: companyId },
|
|
141
|
+
});
|
|
142
|
+
if (!company) {
|
|
143
|
+
throw Error('No finance company found. Please create first.');
|
|
144
|
+
}
|
|
145
|
+
const compSystemCode = company.CompSystemCode;
|
|
146
|
+
const compSystemRefId = company.CompSystemRefId;
|
|
147
|
+
const accSystemCode = company.AccSystemCode;
|
|
148
|
+
const financeCompany = new FinanceCompany(compSystemCode, compSystemRefId, accSystemCode);
|
|
149
|
+
financeCompany.ObjectId = company.CompanyId;
|
|
150
|
+
financeCompany._CompanyId = company.CompanyId;
|
|
151
|
+
const sKey = `${compSystemCode}-${compSystemRefId}-${accSystemCode}`;
|
|
152
|
+
FinanceCompany._htFinanceCompanyIds.add(sKey, financeCompany.ObjectId);
|
|
153
|
+
FinanceCompany._htFinanceCompanies.add(financeCompany.ObjectId, financeCompany);
|
|
154
|
+
}
|
|
155
|
+
console.log('return from hash table');
|
|
156
|
+
return FinanceCompany._htFinanceCompanies.get(companyId);
|
|
157
|
+
}
|
|
158
|
+
static async createFinanceCompany(dbTransaction, loginUser, companyId, compSystemCode, compSystemRefId, accSystemCode) {
|
|
159
|
+
const financeCompany = new FinanceCompany(compSystemCode, compSystemRefId, accSystemCode);
|
|
160
|
+
const company = await FinanceCompany._financeCompanyRepository.findOne({
|
|
161
|
+
where: {
|
|
162
|
+
CompSystemCode: compSystemCode,
|
|
163
|
+
CompSystemRefId: compSystemRefId,
|
|
164
|
+
AccSystemCode: accSystemCode,
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
if (company) {
|
|
168
|
+
throw Error('There is already another Finance Company with the compSystemCode, CompSystemRefId and accSystemCode specified.');
|
|
169
|
+
}
|
|
170
|
+
financeCompany.ObjectId = companyId;
|
|
171
|
+
const accSystemRefId = config_1.ComponentConfig.getComponentConfigValue('finance-config.json', 'accountSystemRefId');
|
|
172
|
+
const postedToAccSystemYN = config_1.ComponentConfig.getComponentConfigValue('finance-config.json', 'postedToAccSystemYN');
|
|
173
|
+
financeCompany.PostedById = loginUser.ObjectId || null;
|
|
174
|
+
financeCompany.PostedDateTime = new Date();
|
|
175
|
+
await FinanceCompany._financeCompanyRepository.create({
|
|
176
|
+
CompanyId: financeCompany.CompanyId,
|
|
177
|
+
CompSystemCode: financeCompany.CompSystemCode,
|
|
178
|
+
CompSystemRefId: financeCompany.CompSystemRefId,
|
|
179
|
+
AccSystemCode: financeCompany.AccSystemCode,
|
|
180
|
+
AccSystemRefId: postedToAccSystemYN === 'Y'
|
|
181
|
+
? accSystemRefId
|
|
182
|
+
: financeCompany.AccSystemRefId,
|
|
183
|
+
PostedToAccSystemYN: postedToAccSystemYN || financeCompany.PostedToAccSystemYN,
|
|
184
|
+
PostedById: financeCompany.PostedById,
|
|
185
|
+
PostedDateTime: financeCompany.PostedDateTime,
|
|
186
|
+
}, {
|
|
187
|
+
transaction: dbTransaction,
|
|
188
|
+
});
|
|
189
|
+
const sKey = `${compSystemCode}-${compSystemRefId}-${accSystemCode}`;
|
|
190
|
+
FinanceCompany._htFinanceCompanyIds.add(sKey, financeCompany.ObjectId);
|
|
191
|
+
FinanceCompany._htFinanceCompanies.add(financeCompany.ObjectId, financeCompany);
|
|
192
|
+
console.log('return from hash table');
|
|
193
|
+
return FinanceCompany._htFinanceCompanies.get(companyId);
|
|
194
|
+
}
|
|
195
|
+
static async findAccount(loginUser, dbTransaction, accountNo) {
|
|
196
|
+
try {
|
|
197
|
+
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
198
|
+
const isPrivileged = await loginUser.checkPrivileges(systemCode, 'FINANCECOMPANY_VIEW_ACCOUNT');
|
|
199
|
+
if (!isPrivileged) {
|
|
200
|
+
throw new general_1.ClassError('FinanceCompany', 'findAccountErrMsg0X', 'User not privileged to view finance company account');
|
|
201
|
+
}
|
|
202
|
+
const record = await FinanceCompany._AccountRepository.findOne({
|
|
203
|
+
where: {
|
|
204
|
+
AccountNo: accountNo,
|
|
205
|
+
},
|
|
206
|
+
transaction: dbTransaction,
|
|
207
|
+
});
|
|
208
|
+
if (record) {
|
|
209
|
+
const account = new account_1.default(dbTransaction);
|
|
210
|
+
account.init(record.get({ plain: true }));
|
|
211
|
+
return account;
|
|
212
|
+
}
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
async createCustomer(dbTransaction, custSystemCode, custSystemRefId, customer, loginUser) {
|
|
220
|
+
try {
|
|
221
|
+
if (!custSystemCode || !custSystemRefId) {
|
|
222
|
+
throw new Error('CustSystemCode and CustomerRefId are required fields.');
|
|
223
|
+
}
|
|
224
|
+
const financeCustomerData = await FinanceCompany._FinanceCustomerRepository.findOne({
|
|
225
|
+
where: {
|
|
226
|
+
CompanyId: this._CompanyId,
|
|
227
|
+
CustSystemCode: custSystemCode,
|
|
228
|
+
CustSystemRefId: custSystemRefId,
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
if (financeCustomerData) {
|
|
232
|
+
throw new Error('Customer already created previously.');
|
|
233
|
+
}
|
|
234
|
+
let AccCustomerRefId = 'REF';
|
|
235
|
+
if (this.AccountingSystem) {
|
|
236
|
+
AccCustomerRefId = await this.AccountingSystem.createCustomer(customer, dbTransaction);
|
|
237
|
+
}
|
|
238
|
+
customer.CompanyId = this._CompanyId;
|
|
239
|
+
const newCustomer = await customer.save(AccCustomerRefId, custSystemCode, custSystemRefId, dbTransaction);
|
|
240
|
+
const activity = new activity_history_1.Activity();
|
|
241
|
+
activity.ActivityId = this._createId().toUpperCase();
|
|
242
|
+
activity.Action = activity_history_1.ActionEnum.CREATE;
|
|
243
|
+
activity.Description = 'Add Finance Customer';
|
|
244
|
+
activity.EntityType = 'FinanceCustomer';
|
|
245
|
+
activity.EntityId = newCustomer.CustomerId;
|
|
246
|
+
activity.EntityValueBefore = JSON.stringify({});
|
|
247
|
+
activity.EntityValueAfter = JSON.stringify(newCustomer);
|
|
248
|
+
await activity.create(loginUser.ObjectId, dbTransaction);
|
|
249
|
+
return customer;
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
async postJournal(dbTransaction, journalEntry, loginUser) {
|
|
256
|
+
const debitTransactions = await journalEntry.DebitTransactions;
|
|
257
|
+
const creditTransactions = await journalEntry.CreditTransactions;
|
|
258
|
+
try {
|
|
259
|
+
if (creditTransactions.length < 1 || (debitTransactions === null || debitTransactions === void 0 ? void 0 : debitTransactions.length) < 1) {
|
|
260
|
+
throw new Error('There should be at least 1 debit ledger transaction and 1 credit ledger transaction in the journal entry');
|
|
261
|
+
}
|
|
262
|
+
let totalCreditAmount = creditTransactions.reduce((accumulator, currentValue) => accumulator + currentValue.CreditAmount, 0);
|
|
263
|
+
let totalDebitAmount = debitTransactions.reduce((accumulator, currentValue) => accumulator + currentValue.DebitAmount, 0);
|
|
264
|
+
console.log('totalCreditAmount: ', totalCreditAmount);
|
|
265
|
+
console.log('totalDebitAmount: ', totalDebitAmount);
|
|
266
|
+
if (typeof totalCreditAmount === 'string') {
|
|
267
|
+
totalCreditAmount = parseFloat(totalCreditAmount);
|
|
268
|
+
}
|
|
269
|
+
if (typeof totalDebitAmount === 'string') {
|
|
270
|
+
totalDebitAmount = parseFloat(totalDebitAmount);
|
|
271
|
+
}
|
|
272
|
+
if (totalCreditAmount.toFixed(2) !== totalDebitAmount.toFixed(2)) {
|
|
273
|
+
throw new Error('Credit ledger transaction and debit ledger transaction should the same amount');
|
|
274
|
+
}
|
|
275
|
+
const newJournalEntry = await journalEntry.save(loginUser.ObjectId, dbTransaction);
|
|
276
|
+
for (const ledgerTransaction of debitTransactions) {
|
|
277
|
+
ledgerTransaction.JournalEntryId = newJournalEntry.JournalEntryId;
|
|
278
|
+
await ledgerTransaction.save(dbTransaction);
|
|
279
|
+
}
|
|
280
|
+
for (const ledgerTransaction of creditTransactions) {
|
|
281
|
+
ledgerTransaction.JournalEntryId = newJournalEntry.JournalEntryId;
|
|
282
|
+
await ledgerTransaction.save(dbTransaction);
|
|
283
|
+
}
|
|
284
|
+
const payload = {
|
|
285
|
+
Action: 'Create',
|
|
286
|
+
Activity: 'Post Journal Entry',
|
|
287
|
+
Description: `Journal Entry (ID: ${newJournalEntry.JournalEntryId}) has been created`,
|
|
288
|
+
EntityType: 'JournalEntry',
|
|
289
|
+
EntityValueBefore: JSON.stringify({}),
|
|
290
|
+
EntityValueAfter: JSON.stringify(newJournalEntry),
|
|
291
|
+
PerformedById: loginUser.ObjectId,
|
|
292
|
+
PerformedAt: new Date(),
|
|
293
|
+
EntityId: newJournalEntry.JournalEntryId,
|
|
294
|
+
};
|
|
295
|
+
await axios_1.default.post(`${process.env.COMMON_API_URL}/activity-histories`, payload);
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
async createAccount(dbTransaction, account, loginUser) {
|
|
302
|
+
try {
|
|
303
|
+
let accSystemRefId;
|
|
304
|
+
if (!account.AccountType) {
|
|
305
|
+
throw new Error('AccountType is required.');
|
|
306
|
+
}
|
|
307
|
+
const accountNoLength = config_1.ComponentConfig.getComponentConfigValue('@tomei/finance', 'accountNoLength');
|
|
308
|
+
if (accountNoLength && account.AccountNo.length > accountNoLength) {
|
|
309
|
+
throw new Error(`Account No length should not exceed ${accountNoLength} characters.`);
|
|
310
|
+
}
|
|
311
|
+
let createAccountPayload = {
|
|
312
|
+
Name: account.Name,
|
|
313
|
+
AcctNum: account.AccountNo,
|
|
314
|
+
AccountType: account.AccountType,
|
|
315
|
+
AccountSubType: account.AccountSubtype,
|
|
316
|
+
};
|
|
317
|
+
if (this.AccountingSystem) {
|
|
318
|
+
accSystemRefId = await this.AccountingSystem.createAccount(account, dbTransaction);
|
|
319
|
+
}
|
|
320
|
+
if (account.isParentAccountExists()) {
|
|
321
|
+
createAccountPayload = Object.assign(Object.assign({}, createAccountPayload), { CurrencyRef: 'MYR', ParentRef: account.ParentAccountNo, SubAccount: true });
|
|
322
|
+
}
|
|
323
|
+
console.log('Finance Company Create Account: Before accSystemAccountId Create');
|
|
324
|
+
console.log('Finance Company Create Account: After accSystemAccountId Create');
|
|
325
|
+
console.log('Finance Company Create Account: Before new Account Create');
|
|
326
|
+
if (accSystemRefId) {
|
|
327
|
+
account.PostedToAccSystemYN = 'Y';
|
|
328
|
+
account.PostedById = loginUser.ObjectId;
|
|
329
|
+
account.PostedDateTime = new Date();
|
|
330
|
+
}
|
|
331
|
+
const newAccount = await account.save(this.CompanyId, accSystemRefId || 'REF', loginUser.ObjectId, dbTransaction);
|
|
332
|
+
console.log('Finance Company Create Account: After new Account Create');
|
|
333
|
+
const payload = {
|
|
334
|
+
Action: 'Create',
|
|
335
|
+
Activity: 'Account Created',
|
|
336
|
+
Description: `Account (ID: ${newAccount.AccountNo}) has been created`,
|
|
337
|
+
EntityType: 'Account',
|
|
338
|
+
EntityValueBefore: JSON.stringify({}),
|
|
339
|
+
EntityValueAfter: JSON.stringify(newAccount),
|
|
340
|
+
PerformedById: loginUser.ObjectId,
|
|
341
|
+
PerformedAt: new Date(),
|
|
342
|
+
EntityId: newAccount.AccountNo,
|
|
343
|
+
};
|
|
344
|
+
await axios_1.default.post(`${process.env.COMMON_API_URL}/activity-histories`, payload);
|
|
345
|
+
return account;
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
throw error;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async issueInvoice(dbTransaction, invoice, loginUser, customer, dtAccountNo) {
|
|
352
|
+
try {
|
|
353
|
+
const duplicateInvoice = await FinanceCompany._DocumentRepository.findOne({
|
|
354
|
+
where: {
|
|
355
|
+
DocNo: invoice.DocNo,
|
|
356
|
+
},
|
|
357
|
+
transaction: dbTransaction,
|
|
358
|
+
});
|
|
359
|
+
if (duplicateInvoice) {
|
|
360
|
+
throw new Error('Invoice number already exists');
|
|
361
|
+
}
|
|
362
|
+
const documentItems = await invoice.getDocumentItems(dbTransaction);
|
|
363
|
+
if (!documentItems.length) {
|
|
364
|
+
throw new Error('Document must have at least 1 document item');
|
|
365
|
+
}
|
|
366
|
+
for (const invoiceItem of documentItems) {
|
|
367
|
+
if (!invoiceItem.CtAccountNo) {
|
|
368
|
+
throw new Error('Each document item should have CtAccountNo provided');
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
invoice.DocType = enum_1.DocType.INVOICE;
|
|
372
|
+
let invoiceMedia;
|
|
373
|
+
if (invoice.UseAccSystemDocYN === 'Y') {
|
|
374
|
+
const accInvoiceRefIdDetail = await this.AccountingSystem.createInvoice({
|
|
375
|
+
customer,
|
|
376
|
+
invoice,
|
|
377
|
+
paymentMode: 'credit',
|
|
378
|
+
}, dbTransaction);
|
|
379
|
+
invoice.DocNo = accInvoiceRefIdDetail.invoiceNo;
|
|
380
|
+
invoice.AccSystemRefId = accInvoiceRefIdDetail.invoiceRefId;
|
|
381
|
+
invoice.PostedToAccSystemYN = 'Y';
|
|
382
|
+
invoice.PostedById = loginUser.ObjectId;
|
|
383
|
+
invoice.PostedDateTime = new Date();
|
|
384
|
+
for (const documentItem of documentItems) {
|
|
385
|
+
const accItem = accInvoiceRefIdDetail.invoiceItems.find((item) => item.name === documentItem.Name);
|
|
386
|
+
if (accItem) {
|
|
387
|
+
documentItem.DocNo = accInvoiceRefIdDetail.invoiceNo;
|
|
388
|
+
documentItem.AccSystemRefId = accItem.itemRefId;
|
|
389
|
+
documentItem.PostedToAccSystemYN = 'Y';
|
|
390
|
+
documentItem.PostedById = loginUser.ObjectId;
|
|
391
|
+
documentItem.PostedDateTime = new Date();
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
invoiceMedia = await invoice.generateInvoice(invoice.IssuedById, customer, dbTransaction);
|
|
397
|
+
}
|
|
398
|
+
await FinanceCompany._DocumentRepository.create({
|
|
399
|
+
DocNo: invoice.DocNo,
|
|
400
|
+
DocType: invoice.DocType,
|
|
401
|
+
DocDate: invoice.DocDate,
|
|
402
|
+
CompanyId: invoice.CompanyId,
|
|
403
|
+
Currency: invoice.Currency,
|
|
404
|
+
Amount: invoice.Amount,
|
|
405
|
+
Description: invoice.Description,
|
|
406
|
+
Status: invoice.Status,
|
|
407
|
+
IssuedById: invoice.IssuedById,
|
|
408
|
+
IssuedToId: invoice.IssuedToId,
|
|
409
|
+
IssuedToType: invoice.IssuedToType,
|
|
410
|
+
RelatedObjectId: invoice.RelatedObjectId,
|
|
411
|
+
RelatedObjectType: invoice.RelatedObjectType,
|
|
412
|
+
CreatedById: invoice.CreatedById,
|
|
413
|
+
CreatedAt: new Date(),
|
|
414
|
+
UpdatedById: invoice.UpdatedById,
|
|
415
|
+
UpdatedAt: new Date(),
|
|
416
|
+
DocPDFFileMediaId: invoice.UseAccSystemDocYN == 'N'
|
|
417
|
+
? invoiceMedia.PDFMedia.MediaId
|
|
418
|
+
: null,
|
|
419
|
+
DocHTMLFileMediaId: invoice.UseAccSystemDocYN == 'N'
|
|
420
|
+
? invoiceMedia.HTMLMedia.MediaId
|
|
421
|
+
: null,
|
|
422
|
+
AccSystemRefId: invoice.AccSystemRefId,
|
|
423
|
+
PostedToAccSystemYN: invoice.PostedToAccSystemYN,
|
|
424
|
+
PostedById: invoice.UseAccSystemDocYN == 'Y' ? invoice.PostedById : null,
|
|
425
|
+
PostedDateTime: new Date(),
|
|
426
|
+
UseAccSystemDocYN: invoice.UseAccSystemDocYN,
|
|
427
|
+
}, {
|
|
428
|
+
transaction: dbTransaction,
|
|
429
|
+
});
|
|
430
|
+
for (const documentItem of documentItems) {
|
|
431
|
+
await FinanceCompany._DocumentItemRepository.create({
|
|
432
|
+
DocumentItemId: this._createId().toUpperCase(),
|
|
433
|
+
DocNo: invoice.DocNo,
|
|
434
|
+
Name: documentItem.Name,
|
|
435
|
+
NameBM: documentItem.NameBM,
|
|
436
|
+
Description: documentItem.Description,
|
|
437
|
+
ItemId: documentItem.ItemId,
|
|
438
|
+
ItemType: documentItem.ItemType,
|
|
439
|
+
ItemSKU: documentItem.ItemSKU,
|
|
440
|
+
ItemSerialNo: documentItem.ItemSerialNo,
|
|
441
|
+
Currency: documentItem.Currency,
|
|
442
|
+
UnitPrice: documentItem.UnitPrice,
|
|
443
|
+
Quantity: documentItem.Quantity,
|
|
444
|
+
QuantityUOM: documentItem.QuantityUOM,
|
|
445
|
+
Amount: documentItem.Amount,
|
|
446
|
+
TaxCode: documentItem.TaxCode,
|
|
447
|
+
TaxAmount: documentItem.TaxAmount,
|
|
448
|
+
TaxRate: documentItem.TaxRate,
|
|
449
|
+
TaxInclusiveYN: documentItem.TaxInclusiveYN,
|
|
450
|
+
DtAccountNo: documentItem.DtAccountNo
|
|
451
|
+
? documentItem.DtAccountNo
|
|
452
|
+
: null,
|
|
453
|
+
CtAccountNo: documentItem.CtAccountNo
|
|
454
|
+
? documentItem.CtAccountNo
|
|
455
|
+
: null,
|
|
456
|
+
AccSystemRefId: documentItem.AccSystemRefId,
|
|
457
|
+
PostedToAccSystemYN: documentItem.PostedToAccSystemYN,
|
|
458
|
+
PostedById: documentItem.PostedById,
|
|
459
|
+
PostedDateTime: documentItem.PostedDateTime,
|
|
460
|
+
}, {
|
|
461
|
+
transaction: dbTransaction,
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
const transactionDate = new Date();
|
|
465
|
+
const htCreditAccountAmount = new general_1.HashTable();
|
|
466
|
+
const htCreditAccountCurrency = new general_1.HashTable();
|
|
467
|
+
const htCreditAccountPurpose = new general_1.HashTable();
|
|
468
|
+
documentItems.forEach((invoiceItem) => {
|
|
469
|
+
if (!htCreditAccountAmount.exists(invoiceItem.CtAccountNo)) {
|
|
470
|
+
htCreditAccountAmount.add(invoiceItem.CtAccountNo, invoiceItem.Amount);
|
|
471
|
+
htCreditAccountCurrency.add(invoiceItem.CtAccountNo, invoiceItem.Currency);
|
|
472
|
+
htCreditAccountPurpose.add(invoiceItem.CtAccountNo, invoiceItem.Name);
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
const d = htCreditAccountAmount.get(invoiceItem.CtAccountNo);
|
|
476
|
+
htCreditAccountAmount.add(invoiceItem.CtAccountNo, d + invoiceItem.Amount);
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
const savedItems = htCreditAccountAmount.list();
|
|
480
|
+
for (const item of savedItems) {
|
|
481
|
+
const journalEntry = new journal_entry_1.default(dbTransaction);
|
|
482
|
+
journalEntry.init({
|
|
483
|
+
CompanyId: this.CompanyId,
|
|
484
|
+
Name: 'Issue Invoice ' + invoice.DocNo,
|
|
485
|
+
});
|
|
486
|
+
const creditAmount = item.value[1];
|
|
487
|
+
const currency = htCreditAccountCurrency.get(item.value[0]);
|
|
488
|
+
const purpose = htCreditAccountPurpose.get(item.value[0]);
|
|
489
|
+
const dt = await journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
|
|
490
|
+
if (dtAccountNo) {
|
|
491
|
+
dt.AccountNo = dtAccountNo;
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
const arAccount = await customer.getAccountReceivable();
|
|
495
|
+
dt.AccountNo = arAccount.AccountNo;
|
|
496
|
+
}
|
|
497
|
+
dt.Currency = currency ? currency : 'MYR';
|
|
498
|
+
dt.DebitAmount = creditAmount ? creditAmount : 0.0;
|
|
499
|
+
dt.Date = transactionDate;
|
|
500
|
+
dt.Description = `${purpose}`;
|
|
501
|
+
dt.Name = `${purpose}`;
|
|
502
|
+
dt.RelatedDocNo = invoice.DocNo;
|
|
503
|
+
dt.RelatedObjectId = invoice.RelatedObjectId;
|
|
504
|
+
dt.RelatedObjectType = invoice.RelatedObjectType;
|
|
505
|
+
const ct = await journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
|
|
506
|
+
ct.AccountNo = item.value[0];
|
|
507
|
+
ct.Currency = currency ? currency : 'MYR';
|
|
508
|
+
ct.CreditAmount = creditAmount ? creditAmount : 0.0;
|
|
509
|
+
ct.Date = transactionDate;
|
|
510
|
+
ct.Description = customer.FullName;
|
|
511
|
+
ct.Name = customer.FullName;
|
|
512
|
+
ct.RelatedDocNo = invoice.DocNo;
|
|
513
|
+
ct.RelatedObjectId = invoice.RelatedObjectId;
|
|
514
|
+
ct.RelatedObjectType = invoice.RelatedObjectType;
|
|
515
|
+
await this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
516
|
+
}
|
|
517
|
+
return invoice;
|
|
518
|
+
}
|
|
519
|
+
catch (err) {
|
|
520
|
+
console.log('Issue invoice err: ', err);
|
|
521
|
+
throw err;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
static async findCustomer(custSystemRefId, dbTransaction) {
|
|
525
|
+
const data = await FinanceCompany._FinanceCustomerRepository.findOne({
|
|
526
|
+
where: {
|
|
527
|
+
CustSystemRefId: custSystemRefId,
|
|
528
|
+
},
|
|
529
|
+
transaction: dbTransaction,
|
|
530
|
+
});
|
|
531
|
+
return data;
|
|
532
|
+
}
|
|
533
|
+
async issueDebitNote(dbTransaction, loginUser, invoice, customer, dtAccountNo) {
|
|
534
|
+
try {
|
|
535
|
+
const duplicateInvoice = await FinanceCompany._DocumentRepository.findOne({
|
|
536
|
+
where: {
|
|
537
|
+
DocNo: invoice.DocNo,
|
|
538
|
+
},
|
|
539
|
+
transaction: dbTransaction,
|
|
540
|
+
});
|
|
541
|
+
if (duplicateInvoice) {
|
|
542
|
+
throw new Error('Invoice number already exists');
|
|
543
|
+
}
|
|
544
|
+
const documentItems = await invoice.getDocumentItems(dbTransaction);
|
|
545
|
+
if (!documentItems.length) {
|
|
546
|
+
throw new Error('Document must have at least 1 document item');
|
|
547
|
+
}
|
|
548
|
+
for (const invoiceItem of documentItems) {
|
|
549
|
+
if (!invoiceItem.CtAccountNo) {
|
|
550
|
+
throw new Error('Each document item should have CtAccountNo provided');
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
invoice.DocType = enum_1.DocType.DEBIT_NOTE;
|
|
554
|
+
if (invoice.UseAccSystemDocYN === 'Y') {
|
|
555
|
+
const accInvoiceRefIDetail = await this.AccountingSystem.createInvoice({
|
|
556
|
+
customer,
|
|
557
|
+
invoice,
|
|
558
|
+
paymentMode: 'credit',
|
|
559
|
+
}, dbTransaction);
|
|
560
|
+
invoice.AccSystemRefId = accInvoiceRefIDetail.invoiceRefId;
|
|
561
|
+
invoice.PostedToAccSystemYN = 'Y';
|
|
562
|
+
invoice.PostedById = loginUser.ObjectId;
|
|
563
|
+
invoice.PostedDateTime = new Date();
|
|
564
|
+
for (const documentItem of documentItems) {
|
|
565
|
+
const accItem = accInvoiceRefIDetail.invoiceItems.find((item) => item.name === documentItem.Name);
|
|
566
|
+
if (accItem) {
|
|
567
|
+
documentItem.AccSystemRefId = accItem.itemRefId;
|
|
568
|
+
documentItem.PostedToAccSystemYN = 'Y';
|
|
569
|
+
documentItem.PostedById = loginUser.ObjectId;
|
|
570
|
+
documentItem.PostedDateTime = new Date();
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
else {
|
|
575
|
+
invoice.generateInvoice(loginUser.IDNo, customer, dbTransaction);
|
|
576
|
+
}
|
|
577
|
+
await FinanceCompany._DocumentRepository.create({
|
|
578
|
+
DocNo: invoice.DocNo,
|
|
579
|
+
DocType: invoice.DocType,
|
|
580
|
+
DocDate: invoice.DocDate,
|
|
581
|
+
CompanyId: invoice.CompanyId,
|
|
582
|
+
Currency: invoice.Currency,
|
|
583
|
+
Amount: invoice.Amount,
|
|
584
|
+
Description: invoice.Description,
|
|
585
|
+
Status: invoice.Status,
|
|
586
|
+
IssuedById: loginUser.ObjectId,
|
|
587
|
+
IssuedToId: customer.ObjectId,
|
|
588
|
+
IssuedToType: invoice.IssuedToType,
|
|
589
|
+
RelatedObjectId: invoice.RelatedObjectId,
|
|
590
|
+
RelatedObjectType: invoice.RelatedObjectType,
|
|
591
|
+
CreatedById: loginUser.ObjectId,
|
|
592
|
+
CreatedAt: new Date(),
|
|
593
|
+
UpdatedById: loginUser.ObjectId,
|
|
594
|
+
UpdatedAt: new Date(),
|
|
595
|
+
DocPDFFileMediaId: invoice.DocPDFFileMediaId,
|
|
596
|
+
DocHTMLFileMediaId: invoice.DocHTMLFileMediaId,
|
|
597
|
+
AccSystemRefId: invoice.AccSystemRefId,
|
|
598
|
+
PostedToAccSystemYN: invoice.PostedToAccSystemYN,
|
|
599
|
+
PostedById: invoice.PostedToAccSystemYN == 'Y' ? invoice.PostedById : null,
|
|
600
|
+
PostedDateTime: new Date(),
|
|
601
|
+
UseAccSystemDocYN: invoice.UseAccSystemDocYN,
|
|
602
|
+
}, {
|
|
603
|
+
transaction: dbTransaction,
|
|
604
|
+
});
|
|
605
|
+
documentItems.forEach(async (documentItem) => {
|
|
606
|
+
await FinanceCompany._DocumentItemRepository.create({
|
|
607
|
+
DocumentItemId: this._createId().toUpperCase(),
|
|
608
|
+
DocNo: documentItem.DocNo,
|
|
609
|
+
Name: documentItem.Name,
|
|
610
|
+
NameBM: documentItem.NameBM,
|
|
611
|
+
Description: documentItem.Description,
|
|
612
|
+
ItemId: documentItem.ItemId,
|
|
613
|
+
ItemType: documentItem.ItemType,
|
|
614
|
+
ItemSKU: documentItem.ItemSKU,
|
|
615
|
+
ItemSerialNo: documentItem.ItemSerialNo,
|
|
616
|
+
Currency: documentItem.Currency,
|
|
617
|
+
UnitPrice: documentItem.UnitPrice,
|
|
618
|
+
Quantity: documentItem.Quantity,
|
|
619
|
+
QuantityUOM: documentItem.QuantityUOM,
|
|
620
|
+
Amount: documentItem.Amount,
|
|
621
|
+
TaxCode: documentItem.TaxCode,
|
|
622
|
+
TaxAmount: documentItem.TaxAmount,
|
|
623
|
+
TaxRate: documentItem.TaxRate,
|
|
624
|
+
TaxInclusiveYN: documentItem.TaxInclusiveYN,
|
|
625
|
+
DtAccountNo: documentItem.DtAccountNo,
|
|
626
|
+
CtAccountNo: documentItem.CtAccountNo,
|
|
627
|
+
AccSystemRefId: documentItem.AccSystemRefId,
|
|
628
|
+
PostedToAccSystemYN: documentItem.PostedToAccSystemYN,
|
|
629
|
+
PostedById: documentItem.PostedById,
|
|
630
|
+
PostedDateTime: documentItem.PostedDateTime,
|
|
631
|
+
}, {
|
|
632
|
+
transaction: dbTransaction,
|
|
633
|
+
});
|
|
634
|
+
});
|
|
635
|
+
const transactionDate = new Date();
|
|
636
|
+
const htCreditAccountAmount = new general_1.HashTable();
|
|
637
|
+
const htCreditAccountCurrency = new general_1.HashTable();
|
|
638
|
+
const htCreditAccountPurpose = new general_1.HashTable();
|
|
639
|
+
documentItems.forEach((invoiceItem) => {
|
|
640
|
+
if (!htCreditAccountAmount.exists(invoiceItem.CtAccountNo)) {
|
|
641
|
+
htCreditAccountAmount.add(invoiceItem.CtAccountNo, invoiceItem.Amount);
|
|
642
|
+
htCreditAccountCurrency.add(invoiceItem.CtAccountNo, invoiceItem.Currency);
|
|
643
|
+
htCreditAccountPurpose.add(invoiceItem.CtAccountNo, invoiceItem.Name);
|
|
644
|
+
}
|
|
645
|
+
else {
|
|
646
|
+
const d = htCreditAccountAmount.get(invoiceItem.CtAccountNo);
|
|
647
|
+
htCreditAccountAmount.add(invoiceItem.CtAccountNo, d + invoiceItem.Amount);
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
const savedItems = htCreditAccountAmount.list();
|
|
651
|
+
for (const item of savedItems) {
|
|
652
|
+
const journalEntry = new journal_entry_1.default(dbTransaction);
|
|
653
|
+
journalEntry.init({
|
|
654
|
+
CompanyId: this.CompanyId,
|
|
655
|
+
Name: 'issue Invoice ' + invoice.DocNo,
|
|
656
|
+
});
|
|
657
|
+
const creditAmount = item.value[1];
|
|
658
|
+
const currency = htCreditAccountCurrency.get(item.value[0]);
|
|
659
|
+
const purpose = htCreditAccountPurpose.get(item.value[0]);
|
|
660
|
+
const dt = await journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
|
|
661
|
+
if (dtAccountNo) {
|
|
662
|
+
dt.AccountNo = dtAccountNo;
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
const arAccount = await customer.getAccountReceivable();
|
|
666
|
+
dt.AccountNo = arAccount.AccountNo;
|
|
667
|
+
}
|
|
668
|
+
dt.Currency = currency ? currency : 'MYR';
|
|
669
|
+
dt.DebitAmount = creditAmount ? creditAmount : 0.0;
|
|
670
|
+
dt.Date = transactionDate;
|
|
671
|
+
dt.Description = `${purpose}`;
|
|
672
|
+
dt.Name = `${purpose}`;
|
|
673
|
+
dt.RelatedDocNo = invoice.DocNo;
|
|
674
|
+
dt.RelatedObjectId = invoice.RelatedObjectId;
|
|
675
|
+
dt.RelatedObjectType = invoice.RelatedObjectType;
|
|
676
|
+
const ct = await journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
|
|
677
|
+
ct.AccountNo = item.value[0];
|
|
678
|
+
ct.Currency = currency ? currency : 'MYR';
|
|
679
|
+
ct.CreditAmount = creditAmount ? creditAmount : 0.0;
|
|
680
|
+
ct.Date = transactionDate;
|
|
681
|
+
ct.Description = customer.FullName;
|
|
682
|
+
ct.Name = customer.FullName;
|
|
683
|
+
ct.RelatedDocNo = invoice.DocNo;
|
|
684
|
+
ct.RelatedObjectId = invoice.RelatedObjectId;
|
|
685
|
+
ct.RelatedObjectType = invoice.RelatedObjectType;
|
|
686
|
+
await this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
687
|
+
}
|
|
688
|
+
return invoice;
|
|
689
|
+
}
|
|
690
|
+
catch (err) {
|
|
691
|
+
console.log('Issue debit note err: ', err);
|
|
692
|
+
throw err;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
async issueCreditNote(dbTransaction, loginUser, creditNote, customer, ctAccountNo) {
|
|
696
|
+
try {
|
|
697
|
+
const duplicateCreditNote = await FinanceCompany._DocumentRepository.findOne({
|
|
698
|
+
where: {
|
|
699
|
+
DocNo: creditNote.DocNo,
|
|
700
|
+
},
|
|
701
|
+
transaction: dbTransaction,
|
|
702
|
+
});
|
|
703
|
+
if (duplicateCreditNote) {
|
|
704
|
+
throw new Error('Invoice number already exists');
|
|
705
|
+
}
|
|
706
|
+
const documentItems = await creditNote.getDocumentItems(dbTransaction);
|
|
707
|
+
if (!documentItems.length) {
|
|
708
|
+
throw new Error('Document must have at least 1 document item');
|
|
709
|
+
}
|
|
710
|
+
for (const invoiceItem of documentItems) {
|
|
711
|
+
if (!invoiceItem.DtAccountNo) {
|
|
712
|
+
throw new Error('Each document item should have DtAccountNo provided');
|
|
713
|
+
}
|
|
714
|
+
const actualDocument = await document_1.default.initDocument(dbTransaction, invoiceItem.ItemId);
|
|
715
|
+
if (actualDocument.IssuedToId !== creditNote.IssuedToId) {
|
|
716
|
+
throw new general_1.ClassError('FinanceCompany', 'FinanceCompanyErrMsgOX', 'To issue credit note, all invoices must belong to same customer.');
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
creditNote.DocType = enum_1.DocType.CREDIT_NOTE;
|
|
720
|
+
creditNote.Status = enum_1.DocumentStatus.SETTLED;
|
|
721
|
+
await FinanceCompany._DocumentRepository.create({
|
|
722
|
+
DocNo: creditNote.DocNo,
|
|
723
|
+
DocType: creditNote.DocType,
|
|
724
|
+
DocDate: creditNote.DocDate,
|
|
725
|
+
CompanyId: creditNote.CompanyId,
|
|
726
|
+
Currency: creditNote.Currency,
|
|
727
|
+
Amount: creditNote.Amount,
|
|
728
|
+
Description: creditNote.Description,
|
|
729
|
+
Status: creditNote.Status,
|
|
730
|
+
IssuedById: loginUser.ObjectId,
|
|
731
|
+
IssuedToId: customer.ObjectId,
|
|
732
|
+
IssuedToType: creditNote.IssuedToType,
|
|
733
|
+
RelatedObjectId: creditNote.RelatedObjectId,
|
|
734
|
+
RelatedObjectType: creditNote.RelatedObjectType,
|
|
735
|
+
CreatedById: loginUser.ObjectId,
|
|
736
|
+
CreatedAt: new Date(),
|
|
737
|
+
UpdatedById: loginUser.ObjectId,
|
|
738
|
+
UpdatedAt: new Date(),
|
|
739
|
+
DocPDFFileMediaId: creditNote.DocPDFFileMediaId,
|
|
740
|
+
DocHTMLFileMediaId: creditNote.DocHTMLFileMediaId,
|
|
741
|
+
AccSystemRefId: creditNote.AccSystemRefId,
|
|
742
|
+
PostedToAccSystemYN: creditNote.PostedToAccSystemYN,
|
|
743
|
+
PostedById: creditNote.PostedToAccSystemYN == 'Y'
|
|
744
|
+
? creditNote.PostedById
|
|
745
|
+
: null,
|
|
746
|
+
PostedDateTime: new Date(),
|
|
747
|
+
UseAccSystemDocYN: creditNote.UseAccSystemDocYN,
|
|
748
|
+
}, {
|
|
749
|
+
transaction: dbTransaction,
|
|
750
|
+
});
|
|
751
|
+
for (const docItem of documentItems) {
|
|
752
|
+
await FinanceCompany._DocumentItemRepository.create({
|
|
753
|
+
DocumentItemId: this._createId().toUpperCase(),
|
|
754
|
+
DocNo: docItem.DocNo,
|
|
755
|
+
Name: docItem.Name,
|
|
756
|
+
NameBM: docItem.NameBM,
|
|
757
|
+
Description: docItem.Description,
|
|
758
|
+
ItemId: docItem.ItemId,
|
|
759
|
+
ItemType: docItem.ItemType,
|
|
760
|
+
ItemSKU: docItem.ItemSKU,
|
|
761
|
+
ItemSerialNo: docItem.ItemSerialNo,
|
|
762
|
+
Currency: docItem.Currency,
|
|
763
|
+
UnitPrice: docItem.UnitPrice,
|
|
764
|
+
Quantity: docItem.Quantity,
|
|
765
|
+
QuantityUOM: docItem.QuantityUOM,
|
|
766
|
+
Amount: docItem.Amount,
|
|
767
|
+
TaxCode: docItem.TaxCode,
|
|
768
|
+
TaxAmount: docItem.TaxAmount,
|
|
769
|
+
TaxRate: docItem.TaxRate,
|
|
770
|
+
TaxInclusiveYN: docItem.TaxInclusiveYN,
|
|
771
|
+
DtAccountNo: docItem.DtAccountNo ? docItem.DtAccountNo : null,
|
|
772
|
+
CtAccountNo: docItem.CtAccountNo ? docItem.CtAccountNo : null,
|
|
773
|
+
}, {
|
|
774
|
+
transaction: dbTransaction,
|
|
775
|
+
});
|
|
776
|
+
await document_1.default.settleByCreditNote(loginUser, dbTransaction, docItem.ItemId, docItem.Amount);
|
|
777
|
+
}
|
|
778
|
+
if (creditNote.UseAccSystemDocYN === 'Y') {
|
|
779
|
+
}
|
|
780
|
+
else {
|
|
781
|
+
creditNote.generateCreditNote(loginUser.IDNo, customer);
|
|
782
|
+
}
|
|
783
|
+
const journalEntry = new journal_entry_1.default(dbTransaction);
|
|
784
|
+
journalEntry.init({
|
|
785
|
+
CompanyId: this.CompanyId,
|
|
786
|
+
Name: 'Issue Credit Note ' + creditNote.DocNo,
|
|
787
|
+
});
|
|
788
|
+
const transactionDate = new Date();
|
|
789
|
+
const creditTransaction = await journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
|
|
790
|
+
if (ctAccountNo) {
|
|
791
|
+
creditTransaction.AccountNo = ctAccountNo;
|
|
792
|
+
}
|
|
793
|
+
else {
|
|
794
|
+
const arAccount = await customer.getAccountPayable();
|
|
795
|
+
creditTransaction.AccountNo = arAccount.AccountNo;
|
|
796
|
+
}
|
|
797
|
+
creditTransaction.Currency = creditNote.Currency;
|
|
798
|
+
creditTransaction.CreditAmount = creditNote.Amount;
|
|
799
|
+
creditTransaction.Date = transactionDate;
|
|
800
|
+
creditTransaction.Description = creditNote.DocNo;
|
|
801
|
+
creditTransaction.Name = creditNote.DocNo;
|
|
802
|
+
creditTransaction.RelatedDocNo = creditNote.DocNo;
|
|
803
|
+
creditTransaction.RelatedObjectId = creditNote.RelatedObjectId;
|
|
804
|
+
creditTransaction.RelatedObjectType = creditNote.RelatedObjectType;
|
|
805
|
+
for (const invoiceItem of documentItems) {
|
|
806
|
+
const itemLedger = await journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
|
|
807
|
+
itemLedger.AccountNo = invoiceItem.DtAccountNo;
|
|
808
|
+
itemLedger.Currency = invoiceItem.Currency;
|
|
809
|
+
itemLedger.DebitAmount = invoiceItem.Amount;
|
|
810
|
+
itemLedger.Date = transactionDate;
|
|
811
|
+
itemLedger.Description = invoiceItem.Name;
|
|
812
|
+
itemLedger.RelatedDocNo = creditNote.DocNo;
|
|
813
|
+
itemLedger.RelatedObjectId = creditNote.RelatedObjectId;
|
|
814
|
+
itemLedger.RelatedObjectType = creditNote.RelatedObjectType;
|
|
815
|
+
}
|
|
816
|
+
await this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
817
|
+
const entityValueAfter = {
|
|
818
|
+
LedgerNo: creditTransaction.LedgerNo,
|
|
819
|
+
TransactionType: creditTransaction.TransactionType,
|
|
820
|
+
JournalEntryId: creditTransaction.JournalEntryId,
|
|
821
|
+
AccountNo: creditTransaction.AccountNo,
|
|
822
|
+
Date: creditTransaction.Date,
|
|
823
|
+
Name: creditTransaction.Name,
|
|
824
|
+
Description: creditTransaction.Description,
|
|
825
|
+
Currency: creditTransaction.Currency,
|
|
826
|
+
DebitAmount: creditTransaction.DebitAmount,
|
|
827
|
+
CreditAmount: creditTransaction.CreditAmount,
|
|
828
|
+
RelatedObjectId: creditTransaction.RelatedObjectId,
|
|
829
|
+
RelatedObjectType: creditTransaction.RelatedObjectType,
|
|
830
|
+
RelatedDocNo: creditTransaction.RelatedDocNo,
|
|
831
|
+
RelatedPaymentId: creditTransaction.RelatedPaymentId,
|
|
832
|
+
};
|
|
833
|
+
const payload = {
|
|
834
|
+
Action: 'Create',
|
|
835
|
+
Activity: 'Issuing a Credit Note Transaction',
|
|
836
|
+
Description: `Credit Transaction (ID: ${creditTransaction.LedgerNo}) has been created`,
|
|
837
|
+
EntityType: 'CreditTransaction',
|
|
838
|
+
EntityValueBefore: JSON.stringify({}),
|
|
839
|
+
EntityValueAfter: JSON.stringify(entityValueAfter),
|
|
840
|
+
PerformedById: loginUser.ObjectId,
|
|
841
|
+
PerformedAt: transactionDate,
|
|
842
|
+
EntityId: creditTransaction.LedgerNo,
|
|
843
|
+
};
|
|
844
|
+
await axios_1.default.post(`${process.env.COMMON_API_URL}/activity-histories`, payload);
|
|
845
|
+
return creditNote;
|
|
846
|
+
}
|
|
847
|
+
catch (err) {
|
|
848
|
+
console.log('Issue credit note err: ', err);
|
|
849
|
+
throw err;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
async collectPayment(dbTransaction, loginUser, payment, collectPaymentType = collect_payment_type_1.CollectPaymentType.AUTOMATIC) {
|
|
853
|
+
try {
|
|
854
|
+
const paymentItems = await payment.getPaymentItems();
|
|
855
|
+
if (paymentItems.length < 1) {
|
|
856
|
+
throw new Error('Atleast one payment item is required to identify what payment is being paid for.');
|
|
857
|
+
}
|
|
858
|
+
const paymentPaidWithItems = await payment.getPaymentPaidWith();
|
|
859
|
+
if (paymentPaidWithItems.length < 1) {
|
|
860
|
+
throw new Error('Atleast one payment paid with item is required to identify how the payment was made.');
|
|
861
|
+
}
|
|
862
|
+
payment.PaymentId = this._createId().toUpperCase();
|
|
863
|
+
payment.PaymentType = enum_1.PaymentType.PAYMENT_RECEIVED;
|
|
864
|
+
payment.ReceivedBy = loginUser.ObjectId;
|
|
865
|
+
payment.IssuedBy = loginUser.ObjectId;
|
|
866
|
+
await FinanceCompany._PaymentRepository.create({
|
|
867
|
+
PaymentId: payment.PaymentId,
|
|
868
|
+
PaymentType: payment.PaymentType,
|
|
869
|
+
PaymentDate: payment.PaymentDate,
|
|
870
|
+
Description: payment.Description,
|
|
871
|
+
Currency: payment.Currency,
|
|
872
|
+
Amount: payment.Amount,
|
|
873
|
+
Status: collectPaymentType === collect_payment_type_1.CollectPaymentType.AUTOMATIC
|
|
874
|
+
? enum_1.PaymentStatus.CONFIRMED
|
|
875
|
+
: enum_1.PaymentStatus.PENDING,
|
|
876
|
+
PostedToAccSystemYN: 'N',
|
|
877
|
+
ReceivedBy: payment.ReceivedBy,
|
|
878
|
+
IssuedBy: payment.IssuedBy,
|
|
879
|
+
Remarks: payment.Remarks,
|
|
880
|
+
RelatedObjectId: payment.RelatedObjectId,
|
|
881
|
+
RelatedObjectType: payment.RelatedObjectType,
|
|
882
|
+
ReceiptDocNo: payment.ReceiptDocNo,
|
|
883
|
+
UpdatedAt: new Date(),
|
|
884
|
+
UpdatedBy: loginUser.ObjectId,
|
|
885
|
+
CreatedAt: new Date(),
|
|
886
|
+
CreatedBy: loginUser.ObjectId,
|
|
887
|
+
}, { transaction: dbTransaction });
|
|
888
|
+
for (const paymentItem of paymentItems) {
|
|
889
|
+
await FinanceCompany._PaymentItemRepository.create({
|
|
890
|
+
PaymentId: payment.PaymentId,
|
|
891
|
+
PayForObjectId: paymentItem.PayForObjectId,
|
|
892
|
+
PayForObjectType: paymentItem.PayForObjectType,
|
|
893
|
+
Currency: paymentItem.Currency,
|
|
894
|
+
Amount: paymentItem.Amount,
|
|
895
|
+
Name: paymentItem.Name,
|
|
896
|
+
Description: paymentItem.Description,
|
|
897
|
+
}, { transaction: dbTransaction });
|
|
898
|
+
}
|
|
899
|
+
for (const paymentPaidWithItem of paymentPaidWithItems) {
|
|
900
|
+
await payment_method_type_1.default.initMethodType(dbTransaction, paymentPaidWithItem.MethodTypeId);
|
|
901
|
+
await FinanceCompany._PaymentPaidWithRepository.create({
|
|
902
|
+
PaymentId: payment.PaymentId,
|
|
903
|
+
MethodTypeId: paymentPaidWithItem.MethodTypeId,
|
|
904
|
+
Currency: paymentPaidWithItem.Currency,
|
|
905
|
+
Amount: paymentPaidWithItem.Amount,
|
|
906
|
+
Status: paymentPaidWithItem.Status,
|
|
907
|
+
TransactionId: paymentPaidWithItem.TransactionId,
|
|
908
|
+
RefBank: paymentPaidWithItem.RefBank,
|
|
909
|
+
RefName: paymentPaidWithItem.RefName,
|
|
910
|
+
RefNo: paymentPaidWithItem.RefNo,
|
|
911
|
+
RefOther1: paymentPaidWithItem.RefOther1,
|
|
912
|
+
RefOther2: paymentPaidWithItem.RefOther2,
|
|
913
|
+
RefOther3: paymentPaidWithItem.RefOther3,
|
|
914
|
+
RefOther4: paymentPaidWithItem.RefOther4,
|
|
915
|
+
RefOther5: paymentPaidWithItem.RefOther5,
|
|
916
|
+
Remarks: paymentPaidWithItem.Remarks,
|
|
917
|
+
PaymentMediaId: paymentPaidWithItem.PaymentMediaId,
|
|
918
|
+
}, { transaction: dbTransaction });
|
|
919
|
+
}
|
|
920
|
+
return payment;
|
|
921
|
+
}
|
|
922
|
+
catch (error) {
|
|
923
|
+
throw error;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
async makePayment(dbTransaction, loginUser, payment, customer, dtAccountNo) {
|
|
927
|
+
let paymentMethodType;
|
|
928
|
+
try {
|
|
929
|
+
const paymentPaidWith = await payment.getPaymentPaidWith();
|
|
930
|
+
if (paymentPaidWith.length < 1) {
|
|
931
|
+
throw new Error('Atleast one payment paid with item is required to identify how the payment was made.');
|
|
932
|
+
}
|
|
933
|
+
paymentMethodType = await payment_method_type_1.default.initMethodType(dbTransaction, paymentPaidWith[0].MethodTypeId);
|
|
934
|
+
const paymentItems = await payment.getPaymentItems();
|
|
935
|
+
if (paymentItems.length < 1) {
|
|
936
|
+
throw new Error('Atleast one payment item is required to identify what payment is being paid for');
|
|
937
|
+
}
|
|
938
|
+
payment.PaymentId = this._createId().toUpperCase();
|
|
939
|
+
payment.PaymentType = enum_1.PaymentType.PAYOUT;
|
|
940
|
+
payment.ReceivedBy = loginUser.ObjectId;
|
|
941
|
+
payment.IssuedBy = loginUser.ObjectId;
|
|
942
|
+
await FinanceCompany._PaymentRepository.create({
|
|
943
|
+
PaymentId: payment.PaymentId,
|
|
944
|
+
PaymentType: payment.PaymentType,
|
|
945
|
+
PaymentDate: payment.PaymentDate,
|
|
946
|
+
Description: payment.Description,
|
|
947
|
+
Currency: payment.Currency,
|
|
948
|
+
ReceivedBy: payment.ReceivedBy,
|
|
949
|
+
IssuedBy: payment.IssuedBy,
|
|
950
|
+
Remarks: payment.Remarks,
|
|
951
|
+
RelatedObjectId: payment.RelatedObjectId,
|
|
952
|
+
RelatedObjectType: payment.RelatedObjectType,
|
|
953
|
+
Amount: payment.Amount,
|
|
954
|
+
Status: enum_1.PaymentStatus.CONFIRMED,
|
|
955
|
+
PostedToAccSystemYN: 'N',
|
|
956
|
+
UpdatedAt: new Date(),
|
|
957
|
+
UpdatedBy: loginUser.ObjectId,
|
|
958
|
+
CreatedAt: new Date(),
|
|
959
|
+
CreatedBy: loginUser.ObjectId,
|
|
960
|
+
}, { transaction: dbTransaction });
|
|
961
|
+
paymentItems.forEach(async (paymentItem) => {
|
|
962
|
+
await FinanceCompany._PaymentItemRepository.create({
|
|
963
|
+
PaymentId: payment.PaymentId,
|
|
964
|
+
PayForObjectId: paymentItem.PayForObjectId,
|
|
965
|
+
PayForObjectType: paymentItem.PayForObjectType,
|
|
966
|
+
Currency: paymentItem.Currency,
|
|
967
|
+
Amount: paymentItem.Amount,
|
|
968
|
+
Name: paymentItem.Name,
|
|
969
|
+
Description: paymentItem.Description,
|
|
970
|
+
}, { transaction: dbTransaction });
|
|
971
|
+
await paymentItem.paid(dbTransaction);
|
|
972
|
+
});
|
|
973
|
+
for (const paymentPaidWithItem of paymentPaidWith) {
|
|
974
|
+
await FinanceCompany._PaymentPaidWithRepository.create({
|
|
975
|
+
PaymentId: payment.PaymentId,
|
|
976
|
+
MethodTypeId: paymentPaidWithItem.MethodTypeId,
|
|
977
|
+
Currency: paymentPaidWithItem.Currency,
|
|
978
|
+
Amount: paymentPaidWithItem.Amount,
|
|
979
|
+
Status: paymentPaidWithItem.Status,
|
|
980
|
+
TransactionId: paymentPaidWithItem.TransactionId,
|
|
981
|
+
RefBank: paymentPaidWithItem.RefBank,
|
|
982
|
+
RefName: paymentPaidWithItem.RefName,
|
|
983
|
+
RefNo: paymentPaidWithItem.RefNo,
|
|
984
|
+
RefOther1: paymentPaidWithItem.RefOther1,
|
|
985
|
+
RefOther2: paymentPaidWithItem.RefOther2,
|
|
986
|
+
RefOther3: paymentPaidWithItem.RefOther3,
|
|
987
|
+
RefOther4: paymentPaidWithItem.RefOther4,
|
|
988
|
+
RefOther5: paymentPaidWithItem.RefOther5,
|
|
989
|
+
Remarks: paymentPaidWithItem.Remarks,
|
|
990
|
+
PaymentMediaId: paymentPaidWithItem.PaymentMediaId,
|
|
991
|
+
}, { transaction: dbTransaction });
|
|
992
|
+
}
|
|
993
|
+
const transactionDate = new Date();
|
|
994
|
+
for (const paymentPaidWithItem of paymentPaidWith) {
|
|
995
|
+
try {
|
|
996
|
+
paymentMethodType = await payment_method_type_1.default.initMethodType(dbTransaction, paymentPaidWithItem.MethodTypeId);
|
|
997
|
+
const journalEntry = new journal_entry_1.default(dbTransaction);
|
|
998
|
+
journalEntry.init({
|
|
999
|
+
CompanyId: this.CompanyId,
|
|
1000
|
+
Name: 'Make Payment for ' + payment.PaymentId,
|
|
1001
|
+
});
|
|
1002
|
+
const creditLT = await journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
|
|
1003
|
+
creditLT.AccountNo = paymentMethodType.AccountNo;
|
|
1004
|
+
creditLT.Currency = paymentPaidWithItem.Currency;
|
|
1005
|
+
creditLT.CreditAmount = paymentPaidWithItem.Amount;
|
|
1006
|
+
creditLT.Date = transactionDate;
|
|
1007
|
+
creditLT.Description = customer.FullName;
|
|
1008
|
+
creditLT.Name = customer.FullName;
|
|
1009
|
+
creditLT.RelatedObjectId = payment.RelatedObjectId;
|
|
1010
|
+
creditLT.RelatedObjectType = payment.RelatedObjectType;
|
|
1011
|
+
const debitLT = await journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
|
|
1012
|
+
if (dtAccountNo) {
|
|
1013
|
+
debitLT.AccountNo = dtAccountNo;
|
|
1014
|
+
}
|
|
1015
|
+
else {
|
|
1016
|
+
const apAccount = await customer.getAccountPayable();
|
|
1017
|
+
debitLT.AccountNo = apAccount.AccountNo;
|
|
1018
|
+
}
|
|
1019
|
+
debitLT.Currency = paymentPaidWithItem.Currency;
|
|
1020
|
+
debitLT.DebitAmount = paymentPaidWithItem.Amount;
|
|
1021
|
+
debitLT.Date = transactionDate;
|
|
1022
|
+
debitLT.Description = paymentMethodType.Name;
|
|
1023
|
+
debitLT.Name = paymentMethodType.Name;
|
|
1024
|
+
debitLT.RelatedObjectId = payment.RelatedObjectId;
|
|
1025
|
+
debitLT.RelatedObjectType = payment.RelatedObjectType;
|
|
1026
|
+
await this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
1027
|
+
}
|
|
1028
|
+
catch (error) {
|
|
1029
|
+
if (error instanceof general_1.RecordNotFoundError) {
|
|
1030
|
+
throw new Error('Invalid Payment Method Type Id');
|
|
1031
|
+
}
|
|
1032
|
+
else {
|
|
1033
|
+
throw error;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
return payment;
|
|
1038
|
+
}
|
|
1039
|
+
catch (error) {
|
|
1040
|
+
if (error instanceof general_1.RecordNotFoundError) {
|
|
1041
|
+
throw new Error('Invalid PaymentMethodType id');
|
|
1042
|
+
}
|
|
1043
|
+
else {
|
|
1044
|
+
throw error;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
get PaymentMethods() {
|
|
1049
|
+
return new Promise((resolve, reject) => {
|
|
1050
|
+
if (this.CompanyId !== 'New') {
|
|
1051
|
+
FinanceCompany._PaymentMethodRepository
|
|
1052
|
+
.findAll({
|
|
1053
|
+
where: {
|
|
1054
|
+
CompanyId: this.CompanyId,
|
|
1055
|
+
},
|
|
1056
|
+
})
|
|
1057
|
+
.then((paymentMethod) => {
|
|
1058
|
+
const paymentMethodObjects = paymentMethod.map((paymentMethodData) => {
|
|
1059
|
+
return new Promise((resolve, reject) => {
|
|
1060
|
+
FinanceCompany._PaymentMethodTypeRepository
|
|
1061
|
+
.findAll({
|
|
1062
|
+
where: {
|
|
1063
|
+
MethodId: paymentMethodData.MethodId,
|
|
1064
|
+
},
|
|
1065
|
+
raw: true,
|
|
1066
|
+
})
|
|
1067
|
+
.then((paymentMethodTypes) => {
|
|
1068
|
+
const paymentMethodObjects = Object.assign(Object.assign({}, paymentMethodData.get({ plain: true })), { Types: paymentMethodTypes });
|
|
1069
|
+
resolve(paymentMethodObjects);
|
|
1070
|
+
})
|
|
1071
|
+
.catch((err) => {
|
|
1072
|
+
reject(err);
|
|
1073
|
+
});
|
|
1074
|
+
}).then((paymentMethods) => paymentMethods);
|
|
1075
|
+
});
|
|
1076
|
+
return Promise.all(paymentMethodObjects);
|
|
1077
|
+
})
|
|
1078
|
+
.then((paymentMethodObjects) => {
|
|
1079
|
+
this._PaymentMethods = paymentMethodObjects;
|
|
1080
|
+
resolve(this._PaymentMethods);
|
|
1081
|
+
})
|
|
1082
|
+
.catch((err) => {
|
|
1083
|
+
reject(err);
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
else {
|
|
1087
|
+
resolve(this._PaymentMethods);
|
|
1088
|
+
}
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
get TaxCodes() {
|
|
1092
|
+
return new Promise((resolve, reject) => {
|
|
1093
|
+
if (this.CompanyId !== 'New') {
|
|
1094
|
+
FinanceCompany._TaxRepository
|
|
1095
|
+
.findAll({
|
|
1096
|
+
where: {
|
|
1097
|
+
CompanyId: this.CompanyId,
|
|
1098
|
+
},
|
|
1099
|
+
transaction: this._DbTransaction,
|
|
1100
|
+
})
|
|
1101
|
+
.then((taxes) => {
|
|
1102
|
+
const taxList = [];
|
|
1103
|
+
taxes.forEach((tax) => {
|
|
1104
|
+
taxList.push(new tax_1.Tax({
|
|
1105
|
+
TaxCode: tax.TaxCode,
|
|
1106
|
+
TaxRate: typeof tax.TaxRate === 'number'
|
|
1107
|
+
? tax.TaxRate
|
|
1108
|
+
: parseFloat(tax.TaxRate),
|
|
1109
|
+
Description: tax.Description,
|
|
1110
|
+
CompanyId: tax.CompanyId,
|
|
1111
|
+
CreatedAt: tax.CreatedAt,
|
|
1112
|
+
CreatedById: tax.CreatedById,
|
|
1113
|
+
UpdatedAt: tax.UpdatedAt,
|
|
1114
|
+
UpdatedById: tax.UpdatedById,
|
|
1115
|
+
}));
|
|
1116
|
+
});
|
|
1117
|
+
this._Taxes = taxList;
|
|
1118
|
+
resolve(this._Taxes);
|
|
1119
|
+
})
|
|
1120
|
+
.catch((err) => {
|
|
1121
|
+
reject(err);
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
else {
|
|
1125
|
+
resolve(this._Taxes);
|
|
1126
|
+
}
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
async LoadPaymentMethods(companyId, paymentMethods, transaction) {
|
|
1130
|
+
const paymentMethod = new payment_method_1.default();
|
|
1131
|
+
for (const method in paymentMethods) {
|
|
1132
|
+
const paymentMethodData = await FinanceCompany._PaymentMethodRepository.findOne({
|
|
1133
|
+
where: {
|
|
1134
|
+
MethodId: paymentMethods[method].id,
|
|
1135
|
+
Name: paymentMethods[method].name,
|
|
1136
|
+
},
|
|
1137
|
+
transaction: transaction,
|
|
1138
|
+
});
|
|
1139
|
+
if (!paymentMethodData) {
|
|
1140
|
+
const newPaymentMethod = await FinanceCompany._PaymentMethodRepository.create({
|
|
1141
|
+
MethodId: paymentMethods[method].id,
|
|
1142
|
+
Name: paymentMethods[method].name,
|
|
1143
|
+
CompanyId: companyId,
|
|
1144
|
+
}, {
|
|
1145
|
+
transaction: transaction,
|
|
1146
|
+
});
|
|
1147
|
+
this._PaymentMethods.push(newPaymentMethod);
|
|
1148
|
+
}
|
|
1149
|
+
this._PaymentMethods.push(paymentMethodData);
|
|
1150
|
+
}
|
|
1151
|
+
this._PaymentMethods.forEach(async (item) => {
|
|
1152
|
+
var _a, _b;
|
|
1153
|
+
const p = item === null || item === void 0 ? void 0 : item.get({ plain: true });
|
|
1154
|
+
for (const method in paymentMethods) {
|
|
1155
|
+
if (!p) {
|
|
1156
|
+
continue;
|
|
1157
|
+
}
|
|
1158
|
+
if (p.MethodId === ((_a = paymentMethods[method]) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
1159
|
+
const paymentMethodTypeData = await FinanceCompany._PaymentMethodTypeRepository.findOne({
|
|
1160
|
+
where: {
|
|
1161
|
+
MethodId: p.MethodId,
|
|
1162
|
+
},
|
|
1163
|
+
transaction: transaction,
|
|
1164
|
+
});
|
|
1165
|
+
if (!paymentMethodTypeData) {
|
|
1166
|
+
const configPaymentMethodTypes = (_b = paymentMethods[method]) === null || _b === void 0 ? void 0 : _b.types;
|
|
1167
|
+
for (const methodType in configPaymentMethodTypes) {
|
|
1168
|
+
const accountData = await FinanceCompany._AccountRepository.findOne({
|
|
1169
|
+
where: {
|
|
1170
|
+
AccountNo: configPaymentMethodTypes[methodType].accountNo,
|
|
1171
|
+
},
|
|
1172
|
+
transaction: transaction,
|
|
1173
|
+
});
|
|
1174
|
+
if (!accountData) {
|
|
1175
|
+
const accountPayload = {
|
|
1176
|
+
CompanyId: companyId,
|
|
1177
|
+
Name: configPaymentMethodTypes[methodType].name,
|
|
1178
|
+
AccountType: 'PaymentMethod',
|
|
1179
|
+
CreatedAt: new Date(),
|
|
1180
|
+
CreatedById: 'System',
|
|
1181
|
+
AccSystemRefId: 'REF',
|
|
1182
|
+
PostedToAccSystemYN: 'N',
|
|
1183
|
+
};
|
|
1184
|
+
try {
|
|
1185
|
+
await FinanceCompany._AccountRepository.create(Object.assign({ AccountNo: configPaymentMethodTypes[methodType].accountNo }, accountPayload), {
|
|
1186
|
+
transaction: transaction,
|
|
1187
|
+
});
|
|
1188
|
+
await FinanceCompany._AccountRepository.create(Object.assign({ AccountNo: configPaymentMethodTypes[methodType]
|
|
1189
|
+
.processingFeeAccountNo }, accountPayload), {
|
|
1190
|
+
transaction: transaction,
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
catch (err) {
|
|
1194
|
+
throw err;
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
const paymentMethodTypePayload = {
|
|
1198
|
+
MethodId: p.MethodId,
|
|
1199
|
+
MethodTypeId: configPaymentMethodTypes[methodType].id,
|
|
1200
|
+
Name: configPaymentMethodTypes[methodType].name,
|
|
1201
|
+
AccountNo: configPaymentMethodTypes[methodType].accountNo,
|
|
1202
|
+
ProcessingFeeRate: configPaymentMethodTypes[methodType].processingFeeRate,
|
|
1203
|
+
ProcessingFeeAccountNo: configPaymentMethodTypes[methodType].processingFeeAccountNo,
|
|
1204
|
+
};
|
|
1205
|
+
try {
|
|
1206
|
+
await paymentMethod.newPaymentMethodType(paymentMethodTypePayload, transaction);
|
|
1207
|
+
}
|
|
1208
|
+
catch (err) { }
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
async LoadTaxCodes(companyId, companyTaxes, transaction) {
|
|
1216
|
+
for (const tax in companyTaxes) {
|
|
1217
|
+
let tx = await FinanceCompany._TaxRepository.findOne({
|
|
1218
|
+
where: {
|
|
1219
|
+
TaxCode: companyTaxes[tax].taxCode,
|
|
1220
|
+
},
|
|
1221
|
+
transaction: transaction,
|
|
1222
|
+
});
|
|
1223
|
+
if (!tx) {
|
|
1224
|
+
const newTx = await FinanceCompany._TaxRepository.create({
|
|
1225
|
+
TaxCode: companyTaxes[tax].taxCode,
|
|
1226
|
+
TaxRate: companyTaxes[tax].taxRate,
|
|
1227
|
+
Description: companyTaxes[tax].description,
|
|
1228
|
+
CompanyId: companyId,
|
|
1229
|
+
UpdatedAt: new Date(),
|
|
1230
|
+
CreatedById: 'System',
|
|
1231
|
+
CreatedAt: new Date(),
|
|
1232
|
+
UpdatedById: 'System',
|
|
1233
|
+
}, {
|
|
1234
|
+
transaction: transaction,
|
|
1235
|
+
});
|
|
1236
|
+
tx = newTx;
|
|
1237
|
+
}
|
|
1238
|
+
this._Taxes.push(new tax_1.Tax(tx.get({ plain: true })));
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
async collectPaymentForMultipleCustomers(dbTransaction, loginUser, payment, creditTransaction, receiptNo, collectPaymentType = collect_payment_type_1.CollectPaymentType.AUTOMATIC) {
|
|
1242
|
+
try {
|
|
1243
|
+
const systemCode = await config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
1244
|
+
const isPrivileged = await loginUser.checkPrivileges(systemCode, 'Collect Payment For Multiple Customers');
|
|
1245
|
+
if (!isPrivileged) {
|
|
1246
|
+
throw new Error('User is not authorized to perform this action');
|
|
1247
|
+
}
|
|
1248
|
+
const paymentItems = await payment.getPaymentItems();
|
|
1249
|
+
if (paymentItems.length < 1) {
|
|
1250
|
+
throw new Error('Atleast one payment item is required to identify what payment is being paid for.');
|
|
1251
|
+
}
|
|
1252
|
+
const paymentPaidWithItems = await payment.getPaymentPaidWith();
|
|
1253
|
+
if (paymentPaidWithItems.length < 1) {
|
|
1254
|
+
throw new Error('Atleast one payment paid with item is required to identify how the payment was made.');
|
|
1255
|
+
}
|
|
1256
|
+
if (paymentItems.length !== creditTransaction.length) {
|
|
1257
|
+
throw new Error('Payment items length is not equal to creditTransaction length');
|
|
1258
|
+
}
|
|
1259
|
+
let totalAmount = 0;
|
|
1260
|
+
paymentItems.forEach((paymentItem) => {
|
|
1261
|
+
totalAmount += paymentItem.Amount;
|
|
1262
|
+
});
|
|
1263
|
+
const totalCreditTransactionAmount = creditTransaction.reduce((accumulator, currentValue) => {
|
|
1264
|
+
return accumulator + currentValue.Amount;
|
|
1265
|
+
}, 0);
|
|
1266
|
+
if (totalAmount !== totalCreditTransactionAmount) {
|
|
1267
|
+
throw new Error('Payment items total Amount is dnot equal to credit transactions total Amount');
|
|
1268
|
+
}
|
|
1269
|
+
payment.PaymentId = this._createId().toUpperCase();
|
|
1270
|
+
payment.PaymentType = enum_1.PaymentType.PAYMENT_RECEIVED;
|
|
1271
|
+
payment.ReceivedBy = loginUser.ObjectId;
|
|
1272
|
+
payment.IssuedBy = loginUser.ObjectId;
|
|
1273
|
+
await FinanceCompany._PaymentRepository.create({
|
|
1274
|
+
PaymentId: payment.PaymentId,
|
|
1275
|
+
PaymentType: payment.PaymentType,
|
|
1276
|
+
PaymentDate: payment.PaymentDate,
|
|
1277
|
+
Description: payment.Description,
|
|
1278
|
+
Currency: payment.Currency,
|
|
1279
|
+
Amount: payment.Amount,
|
|
1280
|
+
Status: collectPaymentType === collect_payment_type_1.CollectPaymentType.MANUAL
|
|
1281
|
+
? enum_1.PaymentStatus.PENDING
|
|
1282
|
+
: enum_1.PaymentStatus.CONFIRMED,
|
|
1283
|
+
PostedToAccSystemYN: 'N',
|
|
1284
|
+
ReceivedBy: payment.ReceivedBy,
|
|
1285
|
+
IssuedBy: payment.IssuedBy,
|
|
1286
|
+
Remarks: payment.Remarks,
|
|
1287
|
+
RelatedObjectId: payment.RelatedObjectId,
|
|
1288
|
+
RelatedObjectType: payment.RelatedObjectType,
|
|
1289
|
+
ReceiptDocNo: payment.ReceiptDocNo,
|
|
1290
|
+
UpdatedAt: new Date(),
|
|
1291
|
+
UpdatedBy: loginUser.ObjectId,
|
|
1292
|
+
CreatedAt: new Date(),
|
|
1293
|
+
CreatedBy: loginUser.ObjectId,
|
|
1294
|
+
}, { transaction: dbTransaction });
|
|
1295
|
+
paymentItems.forEach(async (paymentItem) => {
|
|
1296
|
+
await FinanceCompany._PaymentItemRepository.create({
|
|
1297
|
+
PaymentId: payment.PaymentId,
|
|
1298
|
+
PayForObjectId: paymentItem.PayForObjectId,
|
|
1299
|
+
PayForObjectType: paymentItem.PayForObjectType,
|
|
1300
|
+
Currency: paymentItem.Currency,
|
|
1301
|
+
Amount: paymentItem.Amount,
|
|
1302
|
+
Name: paymentItem.Name,
|
|
1303
|
+
Description: paymentItem.Description,
|
|
1304
|
+
}, { transaction: dbTransaction });
|
|
1305
|
+
});
|
|
1306
|
+
paymentPaidWithItems.forEach(async (paymentPaidWithItem) => {
|
|
1307
|
+
await FinanceCompany._PaymentPaidWithRepository.create({
|
|
1308
|
+
PaymentId: payment.PaymentId,
|
|
1309
|
+
MethodTypeId: paymentPaidWithItem.MethodTypeId,
|
|
1310
|
+
Currency: paymentPaidWithItem.Currency,
|
|
1311
|
+
Amount: paymentPaidWithItem.Amount,
|
|
1312
|
+
Status: paymentPaidWithItem.Status,
|
|
1313
|
+
LedgerNo: paymentPaidWithItem.TransactionId,
|
|
1314
|
+
RefBank: paymentPaidWithItem.RefBank,
|
|
1315
|
+
RefName: paymentPaidWithItem.RefName,
|
|
1316
|
+
RefNo: paymentPaidWithItem.RefNo,
|
|
1317
|
+
RefOther1: paymentPaidWithItem.RefOther1,
|
|
1318
|
+
RefOther2: paymentPaidWithItem.RefOther2,
|
|
1319
|
+
RefOther3: paymentPaidWithItem.RefOther3,
|
|
1320
|
+
RefOther4: paymentPaidWithItem.RefOther4,
|
|
1321
|
+
RefOther5: paymentPaidWithItem.RefOther5,
|
|
1322
|
+
Remarks: paymentPaidWithItem.Remarks,
|
|
1323
|
+
PaymentMediaId: paymentPaidWithItem.PaymentMediaId,
|
|
1324
|
+
}, { transaction: dbTransaction });
|
|
1325
|
+
});
|
|
1326
|
+
return payment;
|
|
1327
|
+
}
|
|
1328
|
+
catch (error) {
|
|
1329
|
+
throw error;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
async confirmPayment(dbTransaction, loginUser, customer, payment, status, remarks, ctAccountNo, receiptNo) {
|
|
1333
|
+
try {
|
|
1334
|
+
this._DbTransaction = dbTransaction;
|
|
1335
|
+
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
1336
|
+
const isPrivileged = await loginUser.checkPrivileges(systemCode, 'FinanceCompany - Confirm Payment');
|
|
1337
|
+
if (!isPrivileged) {
|
|
1338
|
+
throw new general_1.ClassError('FinanceCompany', 'FinanceCompanyConfirmPaymentErrMsg00', `You do not have 'Payment - Confirm' privilege.`);
|
|
1339
|
+
}
|
|
1340
|
+
if (payment.PaymentId === 'New') {
|
|
1341
|
+
throw new general_1.ClassError('FinanceCompany', 'FinanceCompanyConfirmPaymentErrMsg01', `Payment not found.`);
|
|
1342
|
+
}
|
|
1343
|
+
if (payment.Status !== enum_1.PaymentStatus.PENDING) {
|
|
1344
|
+
throw new general_1.ClassError('Payment', 'PaymentConfirmPaymentErrMsg02', `Payment status is not 'Pending'.`);
|
|
1345
|
+
}
|
|
1346
|
+
payment.Remarks = remarks;
|
|
1347
|
+
let receiptDocNo = null;
|
|
1348
|
+
switch (status) {
|
|
1349
|
+
case enum_1.PaymentStatus.REJECTED:
|
|
1350
|
+
payment.Status = enum_1.PaymentStatus.REJECTED;
|
|
1351
|
+
break;
|
|
1352
|
+
case enum_1.PaymentStatus.FAILED:
|
|
1353
|
+
payment.Status = enum_1.PaymentStatus.FAILED;
|
|
1354
|
+
break;
|
|
1355
|
+
case enum_1.PaymentStatus.CONFIRMED:
|
|
1356
|
+
payment.Status = enum_1.PaymentStatus.CONFIRMED;
|
|
1357
|
+
const receiptDocuments = await FinanceCompany._DocumentRepository.findAll({
|
|
1358
|
+
where: {
|
|
1359
|
+
DocType: enum_1.DocType.RECEIPT,
|
|
1360
|
+
CompanyId: this.ObjectId,
|
|
1361
|
+
},
|
|
1362
|
+
});
|
|
1363
|
+
const receipt = new document_1.default(dbTransaction);
|
|
1364
|
+
if (receiptNo) {
|
|
1365
|
+
receipt.DocNo = receiptNo;
|
|
1366
|
+
}
|
|
1367
|
+
else {
|
|
1368
|
+
receipt.DocNo = `EZC-RCT-${receiptDocuments.length + 1}`;
|
|
1369
|
+
}
|
|
1370
|
+
receipt.DocType = enum_1.DocType.RECEIPT;
|
|
1371
|
+
receipt.DocDate = new Date();
|
|
1372
|
+
receipt.CompanyId = this.ObjectId;
|
|
1373
|
+
receipt.Currency = payment.Currency;
|
|
1374
|
+
receipt.Description = 'Payment Received';
|
|
1375
|
+
receipt.IssuedById = loginUser.ObjectId;
|
|
1376
|
+
receipt.IssuedToId = customer.CustomerId;
|
|
1377
|
+
receipt.IssuedToType = (0, typeof_1.type)(customer);
|
|
1378
|
+
receipt.RelatedObjectId = payment.RelatedObjectId;
|
|
1379
|
+
receipt.RelatedObjectType = payment.RelatedObjectType;
|
|
1380
|
+
receipt.UseAccSystemDocYN = 'N';
|
|
1381
|
+
receipt.CreatedById = loginUser.ObjectId;
|
|
1382
|
+
receipt.UpdatedById = loginUser.ObjectId;
|
|
1383
|
+
const paymentItems = await payment.getPaymentItems(dbTransaction);
|
|
1384
|
+
for (const paymentItem of paymentItems) {
|
|
1385
|
+
const receiptItem = new document_item_1.default(dbTransaction, receipt);
|
|
1386
|
+
receiptItem.Name = `Payment for ${paymentItem.PayForObjectType} No. ${paymentItem.PayForObjectId}`;
|
|
1387
|
+
receiptItem.NameBM = `Bayaran untuk ${paymentItem.PayForObjectType} No. ${paymentItem.PayForObjectId}`;
|
|
1388
|
+
receiptItem.Description = '-';
|
|
1389
|
+
receiptItem.Currency = paymentItem.Currency;
|
|
1390
|
+
receiptItem.UnitPrice = paymentItem.Amount;
|
|
1391
|
+
receiptItem.Quantity = 1;
|
|
1392
|
+
receiptItem.Amount = receiptItem.UnitPrice * receiptItem.Quantity;
|
|
1393
|
+
receiptItem.ItemId = receipt.DocNo;
|
|
1394
|
+
receiptItem.ItemType = (0, typeof_1.type)(payment);
|
|
1395
|
+
receiptItem.CtAccountNo = ctAccountNo;
|
|
1396
|
+
await paymentItem.paid(dbTransaction);
|
|
1397
|
+
await receipt.newDocumentItem(receiptItem);
|
|
1398
|
+
}
|
|
1399
|
+
const receiptMedia = await receipt.generateReceipt(receipt.IssuedById, customer, dbTransaction);
|
|
1400
|
+
await FinanceCompany._DocumentRepository.create({
|
|
1401
|
+
DocNo: receipt.DocNo,
|
|
1402
|
+
DocType: receipt.DocType,
|
|
1403
|
+
DocDate: receipt.DocDate,
|
|
1404
|
+
CompanyId: receipt.CompanyId,
|
|
1405
|
+
Currency: receipt.Currency,
|
|
1406
|
+
Amount: receipt.Amount,
|
|
1407
|
+
Description: receipt.Description,
|
|
1408
|
+
Status: receipt.Status,
|
|
1409
|
+
IssuedById: receipt.IssuedById,
|
|
1410
|
+
IssuedToId: receipt.IssuedToId,
|
|
1411
|
+
IssuedToType: receipt.IssuedToType,
|
|
1412
|
+
RelatedObjectId: receipt.RelatedObjectId,
|
|
1413
|
+
RelatedObjectType: receipt.RelatedObjectType,
|
|
1414
|
+
CreatedById: receipt.CreatedById,
|
|
1415
|
+
CreatedAt: new Date(),
|
|
1416
|
+
UpdatedById: receipt.UpdatedById,
|
|
1417
|
+
UpdatedAt: new Date(),
|
|
1418
|
+
DocPDFFileMediaId: receiptMedia.PDFMedia.MediaId,
|
|
1419
|
+
DocHTMLFileMediaId: receiptMedia.HTMLMedia.MediaId,
|
|
1420
|
+
AccSystemRefId: receipt.AccSystemRefId,
|
|
1421
|
+
PostedToAccSystemYN: receipt.PostedToAccSystemYN,
|
|
1422
|
+
PostedById: receipt.PostedToAccSystemYN == 'Y' ? receipt.PostedById : null,
|
|
1423
|
+
PostedDateTime: new Date(),
|
|
1424
|
+
UseAccSystemDocYN: receipt.UseAccSystemDocYN,
|
|
1425
|
+
}, {
|
|
1426
|
+
transaction: dbTransaction,
|
|
1427
|
+
});
|
|
1428
|
+
const receiptItems = await receipt.getDocumentItems(dbTransaction);
|
|
1429
|
+
for (const receiptItem of receiptItems) {
|
|
1430
|
+
await FinanceCompany._DocumentItemRepository.create({
|
|
1431
|
+
DocumentItemId: this._createId().toUpperCase(),
|
|
1432
|
+
DocNo: receipt.DocNo,
|
|
1433
|
+
Name: receiptItem.Name,
|
|
1434
|
+
NameBM: receiptItem.NameBM,
|
|
1435
|
+
Description: receiptItem.Description,
|
|
1436
|
+
ItemId: receiptItem.ItemId,
|
|
1437
|
+
ItemType: receiptItem.ItemType,
|
|
1438
|
+
ItemSKU: receiptItem.ItemSKU,
|
|
1439
|
+
ItemSerialNo: receiptItem.ItemSerialNo,
|
|
1440
|
+
Currency: receiptItem.Currency,
|
|
1441
|
+
UnitPrice: receiptItem.UnitPrice,
|
|
1442
|
+
Quantity: receiptItem.Quantity,
|
|
1443
|
+
QuantityUOM: receiptItem.QuantityUOM,
|
|
1444
|
+
Amount: receiptItem.Amount,
|
|
1445
|
+
TaxCode: receiptItem.TaxCode,
|
|
1446
|
+
TaxAmount: receiptItem.TaxAmount,
|
|
1447
|
+
TaxRate: receiptItem.TaxRate,
|
|
1448
|
+
TaxInclusiveYN: receiptItem.TaxInclusiveYN,
|
|
1449
|
+
DtAccountNo: receiptItem.DtAccountNo
|
|
1450
|
+
? receiptItem.DtAccountNo
|
|
1451
|
+
: null,
|
|
1452
|
+
CtAccountNo: receiptItem.CtAccountNo
|
|
1453
|
+
? receiptItem.CtAccountNo
|
|
1454
|
+
: null,
|
|
1455
|
+
}, {
|
|
1456
|
+
transaction: dbTransaction,
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
payment.ReceiptDocNo = receipt.DocNo;
|
|
1460
|
+
receiptDocNo = receipt.DocNo;
|
|
1461
|
+
const transactionDate = new Date();
|
|
1462
|
+
const paymentPaidWithItems = await payment.getPaymentPaidWith(dbTransaction);
|
|
1463
|
+
for (const paymentPaidWith of paymentPaidWithItems) {
|
|
1464
|
+
let paymentMethodType = await payment_method_type_1.default.initMethodType(dbTransaction, paymentPaidWith.MethodTypeId);
|
|
1465
|
+
const journalEntry = new journal_entry_1.default(dbTransaction);
|
|
1466
|
+
journalEntry.init({
|
|
1467
|
+
CompanyId: this.CompanyId,
|
|
1468
|
+
Name: 'Collect-payments for ' + payment.PaymentId,
|
|
1469
|
+
});
|
|
1470
|
+
const debitLT = await journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.DEBIT);
|
|
1471
|
+
debitLT.AccountNo = paymentMethodType.AccountNo;
|
|
1472
|
+
debitLT.Currency = paymentPaidWith.Currency;
|
|
1473
|
+
debitLT.DebitAmount = paymentPaidWith.Amount;
|
|
1474
|
+
debitLT.Date = transactionDate;
|
|
1475
|
+
debitLT.Description = 'Payment Received';
|
|
1476
|
+
debitLT.Name = customer.FullName;
|
|
1477
|
+
debitLT.RelatedObjectId = payment.PaymentId;
|
|
1478
|
+
debitLT.RelatedObjectType = 'Payment';
|
|
1479
|
+
debitLT.RelatedPaymentId = payment.PaymentId;
|
|
1480
|
+
const creditLT = await journalEntry.newLedgerTransaction(enum_1.TransactionTypeOptions.CREDIT);
|
|
1481
|
+
if (ctAccountNo) {
|
|
1482
|
+
creditLT.AccountNo = ctAccountNo;
|
|
1483
|
+
}
|
|
1484
|
+
else {
|
|
1485
|
+
const arAccount = await customer.getAccountReceivable();
|
|
1486
|
+
creditLT.AccountNo = arAccount.AccountNo;
|
|
1487
|
+
}
|
|
1488
|
+
creditLT.Currency = paymentPaidWith.Currency;
|
|
1489
|
+
creditLT.CreditAmount = paymentPaidWith.Amount;
|
|
1490
|
+
creditLT.Date = transactionDate;
|
|
1491
|
+
creditLT.Description = 'Payment Received';
|
|
1492
|
+
creditLT.Name = paymentMethodType.Name;
|
|
1493
|
+
creditLT.RelatedObjectId = payment.PaymentId;
|
|
1494
|
+
creditLT.RelatedObjectType = (0, typeof_1.type)(payment);
|
|
1495
|
+
creditLT.RelatedPaymentId = payment.PaymentId;
|
|
1496
|
+
await this.postJournal(dbTransaction, journalEntry, loginUser);
|
|
1497
|
+
}
|
|
1498
|
+
break;
|
|
1499
|
+
default:
|
|
1500
|
+
throw new general_1.ClassError('FinanceCompany', 'FinanceCompanyConfirmPaymentErrMsg03', `Invalid status.`);
|
|
1501
|
+
}
|
|
1502
|
+
await FinanceCompany._PaymentRepository.update({
|
|
1503
|
+
ReceiptDocNo: receiptDocNo,
|
|
1504
|
+
Status: payment.Status,
|
|
1505
|
+
UpdatedAt: new Date(),
|
|
1506
|
+
UpdatedBy: loginUser.ObjectId,
|
|
1507
|
+
}, {
|
|
1508
|
+
where: {
|
|
1509
|
+
PaymentId: payment.PaymentId,
|
|
1510
|
+
},
|
|
1511
|
+
transaction: dbTransaction,
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1514
|
+
catch (error) {
|
|
1515
|
+
throw error;
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
FinanceCompany._htFinanceCompanyIds = new general_1.HashTable();
|
|
1520
|
+
FinanceCompany._htFinanceCompanies = new general_1.HashTable();
|
|
1521
|
+
FinanceCompany._financeCompanyRepository = new finance_company_repository_1.FinanceCompanyRepository();
|
|
1522
|
+
FinanceCompany._PaymentRepository = new payment_repository_1.PaymentRepository();
|
|
1523
|
+
FinanceCompany._PaymentItemRepository = new payment_item_repository_1.PaymentItemRepository();
|
|
1524
|
+
FinanceCompany._PaymentPaidWithRepository = new payment_paid_with_repository_1.PaymentPaidWithRepository();
|
|
1525
|
+
FinanceCompany._PaymentMethodRepository = new payment_method_repository_1.PaymentMethodRepository();
|
|
1526
|
+
FinanceCompany._PaymentMethodTypeRepository = new payment_method_type_repository_1.PaymentMethodTypeRepository();
|
|
1527
|
+
FinanceCompany._DocumentRepository = new document_repository_1.DocumentRepository();
|
|
1528
|
+
FinanceCompany._DocumentItemRepository = new document_item_repository_1.DocumentItemRepository();
|
|
1529
|
+
FinanceCompany._FinanceCustomerRepository = new finance_customer_repository_1.FinanceCustomerRepository();
|
|
1530
|
+
FinanceCompany._LedgerTransactionRepository = new ledger_transaction_repository_1.LedgerTransactionRepository();
|
|
1531
|
+
FinanceCompany._AccountRepository = new account_repository_1.AccountRepository();
|
|
1532
|
+
FinanceCompany._TaxRepository = new tax_repository_1.TaxRepository();
|
|
1533
|
+
exports.default = FinanceCompany;
|
|
1577
1534
|
//# sourceMappingURL=finance-company.js.map
|