1
1
import { Component , EventEmitter , Input , OnInit , Output , ViewChild } from '@angular/core' ;
2
- import { AdvancedPaymentAllocation , AdvancedPaymentStrategy , CreditAllocationOrder , FutureInstallmentAllocationRule , PaymentAllocationOrder , PaymentAllocationTransactionType } from '../payment-allocation-model' ;
2
+ import { AdvancedCreditAllocation , AdvancedPaymentAllocation , AdvancedPaymentStrategy , CreditAllocationOrder , FutureInstallmentAllocationRule , PaymentAllocationOrder , PaymentAllocationTransactionType } from '../payment-allocation-model' ;
3
3
import { CdkDragDrop , moveItemInArray } from '@angular/cdk/drag-drop' ;
4
4
import { MatTable } from '@angular/material/table' ;
5
5
import { MatDialog } from '@angular/material/dialog' ;
@@ -14,15 +14,16 @@ import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.co
14
14
export class AdvancePaymentAllocationTabComponent implements OnInit {
15
15
16
16
@Input ( ) advancedPaymentAllocation : AdvancedPaymentAllocation ;
17
+ @Input ( ) advancedCreditAllocation : AdvancedCreditAllocation ;
17
18
18
- @Output ( ) paymentAllocationChange = new EventEmitter < boolean > ( ) ;
19
+ @Output ( ) allocationChanged = new EventEmitter < boolean > ( ) ;
19
20
@Output ( ) transactionTypeRemoved = new EventEmitter < PaymentAllocationTransactionType > ( ) ;
20
21
21
22
paymentAllocationsData : PaymentAllocationOrder [ ] | null = null ;
22
23
creditAllocationsData : CreditAllocationOrder [ ] | null = null ;
23
24
24
25
/** Columns to be displayed in the table. */
25
- displayedColumns : string [ ] = [ 'actions' , 'order' , 'paymentAllocation ' ] ;
26
+ displayedColumns : string [ ] = [ 'actions' , 'order' , 'allocationRule ' ] ;
26
27
27
28
futureInstallmentAllocationRule = new UntypedFormControl ( '' , Validators . required ) ;
28
29
@@ -32,22 +33,21 @@ export class AdvancePaymentAllocationTabComponent implements OnInit {
32
33
private advancedPaymentStrategy : AdvancedPaymentStrategy ) { }
33
34
34
35
ngOnInit ( ) : void {
35
- console . log ( this . advancedPaymentAllocation ) ;
36
+ if ( this . advancedCreditAllocation ) {
37
+ this . creditAllocationsData = this . advancedCreditAllocation ?. creditAllocationOrder ;
38
+ }
39
+
36
40
if ( this . advancedPaymentAllocation ) {
37
- if ( this . advancedPaymentAllocation . creditAllocationOrder ) {
38
- this . creditAllocationsData = this . advancedPaymentAllocation . creditAllocationOrder ;
39
- }
40
- if ( this . advancedPaymentAllocation . paymentAllocationOrder ) {
41
- this . paymentAllocationsData = this . advancedPaymentAllocation . paymentAllocationOrder ;
42
- }
41
+ this . paymentAllocationsData = this . advancedPaymentAllocation ?. paymentAllocationOrder ;
42
+
43
43
if ( this . advancedPaymentAllocation . futureInstallmentAllocationRule ) {
44
44
this . futureInstallmentAllocationRule . patchValue ( this . advancedPaymentAllocation . futureInstallmentAllocationRule . code ) ;
45
45
}
46
46
this . futureInstallmentAllocationRule . valueChanges . subscribe ( ( value : any ) => {
47
47
this . advancedPaymentAllocation . futureInstallmentAllocationRules . forEach ( ( item : FutureInstallmentAllocationRule ) => {
48
48
if ( value === item . code ) {
49
49
this . advancedPaymentAllocation . futureInstallmentAllocationRule = item ;
50
- this . paymentAllocationChange . emit ( true ) ;
50
+ this . allocationChanged . emit ( true ) ;
51
51
}
52
52
} ) ;
53
53
} ) ;
@@ -61,14 +61,14 @@ export class AdvancePaymentAllocationTabComponent implements OnInit {
61
61
this . paymentAllocationsData = [ ...this . paymentAllocationsData ] ;
62
62
this . advancedPaymentAllocation . paymentAllocationOrder = this . paymentAllocationsData ;
63
63
this . table . renderRows ( ) ;
64
- this . paymentAllocationChange . emit ( true ) ;
64
+ this . allocationChanged . emit ( true ) ;
65
65
} else {
66
66
const prevIndex = this . creditAllocationsData . findIndex ( ( d : any ) => d === event . item . data ) ;
67
67
moveItemInArray ( this . creditAllocationsData , prevIndex , event . currentIndex ) ;
68
68
this . creditAllocationsData = [ ...this . creditAllocationsData ] ;
69
- this . advancedPaymentAllocation . creditAllocationOrder = this . creditAllocationsData ;
69
+ this . advancedCreditAllocation . creditAllocationOrder = this . creditAllocationsData ;
70
70
this . table . renderRows ( ) ;
71
- this . paymentAllocationChange . emit ( true ) ;
71
+ this . allocationChanged . emit ( true ) ;
72
72
}
73
73
}
74
74
@@ -80,12 +80,19 @@ export class AdvancePaymentAllocationTabComponent implements OnInit {
80
80
}
81
81
82
82
removeTransaction ( ) : void {
83
+ let transaction : PaymentAllocationTransactionType = null ;
84
+ if ( this . advancedPaymentAllocation && this . advancedPaymentAllocation . transaction ) {
85
+ transaction = this . advancedPaymentAllocation . transaction ;
86
+ } else if ( this . advancedCreditAllocation && this . advancedCreditAllocation . transaction ) {
87
+ transaction = this . advancedCreditAllocation . transaction ;
88
+ transaction . credit = true ;
89
+ }
83
90
const dialogRef = this . dialog . open ( DeleteDialogComponent , {
84
- data : { deleteContext : ` the Transaction Type ${ this . advancedPaymentAllocation . transaction . value } ` }
91
+ data : { deleteContext : ` the Transaction Type ${ transaction . value } ` }
85
92
} ) ;
86
93
dialogRef . afterClosed ( ) . subscribe ( ( response : any ) => {
87
94
if ( response . delete ) {
88
- this . transactionTypeRemoved . emit ( this . advancedPaymentAllocation . transaction ) ;
95
+ this . transactionTypeRemoved . emit ( transaction ) ;
89
96
}
90
97
} ) ;
91
98
}
0 commit comments