diff --git a/src/app/savings/common-resolvers/savings-account-actions.resolver.ts b/src/app/savings/common-resolvers/savings-account-actions.resolver.ts index cabd13903..d34e6da64 100644 --- a/src/app/savings/common-resolvers/savings-account-actions.resolver.ts +++ b/src/app/savings/common-resolvers/savings-account-actions.resolver.ts @@ -34,6 +34,7 @@ export class SavingsAccountActionsResolver implements Resolve { return this.savingsService.getSavingsChargeTemplateResource(savingAccountId); case 'Withdrawal': case 'Deposit': + case 'Close': return this.savingsService.getSavingsTransactionTemplateResource(savingAccountId); default: return undefined; diff --git a/src/app/savings/saving-account-actions/close-savings-account/close-savings-account.component.html b/src/app/savings/saving-account-actions/close-savings-account/close-savings-account.component.html new file mode 100644 index 000000000..ff151496a --- /dev/null +++ b/src/app/savings/saving-account-actions/close-savings-account/close-savings-account.component.html @@ -0,0 +1,98 @@ +
+ + + +
+ + + +
+ + + Closed On Date + + + + + Closed On Date is required + + + + + Withdraw Balance + + + + Is Interest Posting required on closure date? + + +
+ + + Transaction Amount + + + + + Payment Type + + + {{ paymentType.name }} + + + + +
+ Show Payment Details + +
+ + + Account Number + + + + + Cheque + + + + + Routing Code + + + + + Receipt Number + + + + + Bank + + + +
+ + + Note + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/savings/saving-account-actions/close-savings-account/close-savings-account.component.scss b/src/app/savings/saving-account-actions/close-savings-account/close-savings-account.component.scss new file mode 100644 index 000000000..d774f68da --- /dev/null +++ b/src/app/savings/saving-account-actions/close-savings-account/close-savings-account.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; +} diff --git a/src/app/savings/saving-account-actions/close-savings-account/close-savings-account.component.spec.ts b/src/app/savings/saving-account-actions/close-savings-account/close-savings-account.component.spec.ts new file mode 100644 index 000000000..9fb323a67 --- /dev/null +++ b/src/app/savings/saving-account-actions/close-savings-account/close-savings-account.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CloseSavingsAccountComponent } from './close-savings-account.component'; + +describe('CloseSavingsAccountComponent', () => { + let component: CloseSavingsAccountComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CloseSavingsAccountComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CloseSavingsAccountComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/savings/saving-account-actions/close-savings-account/close-savings-account.component.ts b/src/app/savings/saving-account-actions/close-savings-account/close-savings-account.component.ts new file mode 100644 index 000000000..3b7bd97e5 --- /dev/null +++ b/src/app/savings/saving-account-actions/close-savings-account/close-savings-account.component.ts @@ -0,0 +1,133 @@ +/** Angular Imports */ +import { Component, OnInit } from '@angular/core'; +import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms'; +import { DatePipe } from '@angular/common'; +import { ActivatedRoute, Router } from '@angular/router'; + +/** Custom Services */ +import { SavingsService } from 'app/savings/savings.service'; + +/** + * Close Savings Account Component + */ +@Component({ + selector: 'mifosx-close-savings-account', + templateUrl: './close-savings-account.component.html', + styleUrls: ['./close-savings-account.component.scss'] +}) +export class CloseSavingsAccountComponent implements OnInit { + + /** Minimum date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum date allowed. */ + maxDate = new Date(); + /** Close Savings Account form. */ + closeSavingsAccountForm: FormGroup; + /** Savings Account Id */ + accountId: any; + /** Flag to enable payment details fields. */ + addPaymentDetailsFlag = false; + /** Payment Type Options */ + paymentTypeOptions: any; + /** Transaction Amount */ + transactionAmount: any; + + /** + * @param {FormBuilder} formBuilder Form Builder + * @param {SavingsService} savingsService Savings Service + * @param {DatePipe} datePipe Date Pipe + * @param {ActivatedRoute} route Activated Route + * @param {Router} router Router + */ + constructor(private formBuilder: FormBuilder, + private savingsService: SavingsService, + private datePipe: DatePipe, + private route: ActivatedRoute, + private router: Router) { + this.route.data.subscribe((data: { savingsAccountActionData: any }) => { + this.paymentTypeOptions = data.savingsAccountActionData.paymentTypeOptions; + }); + this.route.parent.data.subscribe((data: { savingsAccountData: any }) => { + this.transactionAmount = data.savingsAccountData.summary.accountBalance; + }); + this.accountId = this.route.parent.snapshot.params['savingAccountId']; + } + + /** + * Creates the close savings form. + */ + ngOnInit() { + this.createCloseSavingsAccountForm(); + this.buildDependencies(); + } + + /** + * Creates the close savings account form. + */ + createCloseSavingsAccountForm() { + this.closeSavingsAccountForm = this.formBuilder.group({ + 'closedOnDate': ['', Validators.required], + 'withdrawBalance': [false], + 'postInterestValidationOnClosure': [false], + 'note': [''] + }); + } + + /** + * Subscribe to value changes of withdraw balance checkbox. + */ + buildDependencies() { + this.closeSavingsAccountForm.get('withdrawBalance').valueChanges.subscribe((value: boolean) => { + if (value) { + this.closeSavingsAccountForm.addControl('amount', new FormControl({value: this.transactionAmount, disabled: true})); + this.closeSavingsAccountForm.addControl('paymentTypeId', new FormControl('')); + } else { + this.closeSavingsAccountForm.removeControl('amount'); + this.closeSavingsAccountForm.removeControl('paymentTypeId'); + } + }); + } + + /** + * Method to add payment detail fields to the UI. + */ + addPaymentDetails() { + this.addPaymentDetailsFlag = !this.addPaymentDetailsFlag; + if (this.addPaymentDetailsFlag) { + this.closeSavingsAccountForm.addControl('accountNumber', new FormControl('')); + this.closeSavingsAccountForm.addControl('checkNumber', new FormControl('')); + this.closeSavingsAccountForm.addControl('routingCode', new FormControl('')); + this.closeSavingsAccountForm.addControl('receiptNumber', new FormControl('')); + this.closeSavingsAccountForm.addControl('bankNumber', new FormControl('')); + } else { + this.closeSavingsAccountForm.removeControl('accountNumber'); + this.closeSavingsAccountForm.removeControl('checkNumber'); + this.closeSavingsAccountForm.removeControl('routingCode'); + this.closeSavingsAccountForm.removeControl('receiptNumber'); + this.closeSavingsAccountForm.removeControl('bankNumber'); + } + } + + /** + * Submits the form and closes the saving account, + * if successful redirects to the saving account. + */ + submit() { + // TODO: Update once language and date settings are setup + const locale = 'en'; + const dateFormat = 'dd MMMM yyyy'; + const prevClosedOnDate: Date = this.closeSavingsAccountForm.value.closedOnDate; + this.closeSavingsAccountForm.patchValue({ + closedOnDate: this.datePipe.transform(prevClosedOnDate, dateFormat), + }); + const data = { + ...this.closeSavingsAccountForm.value, + dateFormat, + locale + }; + this.savingsService.executeSavingsAccountCommand(this.accountId, 'close', data).subscribe(() => { + this.router.navigate(['../../'], { relativeTo: this.route }); + }); + } + +} diff --git a/src/app/savings/saving-account-actions/saving-account-actions.component.html b/src/app/savings/saving-account-actions/saving-account-actions.component.html index f7f091dd8..77729545c 100644 --- a/src/app/savings/saving-account-actions/saving-account-actions.component.html +++ b/src/app/savings/saving-account-actions/saving-account-actions.component.html @@ -8,3 +8,4 @@ + diff --git a/src/app/savings/saving-account-actions/saving-account-actions.component.ts b/src/app/savings/saving-account-actions/saving-account-actions.component.ts index 933354c80..7b481a50b 100644 --- a/src/app/savings/saving-account-actions/saving-account-actions.component.ts +++ b/src/app/savings/saving-account-actions/saving-account-actions.component.ts @@ -19,6 +19,7 @@ export class SavingAccountActionsComponent { 'Withdrawal': boolean 'Deposit': boolean 'Activate': boolean + 'Close': boolean 'Undo Approval': boolean 'Post Interest As On': boolean 'Assign Staff': boolean // savings account and template @@ -31,6 +32,7 @@ export class SavingAccountActionsComponent { 'Withdrawal': false, 'Deposit': false, 'Activate': false, + 'Close': false, 'Undo Approval': false, 'Post Interest As On': false, 'Assign Staff': false, diff --git a/src/app/savings/saving-account-actions/savings-account-transactions/savings-account-transactions.component.html b/src/app/savings/saving-account-actions/savings-account-transactions/savings-account-transactions.component.html index 7240be343..3d32c5322 100644 --- a/src/app/savings/saving-account-actions/savings-account-transactions/savings-account-transactions.component.html +++ b/src/app/savings/saving-account-actions/savings-account-transactions/savings-account-transactions.component.html @@ -40,7 +40,7 @@
Show Payment Details
diff --git a/src/app/savings/savings-account-view/savings-account-view.component.ts b/src/app/savings/savings-account-view/savings-account-view.component.ts index 875054600..e54d74210 100644 --- a/src/app/savings/savings-account-view/savings-account-view.component.ts +++ b/src/app/savings/savings-account-view/savings-account-view.component.ts @@ -108,6 +108,7 @@ export class SavingsAccountViewComponent implements OnInit { case 'Reject': case 'Deposit': case 'Activate': + case 'Close': case 'Undo Approval': case 'Post Interest As On': case 'Assign Staff': diff --git a/src/app/savings/savings-routing.module.ts b/src/app/savings/savings-routing.module.ts index cdeb4a4e8..79c569ebe 100644 --- a/src/app/savings/savings-routing.module.ts +++ b/src/app/savings/savings-routing.module.ts @@ -51,7 +51,6 @@ const routes: Routes = [ path: '', component: SavingsAccountViewComponent, resolve: { - savingsAccountData: SavingsAccountViewResolver, savingsDatatables: SavingsDatatablesResolver }, children: [ diff --git a/src/app/savings/savings.module.ts b/src/app/savings/savings.module.ts index bd3ea17c8..11e53f9b9 100644 --- a/src/app/savings/savings.module.ts +++ b/src/app/savings/savings.module.ts @@ -40,6 +40,7 @@ import { WaiveChargeDialogComponent } from './savings-account-view/custom-dialog import { InactivateChargeDialogComponent } from './savings-account-view/custom-dialogs/inactivate-charge-dialog/inactivate-charge-dialog.component'; import { WithdrawByClientSavingsAccountComponent } from './saving-account-actions/withdraw-by-client-savings-account/withdraw-by-client-savings-account.component'; import { AddChargeSavingsAccountComponent } from './saving-account-actions/add-charge-savings-account/add-charge-savings-account.component'; +import { CloseSavingsAccountComponent } from './saving-account-actions/close-savings-account/close-savings-account.component'; /** @@ -85,7 +86,8 @@ import { AddChargeSavingsAccountComponent } from './saving-account-actions/add-c WaiveChargeDialogComponent, InactivateChargeDialogComponent, WithdrawByClientSavingsAccountComponent, - AddChargeSavingsAccountComponent + AddChargeSavingsAccountComponent, + CloseSavingsAccountComponent ], entryComponents: [ CalculateInterestDialogComponent,