From 3bc8e41a46dd951f302f23ef7851f67b67ff85d1 Mon Sep 17 00:00:00 2001 From: Muskan Khedia <36980003+muskankhedia@users.noreply.github.com> Date: Sun, 19 Jul 2020 10:24:52 +0530 Subject: [PATCH] feat: add edit standing instructions details (#1139) Fixes: #1138 --- .../account-transfers-routing.module.ts | 11 ++ .../account-transfers.module.ts | 4 +- .../account-transfers.service.ts | 10 ++ ...instructions-data-and-template.resolver.ts | 32 ++++ .../edit-standing-instructions.component.html | 170 ++++++++++++++++++ .../edit-standing-instructions.component.scss | 0 ...it-standing-instructions.component.spec.ts | 25 +++ .../edit-standing-instructions.component.ts | 149 +++++++++++++++ .../view-standing-instructions.component.html | 2 +- .../standing-instructions-tab.component.html | 3 +- .../edit-loans-account.component.html | 2 +- 11 files changed, 404 insertions(+), 4 deletions(-) create mode 100644 src/app/account-transfers/common-resolvers/standing-instructions-data-and-template.resolver.ts create mode 100644 src/app/account-transfers/edit-standing-instructions/edit-standing-instructions.component.html create mode 100644 src/app/account-transfers/edit-standing-instructions/edit-standing-instructions.component.scss create mode 100644 src/app/account-transfers/edit-standing-instructions/edit-standing-instructions.component.spec.ts create mode 100644 src/app/account-transfers/edit-standing-instructions/edit-standing-instructions.component.ts diff --git a/src/app/account-transfers/account-transfers-routing.module.ts b/src/app/account-transfers/account-transfers-routing.module.ts index e746487bb..e08ae86a5 100644 --- a/src/app/account-transfers/account-transfers-routing.module.ts +++ b/src/app/account-transfers/account-transfers-routing.module.ts @@ -7,9 +7,11 @@ import { extract } from '../core/i18n/i18n.service'; /** Custom Components */ import { ViewStandingInstructionsComponent } from './view-standing-instructions/view-standing-instructions.component'; +import { EditStandingInstructionsComponent } from './edit-standing-instructions/edit-standing-instructions.component'; /** Custom Resolvers */ import { ViewStandingInstructionsResolver } from './common-resolvers/view-standing-instructions.resolver'; +import { StandingInstructionsDataAndTemplateResolver } from './common-resolvers/standing-instructions-data-and-template.resolver'; /** Loans Route. */ const routes: Routes = [ @@ -28,6 +30,14 @@ const routes: Routes = [ standingInstructionsData: ViewStandingInstructionsResolver, }, }, + { + path: 'edit', + data: { title: extract('Edit Standing Instructions'), breadcrumb: 'edit', routeParamBreadcrumb: false }, + component: EditStandingInstructionsComponent, + resolve: { + standingInstructionsDataAndTemplate: StandingInstructionsDataAndTemplateResolver, + }, + } ] }] } @@ -38,6 +48,7 @@ const routes: Routes = [ declarations: [], providers: [ ViewStandingInstructionsResolver, + StandingInstructionsDataAndTemplateResolver ] }) diff --git a/src/app/account-transfers/account-transfers.module.ts b/src/app/account-transfers/account-transfers.module.ts index 24fa7ceb0..6401c0925 100644 --- a/src/app/account-transfers/account-transfers.module.ts +++ b/src/app/account-transfers/account-transfers.module.ts @@ -10,6 +10,7 @@ import { DirectivesModule } from '../directives/directives.module'; /** Custom Components */ import { ViewStandingInstructionsComponent } from './view-standing-instructions/view-standing-instructions.component'; +import { EditStandingInstructionsComponent } from './edit-standing-instructions/edit-standing-instructions.component'; /** * Account Transfers Module @@ -19,7 +20,8 @@ import { ViewStandingInstructionsComponent } from './view-standing-instructions/ @NgModule({ imports: [SharedModule, PipesModule, DirectivesModule, AccountTransfersRoutingModule], declarations: [ - ViewStandingInstructionsComponent + ViewStandingInstructionsComponent, + EditStandingInstructionsComponent ], providers: [DatePipe] }) diff --git a/src/app/account-transfers/account-transfers.service.ts b/src/app/account-transfers/account-transfers.service.ts index ed54875f8..fa6dd9057 100644 --- a/src/app/account-transfers/account-transfers.service.ts +++ b/src/app/account-transfers/account-transfers.service.ts @@ -23,4 +23,14 @@ export class AccountTransfersService { return this.http.get(`/standinginstructions/${standingInstructionsId}`); } + getStandingInstructionsDataAndTemplate(standingInstructionsId: any): Observable { + const httpParams = new HttpParams().set('associations', 'template'); + return this.http.get(`/standinginstructions/${standingInstructionsId}`, { params: httpParams }); + } + + updateStandingInstructionsData(standinginstructionsId: any, data: any): Observable { + const httpParams = new HttpParams().set('command', 'update'); + return this.http.put(`/standinginstructions/${standinginstructionsId}`, data, { params: httpParams }); + } + } diff --git a/src/app/account-transfers/common-resolvers/standing-instructions-data-and-template.resolver.ts b/src/app/account-transfers/common-resolvers/standing-instructions-data-and-template.resolver.ts new file mode 100644 index 000000000..4d69d51c0 --- /dev/null +++ b/src/app/account-transfers/common-resolvers/standing-instructions-data-and-template.resolver.ts @@ -0,0 +1,32 @@ +/** Angular Imports */ +import { Injectable } from '@angular/core'; +import { Resolve, ActivatedRouteSnapshot } from '@angular/router'; + +/** rxjs Imports */ +import { Observable } from 'rxjs'; + +/** Custom Services */ +import { AccountTransfersService } from '../account-transfers.service'; + +/** + * View Standing Instructions resolver. + */ +@Injectable() +export class StandingInstructionsDataAndTemplateResolver implements Resolve { + + /** + * @param {accountTransfersService} AccountTransfersService Account Transfers service. + */ + constructor(private accountTransfersService: AccountTransfersService) { } + + /** + * Returns the Standing Instructions Data. + * @param {ActivatedRouteSnapshot} route Route Snapshot + * @returns {Observable} + */ + resolve(route: ActivatedRouteSnapshot): Observable { + const standingInstructionsId = route.parent.paramMap.get('standingInstructionsId'); + return this.accountTransfersService.getStandingInstructionsDataAndTemplate(standingInstructionsId); + } + +} diff --git a/src/app/account-transfers/edit-standing-instructions/edit-standing-instructions.component.html b/src/app/account-transfers/edit-standing-instructions/edit-standing-instructions.component.html new file mode 100644 index 000000000..326453a51 --- /dev/null +++ b/src/app/account-transfers/edit-standing-instructions/edit-standing-instructions.component.html @@ -0,0 +1,170 @@ +
+ + + +
+ + + +
+ + + Name + + + + + Applicant + + + + + Type + + + + + From Account Type + + + + + Priority + + + {{ priorityType.value }} + + + + Priority is required + + + + + Status + + + {{ statusType.value }} + + + + Status is required + + + + + From Account + + + + + Destination + + + + + To Office + + + + + Beneficiary + + + + + To Account Type + + + + + To Account + + + + + Standing Instruction Type + + + {{ instructionsType.value }} + + + + + + Amount + + + + + Validity From + + + + + Valid From Date is required + + + + + Validity To + + + + + Valid Till Date is required + + + + + Recurrence Type + + + {{ recurrenceType.value }} + + + + Recurrence Type is required + + + + + Interval + + + + + Recurrence Frequency + + + {{ recurrenceFrequencyType.value }} + + + + + + On Month Day + + + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/account-transfers/edit-standing-instructions/edit-standing-instructions.component.scss b/src/app/account-transfers/edit-standing-instructions/edit-standing-instructions.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/account-transfers/edit-standing-instructions/edit-standing-instructions.component.spec.ts b/src/app/account-transfers/edit-standing-instructions/edit-standing-instructions.component.spec.ts new file mode 100644 index 000000000..28151f4b3 --- /dev/null +++ b/src/app/account-transfers/edit-standing-instructions/edit-standing-instructions.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { EditStandingInstructionsComponent } from './edit-standing-instructions.component'; + +describe('EditStandingInstructionsComponent', () => { + let component: EditStandingInstructionsComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ EditStandingInstructionsComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(EditStandingInstructionsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/account-transfers/edit-standing-instructions/edit-standing-instructions.component.ts b/src/app/account-transfers/edit-standing-instructions/edit-standing-instructions.component.ts new file mode 100644 index 000000000..cba72aa45 --- /dev/null +++ b/src/app/account-transfers/edit-standing-instructions/edit-standing-instructions.component.ts @@ -0,0 +1,149 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { AccountTransfersService } from '../account-transfers.service'; +import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'; +import { DatePipe } from '@angular/common'; + +@Component({ + selector: 'mifosx-edit-standing-instructions', + templateUrl: './edit-standing-instructions.component.html', + styleUrls: ['./edit-standing-instructions.component.scss'] +}) +export class EditStandingInstructionsComponent implements OnInit { + + /** Standing Instructions Data */ + standingInstructionsData: any; + /** Standing Instructions Id */ + standingInstructionsId: any; + /** Allow Client Edit */ + allowclientedit = false; + /** Edit Standing Instructions form. */ + editStandingInstructionsForm: FormGroup; + /** Priority Type Data */ + priorityTypeData: any; + /** Status Type Data */ + statusTypeData: any; + /** Instruction Type Data */ + instructionTypeData: any; + /** Recurrence Type Data */ + recurrenceTypeData: any; + /** Recurrence Frequency Type Data */ + recurrenceFrequencyTypeData: any; + /** Minimum date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum date allowed. */ + maxDate = new Date(); + + /** + * Retrieves the standing instructions data from `resolve`. + * @param {ActivatedRoute} route Activated Route. + */ + constructor(private formBuilder: FormBuilder, + private route: ActivatedRoute, + private router: Router, + private accountTransfersService: AccountTransfersService, + private datePipe: DatePipe) { + this.route.data.subscribe((data: { standingInstructionsDataAndTemplate: any }) => { + this.standingInstructionsData = data.standingInstructionsDataAndTemplate; + this.standingInstructionsId = data.standingInstructionsDataAndTemplate.id; + if (this.standingInstructionsData.fromClient.id === this.standingInstructionsData.toClient.id) { + this.allowclientedit = false; + } + this.setOptions(); + }); + } + + /** + * Creates and sets the edit standing instructions form. + */ + ngOnInit() { + this.createEditStandingInstructionsForm(); + const presentDate = new Date(); + const n = presentDate.getFullYear(); + this.standingInstructionsData.recurrenceOnMonthDay.push(n); + this.editStandingInstructionsForm.patchValue({ + 'name': this.standingInstructionsData.name, + 'applicant': this.standingInstructionsData.fromClient.displayName, + 'type': this.standingInstructionsData.transferType.value, + 'priority': this.standingInstructionsData.priority.id, + 'status': this.standingInstructionsData.status.id, + 'fromAccountType': this.standingInstructionsData.fromAccountType.value, + 'fromAccount': this.standingInstructionsData.fromAccount.productName, + 'destination': this.allowclientedit ? 'Within Bank' : 'Own Account', + 'toOffice': this.standingInstructionsData.toOffice.name, + 'toClientId': this.standingInstructionsData.toClient.displayName, + 'toAccountType': this.standingInstructionsData.toAccountType.value, + 'toAccount': this.standingInstructionsData.toAccount.productName, + 'instructionType': this.standingInstructionsData.instructionType.id, + 'amount': this.standingInstructionsData.amount, + 'validFrom': this.standingInstructionsData.validFrom && new Date(this.standingInstructionsData.validFrom), + 'validTill': this.standingInstructionsData.validTill && new Date(this.standingInstructionsData.validTill), + 'recurrenceType': this.standingInstructionsData.recurrenceType.id, + 'recurrenceInterval': this.standingInstructionsData.recurrenceInterval, + 'recurrenceFrequency': this.standingInstructionsData.recurrenceFrequency.id, + 'recurrenceOnMonthDay': new Date(this.standingInstructionsData.recurrenceOnMonthDay) + }); + } + + /** + * Creates the group form. + */ + createEditStandingInstructionsForm() { + this.editStandingInstructionsForm = this.formBuilder.group({ + 'name': [{value: '', disabled: true}], + 'applicant': [{ value: '', disabled: true }], + 'type': [{ value: '', disabled: true }], + 'priority': ['', Validators.required], + 'status': ['', Validators.required], + 'fromAccountType': [{ value: '', disabled: true }], + 'fromAccount': [{ value: '', disabled: true }], + 'destination': [{ value: '', disabled: true }], + 'toOffice': [{ value: '', disabled: true }], + 'toClientId': [{ value: '', disabled: true }], + 'toAccountType': [{ value: '', disabled: true }], + 'toAccount': [{ value: '', disabled: true }], + 'instructionType': '', + 'amount': '', + 'validFrom': ['', Validators.required], + 'validTill': ['', Validators.required], + 'recurrenceType': ['', Validators.required], + 'recurrenceInterval': '', + 'recurrenceFrequency': '', + 'recurrenceOnMonthDay': '' + }); + } + + setOptions() { + this.priorityTypeData = this.standingInstructionsData.priorityOptions; + this.statusTypeData = this.standingInstructionsData.statusOptions; + this.instructionTypeData = this.standingInstructionsData.instructionTypeOptions; + this.recurrenceTypeData = this.standingInstructionsData.recurrenceTypeOptions; + this.recurrenceFrequencyTypeData = this.standingInstructionsData.recurrenceFrequencyOptions; + } + + /** + * Submits the standing instructions form + */ + submit() { + const dateFormat = 'dd MMMM yyyy'; + const standingInstructionData = { + amount: this.editStandingInstructionsForm.value.amount, + dateFormat: dateFormat, + instructionType: this.editStandingInstructionsForm.value.instructionType, + locale: 'en', + monthDayFormat: 'dd MMMM', + priority: this.editStandingInstructionsForm.value.priority, + recurrenceFrequency: this.editStandingInstructionsForm.value.recurrenceFrequency, + recurrenceInterval: this.editStandingInstructionsForm.value.recurrenceInterval, + recurrenceOnMonthDay: this.datePipe.transform(this.editStandingInstructionsForm.value.recurrenceOnMonthDay, 'dd MMMM'), + recurrenceType: this.editStandingInstructionsForm.value.recurrenceType, + status: this.editStandingInstructionsForm.value.status, + validFrom: this.datePipe.transform(this.editStandingInstructionsForm.value.validFrom, dateFormat), + validTill: this.datePipe.transform(this.editStandingInstructionsForm.value.validTill, dateFormat) + }; + this.accountTransfersService.updateStandingInstructionsData(this.standingInstructionsId, standingInstructionData).subscribe((response: any) => { + this.router.navigate(['../../'], { relativeTo: this.route }); + }); + } + +} diff --git a/src/app/account-transfers/view-standing-instructions/view-standing-instructions.component.html b/src/app/account-transfers/view-standing-instructions/view-standing-instructions.component.html index b6b4d2a57..418273221 100644 --- a/src/app/account-transfers/view-standing-instructions/view-standing-instructions.component.html +++ b/src/app/account-transfers/view-standing-instructions/view-standing-instructions.component.html @@ -1,5 +1,5 @@
- diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/standing-instructions-tab/standing-instructions-tab.component.html b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/standing-instructions-tab/standing-instructions-tab.component.html index ca89f53bf..19814011a 100644 --- a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/standing-instructions-tab/standing-instructions-tab.component.html +++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/standing-instructions-tab/standing-instructions-tab.component.html @@ -47,7 +47,8 @@ diff --git a/src/app/loans/edit-loans-account/edit-loans-account.component.html b/src/app/loans/edit-loans-account/edit-loans-account.component.html index 4d5e994d8..22e28307f 100644 --- a/src/app/loans/edit-loans-account/edit-loans-account.component.html +++ b/src/app/loans/edit-loans-account/edit-loans-account.component.html @@ -64,4 +64,4 @@ -
\ No newline at end of file +