feat: fixed deposit account actions (close) (#997)

Fixes: #996
This commit is contained in:
Karan Takalkar
2020-07-05 17:54:27 +05:30
committed by GitHub
parent 1a89f0a4cb
commit efac58fc68
8 changed files with 236 additions and 6 deletions
@@ -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<Object> {
/**
* @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<Object> {
switch (actionName) {
case 'Add Charge':
return this.savingsService.getSavingsChargeTemplateResource(fixedDepositAccountId);
case 'Close':
return this.fixedDepositsService.getFixedDepositsAccountClosureTemplate(fixedDepositAccountId);
default:
return undefined;
}
@@ -0,0 +1,73 @@
<div class="container">
<mat-card>
<form [formGroup]="closeOnMaturityAccountForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Closed On 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="closeOnMaturityAccountForm.controls.closedOnDate.hasError('required')">
Closed On Date is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Maturity Amount</mat-label>
<input type=number matInput formControlName="maturityAmount"/>
</mat-form-field>
<mat-form-field>
<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="closeOnMaturityAccountForm.controls.onAccountClosureId.hasError('required')">
Account action is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field *ngIf="closeOnMaturityAccountForm.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="closeOnMaturityAccountForm.controls.toSavingsAccountId.hasError('required')">
Transfer to savings account is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field *ngIf="closeOnMaturityAccountForm.contains('transferDescription')">
<mat-label>Transfer Description</mat-label>
<input matInput formControlName="transferDescription"/>
</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="warn" [disabled]="!closeOnMaturityAccountForm.valid">Confirm</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -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<CloseFixedDepositsAccountComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CloseFixedDepositsAccountComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CloseFixedDepositsAccountComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -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 });
});
}
}
@@ -5,4 +5,4 @@
<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> -->
<mifosx-close-fixed-deposits-account *ngIf="actions['Close']"></mifosx-close-fixed-deposits-account>
@@ -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,
@@ -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<any>} Fixed Deposits data.
*/
getFixedDepositsAccountData(accountId: string): Observable<any> {
@@ -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<any>}
*/
@@ -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<any>}
*/
getFixedDepositsAccountClosureTemplate(accountId: string): Observable<any> {
const httpParams = new HttpParams().set('command', 'close');
return this.http.get(`/fixeddepositaccounts/${accountId}/template`, { params: httpParams });
}
/**
* @param clientId Client Id
* @param clientName Client Name