feat: savings account actions (withdraw) (#916)

Fixes: #915
This commit is contained in:
Karan Takalkar
2020-06-25 16:59:55 +05:30
committed by GitHub
parent 9f7fcf7aeb
commit 1556915fc9
8 changed files with 158 additions and 2 deletions
@@ -1,3 +1,4 @@
<mifosx-approve-savings-account *ngIf="actions['Approve']"></mifosx-approve-savings-account>
<mifosx-reject-savings-account *ngIf="actions['Reject']"></mifosx-reject-savings-account>
<mifosx-withdraw-savings-account *ngIf="actions['Withdraw']"></mifosx-withdraw-savings-account>
@@ -18,9 +18,11 @@ export class SavingAccountActionsComponent {
actions: {
'Approve': boolean
'Reject': boolean
'Withdraw': boolean
} = {
'Approve': false,
'Reject': false
'Reject': false,
'Withdraw': false
};
/**
@@ -0,0 +1,39 @@
<div class="container">
<mat-card>
<form [formGroup]="withdrawSavingsAccountForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Withdrawn On Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="withdrawnOnDatePicker" required formControlName="withdrawnOnDate">
<mat-datepicker-toggle matSuffix [for]="withdrawnOnDatePicker"></mat-datepicker-toggle>
<mat-datepicker #withdrawnOnDatePicker></mat-datepicker>
<mat-error *ngIf="withdrawSavingsAccountForm.controls.withdrawnOnDate.hasError('required')">
Withdrawn On Date is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Note</mat-label>
<textarea matInput formControlName="note"></textarea>
</mat-form-field>
</div>
</mat-card-content>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../../']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="!withdrawSavingsAccountForm.valid">Confirm</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,3 @@
.container {
max-width: 37rem;
}
@@ -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<WithdrawSavingsAccountComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ WithdrawSavingsAccountComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(WithdrawSavingsAccountComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -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 });
});
}
}
@@ -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':
+3 -1
View File
@@ -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]
})