@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,395 +1,376 @@
|
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
get
|
|
30
|
-
return this.
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
this.
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
this.
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
this.
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
this.
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this.
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
get
|
|
69
|
-
return this.
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
this.
|
|
73
|
-
}
|
|
74
|
-
get
|
|
75
|
-
return
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this.
|
|
89
|
-
this.
|
|
90
|
-
this.
|
|
91
|
-
this.
|
|
92
|
-
this.
|
|
93
|
-
this.
|
|
94
|
-
this.
|
|
95
|
-
this.
|
|
96
|
-
this.
|
|
97
|
-
this.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
this.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
this.
|
|
112
|
-
this.
|
|
113
|
-
this.
|
|
114
|
-
this.
|
|
115
|
-
this.
|
|
116
|
-
this.
|
|
117
|
-
this.
|
|
118
|
-
this.
|
|
119
|
-
this.
|
|
120
|
-
this.
|
|
121
|
-
this.
|
|
122
|
-
this.
|
|
123
|
-
this.
|
|
124
|
-
this.
|
|
125
|
-
this.
|
|
126
|
-
this.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
this.
|
|
140
|
-
this.
|
|
141
|
-
this.
|
|
142
|
-
this.
|
|
143
|
-
this.
|
|
144
|
-
this.
|
|
145
|
-
this.
|
|
146
|
-
this.
|
|
147
|
-
this.
|
|
148
|
-
this.
|
|
149
|
-
this.
|
|
150
|
-
this.
|
|
151
|
-
this.
|
|
152
|
-
this.
|
|
153
|
-
this.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
const browser = yield puppeteer.launch({
|
|
376
|
-
headless: true,
|
|
377
|
-
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
378
|
-
});
|
|
379
|
-
const page = yield browser.newPage();
|
|
380
|
-
const imagePath = path.resolve('./invoice-template/assets/img/ezcash-logo.svg');
|
|
381
|
-
const imageBuffer = yield readFileContent(imagePath);
|
|
382
|
-
const imageDataUrl = `data:image/svg+xml;base64,${imageBuffer.toString('base64')}`;
|
|
383
|
-
const imgTag = `<img src="${imageDataUrl}" alt="Logo">`;
|
|
384
|
-
yield page.setContent(htmlString);
|
|
385
|
-
yield page.addStyleTag({ path: cssLocation });
|
|
386
|
-
const divHandle = yield page.$('.tm_logo');
|
|
387
|
-
yield divHandle.evaluate((div, imgTag) => {
|
|
388
|
-
div.innerHTML = imgTag;
|
|
389
|
-
}, imgTag);
|
|
390
|
-
const currentDate = date.toLocaleDateString('en-GB');
|
|
391
|
-
const invoiceNo = this.DocNo;
|
|
392
|
-
const invoiceTitleInfo = `
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const util = require("util");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const puppeteer = require("puppeteer");
|
|
7
|
+
const media_1 = require("@tomei/media");
|
|
8
|
+
const enum_1 = require("../enum");
|
|
9
|
+
const document_item_repository_1 = require("./document-item.repository");
|
|
10
|
+
const document_item_1 = require("./document-item");
|
|
11
|
+
const account_system_entity_1 = require("../account-system-entity/account-system-entity");
|
|
12
|
+
const document_repository_1 = require("./document.repository");
|
|
13
|
+
const document_item_entity_1 = require("../models/document-item.entity");
|
|
14
|
+
const general_1 = require("@tomei/general");
|
|
15
|
+
const config_1 = require("@tomei/config");
|
|
16
|
+
const sequelize_1 = require("sequelize");
|
|
17
|
+
const login_user_1 = require("../helpers/login-user");
|
|
18
|
+
const activity_history_1 = require("@tomei/activity-history");
|
|
19
|
+
class Document extends account_system_entity_1.AccountSystemEntity {
|
|
20
|
+
get ObjectType() {
|
|
21
|
+
return this._ObjectType;
|
|
22
|
+
}
|
|
23
|
+
get IsNewRecord() {
|
|
24
|
+
return this._IsNewRecord;
|
|
25
|
+
}
|
|
26
|
+
set IsNewRecord(record) {
|
|
27
|
+
this._IsNewRecord = record;
|
|
28
|
+
}
|
|
29
|
+
get DocType() {
|
|
30
|
+
return this._DocType;
|
|
31
|
+
}
|
|
32
|
+
set DocType(docType) {
|
|
33
|
+
this._DocType = docType;
|
|
34
|
+
}
|
|
35
|
+
get DocDate() {
|
|
36
|
+
return this._DocDate;
|
|
37
|
+
}
|
|
38
|
+
set DocDate(date) {
|
|
39
|
+
this._DocDate = date;
|
|
40
|
+
}
|
|
41
|
+
get DocHTMLFileMediaId() {
|
|
42
|
+
return this._DocHTMLFileMediaId;
|
|
43
|
+
}
|
|
44
|
+
set DocHTMLFileMediaId(mediaId) {
|
|
45
|
+
this._DocHTMLFileMediaId = mediaId;
|
|
46
|
+
}
|
|
47
|
+
get DocPDFFileMediaId() {
|
|
48
|
+
return this._DocPDFFileMediaId;
|
|
49
|
+
}
|
|
50
|
+
set DocPDFFileMediaId(mediaId) {
|
|
51
|
+
this._DocPDFFileMediaId = mediaId;
|
|
52
|
+
}
|
|
53
|
+
get Amount() {
|
|
54
|
+
return this._Amount;
|
|
55
|
+
}
|
|
56
|
+
set Amount(amount) {
|
|
57
|
+
this._Amount = amount;
|
|
58
|
+
}
|
|
59
|
+
get Status() {
|
|
60
|
+
return this._Status;
|
|
61
|
+
}
|
|
62
|
+
set Status(status) {
|
|
63
|
+
this._Status = status;
|
|
64
|
+
}
|
|
65
|
+
get RepositoryBase() {
|
|
66
|
+
return Document._RepositoryBase;
|
|
67
|
+
}
|
|
68
|
+
get ObjectId() {
|
|
69
|
+
return this.DocNo;
|
|
70
|
+
}
|
|
71
|
+
get ObjectName() {
|
|
72
|
+
return this.DocNo;
|
|
73
|
+
}
|
|
74
|
+
get TableName() {
|
|
75
|
+
return 'finance_Document';
|
|
76
|
+
}
|
|
77
|
+
constructor(dbTransaction, documentData) {
|
|
78
|
+
super();
|
|
79
|
+
this.DocNo = 'New';
|
|
80
|
+
this._DocDate = new Date();
|
|
81
|
+
this.Currency = 'MYR';
|
|
82
|
+
this._Amount = 0;
|
|
83
|
+
this.Description = '';
|
|
84
|
+
this._Status = enum_1.DocumentStatus.UNPAID;
|
|
85
|
+
this.IssuedById = '';
|
|
86
|
+
this.IssuedToId = '';
|
|
87
|
+
this.IssuedToType = '';
|
|
88
|
+
this.RelatedObjectId = '';
|
|
89
|
+
this.RelatedObjectType = '';
|
|
90
|
+
this.CreatedById = '';
|
|
91
|
+
this.UpdatedById = '';
|
|
92
|
+
this.UseAccSystemDocYN = 'N';
|
|
93
|
+
this._ObjectType = 'Document';
|
|
94
|
+
this._DocHTMLFileMediaId = '';
|
|
95
|
+
this._DocPDFFileMediaId = '';
|
|
96
|
+
this._IsNewRecord = true;
|
|
97
|
+
this._DocumentItems = [];
|
|
98
|
+
if (dbTransaction) {
|
|
99
|
+
this._DbTransaction = dbTransaction;
|
|
100
|
+
}
|
|
101
|
+
if (documentData) {
|
|
102
|
+
this.DocNo = documentData.DocNo;
|
|
103
|
+
this.DocType = documentData.DocType;
|
|
104
|
+
this.DocDate = documentData.DocDate;
|
|
105
|
+
this.CompanyId = documentData.CompanyId;
|
|
106
|
+
this.Currency = documentData.Currency;
|
|
107
|
+
this.Amount = documentData.Amount;
|
|
108
|
+
this.Description = documentData.Description;
|
|
109
|
+
this.Status = documentData.Status;
|
|
110
|
+
this.IssuedById = documentData.IssuedById;
|
|
111
|
+
this.IssuedToId = documentData.IssuedToId;
|
|
112
|
+
this.IssuedToType = documentData.IssuedToType;
|
|
113
|
+
this.RelatedObjectId = documentData.RelatedObjectId;
|
|
114
|
+
this.RelatedObjectType = documentData.RelatedObjectType;
|
|
115
|
+
this.CreatedById = documentData.CreatedById;
|
|
116
|
+
this.CreatedAt = documentData.CreatedAt;
|
|
117
|
+
this.UpdatedById = documentData.UpdatedById;
|
|
118
|
+
this.UpdatedAt = documentData.UpdatedAt;
|
|
119
|
+
this.DocPDFFileMediaId = documentData.DocPDFFileMediaId;
|
|
120
|
+
this.DocHTMLFileMediaId = documentData.DocHTMLFileMediaId;
|
|
121
|
+
this.AccSystemRefId = documentData.AccSystemRefId;
|
|
122
|
+
this.PostedToAccSystemYN = documentData.PostedToAccSystemYN;
|
|
123
|
+
this.PostedById = documentData.PostedById;
|
|
124
|
+
this.PostedDateTime = documentData.PostedDateTime;
|
|
125
|
+
this.UseAccSystemDocYN = documentData.UseAccSystemDocYN;
|
|
126
|
+
this.IsNewRecord = false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
init(params) {
|
|
130
|
+
this.DocNo = params.DocNo;
|
|
131
|
+
this.DocType = params.DocType;
|
|
132
|
+
this.DocDate = params.DocDate;
|
|
133
|
+
this.CompanyId = params.CompanyId;
|
|
134
|
+
this.Currency = params.Currency;
|
|
135
|
+
this.Amount = params.Amount;
|
|
136
|
+
this.Description = params.Description;
|
|
137
|
+
this.Status = params.Status;
|
|
138
|
+
this.IssuedById = params.IssuedById;
|
|
139
|
+
this.IssuedToId = params.IssuedToId;
|
|
140
|
+
this.IssuedToType = params.IssuedToType;
|
|
141
|
+
this.RelatedObjectId = params.RelatedObjectId;
|
|
142
|
+
this.RelatedObjectType = params.RelatedObjectType;
|
|
143
|
+
this.CreatedById = params.CreatedById;
|
|
144
|
+
this.CreatedAt = params.CreatedAt;
|
|
145
|
+
this.UpdatedById = params.UpdatedById;
|
|
146
|
+
this.UpdatedAt = params.UpdatedAt;
|
|
147
|
+
this.DocPDFFileMediaId = params.DocPDFFileMediaId;
|
|
148
|
+
this.DocHTMLFileMediaId = params.DocHTMLFileMediaId;
|
|
149
|
+
this.AccSystemRefId = params.AccSystemRefId;
|
|
150
|
+
this.PostedToAccSystemYN = params.PostedToAccSystemYN;
|
|
151
|
+
this.PostedById = params.PostedById;
|
|
152
|
+
this.PostedDateTime = params.PostedDateTime;
|
|
153
|
+
this.UseAccSystemDocYN = params.UseAccSystemDocYN;
|
|
154
|
+
}
|
|
155
|
+
static async initDocument(dbTransaction, docNo) {
|
|
156
|
+
try {
|
|
157
|
+
const documentData = await this._RepositoryBase.findOne({
|
|
158
|
+
where: {
|
|
159
|
+
DocNo: docNo,
|
|
160
|
+
},
|
|
161
|
+
include: [
|
|
162
|
+
{
|
|
163
|
+
model: document_item_entity_1.default,
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
transaction: dbTransaction,
|
|
167
|
+
});
|
|
168
|
+
if (documentData) {
|
|
169
|
+
const document = new Document(dbTransaction, {
|
|
170
|
+
DocNo: documentData.DocNo,
|
|
171
|
+
DocType: documentData.DocType,
|
|
172
|
+
CompanyId: documentData.CompanyId,
|
|
173
|
+
DocDate: documentData.DocDate,
|
|
174
|
+
Currency: documentData.Currency,
|
|
175
|
+
Amount: documentData.Amount,
|
|
176
|
+
Description: documentData.Description,
|
|
177
|
+
Status: documentData.Status,
|
|
178
|
+
IssuedById: documentData.IssuedById,
|
|
179
|
+
IssuedToId: documentData.IssuedToId,
|
|
180
|
+
IssuedToType: documentData.IssuedToType,
|
|
181
|
+
RelatedObjectId: documentData.RelatedObjectId,
|
|
182
|
+
RelatedObjectType: documentData.RelatedObjectType,
|
|
183
|
+
CreatedById: documentData.CreatedById,
|
|
184
|
+
CreatedAt: documentData.CreatedAt,
|
|
185
|
+
UpdatedById: documentData.UpdatedById,
|
|
186
|
+
UpdatedAt: documentData.UpdatedAt,
|
|
187
|
+
DocPDFFileMediaId: documentData.DocPDFFileMediaId,
|
|
188
|
+
DocHTMLFileMediaId: documentData.DocHTMLFileMediaId,
|
|
189
|
+
AccSystemRefId: documentData.AccSystemRefId,
|
|
190
|
+
PostedToAccSystemYN: documentData.PostedToAccSystemYN,
|
|
191
|
+
PostedById: documentData.PostedById,
|
|
192
|
+
PostedDateTime: documentData.PostedDateTime,
|
|
193
|
+
UseAccSystemDocYN: documentData.UseAccSystemDocYN,
|
|
194
|
+
});
|
|
195
|
+
return document;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
const notFoundError = new general_1.ClassError('Document', 'InitDocumentErrMsg00', `No Document record found.`);
|
|
199
|
+
throw notFoundError;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async reCalculateAmount() {
|
|
207
|
+
const roundToTwoDecimals = (value) => Math.round(value * 100) / 100;
|
|
208
|
+
this.Amount = 0;
|
|
209
|
+
for (const documentItem of this._DocumentItems) {
|
|
210
|
+
this.Amount = roundToTwoDecimals(this.Amount + documentItem.Amount);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
get DocumentItems() {
|
|
214
|
+
return new Promise((resolve, reject) => {
|
|
215
|
+
if (!this.IsNewRecord) {
|
|
216
|
+
document_item_1.default.initDocumentItems(this._DbTransaction, this)
|
|
217
|
+
.then((documentItems) => {
|
|
218
|
+
resolve(documentItems);
|
|
219
|
+
})
|
|
220
|
+
.catch((err) => {
|
|
221
|
+
reject(err);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
resolve(this._DocumentItems);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
async getDocumentItems(dbTransaction) {
|
|
230
|
+
try {
|
|
231
|
+
if (!this.IsNewRecord) {
|
|
232
|
+
const documentItems = await document_item_1.default.initDocumentItems(dbTransaction, this);
|
|
233
|
+
this._DocumentItems = documentItems;
|
|
234
|
+
}
|
|
235
|
+
return this._DocumentItems;
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
static async settleByCreditNote(loginUser, dbTransaction, DocNo, AmountToReduce) {
|
|
242
|
+
const document = await this.initDocument(dbTransaction, DocNo);
|
|
243
|
+
if (document.DocType !== enum_1.DocType.INVOICE) {
|
|
244
|
+
throw new general_1.ClassError('Document', 'SettleByCreditNoteErrMsgXX', 'Only Invoice can be issued credit note.');
|
|
245
|
+
}
|
|
246
|
+
if (AmountToReduce > document.Amount) {
|
|
247
|
+
throw new general_1.ClassError('Document', 'SettleByCreditNoteErrMsgXX', 'Amount to reduce is more than the document amount.');
|
|
248
|
+
}
|
|
249
|
+
const EntityValueBefore = {
|
|
250
|
+
DocNo: document.DocNo,
|
|
251
|
+
DocType: document.DocType,
|
|
252
|
+
CompanyId: document.CompanyId,
|
|
253
|
+
DocDate: document.DocDate,
|
|
254
|
+
Currency: document.Currency,
|
|
255
|
+
Amount: document.Amount,
|
|
256
|
+
Description: document.Description,
|
|
257
|
+
Status: document.Status,
|
|
258
|
+
IssuedById: document.IssuedById,
|
|
259
|
+
IssuedToId: document.IssuedToId,
|
|
260
|
+
IssuedToType: document.IssuedToType,
|
|
261
|
+
RelatedObjectId: document.RelatedObjectId,
|
|
262
|
+
RelatedObjectType: document.RelatedObjectType,
|
|
263
|
+
CreatedById: document.CreatedById,
|
|
264
|
+
CreatedAt: document.CreatedAt,
|
|
265
|
+
UpdatedById: document.UpdatedById,
|
|
266
|
+
UpdatedAt: document.UpdatedAt,
|
|
267
|
+
DocPDFFileMediaId: document.DocPDFFileMediaId,
|
|
268
|
+
DocHTMLFileMediaId: document.DocHTMLFileMediaId,
|
|
269
|
+
AccSystemRefId: document.AccSystemRefId,
|
|
270
|
+
PostedToAccSystemYN: document.PostedToAccSystemYN,
|
|
271
|
+
PostedById: document.PostedById,
|
|
272
|
+
PostedDateTime: document.PostedDateTime,
|
|
273
|
+
UseAccSystemDocYN: document.UseAccSystemDocYN,
|
|
274
|
+
};
|
|
275
|
+
let updatedStatus;
|
|
276
|
+
if (AmountToReduce == document.Amount) {
|
|
277
|
+
updatedStatus = enum_1.DocumentStatus.SETTLED;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
updatedStatus = enum_1.DocumentStatus.PARTIALSETTLED;
|
|
281
|
+
}
|
|
282
|
+
await this._RepositoryBase.update({
|
|
283
|
+
Amount: AmountToReduce,
|
|
284
|
+
Status: updatedStatus,
|
|
285
|
+
UpdatedAt: document.UpdatedAt,
|
|
286
|
+
UpdatedById: document.UpdatedById,
|
|
287
|
+
}, {
|
|
288
|
+
where: {
|
|
289
|
+
DocNo: document.DocNo,
|
|
290
|
+
},
|
|
291
|
+
transaction: dbTransaction,
|
|
292
|
+
});
|
|
293
|
+
const UpdatedDocument = await this.initDocument(dbTransaction, DocNo);
|
|
294
|
+
const EntityValueAfter = {
|
|
295
|
+
DocNo: UpdatedDocument.DocNo,
|
|
296
|
+
DocType: UpdatedDocument.DocType,
|
|
297
|
+
CompanyId: UpdatedDocument.CompanyId,
|
|
298
|
+
DocDate: UpdatedDocument.DocDate,
|
|
299
|
+
Currency: UpdatedDocument.Currency,
|
|
300
|
+
Amount: UpdatedDocument.Amount,
|
|
301
|
+
Description: UpdatedDocument.Description,
|
|
302
|
+
Status: UpdatedDocument.Status,
|
|
303
|
+
IssuedById: UpdatedDocument.IssuedById,
|
|
304
|
+
IssuedToId: UpdatedDocument.IssuedToId,
|
|
305
|
+
IssuedToType: UpdatedDocument.IssuedToType,
|
|
306
|
+
RelatedObjectId: UpdatedDocument.RelatedObjectId,
|
|
307
|
+
RelatedObjectType: UpdatedDocument.RelatedObjectType,
|
|
308
|
+
CreatedById: UpdatedDocument.CreatedById,
|
|
309
|
+
CreatedAt: UpdatedDocument.CreatedAt,
|
|
310
|
+
UpdatedById: UpdatedDocument.UpdatedById,
|
|
311
|
+
UpdatedAt: UpdatedDocument.UpdatedAt,
|
|
312
|
+
DocPDFFileMediaId: UpdatedDocument.DocPDFFileMediaId,
|
|
313
|
+
DocHTMLFileMediaId: UpdatedDocument.DocHTMLFileMediaId,
|
|
314
|
+
AccSystemRefId: UpdatedDocument.AccSystemRefId,
|
|
315
|
+
PostedToAccSystemYN: UpdatedDocument.PostedToAccSystemYN,
|
|
316
|
+
PostedById: UpdatedDocument.PostedById,
|
|
317
|
+
PostedDateTime: UpdatedDocument.PostedDateTime,
|
|
318
|
+
UseAccSystemDocYN: UpdatedDocument.UseAccSystemDocYN,
|
|
319
|
+
};
|
|
320
|
+
const activity = new activity_history_1.Activity();
|
|
321
|
+
activity.ActivityId = activity.createId();
|
|
322
|
+
activity.Action = activity_history_1.ActionEnum.UPDATE;
|
|
323
|
+
activity.Description = `Settle Finance Document (${UpdatedDocument._DocType}) from Credit Note.`;
|
|
324
|
+
activity.EntityType = 'FinanceCustomer';
|
|
325
|
+
activity.EntityId = DocNo;
|
|
326
|
+
activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
|
|
327
|
+
activity.EntityValueAfter = JSON.stringify(EntityValueAfter);
|
|
328
|
+
await activity.create(loginUser.ObjectId, dbTransaction);
|
|
329
|
+
return UpdatedDocument;
|
|
330
|
+
}
|
|
331
|
+
static async DEFAULT_INVOICE_TEMPLATE_HTML() {
|
|
332
|
+
const templateLocation = path.resolve('./invoice-template/index.html');
|
|
333
|
+
const readFileContent = util.promisify(fs.readFile);
|
|
334
|
+
const htmlBuffer = await readFileContent(templateLocation);
|
|
335
|
+
const htmlStream = {
|
|
336
|
+
buffer: htmlBuffer,
|
|
337
|
+
fieldname: 'FileStream',
|
|
338
|
+
originalname: 'index.html',
|
|
339
|
+
mimetype: 'text/html',
|
|
340
|
+
size: htmlBuffer.length,
|
|
341
|
+
encoding: '8bit',
|
|
342
|
+
filename: 'sample-invoice.html',
|
|
343
|
+
destination: path.dirname(templateLocation),
|
|
344
|
+
path: '',
|
|
345
|
+
stream: null,
|
|
346
|
+
};
|
|
347
|
+
return htmlStream;
|
|
348
|
+
}
|
|
349
|
+
async DEFAULT_INVOICE_TEMPLATE_PDF(customer, date = new Date()) {
|
|
350
|
+
const templateLocation = path.resolve('./invoice-template/index.html');
|
|
351
|
+
const cssLocation = path.resolve('./invoice-template/assets/css/style.css');
|
|
352
|
+
const readFileContent = util.promisify(fs.readFile);
|
|
353
|
+
const [htmlString] = await Promise.all([
|
|
354
|
+
readFileContent(templateLocation, 'utf8'),
|
|
355
|
+
]);
|
|
356
|
+
const browser = await puppeteer.launch({
|
|
357
|
+
headless: true,
|
|
358
|
+
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
359
|
+
});
|
|
360
|
+
const page = await browser.newPage();
|
|
361
|
+
const imagePath = path.resolve('./invoice-template/assets/img/ezcash-logo.svg');
|
|
362
|
+
const imageBuffer = await readFileContent(imagePath);
|
|
363
|
+
const imageDataUrl = `data:image/svg+xml;base64,${imageBuffer.toString('base64')}`;
|
|
364
|
+
const imgTag = `<img src="${imageDataUrl}" alt="Logo">`;
|
|
365
|
+
await page.setContent(htmlString);
|
|
366
|
+
await page.addStyleTag({ path: cssLocation });
|
|
367
|
+
const divHandle = await page.$('.tm_logo');
|
|
368
|
+
await divHandle.evaluate((div, imgTag) => {
|
|
369
|
+
div.innerHTML = imgTag;
|
|
370
|
+
}, imgTag);
|
|
371
|
+
const currentDate = date.toLocaleDateString('en-GB');
|
|
372
|
+
const invoiceNo = this.DocNo;
|
|
373
|
+
const invoiceTitleInfo = `
|
|
393
374
|
<div class="tm_invoice_seperator tm_gray_bg"></div>
|
|
394
375
|
<div class="tm_invoice_info_list">
|
|
395
376
|
<p class="tm_invoice_number tm_m0">
|
|
@@ -399,12 +380,12 @@ class Document extends account_system_entity_1.AccountSystemEntity {
|
|
|
399
380
|
Date: <b class="tm_primary_color">${currentDate}</b>
|
|
400
381
|
</p>
|
|
401
382
|
</div>
|
|
402
|
-
`;
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
383
|
+
`;
|
|
384
|
+
const invoiceTitleInfoHandle = await page.$('.tm_invoice_info');
|
|
385
|
+
await invoiceTitleInfoHandle.evaluate((invoice, invoiceTitleInfo) => {
|
|
386
|
+
invoice.innerHTML = invoiceTitleInfo;
|
|
387
|
+
}, invoiceTitleInfo);
|
|
388
|
+
const invoiceCustomerContent = `
|
|
408
389
|
<p class="tm_mb2">
|
|
409
390
|
<b class="tm_primary_color">Invoice To:</b>
|
|
410
391
|
</p>
|
|
@@ -414,24 +395,24 @@ class Document extends account_system_entity_1.AccountSystemEntity {
|
|
|
414
395
|
${customer.DefaultAddress.Country} <br />
|
|
415
396
|
${customer.Email}
|
|
416
397
|
</p>
|
|
417
|
-
`;
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
398
|
+
`;
|
|
399
|
+
const invoiceCustomerHandle = await page.$('.tm_customer_detail');
|
|
400
|
+
await invoiceCustomerHandle.evaluate((invoice, invoiceCustomerContent) => {
|
|
401
|
+
invoice.innerHTML = invoiceCustomerContent;
|
|
402
|
+
}, invoiceCustomerContent);
|
|
403
|
+
const invoicePayToContent = ``;
|
|
404
|
+
const invoicePayToHandle = await page.$('.tm_payto_detail');
|
|
405
|
+
await invoicePayToHandle.evaluate((invoice, invoicePayToContent) => {
|
|
406
|
+
invoice.innerHTML = invoicePayToContent;
|
|
407
|
+
}, invoicePayToContent);
|
|
408
|
+
const invoicePaymentInfoContent = ``;
|
|
409
|
+
const invoicePaymentInfoHandle = await page.$('.tm_payment_info');
|
|
410
|
+
await invoicePaymentInfoHandle.evaluate((invoice, invoicePaymentInfoContent) => {
|
|
411
|
+
invoice.innerHTML = invoicePaymentInfoContent;
|
|
412
|
+
}, invoicePaymentInfoContent);
|
|
413
|
+
const invoiceSubtotal = +this.Amount;
|
|
414
|
+
const invoiceTax = 0;
|
|
415
|
+
const invoiceRightFooterContent = `
|
|
435
416
|
<table>
|
|
436
417
|
<tbody>
|
|
437
418
|
<tr>
|
|
@@ -472,12 +453,12 @@ class Document extends account_system_entity_1.AccountSystemEntity {
|
|
|
472
453
|
</tr>
|
|
473
454
|
</tbody>
|
|
474
455
|
</table>
|
|
475
|
-
`;
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
456
|
+
`;
|
|
457
|
+
const invoiceRightFooterHandle = await page.$('.tm_item_total_section');
|
|
458
|
+
await invoiceRightFooterHandle.evaluate((invoice, invoiceRightFooterContent) => {
|
|
459
|
+
invoice.innerHTML = invoiceRightFooterContent;
|
|
460
|
+
}, invoiceRightFooterContent);
|
|
461
|
+
const invoiceTNCContent = `
|
|
481
462
|
<li>
|
|
482
463
|
All payment must be made to:
|
|
483
464
|
<ul>
|
|
@@ -489,15 +470,15 @@ class Document extends account_system_entity_1.AccountSystemEntity {
|
|
|
489
470
|
<li>
|
|
490
471
|
Once payment has been made, please email your transaction confirmation slip to <i>payment@ezcash.com.my</i>
|
|
491
472
|
</li>
|
|
492
|
-
`;
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
473
|
+
`;
|
|
474
|
+
const invoiceTNCHandle = await page.$('.tm_tnc_content');
|
|
475
|
+
await invoiceTNCHandle.evaluate((invoice, invoiceTNCContent) => {
|
|
476
|
+
invoice.innerHTML = invoiceTNCContent;
|
|
477
|
+
}, invoiceTNCContent);
|
|
478
|
+
const invoiceDocumentItems = await this.DocumentItems;
|
|
479
|
+
let invoiceItemContent = ``;
|
|
480
|
+
invoiceDocumentItems.forEach((documentItem, i) => {
|
|
481
|
+
invoiceItemContent += `
|
|
501
482
|
<tr>
|
|
502
483
|
<td class="tm_width_3">${i + 1}. ${documentItem.Name}</td>
|
|
503
484
|
<td class="tm_width_4">
|
|
@@ -507,72 +488,71 @@ class Document extends account_system_entity_1.AccountSystemEntity {
|
|
|
507
488
|
<td class="tm_width_1">${documentItem.Quantity}</td>
|
|
508
489
|
<td class="tm_width_2 tm_text_right">${documentItem.Currency} ${+documentItem.UnitPrice * +documentItem.Quantity}</td>
|
|
509
490
|
</tr>
|
|
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
|
-
DEFAULT_RECEIPT_TEMPLATE_PDF(customer, date = new Date()) {
|
|
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
|
-
const receiptTitle = `
|
|
491
|
+
`;
|
|
492
|
+
});
|
|
493
|
+
const invoiceDocumentItemHandle = await page.$('.tm_items_content');
|
|
494
|
+
await invoiceDocumentItemHandle.evaluate((invoice, invoiceItemContent) => {
|
|
495
|
+
invoice.innerHTML = invoiceItemContent;
|
|
496
|
+
}, invoiceItemContent);
|
|
497
|
+
const pdfBuffer = await page.pdf({
|
|
498
|
+
format: 'a4',
|
|
499
|
+
printBackground: true,
|
|
500
|
+
margin: {
|
|
501
|
+
left: '0px',
|
|
502
|
+
top: '0px',
|
|
503
|
+
right: '0px',
|
|
504
|
+
bottom: '0px',
|
|
505
|
+
},
|
|
506
|
+
});
|
|
507
|
+
const pdfBufferAsBuffer = Buffer.from(pdfBuffer);
|
|
508
|
+
const pdfStream = {
|
|
509
|
+
buffer: pdfBufferAsBuffer,
|
|
510
|
+
fieldname: 'FileStream',
|
|
511
|
+
originalname: 'sample-invoice.pdf',
|
|
512
|
+
mimetype: 'application/pdf',
|
|
513
|
+
size: pdfBuffer.length,
|
|
514
|
+
encoding: '8bit',
|
|
515
|
+
filename: 'sample-invoice.pdf',
|
|
516
|
+
destination: '',
|
|
517
|
+
path: '',
|
|
518
|
+
stream: null,
|
|
519
|
+
};
|
|
520
|
+
return pdfStream;
|
|
521
|
+
}
|
|
522
|
+
async DEFAULT_RECEIPT_TEMPLATE_PDF(customer, date = new Date()) {
|
|
523
|
+
const templateLocation = path.resolve('./invoice-template/index.html');
|
|
524
|
+
const cssLocation = path.resolve('./invoice-template/assets/css/style.css');
|
|
525
|
+
const readFileContent = util.promisify(fs.readFile);
|
|
526
|
+
const [htmlString] = await Promise.all([
|
|
527
|
+
readFileContent(templateLocation, 'utf8'),
|
|
528
|
+
]);
|
|
529
|
+
const browser = await puppeteer.launch({
|
|
530
|
+
headless: true,
|
|
531
|
+
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
532
|
+
});
|
|
533
|
+
const page = await browser.newPage();
|
|
534
|
+
const imagePath = path.resolve('./invoice-template/assets/img/ezcash-logo.svg');
|
|
535
|
+
const imageBuffer = await readFileContent(imagePath);
|
|
536
|
+
const imageDataUrl = `data:image/svg+xml;base64,${imageBuffer.toString('base64')}`;
|
|
537
|
+
const imgTag = `<img src="${imageDataUrl}" alt="Logo">`;
|
|
538
|
+
await page.setContent(htmlString);
|
|
539
|
+
await page.addStyleTag({ path: cssLocation });
|
|
540
|
+
const divHandle = await page.$('.tm_logo');
|
|
541
|
+
await divHandle.evaluate((div, imgTag) => {
|
|
542
|
+
div.innerHTML = imgTag;
|
|
543
|
+
}, imgTag);
|
|
544
|
+
const currentDate = date.toLocaleDateString('en-GB');
|
|
545
|
+
const receiptNo = this.DocNo;
|
|
546
|
+
const receiptTitle = `
|
|
567
547
|
<div class="tm_primary_color tm_f50 tm_text_uppercase">
|
|
568
548
|
Receipt
|
|
569
549
|
</div>
|
|
570
|
-
`;
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
550
|
+
`;
|
|
551
|
+
const receiptTitleHandle = await page.$('.tm_invoice_title');
|
|
552
|
+
await receiptTitleHandle.evaluate((receipt, receiptTitle) => {
|
|
553
|
+
receipt.innerHTML = receiptTitle;
|
|
554
|
+
}, receiptTitle);
|
|
555
|
+
const receiptTitleInfo = `
|
|
576
556
|
<div class="tm_invoice_seperator tm_gray_bg"></div>
|
|
577
557
|
<div class="tm_invoice_info_list">
|
|
578
558
|
<p class="tm_invoice_number tm_m0">
|
|
@@ -582,12 +562,12 @@ class Document extends account_system_entity_1.AccountSystemEntity {
|
|
|
582
562
|
Date: <b class="tm_primary_color">${currentDate}</b>
|
|
583
563
|
</p>
|
|
584
564
|
</div>
|
|
585
|
-
`;
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
565
|
+
`;
|
|
566
|
+
const receiptTitleInfoHandle = await page.$('.tm_invoice_info');
|
|
567
|
+
await receiptTitleInfoHandle.evaluate((receipt, receiptTitleInfo) => {
|
|
568
|
+
receipt.innerHTML = receiptTitleInfo;
|
|
569
|
+
}, receiptTitleInfo);
|
|
570
|
+
const receiptCustomerContent = `
|
|
591
571
|
<p class="tm_mb2">
|
|
592
572
|
<b class="tm_primary_color">Issued To:</b>
|
|
593
573
|
</p>
|
|
@@ -597,24 +577,24 @@ class Document extends account_system_entity_1.AccountSystemEntity {
|
|
|
597
577
|
${customer.DefaultAddress.Country} <br />
|
|
598
578
|
${customer.Email}
|
|
599
579
|
</p>
|
|
600
|
-
`;
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
580
|
+
`;
|
|
581
|
+
const receiptCustomerHandle = await page.$('.tm_customer_detail');
|
|
582
|
+
await receiptCustomerHandle.evaluate((receipt, receiptCustomerContent) => {
|
|
583
|
+
receipt.innerHTML = receiptCustomerContent;
|
|
584
|
+
}, receiptCustomerContent);
|
|
585
|
+
const receiptPayToContent = ``;
|
|
586
|
+
const receiptPayToHandle = await page.$('.tm_payto_detail');
|
|
587
|
+
await receiptPayToHandle.evaluate((receipt, receiptPayToContent) => {
|
|
588
|
+
receipt.innerHTML = receiptPayToContent;
|
|
589
|
+
}, receiptPayToContent);
|
|
590
|
+
const receiptPaymentInfoContent = ``;
|
|
591
|
+
const receiptPaymentInfoHandle = await page.$('.tm_payment_info');
|
|
592
|
+
await receiptPaymentInfoHandle.evaluate((receipt, receiptPaymentInfoContent) => {
|
|
593
|
+
receipt.innerHTML = receiptPaymentInfoContent;
|
|
594
|
+
}, receiptPaymentInfoContent);
|
|
595
|
+
const receiptSubtotal = +this.Amount;
|
|
596
|
+
const receiptTax = 0;
|
|
597
|
+
const receiptRightFooterContent = `
|
|
618
598
|
<table>
|
|
619
599
|
<tbody>
|
|
620
600
|
<tr>
|
|
@@ -655,15 +635,15 @@ class Document extends account_system_entity_1.AccountSystemEntity {
|
|
|
655
635
|
</tr>
|
|
656
636
|
</tbody>
|
|
657
637
|
</table>
|
|
658
|
-
`;
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
638
|
+
`;
|
|
639
|
+
const receiptRightFooterHandle = await page.$('.tm_item_total_section');
|
|
640
|
+
await receiptRightFooterHandle.evaluate((receipt, receiptRightFooterContent) => {
|
|
641
|
+
receipt.innerHTML = receiptRightFooterContent;
|
|
642
|
+
}, receiptRightFooterContent);
|
|
643
|
+
const receiptDocumentItems = await this.DocumentItems;
|
|
644
|
+
let receiptItemContent = ``;
|
|
645
|
+
receiptDocumentItems.forEach((documentItem, i) => {
|
|
646
|
+
receiptItemContent += `
|
|
667
647
|
<tr>
|
|
668
648
|
<td class="tm_width_3">${i + 1}. ${documentItem.Name}</td>
|
|
669
649
|
<td class="tm_width_4">
|
|
@@ -673,249 +653,238 @@ class Document extends account_system_entity_1.AccountSystemEntity {
|
|
|
673
653
|
<td class="tm_width_1">${documentItem.Quantity}</td>
|
|
674
654
|
<td class="tm_width_2 tm_text_right">${documentItem.Currency} ${+documentItem.UnitPrice * +documentItem.Quantity}</td>
|
|
675
655
|
</tr>
|
|
676
|
-
`;
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
656
|
+
`;
|
|
657
|
+
});
|
|
658
|
+
const receiptDocumentItemHandle = await page.$('.tm_items_content');
|
|
659
|
+
await receiptDocumentItemHandle.evaluate((receipt, receiptItemContent) => {
|
|
660
|
+
receipt.innerHTML = receiptItemContent;
|
|
661
|
+
}, receiptItemContent);
|
|
662
|
+
const receiptFooterContent = `
|
|
683
663
|
<p class="tm_mb5 tm_text_center tm_f11">
|
|
684
664
|
<i>
|
|
685
665
|
Thank you for your payment. This is computer generated receipt
|
|
686
666
|
- no signature is required.
|
|
687
667
|
</i>
|
|
688
668
|
</p>
|
|
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
|
-
get DocumentFileInHTML() {
|
|
720
|
-
return (() =>
|
|
721
|
-
const { HTMLMedia } =
|
|
722
|
-
return HTMLMedia;
|
|
723
|
-
})
|
|
724
|
-
}
|
|
725
|
-
get DocumentFileInPDF() {
|
|
726
|
-
return (() =>
|
|
727
|
-
const { PDFMedia } =
|
|
728
|
-
return PDFMedia;
|
|
729
|
-
})
|
|
730
|
-
}
|
|
731
|
-
generateInvoice(userId, customer, dbTransaction, date) {
|
|
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
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
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
|
-
catch (error) {
|
|
912
|
-
throw error;
|
|
913
|
-
}
|
|
914
|
-
});
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
exports.default = Document;
|
|
918
|
-
Document._RepositoryBase = new document_repository_1.DocumentRepository();
|
|
919
|
-
Document._DocumentItemRepository = new document_item_repository_1.DocumentItemRepository();
|
|
920
|
-
Document._MediaRepository = new media_1.MediasRepository();
|
|
669
|
+
`;
|
|
670
|
+
const receiptFooterHandle = await page.$('.tm_footer_section');
|
|
671
|
+
await receiptFooterHandle.evaluate((receipt, receiptFooterContent) => {
|
|
672
|
+
receipt.innerHTML = receiptFooterContent;
|
|
673
|
+
}, receiptFooterContent);
|
|
674
|
+
const pdfBuffer = await page.pdf({
|
|
675
|
+
format: 'a4',
|
|
676
|
+
printBackground: true,
|
|
677
|
+
margin: {
|
|
678
|
+
left: '0px',
|
|
679
|
+
top: '0px',
|
|
680
|
+
right: '0px',
|
|
681
|
+
bottom: '0px',
|
|
682
|
+
},
|
|
683
|
+
});
|
|
684
|
+
const pdfBufferAsBuffer = Buffer.from(pdfBuffer);
|
|
685
|
+
const pdfStream = {
|
|
686
|
+
buffer: pdfBufferAsBuffer,
|
|
687
|
+
fieldname: 'FileStream',
|
|
688
|
+
originalname: 'sample-invoice.pdf',
|
|
689
|
+
mimetype: 'application/pdf',
|
|
690
|
+
size: pdfBuffer.length,
|
|
691
|
+
encoding: '8bit',
|
|
692
|
+
filename: 'sample-invoice.pdf',
|
|
693
|
+
destination: '',
|
|
694
|
+
path: '',
|
|
695
|
+
stream: null,
|
|
696
|
+
};
|
|
697
|
+
return pdfStream;
|
|
698
|
+
}
|
|
699
|
+
get DocumentFileInHTML() {
|
|
700
|
+
return (async () => {
|
|
701
|
+
const { HTMLMedia } = await this.generateInvoice();
|
|
702
|
+
return HTMLMedia;
|
|
703
|
+
})();
|
|
704
|
+
}
|
|
705
|
+
get DocumentFileInPDF() {
|
|
706
|
+
return (async () => {
|
|
707
|
+
const { PDFMedia } = await this.generateInvoice();
|
|
708
|
+
return PDFMedia;
|
|
709
|
+
})();
|
|
710
|
+
}
|
|
711
|
+
async generateInvoice(userId, customer, dbTransaction, date) {
|
|
712
|
+
const media = new media_1.Medias(this.mediaCommonService);
|
|
713
|
+
const htmlPayload = {
|
|
714
|
+
ObjectId: this.DocNo,
|
|
715
|
+
ObjectType: 'Document',
|
|
716
|
+
Type: media_1.MediaType.Document,
|
|
717
|
+
FileName: `${this.DocType}-${this.DocNo}`,
|
|
718
|
+
FileStream: await Document.DEFAULT_INVOICE_TEMPLATE_HTML(),
|
|
719
|
+
FileExtension: 'html',
|
|
720
|
+
Title: `${this.DocType}-${this.DocNo}.html`,
|
|
721
|
+
Description: `HTML ${this.DocType}`,
|
|
722
|
+
IsEncryptedYN: 'N',
|
|
723
|
+
};
|
|
724
|
+
const user = new login_user_1.LoginUser(userId !== null && userId !== void 0 ? userId : 'System', null, null);
|
|
725
|
+
const HTMLInvoiceMedia = await media.postInternal(await Document.DEFAULT_INVOICE_TEMPLATE_HTML(), htmlPayload, user, dbTransaction);
|
|
726
|
+
const pdfPayload = {
|
|
727
|
+
ObjectId: this.DocNo,
|
|
728
|
+
ObjectType: 'Document',
|
|
729
|
+
Type: media_1.MediaType.Document,
|
|
730
|
+
FileName: `${this.DocType}-${this.DocNo}`,
|
|
731
|
+
FileStream: await this.DEFAULT_INVOICE_TEMPLATE_PDF(customer, date),
|
|
732
|
+
FileExtension: 'pdf',
|
|
733
|
+
Title: `${this.DocType}-${this.DocNo}.pdf`,
|
|
734
|
+
Description: `PDF ${this.DocType}`,
|
|
735
|
+
IsEncryptedYN: 'N',
|
|
736
|
+
};
|
|
737
|
+
const PDFInvoiceMedia = await media.postInternal(await this.DEFAULT_INVOICE_TEMPLATE_PDF(customer, date), pdfPayload, user, dbTransaction);
|
|
738
|
+
return {
|
|
739
|
+
HTMLMedia: HTMLInvoiceMedia,
|
|
740
|
+
PDFMedia: PDFInvoiceMedia,
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
async generateReceipt(userId, customer, transaction, date) {
|
|
744
|
+
const media = new media_1.Medias(this.mediaCommonService);
|
|
745
|
+
const user = new login_user_1.LoginUser(userId !== null && userId !== void 0 ? userId : 'System', null, null);
|
|
746
|
+
const htmlPayload = {
|
|
747
|
+
ObjectId: this.DocNo,
|
|
748
|
+
ObjectType: 'Document',
|
|
749
|
+
Type: media_1.MediaType.Document,
|
|
750
|
+
FileName: `${this.DocType}-${this.DocNo}`,
|
|
751
|
+
FileStream: await Document.DEFAULT_INVOICE_TEMPLATE_HTML(),
|
|
752
|
+
FileExtension: 'html',
|
|
753
|
+
Title: `${this.DocType}-${this.DocNo}.html`,
|
|
754
|
+
Description: `HTML ${this.DocType}`,
|
|
755
|
+
IsEncryptedYN: 'N',
|
|
756
|
+
};
|
|
757
|
+
const HTMLInvoiceMedia = await media.postInternal(await Document.DEFAULT_INVOICE_TEMPLATE_HTML(), htmlPayload, user, transaction);
|
|
758
|
+
const pdfPayload = {
|
|
759
|
+
ObjectId: this.DocNo,
|
|
760
|
+
ObjectType: 'Document',
|
|
761
|
+
Type: media_1.MediaType.Document,
|
|
762
|
+
FileName: `${this.DocType}-${this.DocNo}`,
|
|
763
|
+
FileStream: await this.DEFAULT_RECEIPT_TEMPLATE_PDF(customer, date),
|
|
764
|
+
FileExtension: 'pdf',
|
|
765
|
+
Title: `${this.DocType}-${this.DocNo}.pdf`,
|
|
766
|
+
Description: `PDF ${this.DocType}`,
|
|
767
|
+
IsEncryptedYN: 'N',
|
|
768
|
+
};
|
|
769
|
+
const PDFInvoiceMedia = await media.postInternal(await this.DEFAULT_RECEIPT_TEMPLATE_PDF(customer, date), pdfPayload, user, transaction);
|
|
770
|
+
return {
|
|
771
|
+
HTMLMedia: HTMLInvoiceMedia,
|
|
772
|
+
PDFMedia: PDFInvoiceMedia,
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
async generateCreditNote(userId, customer) {
|
|
776
|
+
console.log(userId, customer, '<< generateCreditNote');
|
|
777
|
+
}
|
|
778
|
+
async newDocumentItem(documentItem) {
|
|
779
|
+
let di;
|
|
780
|
+
if (documentItem) {
|
|
781
|
+
di = documentItem;
|
|
782
|
+
}
|
|
783
|
+
else {
|
|
784
|
+
di = new document_item_1.default(this._DbTransaction, this);
|
|
785
|
+
}
|
|
786
|
+
di.DocNo = this.DocNo;
|
|
787
|
+
this._DocumentItems.push(di);
|
|
788
|
+
this.reCalculateAmount();
|
|
789
|
+
return documentItem;
|
|
790
|
+
}
|
|
791
|
+
async getPreviousDocument(docType) {
|
|
792
|
+
return await this.RepositoryBase.findOne({
|
|
793
|
+
where: {
|
|
794
|
+
DocType: docType,
|
|
795
|
+
},
|
|
796
|
+
order: [['CreatedAt', 'DESC']],
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
static async findAll(loginUser, dbTransaction, page, row, search, order, accountingSystem) {
|
|
800
|
+
var _a;
|
|
801
|
+
try {
|
|
802
|
+
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
|
|
803
|
+
const isPrivileged = await loginUser.checkPrivileges(systemCode, 'Invoice - View');
|
|
804
|
+
if (!isPrivileged) {
|
|
805
|
+
throw new general_1.ClassError('Document', 'DocumentFindAllErrMsg00', `You do not have 'Invoice - View' privilege.`);
|
|
806
|
+
}
|
|
807
|
+
let options = {
|
|
808
|
+
transaction: dbTransaction,
|
|
809
|
+
order: [['CreatedAt', 'DESC']],
|
|
810
|
+
};
|
|
811
|
+
const searchObj = {};
|
|
812
|
+
if (search === null || search === void 0 ? void 0 : search.DocNo) {
|
|
813
|
+
searchObj.DocNo = search.DocNo;
|
|
814
|
+
}
|
|
815
|
+
if (search === null || search === void 0 ? void 0 : search.DocType) {
|
|
816
|
+
searchObj.DocType = search.DocType;
|
|
817
|
+
}
|
|
818
|
+
if (search === null || search === void 0 ? void 0 : search.StartDate) {
|
|
819
|
+
searchObj.DocDate = Object.assign(Object.assign({}, searchObj.DocDate), { [sequelize_1.Op.gte]: new Date(search.StartDate).toISOString() });
|
|
820
|
+
}
|
|
821
|
+
if (search === null || search === void 0 ? void 0 : search.EndDate) {
|
|
822
|
+
searchObj.DocDate = Object.assign(Object.assign({}, searchObj.DocDate), { [sequelize_1.Op.lte]: new Date(search.EndDate).toISOString() });
|
|
823
|
+
}
|
|
824
|
+
if (search === null || search === void 0 ? void 0 : search.IssuedToId) {
|
|
825
|
+
searchObj.IssuedToId = search.IssuedToId;
|
|
826
|
+
}
|
|
827
|
+
if (search === null || search === void 0 ? void 0 : search.IssuedToType) {
|
|
828
|
+
searchObj.IssuedToType = search.IssuedToType;
|
|
829
|
+
}
|
|
830
|
+
if (search === null || search === void 0 ? void 0 : search.Status) {
|
|
831
|
+
searchObj.Status = search.Status;
|
|
832
|
+
}
|
|
833
|
+
if (search === null || search === void 0 ? void 0 : search.RelatedObjectId) {
|
|
834
|
+
searchObj.RelatedObjectId = search.RelatedObjectId;
|
|
835
|
+
}
|
|
836
|
+
if (search === null || search === void 0 ? void 0 : search.RelatedObjectType) {
|
|
837
|
+
searchObj.RelatedObjectType = search.RelatedObjectType;
|
|
838
|
+
}
|
|
839
|
+
if (search === null || search === void 0 ? void 0 : search.Description) {
|
|
840
|
+
searchObj.Description = search.Description;
|
|
841
|
+
}
|
|
842
|
+
if (page && row) {
|
|
843
|
+
options = Object.assign(Object.assign({}, options), { limit: row, offset: row * (page - 1) });
|
|
844
|
+
}
|
|
845
|
+
if (order) {
|
|
846
|
+
options = Object.assign(Object.assign({}, options), { order: order });
|
|
847
|
+
}
|
|
848
|
+
if (Object.keys(searchObj).length) {
|
|
849
|
+
options = Object.assign(Object.assign({}, options), { where: searchObj });
|
|
850
|
+
}
|
|
851
|
+
let documents = await Document._RepositoryBase.findAllWithPagination(options);
|
|
852
|
+
let isChangesExit = false;
|
|
853
|
+
for (let i = 0; i < ((_a = documents === null || documents === void 0 ? void 0 : documents.rows) === null || _a === void 0 ? void 0 : _a.length); i++) {
|
|
854
|
+
const doc = await (documents === null || documents === void 0 ? void 0 : documents.rows[i]);
|
|
855
|
+
if (doc.UseAccSystemDocYN.toLowerCase() === 'y') {
|
|
856
|
+
console.log(doc.UseAccSystemDocYN.toLowerCase());
|
|
857
|
+
if (accountingSystem === null || accountingSystem === undefined) {
|
|
858
|
+
throw new general_1.ClassError('Document', 'DocumentFindAllErrMsg01', `Accounting System is not set`);
|
|
859
|
+
}
|
|
860
|
+
const invoiceStatus = await accountingSystem.getInvoiceStatus(doc.AccSystemRefId);
|
|
861
|
+
if (doc.Status !== invoiceStatus) {
|
|
862
|
+
doc.Status = invoiceStatus;
|
|
863
|
+
await this._RepositoryBase.update({
|
|
864
|
+
Status: invoiceStatus,
|
|
865
|
+
}, {
|
|
866
|
+
where: {
|
|
867
|
+
DocNo: doc.DocNo,
|
|
868
|
+
},
|
|
869
|
+
transaction: dbTransaction,
|
|
870
|
+
});
|
|
871
|
+
isChangesExit = true;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
if (isChangesExit) {
|
|
876
|
+
documents =
|
|
877
|
+
await Document._RepositoryBase.findAllWithPagination(options);
|
|
878
|
+
}
|
|
879
|
+
return documents;
|
|
880
|
+
}
|
|
881
|
+
catch (error) {
|
|
882
|
+
throw error;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
Document._RepositoryBase = new document_repository_1.DocumentRepository();
|
|
887
|
+
Document._DocumentItemRepository = new document_item_repository_1.DocumentItemRepository();
|
|
888
|
+
Document._MediaRepository = new media_1.MediasRepository();
|
|
889
|
+
exports.default = Document;
|
|
921
890
|
//# sourceMappingURL=document.js.map
|