@tomei/rental 0.9.4 → 0.9.5
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/.commitlintrc.json +22 -22
- package/.eslintrc +16 -16
- package/.eslintrc.js +35 -35
- package/.gitlab-ci.yml +16 -16
- package/.husky/commit-msg +15 -15
- package/.husky/pre-commit +7 -7
- package/.prettierrc +4 -4
- package/Jenkinsfile +51 -51
- package/README.md +8 -8
- package/dist/src/components/rental/rental.js +29 -13
- package/dist/src/components/rental/rental.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/jest.config.js +10 -10
- package/migrations/booking-table-migration.js +79 -79
- package/migrations/joint-hirer-table-migration.js +52 -52
- package/migrations/rental-aggrement-table-migration.js +22 -22
- package/migrations/rental-price-table-migration.js +32 -32
- package/migrations/rental-table-migrations.js +96 -96
- package/package.json +75 -75
- package/sonar-project.properties +12 -12
- package/src/components/agreement/agreement.repository.ts +54 -54
- package/src/components/agreement/agreement.ts +43 -43
- package/src/components/booking/booking.repository.ts +51 -51
- package/src/components/booking/booking.ts +291 -291
- package/src/components/joint-hirer/joint-hirer.repository.ts +54 -54
- package/src/components/rental/rental.repository.ts +51 -51
- package/src/components/rental/rental.ts +720 -706
- package/src/components/rental-price/rental-price.repository.ts +54 -54
- package/src/components/rental-price/rental-price.ts +100 -100
- package/src/database.ts +27 -27
- package/src/enum/account-type.enum.ts +4 -4
- package/src/enum/booking.enum.ts +5 -5
- package/src/enum/index.ts +5 -5
- package/src/enum/rental-status.enum.ts +39 -39
- package/src/index.ts +28 -28
- package/src/interfaces/agreement-attr.interface.ts +4 -4
- package/src/interfaces/booking-attr.interface.ts +19 -19
- package/src/interfaces/index.ts +13 -13
- package/src/interfaces/joint-hirer-attr.interface.ts +10 -10
- package/src/interfaces/rental-attr.interface.ts +25 -25
- package/src/interfaces/rental-find-all-search-attr.interface.ts +11 -11
- package/src/interfaces/rental-price-attr.interface.ts +7 -7
- package/src/models/agreement.entity.ts +26 -26
- package/src/models/booking.entity.ts +105 -105
- package/src/models/index.ts +13 -13
- package/src/models/joint-hirer.entity.ts +63 -63
- package/src/models/rental-price.entity.ts +38 -38
- package/src/models/rental.entity.ts +133 -133
- package/tomei-rental-0.9.4.tgz +0 -0
- package/tsconfig.build.json +5 -5
- package/tsconfig.json +23 -23
|
@@ -1,706 +1,720 @@
|
|
|
1
|
-
import { IRentalAttr } from '../../interfaces/rental-attr.interface';
|
|
2
|
-
import { RentalStatusEnum } from '../../enum/rental-status.enum';
|
|
3
|
-
import { RentalRepository } from './rental.repository';
|
|
4
|
-
import { ClassError, ObjectBase } from '@tomei/general';
|
|
5
|
-
import { ApplicationConfig } from '@tomei/config';
|
|
6
|
-
import { LoginUser } from '@tomei/sso';
|
|
7
|
-
import { RentalPrice } from '../rental-price/rental-price';
|
|
8
|
-
import { Op, QueryTypes } from 'sequelize';
|
|
9
|
-
import { ActionEnum, Activity } from '@tomei/activity-history';
|
|
10
|
-
import { IRentalFindAllSearchAttr } from '../../interfaces/rental-find-all-search-attr.interface';
|
|
11
|
-
import { RentalAccountTypeEnum } from '../../enum/account-type.enum';
|
|
12
|
-
import { JointHirer } from '../joint-hirer/joint-hirer';
|
|
13
|
-
import { JointHirerModel } from '../../models/joint-hirer.entity';
|
|
14
|
-
import { AgreementRepository } from '../agreement/agreement.repository';
|
|
15
|
-
import * as rentalDb from '../../database';
|
|
16
|
-
import { RentalModel } from '../../models/rental.entity';
|
|
17
|
-
import { JointHirerRepository } from '../joint-hirer/joint-hirer.repository';
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
protected
|
|
38
|
-
protected
|
|
39
|
-
protected
|
|
40
|
-
protected
|
|
41
|
-
protected
|
|
42
|
-
protected
|
|
43
|
-
protected static
|
|
44
|
-
protected static
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this.
|
|
87
|
-
this.
|
|
88
|
-
this.
|
|
89
|
-
this.
|
|
90
|
-
this.
|
|
91
|
-
this.
|
|
92
|
-
this.
|
|
93
|
-
this.
|
|
94
|
-
this.
|
|
95
|
-
this.
|
|
96
|
-
this.
|
|
97
|
-
this.
|
|
98
|
-
this.
|
|
99
|
-
this.
|
|
100
|
-
this.
|
|
101
|
-
this.
|
|
102
|
-
this.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
'
|
|
121
|
-
'
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
*
|
|
129
|
-
* @param {
|
|
130
|
-
* @param {
|
|
131
|
-
* @
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
'
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
this.
|
|
163
|
-
this.
|
|
164
|
-
this.
|
|
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
|
-
this.
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
this.
|
|
202
|
-
this.
|
|
203
|
-
this.
|
|
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
|
-
activity
|
|
242
|
-
activity.
|
|
243
|
-
activity.
|
|
244
|
-
activity.
|
|
245
|
-
activity.
|
|
246
|
-
activity.
|
|
247
|
-
activity.
|
|
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
|
-
options
|
|
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
|
-
|
|
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
|
-
|
|
489
|
-
|
|
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
|
-
|
|
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
|
-
const
|
|
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
|
-
// 3
|
|
693
|
-
//
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
1
|
+
import { IRentalAttr } from '../../interfaces/rental-attr.interface';
|
|
2
|
+
import { RentalStatusEnum } from '../../enum/rental-status.enum';
|
|
3
|
+
import { RentalRepository } from './rental.repository';
|
|
4
|
+
import { ClassError, ObjectBase } from '@tomei/general';
|
|
5
|
+
import { ApplicationConfig } from '@tomei/config';
|
|
6
|
+
import { LoginUser } from '@tomei/sso';
|
|
7
|
+
import { RentalPrice } from '../rental-price/rental-price';
|
|
8
|
+
import { Op, QueryTypes } from 'sequelize';
|
|
9
|
+
import { ActionEnum, Activity } from '@tomei/activity-history';
|
|
10
|
+
import { IRentalFindAllSearchAttr } from '../../interfaces/rental-find-all-search-attr.interface';
|
|
11
|
+
import { RentalAccountTypeEnum } from '../../enum/account-type.enum';
|
|
12
|
+
import { JointHirer } from '../joint-hirer/joint-hirer';
|
|
13
|
+
import { JointHirerModel } from '../../models/joint-hirer.entity';
|
|
14
|
+
import { AgreementRepository } from '../agreement/agreement.repository';
|
|
15
|
+
import * as rentalDb from '../../database';
|
|
16
|
+
import { RentalModel } from '../../models/rental.entity';
|
|
17
|
+
import { JointHirerRepository } from '../joint-hirer/joint-hirer.repository';
|
|
18
|
+
import { AgreementModel } from '../../models';
|
|
19
|
+
|
|
20
|
+
export class Rental extends ObjectBase {
|
|
21
|
+
ObjectId: string;
|
|
22
|
+
ObjectName: string;
|
|
23
|
+
ObjectType = 'Rental';
|
|
24
|
+
TableName: string;
|
|
25
|
+
CustomerId: string;
|
|
26
|
+
CustomerType: string;
|
|
27
|
+
ItemId: string;
|
|
28
|
+
ItemType: string;
|
|
29
|
+
PriceId: string;
|
|
30
|
+
StartDateTime: Date;
|
|
31
|
+
EndDateTime: Date;
|
|
32
|
+
CancelRemarks: string;
|
|
33
|
+
TerminateRemarks: string;
|
|
34
|
+
AgreementNo: string;
|
|
35
|
+
AccountType: RentalAccountTypeEnum;
|
|
36
|
+
JointHirers: JointHirer[] = [];
|
|
37
|
+
protected _Status: RentalStatusEnum;
|
|
38
|
+
protected _EscheatmentYN: string = 'N';
|
|
39
|
+
protected _CreatedById: string;
|
|
40
|
+
protected _CreatedAt: Date;
|
|
41
|
+
protected _UpdatedById: string;
|
|
42
|
+
protected _UpdatedAt: Date;
|
|
43
|
+
protected static _Repo = new RentalRepository();
|
|
44
|
+
protected static _AgreementRepo = new AgreementRepository();
|
|
45
|
+
protected static _JointHirerRepo = new JointHirerRepository();
|
|
46
|
+
|
|
47
|
+
get RentalId(): string {
|
|
48
|
+
return this.ObjectId;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
set RentalId(value: string) {
|
|
52
|
+
this.ObjectId = value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get Status(): RentalStatusEnum {
|
|
56
|
+
return this._Status;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get EscheatmentYN(): string {
|
|
60
|
+
return this._EscheatmentYN;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get CreatedById(): string {
|
|
64
|
+
return this._CreatedById;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get CreatedAt(): Date {
|
|
68
|
+
return this._CreatedAt;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get UpdatedById(): string {
|
|
72
|
+
return this._UpdatedById;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get UpdatedAt(): Date {
|
|
76
|
+
return this._UpdatedAt;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private setTerminated() {
|
|
80
|
+
this._Status = RentalStatusEnum.TERMINATED;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
protected constructor(rentalAttr?: IRentalAttr) {
|
|
84
|
+
super();
|
|
85
|
+
if (rentalAttr) {
|
|
86
|
+
this.RentalId = rentalAttr.RentalId;
|
|
87
|
+
this.CustomerId = rentalAttr.CustomerId;
|
|
88
|
+
this.CustomerType = rentalAttr.CustomerType;
|
|
89
|
+
this.ItemId = rentalAttr.ItemId;
|
|
90
|
+
this.ItemType = rentalAttr.ItemType;
|
|
91
|
+
this.PriceId = rentalAttr.PriceId;
|
|
92
|
+
this.StartDateTime = rentalAttr.StartDateTime;
|
|
93
|
+
this.EndDateTime = rentalAttr.EndDateTime;
|
|
94
|
+
this.CancelRemarks = rentalAttr.CancelRemarks;
|
|
95
|
+
this.TerminateRemarks = rentalAttr.TerminateRemarks;
|
|
96
|
+
this.AgreementNo = rentalAttr.AgreementNo;
|
|
97
|
+
this.AccountType = rentalAttr.AccountType;
|
|
98
|
+
this._Status = rentalAttr.Status;
|
|
99
|
+
this._EscheatmentYN = rentalAttr.EscheatmentYN;
|
|
100
|
+
this._CreatedById = rentalAttr.CreatedById;
|
|
101
|
+
this._CreatedAt = rentalAttr.CreatedAt;
|
|
102
|
+
this._UpdatedById = rentalAttr.UpdatedById;
|
|
103
|
+
this._UpdatedAt = rentalAttr.UpdatedAt;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public static async init(dbTransaction?: any, rentalId?: string) {
|
|
108
|
+
try {
|
|
109
|
+
if (rentalId) {
|
|
110
|
+
const rental = await Rental._Repo.findByPk(rentalId, dbTransaction);
|
|
111
|
+
if (rental) {
|
|
112
|
+
return new Rental(rental);
|
|
113
|
+
} else {
|
|
114
|
+
throw new ClassError('Rental', 'RentalErrMsg00', 'Rental Not Found');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return new Rental();
|
|
118
|
+
} catch (error) {
|
|
119
|
+
throw new ClassError(
|
|
120
|
+
'Rental',
|
|
121
|
+
'RentalErrMsg00',
|
|
122
|
+
'Failed To Initialize Price',
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Create a new Rental record.
|
|
129
|
+
* @param {RentalPrice} rentalPrice - The rental pricing information.
|
|
130
|
+
* @param {LoginUser} loginUser - The user initiating the creation.
|
|
131
|
+
* @param {any} [dbTransaction] - Optional database transaction for atomic operations.
|
|
132
|
+
* @throws {ClassError} Throws an error if:
|
|
133
|
+
* 1. loginUser does not have 'Rental - Create' privilege.
|
|
134
|
+
* 2. Rental item is not available at the current date.
|
|
135
|
+
* @returns {Promise<any>} A Promise resolving to the created rental record.
|
|
136
|
+
*/
|
|
137
|
+
public async create(
|
|
138
|
+
rentalPrice: RentalPrice,
|
|
139
|
+
loginUser: LoginUser,
|
|
140
|
+
jointHirers?: JointHirer[],
|
|
141
|
+
dbTransaction?: any,
|
|
142
|
+
): Promise<any> {
|
|
143
|
+
try {
|
|
144
|
+
/*Part 1: Check Privilege*/
|
|
145
|
+
const systemCode =
|
|
146
|
+
ApplicationConfig.getComponentConfigValue('system-code');
|
|
147
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
|
148
|
+
systemCode,
|
|
149
|
+
'Rental - Create',
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
if (!isPrivileged) {
|
|
153
|
+
throw new ClassError(
|
|
154
|
+
'Rental',
|
|
155
|
+
'RentalErrMsg01',
|
|
156
|
+
"You do not have 'Rental - Create' privilege.",
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/*Part 2: Make Sure Rental Item Available*/
|
|
161
|
+
const isItemAvailable = await Rental.isItemAvailable(
|
|
162
|
+
this.ItemId,
|
|
163
|
+
this.ItemType,
|
|
164
|
+
this.StartDateTime,
|
|
165
|
+
this.EndDateTime,
|
|
166
|
+
dbTransaction,
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
if (!isItemAvailable) {
|
|
170
|
+
throw new ClassError(
|
|
171
|
+
'Rental',
|
|
172
|
+
'RentalErrMsg02',
|
|
173
|
+
'Rental Item is not available at current date.',
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Part 3: Create Rental Agreement Record
|
|
178
|
+
// Call Rental._AgreementRepo create method by passing:
|
|
179
|
+
// AgreementNo: this.AgreementNo
|
|
180
|
+
// Status: "Not Generated"
|
|
181
|
+
// dbTransaction
|
|
182
|
+
await Rental._AgreementRepo.create(
|
|
183
|
+
{
|
|
184
|
+
AgreementNo: this.AgreementNo,
|
|
185
|
+
Status: 'Not Generated',
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
transaction: dbTransaction,
|
|
189
|
+
},
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
/*Part 4: Insert Rental & The Agreed Rental Price*/
|
|
193
|
+
await rentalPrice.create(loginUser, dbTransaction);
|
|
194
|
+
|
|
195
|
+
this.PriceId = rentalPrice.PriceId;
|
|
196
|
+
|
|
197
|
+
this.RentalId = this.createId();
|
|
198
|
+
// if (!this.Status) {
|
|
199
|
+
this._Status = RentalStatusEnum.PENDING_SIGNING;
|
|
200
|
+
// }
|
|
201
|
+
this._CreatedById = loginUser.ObjectId;
|
|
202
|
+
this._UpdatedById = loginUser.ObjectId;
|
|
203
|
+
this._CreatedAt = new Date();
|
|
204
|
+
this._UpdatedAt = new Date();
|
|
205
|
+
|
|
206
|
+
const data = {
|
|
207
|
+
RentalId: this.RentalId,
|
|
208
|
+
CustomerId: this.CustomerId,
|
|
209
|
+
CustomerType: this.CustomerType,
|
|
210
|
+
ItemId: this.ItemId,
|
|
211
|
+
ItemType: this.ItemType,
|
|
212
|
+
PriceId: this.PriceId,
|
|
213
|
+
StartDateTime: this.StartDateTime,
|
|
214
|
+
EndDateTime: this.EndDateTime,
|
|
215
|
+
CancelRemarks: this.CancelRemarks,
|
|
216
|
+
TerminateRemarks: this.TerminateRemarks,
|
|
217
|
+
AgreementNo: this.AgreementNo,
|
|
218
|
+
AccountType: this.AccountType,
|
|
219
|
+
Status: this.Status,
|
|
220
|
+
EscheatmentYN: this.EscheatmentYN,
|
|
221
|
+
CreatedById: this.CreatedById,
|
|
222
|
+
CreatedAt: this.CreatedAt,
|
|
223
|
+
UpdatedById: this.UpdatedById,
|
|
224
|
+
UpdatedAt: this.UpdatedAt,
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
await Rental._Repo.create(data, {
|
|
228
|
+
transaction: dbTransaction,
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
//For every data inside Param.jointHirers, update the rentalId and call jointHirer.create
|
|
232
|
+
if (jointHirers) {
|
|
233
|
+
for (let i = 0; i < jointHirers.length; i++) {
|
|
234
|
+
jointHirers[i].RentalId = this.RentalId;
|
|
235
|
+
await jointHirers[i].create(loginUser, dbTransaction);
|
|
236
|
+
this.JointHirers.push(jointHirers[i]);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/*Part 5: Record Create Rental Activity*/
|
|
241
|
+
const activity = new Activity();
|
|
242
|
+
activity.ActivityId = activity.createId();
|
|
243
|
+
activity.Action = ActionEnum.ADD;
|
|
244
|
+
activity.Description = 'Add Rental';
|
|
245
|
+
activity.EntityType = 'Rental';
|
|
246
|
+
activity.EntityId = this.RentalId;
|
|
247
|
+
activity.EntityValueBefore = JSON.stringify({});
|
|
248
|
+
activity.EntityValueAfter = JSON.stringify(data);
|
|
249
|
+
await activity.create(loginUser.ObjectId, dbTransaction);
|
|
250
|
+
|
|
251
|
+
/*Part 6: Return Result*/
|
|
252
|
+
return this;
|
|
253
|
+
} catch (error) {
|
|
254
|
+
throw error;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
public static async isItemAvailable(
|
|
259
|
+
itemId: string,
|
|
260
|
+
itemType: string,
|
|
261
|
+
startDateTime: Date,
|
|
262
|
+
endDateTime: Date,
|
|
263
|
+
dbTransaction?: any,
|
|
264
|
+
) {
|
|
265
|
+
try {
|
|
266
|
+
const item = await Rental._Repo.findOne({
|
|
267
|
+
where: {
|
|
268
|
+
ItemId: itemId,
|
|
269
|
+
ItemType: itemType,
|
|
270
|
+
StartDateTime: {
|
|
271
|
+
[Op.lte]: endDateTime,
|
|
272
|
+
},
|
|
273
|
+
EndDateTime: {
|
|
274
|
+
[Op.gte]: startDateTime,
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
transaction: dbTransaction,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
if (item) {
|
|
281
|
+
return false;
|
|
282
|
+
} else {
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
} catch (error) {
|
|
286
|
+
throw error;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
public static async findAll(
|
|
291
|
+
loginUser: LoginUser,
|
|
292
|
+
dbTransaction: any,
|
|
293
|
+
page?: number,
|
|
294
|
+
row?: number,
|
|
295
|
+
search?: IRentalFindAllSearchAttr,
|
|
296
|
+
) {
|
|
297
|
+
try {
|
|
298
|
+
const systemCode = await ApplicationConfig.getComponentConfigValue(
|
|
299
|
+
'system-code',
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
|
303
|
+
systemCode,
|
|
304
|
+
'Rental - View',
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
if (!isPrivileged) {
|
|
308
|
+
throw new ClassError(
|
|
309
|
+
'Rental',
|
|
310
|
+
'RentalErrMsg01',
|
|
311
|
+
"You do not have 'Rental - View' privilege.",
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const queryObj: any = {};
|
|
316
|
+
|
|
317
|
+
let options: any = {
|
|
318
|
+
transaction: dbTransaction,
|
|
319
|
+
order: [['CreatedAt', 'DESC']],
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
if (page && row) {
|
|
323
|
+
options = {
|
|
324
|
+
...options,
|
|
325
|
+
limit: row,
|
|
326
|
+
offset: row * (page - 1),
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (search) {
|
|
331
|
+
Object.entries(search).forEach(([key, value]) => {
|
|
332
|
+
if (key === 'StartDateTime') {
|
|
333
|
+
queryObj[key] = {
|
|
334
|
+
[Op.gte]: value,
|
|
335
|
+
};
|
|
336
|
+
} else if (key === 'EndDateTime') {
|
|
337
|
+
queryObj[key] = {
|
|
338
|
+
[Op.lte]: value,
|
|
339
|
+
};
|
|
340
|
+
} else if (key === 'CustomerId') {
|
|
341
|
+
queryObj[key] = {
|
|
342
|
+
[Op.substring]: value,
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
options.include = [
|
|
346
|
+
{
|
|
347
|
+
model: JointHirerModel,
|
|
348
|
+
required: false,
|
|
349
|
+
where: {
|
|
350
|
+
CustomerId: {
|
|
351
|
+
[Op.substring]: value,
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
];
|
|
356
|
+
} else {
|
|
357
|
+
queryObj[key] = {
|
|
358
|
+
[Op.substring]: value,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
if (options?.include?.length > 1) {
|
|
363
|
+
options.include.push({
|
|
364
|
+
model: AgreementModel,
|
|
365
|
+
required: false,
|
|
366
|
+
});
|
|
367
|
+
} else {
|
|
368
|
+
options.include = [
|
|
369
|
+
{
|
|
370
|
+
model: AgreementModel,
|
|
371
|
+
required: false,
|
|
372
|
+
},
|
|
373
|
+
];
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
options = {
|
|
377
|
+
...options,
|
|
378
|
+
where: queryObj,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return await Rental._Repo.findAndCountAll(options);
|
|
383
|
+
} catch (err) {
|
|
384
|
+
throw err;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
public static async checkActiveByItemId(
|
|
389
|
+
loginUser: LoginUser,
|
|
390
|
+
itemId: string,
|
|
391
|
+
itemType: string,
|
|
392
|
+
dbTransaction?: any,
|
|
393
|
+
) {
|
|
394
|
+
try {
|
|
395
|
+
const systemCode = await ApplicationConfig.getComponentConfigValue(
|
|
396
|
+
'system-code',
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
|
400
|
+
systemCode,
|
|
401
|
+
'Rental - View',
|
|
402
|
+
);
|
|
403
|
+
|
|
404
|
+
if (!isPrivileged) {
|
|
405
|
+
throw new ClassError(
|
|
406
|
+
'Rental',
|
|
407
|
+
'RentalErrMsg01',
|
|
408
|
+
"You do not have 'Rental - View' privilege.",
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const queryObj: any = {
|
|
413
|
+
ItemId: itemId,
|
|
414
|
+
ItemType: itemType,
|
|
415
|
+
Status: RentalStatusEnum.ACTIVE,
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
const options: any = {
|
|
419
|
+
transaction: dbTransaction,
|
|
420
|
+
where: queryObj,
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
const rental = await Rental._Repo.findOne(options);
|
|
424
|
+
|
|
425
|
+
if (rental) {
|
|
426
|
+
return true;
|
|
427
|
+
} else {
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
} catch (err) {
|
|
431
|
+
throw err;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Sets the StartDateTime property of the Rental class as custom setter.
|
|
437
|
+
* @param {Date} startDateTime - The start date and time of the rental.
|
|
438
|
+
* @throws {ClassError} Throws an error if:
|
|
439
|
+
* 1. startDateTime is a past date.
|
|
440
|
+
* 2. startDateTime is more than the EndDateTime.
|
|
441
|
+
* @returns {void}
|
|
442
|
+
*/
|
|
443
|
+
setStartDateTime(startDateTime: Date): void {
|
|
444
|
+
const startDateTimeObject = new Date(startDateTime);
|
|
445
|
+
startDateTimeObject.setHours(0, 0, 0, 0);
|
|
446
|
+
|
|
447
|
+
/*Part 1: Make Sure Future Date Time*/
|
|
448
|
+
if (startDateTimeObject < new Date(new Date().setHours(0, 0, 0, 0))) {
|
|
449
|
+
throw new ClassError(
|
|
450
|
+
'Rental',
|
|
451
|
+
'RentalErrMsg02',
|
|
452
|
+
'StartDateTime cannot be a past datetime.',
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/*Part 2: Make Sure Less Than End Date Time*/
|
|
457
|
+
if (this.EndDateTime && startDateTimeObject > this.EndDateTime) {
|
|
458
|
+
throw new ClassError(
|
|
459
|
+
'Rental',
|
|
460
|
+
'RentalErrMsg03',
|
|
461
|
+
'StartDateTime cannot be more than EndDateTime.',
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/*Part 3: Set Status Whether Reserved or Active*/
|
|
466
|
+
if (startDateTimeObject > new Date(new Date().setHours(0, 0, 0, 0))) {
|
|
467
|
+
this._Status = RentalStatusEnum.RESERVED;
|
|
468
|
+
} else {
|
|
469
|
+
this._Status = RentalStatusEnum.ACTIVE;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
public async periodEndProcess(
|
|
474
|
+
loginUser: LoginUser,
|
|
475
|
+
dbTransaction: any,
|
|
476
|
+
stockInventory: any,
|
|
477
|
+
) {
|
|
478
|
+
try {
|
|
479
|
+
// Privilege Checking
|
|
480
|
+
const systemCode = await ApplicationConfig.getComponentConfigValue(
|
|
481
|
+
'system-code',
|
|
482
|
+
);
|
|
483
|
+
|
|
484
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
|
485
|
+
systemCode,
|
|
486
|
+
'Rental – PeriodEndProcess',
|
|
487
|
+
);
|
|
488
|
+
|
|
489
|
+
if (!isPrivileged) {
|
|
490
|
+
throw new ClassError(
|
|
491
|
+
'Rental',
|
|
492
|
+
'RentalErrMsg04',
|
|
493
|
+
"You do not have 'Rental - PeriodEndProcess' privilege.",
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// Validate Existing Rental
|
|
498
|
+
if (this.AgreementNo === undefined || this.AgreementNo === null) {
|
|
499
|
+
throw new ClassError(
|
|
500
|
+
'Rental',
|
|
501
|
+
'RentalErrMsg05',
|
|
502
|
+
'Rental must be existing rental.',
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// Validate Rental End Period
|
|
507
|
+
if (this.EndDateTime === new Date(new Date().setHours(0, 0, 0, 0))) {
|
|
508
|
+
throw new ClassError(
|
|
509
|
+
'Rental',
|
|
510
|
+
'RentalErrMsg06',
|
|
511
|
+
'Rental period is not ending today.',
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// Mark Rental Item as Available
|
|
516
|
+
await stockInventory.setAvailable(loginUser, dbTransaction);
|
|
517
|
+
|
|
518
|
+
// Capture Record Info Before Changes
|
|
519
|
+
const entityValueBefore = {
|
|
520
|
+
RentalId: this.RentalId,
|
|
521
|
+
CustomerId: this.CustomerId,
|
|
522
|
+
CustomerType: this.CustomerType,
|
|
523
|
+
ItemId: this.ItemId,
|
|
524
|
+
ItemType: this.ItemType,
|
|
525
|
+
PriceId: this.PriceId,
|
|
526
|
+
StartDateTime: this.StartDateTime,
|
|
527
|
+
EndDateTime: this.EndDateTime,
|
|
528
|
+
CancelRemarks: this.CancelRemarks,
|
|
529
|
+
TerminateRemarks: this.TerminateRemarks,
|
|
530
|
+
AgreementNo: this.AgreementNo,
|
|
531
|
+
AccountType: this.AccountType,
|
|
532
|
+
Status: this.Status,
|
|
533
|
+
EscheatmentYN: this.EscheatmentYN,
|
|
534
|
+
CreatedById: this.CreatedById,
|
|
535
|
+
CreatedAt: this.CreatedAt,
|
|
536
|
+
UpdatedById: this.UpdatedById,
|
|
537
|
+
UpdatedAt: this.UpdatedAt,
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
// Mark Rental as Terminated and Capture Updater Info
|
|
541
|
+
this.setTerminated();
|
|
542
|
+
this._UpdatedById = loginUser.ObjectId;
|
|
543
|
+
this._UpdatedAt = new Date();
|
|
544
|
+
|
|
545
|
+
// Capture Record Info after Changes
|
|
546
|
+
const entityValueAfter = {
|
|
547
|
+
RentalId: this.RentalId,
|
|
548
|
+
CustomerId: this.CustomerId,
|
|
549
|
+
CustomerType: this.CustomerType,
|
|
550
|
+
ItemId: this.ItemId,
|
|
551
|
+
ItemType: this.ItemType,
|
|
552
|
+
PriceId: this.PriceId,
|
|
553
|
+
StartDateTime: this.StartDateTime,
|
|
554
|
+
EndDateTime: this.EndDateTime,
|
|
555
|
+
CancelRemarks: this.CancelRemarks,
|
|
556
|
+
TerminateRemarks: this.TerminateRemarks,
|
|
557
|
+
AgreementNo: this.AgreementNo,
|
|
558
|
+
AccountType: this.AccountType,
|
|
559
|
+
Status: this.Status,
|
|
560
|
+
EscheatmentYN: this.EscheatmentYN,
|
|
561
|
+
CreatedById: this.CreatedById,
|
|
562
|
+
CreatedAt: this.CreatedAt,
|
|
563
|
+
UpdatedById: this.UpdatedById,
|
|
564
|
+
UpdatedAt: this.UpdatedAt,
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
// Record the Update Activity
|
|
568
|
+
const activity = new Activity();
|
|
569
|
+
activity.ActivityId = activity.createId();
|
|
570
|
+
activity.Action = ActionEnum.UPDATE;
|
|
571
|
+
activity.Description = 'Set Rental as Terminated';
|
|
572
|
+
activity.EntityType = 'Rental';
|
|
573
|
+
activity.EntityId = this.RentalId;
|
|
574
|
+
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
|
575
|
+
activity.EntityValueAfter = JSON.stringify(entityValueAfter);
|
|
576
|
+
await activity.create(loginUser.ObjectId, dbTransaction);
|
|
577
|
+
|
|
578
|
+
return this;
|
|
579
|
+
} catch (err) {
|
|
580
|
+
throw err;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
async getCustomerActiveRentals(
|
|
585
|
+
loginUser: LoginUser,
|
|
586
|
+
dbTransaction: any,
|
|
587
|
+
CustomerId: string,
|
|
588
|
+
): Promise<IRentalAttr[]> {
|
|
589
|
+
try {
|
|
590
|
+
// Part 1: Privilege Checking
|
|
591
|
+
// Call loginUser.checkPrivileges() by passing:
|
|
592
|
+
// SystemCode: <get_from_app_config>
|
|
593
|
+
// PrivilegeCode: "RENTAL_VIEW"
|
|
594
|
+
const systemCode =
|
|
595
|
+
ApplicationConfig.getComponentConfigValue('system-code');
|
|
596
|
+
const isPrivileged = loginUser.checkPrivileges(systemCode, 'RENTAL_VIEW');
|
|
597
|
+
|
|
598
|
+
if (!isPrivileged) {
|
|
599
|
+
throw new ClassError(
|
|
600
|
+
'Rental',
|
|
601
|
+
'RentalErrMsg01',
|
|
602
|
+
"You do not have 'Rental - View' privilege.",
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// Part 2: Retrieve Rentals and Returns
|
|
607
|
+
// Call Rental._Repo findAll method by passing:
|
|
608
|
+
// where:
|
|
609
|
+
// Status: "Active"
|
|
610
|
+
// [Op.OR]:
|
|
611
|
+
// CustomerId: Params.CustomerId
|
|
612
|
+
// '$JointHirers.CustomerId$': Params.CustomerId
|
|
613
|
+
// include:
|
|
614
|
+
// model: JointHirerModel
|
|
615
|
+
// attributes: []
|
|
616
|
+
const query = `
|
|
617
|
+
SELECT
|
|
618
|
+
r.*
|
|
619
|
+
FROM
|
|
620
|
+
rental_Rental r
|
|
621
|
+
LEFT JOIN
|
|
622
|
+
rental_JointHirer jh ON r.RentalId = jh.RentalId
|
|
623
|
+
WHERE
|
|
624
|
+
r.Status = 'Active'
|
|
625
|
+
AND (
|
|
626
|
+
r.CustomerId = '${CustomerId}'
|
|
627
|
+
OR jh.CustomerId = '${CustomerId}'
|
|
628
|
+
);
|
|
629
|
+
`;
|
|
630
|
+
const db = rentalDb.getConnection();
|
|
631
|
+
const result = await db.query(query, {
|
|
632
|
+
type: QueryTypes.SELECT,
|
|
633
|
+
transaction: dbTransaction,
|
|
634
|
+
model: RentalModel,
|
|
635
|
+
mapToModel: true,
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
// Format the returned records
|
|
639
|
+
const records: IRentalAttr[] = result.map((record: RentalModel) => {
|
|
640
|
+
return {
|
|
641
|
+
RentalId: record.RentalId,
|
|
642
|
+
CustomerId: record.CustomerId,
|
|
643
|
+
CustomerType: record.CustomerType,
|
|
644
|
+
ItemId: record.ItemId,
|
|
645
|
+
ItemType: record.ItemType,
|
|
646
|
+
PriceId: record.PriceId,
|
|
647
|
+
StartDateTime: record.StartDateTime,
|
|
648
|
+
EndDateTime: record.EndDateTime,
|
|
649
|
+
CancelRemarks: record.CancelRemarks,
|
|
650
|
+
TerminateRemarks: record.TerminateRemarks,
|
|
651
|
+
AgreementNo: record.AgreementNo,
|
|
652
|
+
AccountType: record.AccountType,
|
|
653
|
+
Status: record.Status,
|
|
654
|
+
EscheatmentYN: record.EscheatmentYN,
|
|
655
|
+
CreatedById: record.CreatedById,
|
|
656
|
+
CreatedAt: record.CreatedAt,
|
|
657
|
+
UpdatedById: record.UpdatedById,
|
|
658
|
+
UpdatedAt: record.UpdatedAt,
|
|
659
|
+
};
|
|
660
|
+
});
|
|
661
|
+
// Return the returned records.
|
|
662
|
+
return records;
|
|
663
|
+
} catch (error) {
|
|
664
|
+
throw error;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
async getCustomerIds(loginUser: LoginUser, dbTransaction: any) {
|
|
669
|
+
try {
|
|
670
|
+
// Part 1: Privilege Checking
|
|
671
|
+
// Call loginUser.checkPrivileges() by passing:
|
|
672
|
+
// SystemCode: <get_from_app_config>
|
|
673
|
+
// PrivilegeCode: "RENTAL_VIEW"
|
|
674
|
+
const systemCode =
|
|
675
|
+
ApplicationConfig.getComponentConfigValue('system-code');
|
|
676
|
+
const isPrivileged = loginUser.checkPrivileges(systemCode, 'RENTAL_VIEW');
|
|
677
|
+
|
|
678
|
+
if (!isPrivileged) {
|
|
679
|
+
throw new ClassError(
|
|
680
|
+
'Rental',
|
|
681
|
+
'RentalErrMsg01',
|
|
682
|
+
"You do not have 'Rental - View' privilege.",
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// Part 2: Validation
|
|
687
|
+
// Make sure this.RentalId exists, if not throw new ClassError by passing
|
|
688
|
+
if (!this.RentalId) {
|
|
689
|
+
throw new ClassError('Rental', 'RentalErrMsg01', 'RentalId is missing');
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
//Part 3: Retrieve Listing and Returns
|
|
693
|
+
// 3.1 Call Rental._JointHirerRepo findAll method by passing:
|
|
694
|
+
// where:
|
|
695
|
+
// RentalId: this.RentalId
|
|
696
|
+
// dbTransaction
|
|
697
|
+
const options: any = {
|
|
698
|
+
where: {
|
|
699
|
+
RentalId: this.RentalId,
|
|
700
|
+
},
|
|
701
|
+
transaction: dbTransaction,
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
const joinHirers = await Rental._JointHirerRepo.findAll(options);
|
|
705
|
+
|
|
706
|
+
// 3.2 Create a new array variable and set its value to joint hirer and Rental.CustomerId
|
|
707
|
+
// array translated to only CustomerId. Then, append this.CustomerId to the array.
|
|
708
|
+
const customerIds: string[] = [this.CustomerId];
|
|
709
|
+
for (let i = 0; i < joinHirers.length; i++) {
|
|
710
|
+
const jointHirer = joinHirers[i];
|
|
711
|
+
customerIds.push(jointHirer.CustomerId);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// 3.3 Return the array.
|
|
715
|
+
return customerIds;
|
|
716
|
+
} catch (error) {
|
|
717
|
+
throw error;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|