feat: fixed deposit account actions (premature-close) (#995)

Fixes: #994
This commit is contained in:
Karan Takalkar
2020-07-05 16:34:06 +05:30
committed by GitHub
parent 1486b78441
commit 1a89f0a4cb
6 changed files with 248 additions and 1 deletions
@@ -4,4 +4,5 @@
<mifosx-undo-approval-fixed-deposits-account *ngIf="actions['Undo Approval']"></mifosx-undo-approval-fixed-deposits-account>
<mifosx-withdraw-by-client-fixed-deposits-account *ngIf="actions['Withdraw By Client']"></mifosx-withdraw-by-client-fixed-deposits-account>
<mifosx-add-charge-fixed-deposits-account *ngIf="actions['Add Charge']"></mifosx-add-charge-fixed-deposits-account>
<mifosx-premature-close-fixed-deposits-account *ngIf="actions['Premature Close']"></mifosx-premature-close-fixed-deposits-account>
<!-- <mifosx-close-fixed-deposits-account *ngIf="actions['Close']"></mifosx-close-fixed-deposits-account> -->
@@ -0,0 +1,73 @@
<div class="container">
<mat-card>
<form [formGroup]="prematureCloseAccountForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Premature Close Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="closedOnDatePicker" required formControlName="closedOnDate">
<mat-datepicker-toggle matSuffix [for]="closedOnDatePicker"></mat-datepicker-toggle>
<mat-datepicker #closedOnDatePicker></mat-datepicker>
<mat-error *ngIf="prematureCloseAccountForm.controls.closedOnDate.hasError('required')">
Premature Close Date is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field *ngIf="prematureCloseAccountForm.controls.maturityAmount">
<mat-label>Maturity Amount</mat-label>
<input type=number matInput formControlName="maturityAmount"/>
</mat-form-field>
<mat-form-field *ngIf="prematureCloseAccountForm.contains('onAccountClosureId')">
<mat-label>Action</mat-label>
<mat-select required formControlName="onAccountClosureId">
<mat-option *ngFor="let closureOption of onAccountClosureOptions" [value]="closureOption.id">
{{ closureOption.value }}
</mat-option>
</mat-select>
<mat-error *ngIf="prematureCloseAccountForm.controls.onAccountClosureId.hasError('required')">
Account action is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field *ngIf="prematureCloseAccountForm.contains('toSavingsAccountId')">
<mat-label>Transfer to Savings</mat-label>
<mat-select required formControlName="toSavingsAccountId">
<mat-option *ngFor="let account of savingsAccountsData" [value]="account.id">
{{ account.accountNo }}
</mat-option>
</mat-select>
<mat-error *ngIf="prematureCloseAccountForm.controls.toSavingsAccountId.hasError('required')">
Transfer to savings account is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field *ngIf="prematureCloseAccountForm.contains('transferDescription')">
<mat-label>Transfer Description</mat-label>
<input matInput formControlName="transferDescription"/>
</mat-form-field>
<mat-form-field *ngIf="prematureCloseAccountForm.contains('note')">
<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="warn" [disabled]="!prematureCloseAccountForm.valid">Confirm</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { PrematureCloseFixedDepositsAccountComponent } from './premature-close-fixed-deposits-account.component';
describe('PrematureCloseFixedDepositsAccountComponent', () => {
let component: PrematureCloseFixedDepositsAccountComponent;
let fixture: ComponentFixture<PrematureCloseFixedDepositsAccountComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ PrematureCloseFixedDepositsAccountComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(PrematureCloseFixedDepositsAccountComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,143 @@
/** 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';
/**
* Premature Close Fixed Deposits Account Component
*/
@Component({
selector: 'mifosx-premature-close-fixed-deposits-account',
templateUrl: './premature-close-fixed-deposits-account.component.html',
styleUrls: ['./premature-close-fixed-deposits-account.component.scss']
})
export class PrematureCloseFixedDepositsAccountComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Premature Close FD Account form. */
prematureCloseAccountForm: FormGroup;
/** Savings Account Data */
savingsAccountsData: any;
/** On account Closure Options */
onAccountClosureOptions: any;
/** Fixed Deposits Account Id */
accountId: any;
/** Form submission event */
isSubmitted = false;
/**
* @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.accountId = this.route.parent.snapshot.params['fixedDepositAccountId'];
}
/**
* Creates the premature close fd account form.
*/
ngOnInit() {
this.createPrematureCloseAccountForm();
this.buildDependencies();
}
/**
* Creates the premature close fd account form.
*/
createPrematureCloseAccountForm() {
this.prematureCloseAccountForm = this.formBuilder.group({
'closedOnDate': ['', Validators.required]
});
}
/**
* Subscribes to value changes of parent control.
*/
buildDependencies() {
this.prematureCloseAccountForm.get('closedOnDate').valueChanges.subscribe((value: Date) => {
if (!this.isSubmitted) {
this.calculatePrematureAmount(value);
}
});
}
/**
* Calculates prematue amount based on closed on date.
* @param {Date} date Premature Close Date
*/
calculatePrematureAmount(date: Date) {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const data = {
closedOnDate: this.datePipe.transform(date, dateFormat),
dateFormat,
locale
};
this.fixedDepositsService.executeFixedDepositsAccountCommand(this.accountId, 'calculatePrematureAmount', data)
.subscribe((response: any) => {
this.savingsAccountsData = response.savingsAccounts;
this.onAccountClosureOptions = response.onAccountClosureOptions;
this.prematureCloseAccountForm.addControl('maturityAmount', new FormControl({value: '', disabled: true}));
this.prematureCloseAccountForm.addControl('onAccountClosureId', new FormControl('', Validators.required));
this.prematureCloseAccountForm.addControl('note', new FormControl(''));
this.prematureCloseAccountForm.get('maturityAmount').patchValue(response.maturityAmount);
this.addTransferDetails();
});
}
/**
* Subscribes to value changes of `onAccountClosureId` adds and removes transfer details accordingly.
*/
addTransferDetails() {
this.prematureCloseAccountForm.get('onAccountClosureId').valueChanges.subscribe((id: any) => {
if (id === 200) {
this.prematureCloseAccountForm.addControl('toSavingsAccountId', new FormControl('', Validators.required));
this.prematureCloseAccountForm.addControl('transferDescription', new FormControl(''));
} else {
this.prematureCloseAccountForm.removeControl('toSavingsAccountId');
this.prematureCloseAccountForm.removeControl('transferDescription');
}
});
}
/**
* Submits the form and premature closes the fd account,
* if successful redirects to the fd account.
*/
submit() {
this.isSubmitted = true;
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const prevClosedDate: Date = this.prematureCloseAccountForm.value.closedOnDate;
this.prematureCloseAccountForm.patchValue({
closedOnDate: this.datePipe.transform(prevClosedDate, dateFormat),
});
const data = {
...this.prematureCloseAccountForm.value,
dateFormat,
locale
};
this.fixedDepositsService.executeFixedDepositsAccountCommand(this.accountId, 'prematureClose', data).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -30,6 +30,7 @@ import { ViewTransactionComponent } from './fixed-deposit-account-view/view-tran
import { WaiveChargeDialogComponent } from './fixed-deposit-account-view/custom-dialogs/waive-charge-dialog/waive-charge-dialog.component';
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';
@NgModule({
declarations: [
@@ -53,7 +54,8 @@ import { AddChargeFixedDepositsAccountComponent } from './fixed-deposits-account
ViewTransactionComponent,
WaiveChargeDialogComponent,
InactivateChargeDialogComponent,
AddChargeFixedDepositsAccountComponent
AddChargeFixedDepositsAccountComponent,
PrematureCloseFixedDepositsAccountComponent
],
imports: [
SharedModule,