From 1486b78441a694c8baeb2404e561e86275ced482 Mon Sep 17 00:00:00 2001 From: Karan Takalkar Date: Sat, 4 Jul 2020 20:07:38 +0530 Subject: [PATCH] feat: fixed deposits account actions (add-charge) (#993) Fixes: #992 --- .../fixed-deposit-account-actions.resolver.ts | 38 +++++ ...tivate-fixed-deposits-account.component.ts | 8 +- ...arge-fixed-deposits-account.component.html | 93 ++++++++++++ ...arge-fixed-deposits-account.component.scss | 3 + ...e-fixed-deposits-account.component.spec.ts | 25 ++++ ...charge-fixed-deposits-account.component.ts | 141 ++++++++++++++++++ ...ed-deposits-account-actions.component.html | 4 +- ...ixed-deposits-account-actions.component.ts | 2 + .../fixed-deposits-routing.module.ts | 15 +- .../fixed-deposits/fixed-deposits.module.ts | 4 +- .../fixed-deposits/fixed-deposits.service.ts | 2 +- 11 files changed, 321 insertions(+), 14 deletions(-) create mode 100644 src/app/deposits/fixed-deposits/common-resolvers/fixed-deposit-account-actions.resolver.ts create mode 100644 src/app/deposits/fixed-deposits/fixed-deposits-account-actions/add-charge-fixed-deposits-account/add-charge-fixed-deposits-account.component.html create mode 100644 src/app/deposits/fixed-deposits/fixed-deposits-account-actions/add-charge-fixed-deposits-account/add-charge-fixed-deposits-account.component.scss create mode 100644 src/app/deposits/fixed-deposits/fixed-deposits-account-actions/add-charge-fixed-deposits-account/add-charge-fixed-deposits-account.component.spec.ts create mode 100644 src/app/deposits/fixed-deposits/fixed-deposits-account-actions/add-charge-fixed-deposits-account/add-charge-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 new file mode 100644 index 000000000..afba75ed8 --- /dev/null +++ b/src/app/deposits/fixed-deposits/common-resolvers/fixed-deposit-account-actions.resolver.ts @@ -0,0 +1,38 @@ +/** Angular Imports */ +import { Injectable } from '@angular/core'; +import { Resolve, ActivatedRouteSnapshot } from '@angular/router'; + +/** rxjs Imports */ +import { Observable } from 'rxjs'; + +/** Custom Services */ +import { SavingsService } from 'app/savings/savings.service'; + +/** + * Fixed Deposits Account Actions data resolver. + */ +@Injectable() +export class FixedDepositsAccountActionsResolver implements Resolve { + + /** + * @param {SavingsService} SavingsService Savings service. + */ + constructor(private savingsService: SavingsService) { } + + /** + * Returns the Fixed deposits account actions data. + * @param {ActivatedRouteSnapshot} route Route Snapshot + * @returns {Observable} + */ + resolve(route: ActivatedRouteSnapshot): Observable { + const actionName = route.paramMap.get('name'); + const fixedDepositAccountId = route.paramMap.get('fixedDepositAccountId') || route.parent.parent.paramMap.get('fixedDepositAccountId'); + switch (actionName) { + case 'Add Charge': + return this.savingsService.getSavingsChargeTemplateResource(fixedDepositAccountId); + default: + return undefined; + } + } + +} diff --git a/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/activate-fixed-deposits-account/activate-fixed-deposits-account.component.ts b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/activate-fixed-deposits-account/activate-fixed-deposits-account.component.ts index 48415e9ff..265f41854 100644 --- a/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/activate-fixed-deposits-account/activate-fixed-deposits-account.component.ts +++ b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/activate-fixed-deposits-account/activate-fixed-deposits-account.component.ts @@ -35,10 +35,10 @@ export class ActivateFixedDepositsAccountComponent implements OnInit { * @param {Router} router Router */ constructor(private formBuilder: FormBuilder, - private savingsService: SavingsService, - private datePipe: DatePipe, - private route: ActivatedRoute, - private router: Router) { + private savingsService: SavingsService, + private datePipe: DatePipe, + private route: ActivatedRoute, + private router: Router) { this.accountId = this.route.parent.snapshot.params['fixedDepositAccountId']; } diff --git a/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/add-charge-fixed-deposits-account/add-charge-fixed-deposits-account.component.html b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/add-charge-fixed-deposits-account/add-charge-fixed-deposits-account.component.html new file mode 100644 index 000000000..037d17406 --- /dev/null +++ b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/add-charge-fixed-deposits-account/add-charge-fixed-deposits-account.component.html @@ -0,0 +1,93 @@ +
+ + + +
+ + + +
+ + Charge + + + {{ savingsCharge.name + ' (' + savingsCharge.currency.name + ')' }} + + + + Charge is required + + + +
+ + + Amount + + + Amount is required + + + + + Charge Calculation + + + {{ chargeCalculation.value }} + + + + + + Charge time type + + + {{ chargeTime.value }} + + + + + + Due for collection on + + + + + Due for collection on is required + + + + + Due On + + + + + Due Date is required + + + + + Repeats Every + + + +
+ +
+ + + + + + +
+ +
+ +
+ +
diff --git a/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/add-charge-fixed-deposits-account/add-charge-fixed-deposits-account.component.scss b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/add-charge-fixed-deposits-account/add-charge-fixed-deposits-account.component.scss new file mode 100644 index 000000000..aeead06e0 --- /dev/null +++ b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/add-charge-fixed-deposits-account/add-charge-fixed-deposits-account.component.scss @@ -0,0 +1,3 @@ +.container { + width: 37rem; +} diff --git a/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/add-charge-fixed-deposits-account/add-charge-fixed-deposits-account.component.spec.ts b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/add-charge-fixed-deposits-account/add-charge-fixed-deposits-account.component.spec.ts new file mode 100644 index 000000000..cc354984a --- /dev/null +++ b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/add-charge-fixed-deposits-account/add-charge-fixed-deposits-account.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AddChargeFixedDepositsAccountComponent } from './add-charge-fixed-deposits-account.component'; + +describe('AddChargeFixedDepositsAccountComponent', () => { + let component: AddChargeFixedDepositsAccountComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ AddChargeFixedDepositsAccountComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(AddChargeFixedDepositsAccountComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/add-charge-fixed-deposits-account/add-charge-fixed-deposits-account.component.ts b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/add-charge-fixed-deposits-account/add-charge-fixed-deposits-account.component.ts new file mode 100644 index 000000000..ecc148620 --- /dev/null +++ b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/add-charge-fixed-deposits-account/add-charge-fixed-deposits-account.component.ts @@ -0,0 +1,141 @@ +/** Angular Imports */ +import { Component, OnInit } from '@angular/core'; +import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms'; +import { Router, ActivatedRoute } from '@angular/router'; +import { DatePipe } from '@angular/common'; + +/** Custom Services */ +import { SavingsService } from 'app/savings/savings.service'; + +/** + * Add Fixed Deposits Charge component. + * Fixed deposits endpoint is not supported so using Savings endpoint. + */ +@Component({ + selector: 'mifosx-add-charge-fixed-deposits-account', + templateUrl: './add-charge-fixed-deposits-account.component.html', + styleUrls: ['./add-charge-fixed-deposits-account.component.scss'] +}) +export class AddChargeFixedDepositsAccountComponent implements OnInit { + + /** Minimum Due Date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum Due Date allowed. */ + maxDate = new Date(); + /** Add Fixed Deposits Charge form. */ + fixedDepositsChargeForm: FormGroup; + /** savings charge options. */ + savingsChargeOptions: any; + /** savings Id of the savings account. */ + fixedDepositAccountId: string; + /** charge details */ + chargeDetails: any; + + /** + * Retrieves charge template data from `resolve` + * @param {FormBuilder} formBuilder Form Builder + * @param {ActivatedRoute} route Activated Route + * @param {Router} router Router + * @param {DatePipe} datePipe Date Pipe + * @param {SavingsService} savingsService Savings Service + */ + constructor( + private formBuilder: FormBuilder, + private route: ActivatedRoute, + private router: Router, + private datePipe: DatePipe, + private savingsService: SavingsService + ) { + this.route.data.subscribe((data: { fixedDepositsAccountActionData: any }) => { + this.savingsChargeOptions = data.fixedDepositsAccountActionData.chargeOptions; + }); + this.fixedDepositAccountId = this.route.parent.snapshot.params['fixedDepositAccountId']; + } + + /** + * Creates the Fixed Deposits Charge form. + */ + ngOnInit() { + this.createFixedDepositsChargeForm(); + this.buildDependencies(); + } + + buildDependencies() { + this.fixedDepositsChargeForm.controls.chargeId.valueChanges.subscribe(chargeId => { + this.savingsService.getChargeTemplate(chargeId).subscribe((data: any) => { + this.chargeDetails = data; + const chargeTimeType = data.chargeTimeType.id; + if (data.chargeTimeType.value === 'Withdrawal Fee' || data.chargeTimeType.value === 'Saving No Activity Fee') { + this.chargeDetails.dueDateNotRequired = true; + } + if (data.chargeTimeType.value === 'Annual Fee' || data.chargeTimeType.value === 'Monthly Fee') { + this.chargeDetails.chargeTimeTypeAnnualOrMonth = true; + } + if (!this.chargeDetails.dueDateNotRequired && !this.chargeDetails.chargeTimeTypeAnnualOrMonth) { + this.fixedDepositsChargeForm.addControl('dueDate', new FormControl('', Validators.required)); + } else { + this.fixedDepositsChargeForm.removeControl('dueDate'); + } + if (!this.chargeDetails.dueDateNotRequired && this.chargeDetails.chargeTimeTypeAnnualOrMonth) { + this.fixedDepositsChargeForm.addControl('feeOnMonthDay', new FormControl('', Validators.required)); + } else { + this.fixedDepositsChargeForm.removeControl('feeOnMonthDay'); + } + if (chargeTimeType.value === 'Monthly Fee') { + this.fixedDepositsChargeForm.addControl('feeInterval', new FormControl(data.feeInterval, Validators.required)); + } else { + this.fixedDepositsChargeForm.removeControl('feeInterval'); + } + this.fixedDepositsChargeForm.patchValue({ + 'amount': data.amount, + 'chargeCalculationType': data.chargeCalculationType.id, + 'chargeTimeType': data.chargeTimeType.id + }); + }); + }); + } + + /** + * Creates the Fixed Deposits Charge form. + */ + createFixedDepositsChargeForm() { + this.fixedDepositsChargeForm = this.formBuilder.group({ + 'chargeId': ['', Validators.required], + 'amount': ['', Validators.required], + 'chargeCalculationType': [{ value: '', disabled: true }], + 'chargeTimeType': [{ value: '', disabled: true }] + }); + } + + /** + * Submits savings charge. + */ + submit() { + const savingsCharge = this.fixedDepositsChargeForm.value; + savingsCharge.locale = 'en'; + if (!savingsCharge.feeInterval) { + savingsCharge.feeInterval = this.chargeDetails.feeInterval; + } + if (this.chargeDetails.dueDateNotRequired !== true) { + if (this.chargeDetails.chargeTimeTypeAnnualOrMonth === true) { + const monthDayFormat = 'MMMM-dd'; // TODO: Update once language and date settings are setup + savingsCharge.monthDayFormat = monthDayFormat; + if (savingsCharge.feeOnMonthDay) { + const prevDate = this.fixedDepositsChargeForm.value.feeOnMonthDay; + savingsCharge.feeOnMonthDay = this.datePipe.transform(prevDate, monthDayFormat); + } + } else { + const dateFormat = 'yyyy-MM-dd'; + savingsCharge.dateFormat = dateFormat; + if (savingsCharge.dueDate) { + const prevDate = this.fixedDepositsChargeForm.value.dueDate; + savingsCharge.dueDate = this.datePipe.transform(prevDate, dateFormat); + } + } + } + this.savingsService.createSavingsCharge(this.fixedDepositAccountId, 'charges', savingsCharge).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 4c1449497..3892f2571 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 @@ -3,5 +3,5 @@ - + + diff --git a/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/fixed-deposits-account-actions.component.ts b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/fixed-deposits-account-actions.component.ts index a73c28167..2baf468a6 100644 --- a/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/fixed-deposits-account-actions.component.ts +++ b/src/app/deposits/fixed-deposits/fixed-deposits-account-actions/fixed-deposits-account-actions.component.ts @@ -20,6 +20,7 @@ export class FixedDepositsAccountActionsComponent { 'Close': boolean 'Undo Approval': boolean 'Add Charge': boolean + 'Premature Close': boolean 'Withdraw By Client': boolean } = { 'Approve': false, @@ -28,6 +29,7 @@ export class FixedDepositsAccountActionsComponent { 'Close': false, 'Undo Approval': false, 'Add Charge': false, + 'Premature Close': false, 'Withdraw By Client': false }; diff --git a/src/app/deposits/fixed-deposits/fixed-deposits-routing.module.ts b/src/app/deposits/fixed-deposits/fixed-deposits-routing.module.ts index 35eb2fe83..1ac6b4028 100644 --- a/src/app/deposits/fixed-deposits/fixed-deposits-routing.module.ts +++ b/src/app/deposits/fixed-deposits/fixed-deposits-routing.module.ts @@ -20,6 +20,7 @@ import { FixedDepositsAccountViewResolver } from '../fixed-deposits/common-resol import { SavingsDatatableResolver } from 'app/savings/common-resolvers/savings-datatable.resolver'; import { SavingsDatatablesResolver } from 'app/savings/common-resolvers/savings-datatables.resolver'; import { FixedDepositsAccountTransactionResolver } from '../fixed-deposits/common-resolvers/fixed-deposit-account-transaction.resolver'; +import { FixedDepositsAccountActionsResolver } from '../fixed-deposits/common-resolvers/fixed-deposit-account-actions.resolver'; const routes: Routes = [ { @@ -29,15 +30,13 @@ const routes: Routes = [ { path: ':fixedDepositAccountId', data: { title: extract('Fixed Deposit Account View'), routeParamBreadcrumb: 'fixedDepositAccountId' }, - resolve: { - savingsDatatables: SavingsDatatablesResolver - }, children: [ { path: '', component: FixedDepositAccountViewComponent, resolve: { - fixedDepositsAccountData: FixedDepositsAccountViewResolver + fixedDepositsAccountData: FixedDepositsAccountViewResolver, + savingsDatatables: SavingsDatatablesResolver }, children: [ { @@ -101,7 +100,10 @@ const routes: Routes = [ { path: 'actions/:name', data: { title: extract('Fixed Deposits Account Actions'), routeParamBreadcrumb: 'name' }, - component: FixedDepositsAccountActionsComponent + component: FixedDepositsAccountActionsComponent, + resolve: { + fixedDepositsAccountActionData: FixedDepositsAccountActionsResolver + } } ] } @@ -116,7 +118,8 @@ const routes: Routes = [ FixedDepositsAccountViewResolver, SavingsDatatableResolver, SavingsDatatablesResolver, - FixedDepositsAccountTransactionResolver + FixedDepositsAccountTransactionResolver, + FixedDepositsAccountActionsResolver ] }) export class FixedDepositsRoutingModule { } diff --git a/src/app/deposits/fixed-deposits/fixed-deposits.module.ts b/src/app/deposits/fixed-deposits/fixed-deposits.module.ts index 5a5f05e0a..26ce13df3 100644 --- a/src/app/deposits/fixed-deposits/fixed-deposits.module.ts +++ b/src/app/deposits/fixed-deposits/fixed-deposits.module.ts @@ -29,6 +29,7 @@ import { WithdrawByClientFixedDepositsAccountComponent } from './fixed-deposits- import { ViewTransactionComponent } from './fixed-deposit-account-view/view-transaction/view-transaction.component'; 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'; @NgModule({ declarations: [ @@ -51,7 +52,8 @@ import { InactivateChargeDialogComponent } from './fixed-deposit-account-view/cu WithdrawByClientFixedDepositsAccountComponent, ViewTransactionComponent, WaiveChargeDialogComponent, - InactivateChargeDialogComponent + InactivateChargeDialogComponent, + AddChargeFixedDepositsAccountComponent ], 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 47cb75899..24ce6b757 100644 --- a/src/app/deposits/fixed-deposits/fixed-deposits.service.ts +++ b/src/app/deposits/fixed-deposits/fixed-deposits.service.ts @@ -33,7 +33,7 @@ export class FixedDepositsService { } /** - * @param {string} accountId Savings Account Id + * @param {string} accountId Account Id * @param {string} command Command * @param {any} data Data * @returns {Observable}