From efac58fc6859e0168a4fdc6ee3959c5733c13ef5 Mon Sep 17 00:00:00 2001 From: Karan Takalkar Date: Sun, 5 Jul 2020 17:54:27 +0530 Subject: [PATCH] feat: fixed deposit account actions (close) (#997) Fixes: #996 --- .../fixed-deposit-account-actions.resolver.ts | 7 +- ...lose-fixed-deposits-account.component.html | 73 +++++++++++ ...lose-fixed-deposits-account.component.scss | 3 + ...e-fixed-deposits-account.component.spec.ts | 25 ++++ .../close-fixed-deposits-account.component.ts | 113 ++++++++++++++++++ ...ed-deposits-account-actions.component.html | 2 +- .../fixed-deposits/fixed-deposits.module.ts | 4 +- .../fixed-deposits/fixed-deposits.service.ts | 15 ++- 8 files changed, 236 insertions(+), 6 deletions(-) create mode 100644 src/app/deposits/fixed-deposits/fixed-deposits-account-actions/close-fixed-deposits-account/close-fixed-deposits-account.component.html create mode 100644 src/app/deposits/fixed-deposits/fixed-deposits-account-actions/close-fixed-deposits-account/close-fixed-deposits-account.component.scss create mode 100644 src/app/deposits/fixed-deposits/fixed-deposits-account-actions/close-fixed-deposits-account/close-fixed-deposits-account.component.spec.ts create mode 100644 src/app/deposits/fixed-deposits/fixed-deposits-account-actions/close-fixed-deposits-account/close-fixed-deposits-account.component.ts diff --git a/src/app/deposits/fixed-deposits/common-resolvers/fixed-deposit-account-actions.resolver.ts b/src/app/deposits/fixed-deposits/common-resolvers/fixed-deposit-account-actions.resolver.ts index afba75ed8..5273850b6 100644 --- a/src/app/deposits/fixed-deposits/common-resolvers/fixed-deposit-account-actions.resolver.ts +++ b/src/app/deposits/fixed-deposits/common-resolvers/fixed-deposit-account-actions.resolver.ts @@ -7,6 +7,7 @@ import { Observable } from 'rxjs'; /** Custom Services */ import { SavingsService } from 'app/savings/savings.service'; +import { FixedDepositsService } from '../fixed-deposits.service'; /** * Fixed Deposits Account Actions data resolver. @@ -16,8 +17,10 @@ export class FixedDepositsAccountActionsResolver implements Resolve { /** * @param {SavingsService} SavingsService Savings service. + * @param {FixedDepositsService} fixedDepositsService Fixed Deposits Service. */ - constructor(private savingsService: SavingsService) { } + constructor(private savingsService: SavingsService, + private fixedDepositsService: FixedDepositsService) { } /** * Returns the Fixed deposits account actions data. @@ -30,6 +33,8 @@ export class FixedDepositsAccountActionsResolver implements Resolve { switch (actionName) { case 'Add Charge': return this.savingsService.getSavingsChargeTemplateResource(fixedDepositAccountId); + case 'Close': + return this.fixedDepositsService.getFixedDepositsAccountClosureTemplate(fixedDepositAccountId); default: return undefined; } diff --git a/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/close-fixed-deposits-account/close-fixed-deposits-account.component.html b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/close-fixed-deposits-account/close-fixed-deposits-account.component.html new file mode 100644 index 000000000..c7fb1e2cd --- /dev/null +++ b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/close-fixed-deposits-account/close-fixed-deposits-account.component.html @@ -0,0 +1,73 @@ +
+ + + +
+ + + +
+ + + Closed On Date + + + + + Closed On Date is required + + + + + Maturity Amount + + + + + Action + + + {{ closureOption.value }} + + + + Account action is required + + + + + Transfer to Savings + + + {{ account.accountNo }} + + + + Transfer to savings account is required + + + + + Transfer Description + + + + + Note + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/close-fixed-deposits-account/close-fixed-deposits-account.component.scss b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/close-fixed-deposits-account/close-fixed-deposits-account.component.scss new file mode 100644 index 000000000..d774f68da --- /dev/null +++ b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/close-fixed-deposits-account/close-fixed-deposits-account.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; +} diff --git a/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/close-fixed-deposits-account/close-fixed-deposits-account.component.spec.ts b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/close-fixed-deposits-account/close-fixed-deposits-account.component.spec.ts new file mode 100644 index 000000000..85534634c --- /dev/null +++ b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/close-fixed-deposits-account/close-fixed-deposits-account.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CloseFixedDepositsAccountComponent } from './close-fixed-deposits-account.component'; + +describe('CloseFixedDepositsAccountComponent', () => { + let component: CloseFixedDepositsAccountComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CloseFixedDepositsAccountComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CloseFixedDepositsAccountComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/close-fixed-deposits-account/close-fixed-deposits-account.component.ts b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/close-fixed-deposits-account/close-fixed-deposits-account.component.ts new file mode 100644 index 000000000..40bbde526 --- /dev/null +++ b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/close-fixed-deposits-account/close-fixed-deposits-account.component.ts @@ -0,0 +1,113 @@ +/** 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 { FixedDepositsService } from '../../fixed-deposits.service'; + +/** + * Close On Maturity Fixed Deposits Account Component + */ +@Component({ + selector: 'mifosx-close-fixed-deposits-account', + templateUrl: './close-fixed-deposits-account.component.html', + styleUrls: ['./close-fixed-deposits-account.component.scss'] +}) +export class CloseFixedDepositsAccountComponent implements OnInit { + + /** Minimum date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum date allowed. */ + maxDate = new Date(); + /** Close on maturity FD Account form. */ + closeOnMaturityAccountForm: FormGroup; + /** Savings Account Data */ + savingsAccountsData: any; + /** On account Closure Options */ + onAccountClosureOptions: any; + /** Fixed Deposits Account Id */ + accountId: any; + /** Maturity Amount */ + maturityAmount: any; + + /** + * Fetches close action data from `resolve` + * @param {FormBuilder} formBuilder Form Builder + * @param {FixedDepositsService} fixedDepositsService Fixed Deposits Service + * @param {DatePipe} datePipe Date Pipe + * @param {ActivatedRoute} route Activated Route + * @param {Router} router Router + */ + constructor(private formBuilder: FormBuilder, + private fixedDepositsService: FixedDepositsService, + private datePipe: DatePipe, + private route: ActivatedRoute, + private router: Router) { + this.route.data.subscribe((data: { fixedDepositsAccountActionData: any }) => { + this.savingsAccountsData = data.fixedDepositsAccountActionData.savingsAccounts; + this.onAccountClosureOptions = data.fixedDepositsAccountActionData.onAccountClosureOptions; + this.maturityAmount = data.fixedDepositsAccountActionData.maturityAmount; + }); + this.accountId = this.route.parent.snapshot.params['fixedDepositAccountId']; + } + + /** + * Creates the close on maturity fd account form. + */ + ngOnInit() { + this.createCloseOnMaturityAccountForm(); + this.addTransferDetails(); + } + + /** + * Creates the close on maturity fd account form. + */ + createCloseOnMaturityAccountForm() { + this.closeOnMaturityAccountForm = this.formBuilder.group({ + 'closedOnDate': ['', Validators.required], + 'maturityAmount': [{value: this.maturityAmount, disabled: true}], + 'onAccountClosureId': ['', Validators.required], + 'note': [''] + }); + } + + /** + * Subscribes to value changes of `onAccountClosureId` adds and removes transfer details accordingly. + */ + addTransferDetails() { + this.closeOnMaturityAccountForm.get('onAccountClosureId').valueChanges.subscribe((id: any) => { + if (id === 200) { + this.closeOnMaturityAccountForm.addControl('toSavingsAccountId', new FormControl('', Validators.required)); + this.closeOnMaturityAccountForm.addControl('transferDescription', new FormControl('')); + } else { + this.closeOnMaturityAccountForm.removeControl('toSavingsAccountId'); + this.closeOnMaturityAccountForm.removeControl('transferDescription'); + } + }); + } + + /** + * Submits the form and close the fd account on maturity, + * if successful redirects to the fd account. + */ + submit() { + // TODO: Update once language and date settings are setup + const locale = 'en'; + const dateFormat = 'dd MMMM yyyy'; + const prevClosedDate: Date = this.closeOnMaturityAccountForm.value.closedOnDate; + this.closeOnMaturityAccountForm.patchValue({ + closedOnDate: this.datePipe.transform(prevClosedDate, dateFormat), + }); + const data = { + ...this.closeOnMaturityAccountForm.value, + dateFormat, + locale + }; + this.fixedDepositsService.executeFixedDepositsAccountCommand(this.accountId, 'close', data).subscribe(() => { + this.router.navigate(['../../'], { relativeTo: this.route }); + }); + } + +} diff --git a/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/fixed-deposits-account-actions.component.html b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/fixed-deposits-account-actions.component.html index 89052f951..4d25bd076 100644 --- a/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/fixed-deposits-account-actions.component.html +++ b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/fixed-deposits-account-actions.component.html @@ -5,4 +5,4 @@ - + diff --git a/src/app/deposits/fixed-deposits/fixed-deposits.module.ts b/src/app/deposits/fixed-deposits/fixed-deposits.module.ts index 8c57a7033..96cd36dc2 100644 --- a/src/app/deposits/fixed-deposits/fixed-deposits.module.ts +++ b/src/app/deposits/fixed-deposits/fixed-deposits.module.ts @@ -31,6 +31,7 @@ import { WaiveChargeDialogComponent } from './fixed-deposit-account-view/custom- import { InactivateChargeDialogComponent } from './fixed-deposit-account-view/custom-dialogs/inactivate-charge-dialog/inactivate-charge-dialog.component'; import { AddChargeFixedDepositsAccountComponent } from './fixed-deposits-account-actions/add-charge-fixed-deposits-account/add-charge-fixed-deposits-account.component'; import { PrematureCloseFixedDepositsAccountComponent } from './fixed-deposits-account-actions/premature-close-fixed-deposits-account/premature-close-fixed-deposits-account.component'; +import { CloseFixedDepositsAccountComponent } from './fixed-deposits-account-actions/close-fixed-deposits-account/close-fixed-deposits-account.component'; @NgModule({ declarations: [ @@ -55,7 +56,8 @@ import { PrematureCloseFixedDepositsAccountComponent } from './fixed-deposits-ac WaiveChargeDialogComponent, InactivateChargeDialogComponent, AddChargeFixedDepositsAccountComponent, - PrematureCloseFixedDepositsAccountComponent + PrematureCloseFixedDepositsAccountComponent, + CloseFixedDepositsAccountComponent ], imports: [ SharedModule, diff --git a/src/app/deposits/fixed-deposits/fixed-deposits.service.ts b/src/app/deposits/fixed-deposits/fixed-deposits.service.ts index 24ce6b757..31a810e43 100644 --- a/src/app/deposits/fixed-deposits/fixed-deposits.service.ts +++ b/src/app/deposits/fixed-deposits/fixed-deposits.service.ts @@ -16,7 +16,7 @@ export class FixedDepositsService { constructor(private http: HttpClient) {} /** - * @param accountId Account Id of group to get data for. + * @param accountId Account Id. * @returns {Observable} Fixed Deposits data. */ getFixedDepositsAccountData(accountId: string): Observable { @@ -44,7 +44,7 @@ export class FixedDepositsService { } /** - * @param {string} accountId Savings Account Id + * @param {string} accountId Fixed Deposits Account Id * @param {string} transactionId Transaction Id * @returns {Observable} */ @@ -53,7 +53,7 @@ export class FixedDepositsService { } /** - * @param {string} accountId Savings Account Id + * @param {string} accountId Fixed Deposits Account Id * @param {string} command Command * @param {any} data Data * @param {string} transactionId Transaction Id @@ -64,6 +64,15 @@ export class FixedDepositsService { return this.http.post(`/fixeddepositaccounts/${accountId}/transactions/${transactionId}`, data, { params: httpParams }); } + /** + * @param {string} accountId Fixed Deposits Account Id + * @returns {Observable} + */ + getFixedDepositsAccountClosureTemplate(accountId: string): Observable { + const httpParams = new HttpParams().set('command', 'close'); + return this.http.get(`/fixeddepositaccounts/${accountId}/template`, { params: httpParams }); + } + /** * @param clientId Client Id * @param clientName Client Name