From 1556915fc9e554e0518f76330bde74e4c392ea3c Mon Sep 17 00:00:00 2001 From: Karan Takalkar Date: Thu, 25 Jun 2020 16:59:55 +0530 Subject: [PATCH] feat: savings account actions (withdraw) (#916) Fixes: #915 --- .../saving-account-actions.component.html | 1 + .../saving-account-actions.component.ts | 4 +- .../withdraw-savings-account.component.html | 39 +++++++++ .../withdraw-savings-account.component.scss | 3 + ...withdraw-savings-account.component.spec.ts | 25 ++++++ .../withdraw-savings-account.component.ts | 83 +++++++++++++++++++ .../savings-account-view.component.ts | 1 + src/app/savings/savings.module.ts | 4 +- 8 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 src/app/savings/saving-account-actions/withdraw-savings-account/withdraw-savings-account.component.html create mode 100644 src/app/savings/saving-account-actions/withdraw-savings-account/withdraw-savings-account.component.scss create mode 100644 src/app/savings/saving-account-actions/withdraw-savings-account/withdraw-savings-account.component.spec.ts create mode 100644 src/app/savings/saving-account-actions/withdraw-savings-account/withdraw-savings-account.component.ts 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 48eb85865..ac1f0c4e9 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 @@ -1,3 +1,4 @@ + \ No newline at end of file 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 1573a5ed5..6f814ddd6 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 @@ -18,9 +18,11 @@ export class SavingAccountActionsComponent { actions: { 'Approve': boolean 'Reject': boolean + 'Withdraw': boolean } = { 'Approve': false, - 'Reject': false + 'Reject': false, + 'Withdraw': false }; /** diff --git a/src/app/savings/saving-account-actions/withdraw-savings-account/withdraw-savings-account.component.html b/src/app/savings/saving-account-actions/withdraw-savings-account/withdraw-savings-account.component.html new file mode 100644 index 000000000..ac5938965 --- /dev/null +++ b/src/app/savings/saving-account-actions/withdraw-savings-account/withdraw-savings-account.component.html @@ -0,0 +1,39 @@ +
+ + + +
+ + + +
+ + + Withdrawn On Date + + + + + Withdrawn On Date is required + + + + + Note + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/savings/saving-account-actions/withdraw-savings-account/withdraw-savings-account.component.scss b/src/app/savings/saving-account-actions/withdraw-savings-account/withdraw-savings-account.component.scss new file mode 100644 index 000000000..d774f68da --- /dev/null +++ b/src/app/savings/saving-account-actions/withdraw-savings-account/withdraw-savings-account.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; +} diff --git a/src/app/savings/saving-account-actions/withdraw-savings-account/withdraw-savings-account.component.spec.ts b/src/app/savings/saving-account-actions/withdraw-savings-account/withdraw-savings-account.component.spec.ts new file mode 100644 index 000000000..9a15c22b6 --- /dev/null +++ b/src/app/savings/saving-account-actions/withdraw-savings-account/withdraw-savings-account.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { WithdrawSavingsAccountComponent } from './withdraw-savings-account.component'; + +describe('WithdrawSavingsAccountComponent', () => { + let component: WithdrawSavingsAccountComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ WithdrawSavingsAccountComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(WithdrawSavingsAccountComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/savings/saving-account-actions/withdraw-savings-account/withdraw-savings-account.component.ts b/src/app/savings/saving-account-actions/withdraw-savings-account/withdraw-savings-account.component.ts new file mode 100644 index 000000000..9a4ac6817 --- /dev/null +++ b/src/app/savings/saving-account-actions/withdraw-savings-account/withdraw-savings-account.component.ts @@ -0,0 +1,83 @@ +/** Angular Imports */ +import { Component, OnInit } from '@angular/core'; +import { FormGroup, FormBuilder, Validators } from '@angular/forms'; +import { DatePipe } from '@angular/common'; +import { ActivatedRoute, Router } from '@angular/router'; + +/** Custom Services */ +import { SavingsService } from 'app/savings/savings.service'; + +/** + * Withdraw Savings Account Component + */ +@Component({ + selector: 'mifosx-withdraw-savings-account', + templateUrl: './withdraw-savings-account.component.html', + styleUrls: ['./withdraw-savings-account.component.scss'] +}) +export class WithdrawSavingsAccountComponent implements OnInit { + + /** Minimum date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum date allowed. */ + maxDate = new Date(); + /** Withdraw Savings Account form. */ + withdrawSavingsAccountForm: FormGroup; + /** Savings Account Id */ + accountId: 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.accountId = this.route.parent.snapshot.params['savingAccountId']; + } + + /** + * Creates the withdraw savings form. + */ + ngOnInit() { + this.createWithdrawSavingsAccountForm(); + } + + /** + * Creates the withdraw savings account form. + */ + createWithdrawSavingsAccountForm() { + this.withdrawSavingsAccountForm = this.formBuilder.group({ + 'withdrawnOnDate': ['', Validators.required], + 'note': [''] + }); + } + + /** + * Submits the form and withdraws 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 prevWithdrawnOnDate: Date = this.withdrawSavingsAccountForm.value.withdrawnOnDate; + this.withdrawSavingsAccountForm.patchValue({ + withdrawnOnDate: this.datePipe.transform(prevWithdrawnOnDate, dateFormat), + }); + const data = { + ...this.withdrawSavingsAccountForm.value, + dateFormat, + locale + }; + this.savingsService.executeSavingsAccountCommand(this.accountId, 'withdrawnByApplicant', data).subscribe(() => { + this.router.navigate(['../../'], { relativeTo: this.route }); + }); + } + +} 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 fb9e8e14c..ec3ab582a 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 @@ -100,6 +100,7 @@ export class SavingsAccountViewComponent implements OnInit { switch (name) { case 'Approve': case 'Reject': + case 'Withdraw': this.router.navigate([`actions/${name}`], { relativeTo: this.route }); break; case 'Modify Application': diff --git a/src/app/savings/savings.module.ts b/src/app/savings/savings.module.ts index 24a75164f..b705117fa 100644 --- a/src/app/savings/savings.module.ts +++ b/src/app/savings/savings.module.ts @@ -27,6 +27,7 @@ import { SavingsAccountPreviewStepComponent } from './savings-account-stepper/sa import { EditSavingsAccountComponent } from './edit-savings-account/edit-savings-account.component'; import { ApproveSavingsAccountComponent } from './saving-account-actions/approve-savings-account/approve-savings-account.component'; import { RejectSavingsAccountComponent } from './saving-account-actions/reject-savings-account/reject-savings-account.component'; +import { WithdrawSavingsAccountComponent } from './saving-account-actions/withdraw-savings-account/withdraw-savings-account.component'; /** * Savings Module @@ -58,7 +59,8 @@ import { RejectSavingsAccountComponent } from './saving-account-actions/reject-s SavingsAccountPreviewStepComponent, EditSavingsAccountComponent, ApproveSavingsAccountComponent, - RejectSavingsAccountComponent + RejectSavingsAccountComponent, + WithdrawSavingsAccountComponent ], providers: [DatePipe] })