1
- import { Component , Input , OnInit } from '@angular/core' ;
1
+ import { Component , Input , OnChanges , OnInit , SimpleChanges } from '@angular/core' ;
2
2
import { UntypedFormArray , UntypedFormBuilder , UntypedFormControl , UntypedFormGroup , Validators } from '@angular/forms' ;
3
3
import { MatDialog } from '@angular/material/dialog' ;
4
4
@@ -9,16 +9,18 @@ import { TranslateService } from '@ngx-translate/core';
9
9
import { FormfieldBase } from 'app/shared/form-dialog/formfield/model/formfield-base' ;
10
10
import { SelectBase } from 'app/shared/form-dialog/formfield/model/select-base' ;
11
11
import { ChargeOffReasonToExpenseAccountMapping } from 'app/shared/models/general.model' ;
12
+ import { CapitalizedIncome } from '../loan-product-payment-strategy-step/payment-allocation-model' ;
12
13
13
14
@Component ( {
14
15
selector : 'mifosx-loan-product-accounting-step' ,
15
16
templateUrl : './loan-product-accounting-step.component.html' ,
16
17
styleUrls : [ './loan-product-accounting-step.component.scss' ]
17
18
} )
18
- export class LoanProductAccountingStepComponent implements OnInit {
19
+ export class LoanProductAccountingStepComponent implements OnInit , OnChanges {
19
20
@Input ( ) loanProductsTemplate : any ;
20
21
@Input ( ) accountingRuleData : any ;
21
22
@Input ( ) loanProductFormValid : boolean ;
23
+ @Input ( ) capitalizedIncome : CapitalizedIncome ;
22
24
23
25
loanProductAccountingForm : UntypedFormGroup ;
24
26
@@ -61,6 +63,10 @@ export class LoanProductAccountingStepComponent implements OnInit {
61
63
this . setConditionalControls ( ) ;
62
64
}
63
65
66
+ ngOnChanges ( changes : SimpleChanges ) : void {
67
+ this . setCapitalizedIncomeControls ( ) ;
68
+ }
69
+
64
70
ngOnInit ( ) {
65
71
this . chargeData = this . loanProductsTemplate . chargeOptions || [ ] ;
66
72
this . penaltyData = this . loanProductsTemplate . penaltyOptions || [ ] ;
@@ -79,6 +85,7 @@ export class LoanProductAccountingStepComponent implements OnInit {
79
85
} ) ;
80
86
81
87
const accountingMappings = this . loanProductsTemplate . accountingMappings ;
88
+ this . setCapitalizedIncomeControls ( ) ;
82
89
switch ( this . loanProductsTemplate . accountingRule . id ) {
83
90
case 3 :
84
91
case 4 :
@@ -90,6 +97,12 @@ export class LoanProductAccountingStepComponent implements OnInit {
90
97
this . loanProductAccountingForm . patchValue ( {
91
98
enableAccrualActivityPosting : this . loanProductsTemplate . enableAccrualActivityPosting
92
99
} ) ;
100
+ if ( this . capitalizedIncome . enableIncomeCapitalization ) {
101
+ this . loanProductAccountingForm . patchValue ( {
102
+ deferredIncomeLiabilityAccountId : accountingMappings . deferredIncomeLiabilityAccount . id ,
103
+ incomeFromCapitalizationAccountId : accountingMappings . incomeFromCapitalizationAccount . id
104
+ } ) ;
105
+ }
93
106
/* falls through */
94
107
case 2 :
95
108
this . loanProductAccountingForm . patchValue ( {
@@ -524,4 +537,22 @@ export class LoanProductAccountingStepComponent implements OnInit {
524
537
get loanProductAccounting ( ) {
525
538
return this . loanProductAccountingForm . value ;
526
539
}
540
+
541
+ setCapitalizedIncomeControls ( ) {
542
+ if ( this . isAccountingAccrualBased ) {
543
+ if ( this . capitalizedIncome . enableIncomeCapitalization ) {
544
+ this . loanProductAccountingForm . addControl (
545
+ 'deferredIncomeLiabilityAccountId' ,
546
+ new UntypedFormControl ( '' , Validators . required )
547
+ ) ;
548
+ this . loanProductAccountingForm . addControl (
549
+ 'incomeFromCapitalizationAccountId' ,
550
+ new UntypedFormControl ( '' , Validators . required )
551
+ ) ;
552
+ } else {
553
+ this . loanProductAccountingForm . removeControl ( 'deferredIncomeLiabilityAccountId' ) ;
554
+ this . loanProductAccountingForm . removeControl ( 'incomeFromCapitalizationAccountId' ) ;
555
+ }
556
+ }
557
+ }
527
558
}
0 commit comments