diff --git a/src/app/account-transfers/account-transfers-routing.module.ts b/src/app/account-transfers/account-transfers-routing.module.ts index e08ae86a5..1ea58416a 100644 --- a/src/app/account-transfers/account-transfers-routing.module.ts +++ b/src/app/account-transfers/account-transfers-routing.module.ts @@ -8,16 +8,26 @@ 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'; +import { CreateStandingInstructionsComponent } from './create-standing-instructions/create-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'; +import { StandingInstructionsTemplateResolver } from './common-resolvers/standing-instructions-template.resolver'; /** Loans Route. */ const routes: Routes = [ { path: '', children: [ + { + path: 'create-standing-instructions', + data: { title: extract('Create Standing Instructions'), breadcrumb: 'Create Standing Instructions', routeParamBreadcrumb: 'Create Standing Instructions' }, + component: CreateStandingInstructionsComponent, + resolve: { + standingIntructionsTemplate: StandingInstructionsTemplateResolver + } + }, { path: ':standingInstructionsId', data: { title: extract('Standing Instructions'), routeParamBreadcrumb: 'standingInstructionsId' }, @@ -39,8 +49,9 @@ const routes: Routes = [ }, } ] - }] - } + } + ] + }, ]; @NgModule({ imports: [RouterModule.forChild(routes)], @@ -48,7 +59,8 @@ const routes: Routes = [ declarations: [], providers: [ ViewStandingInstructionsResolver, - StandingInstructionsDataAndTemplateResolver + StandingInstructionsDataAndTemplateResolver, + StandingInstructionsTemplateResolver ] }) diff --git a/src/app/account-transfers/account-transfers.module.ts b/src/app/account-transfers/account-transfers.module.ts index 6401c0925..e485d08a1 100644 --- a/src/app/account-transfers/account-transfers.module.ts +++ b/src/app/account-transfers/account-transfers.module.ts @@ -11,6 +11,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'; +import { CreateStandingInstructionsComponent } from './create-standing-instructions/create-standing-instructions.component'; /** * Account Transfers Module @@ -21,7 +22,8 @@ import { EditStandingInstructionsComponent } from './edit-standing-instructions/ imports: [SharedModule, PipesModule, DirectivesModule, AccountTransfersRoutingModule], declarations: [ ViewStandingInstructionsComponent, - EditStandingInstructionsComponent + EditStandingInstructionsComponent, + CreateStandingInstructionsComponent ], providers: [DatePipe] }) diff --git a/src/app/account-transfers/account-transfers.service.ts b/src/app/account-transfers/account-transfers.service.ts index fa6dd9057..fb2dc9445 100644 --- a/src/app/account-transfers/account-transfers.service.ts +++ b/src/app/account-transfers/account-transfers.service.ts @@ -33,4 +33,22 @@ export class AccountTransfersService { return this.http.put(`/standinginstructions/${standinginstructionsId}`, data, { params: httpParams }); } + getStandingInstructionsTemplate(clientId: any, officeId: any, accountTypeId: string, formValue?: any): Observable { + let httpParams = new HttpParams().set('fromAccountType', accountTypeId) + .set('fromClientId', clientId) + .set('fromOfficeId', officeId); + if (formValue) { + const propNames = Object.getOwnPropertyNames(formValue); + for (let i = 0; i < propNames.length; i++) { + const propName = propNames[i]; + httpParams = httpParams.set(propName, formValue[propName]); + } + } + return this.http.get(`/standinginstructions/template`, { params: httpParams }); + } + + createStandingInstructions(data: Object): Observable { + return this.http.post(`/standinginstructions`, data); + } + } diff --git a/src/app/account-transfers/common-resolvers/standing-instructions-template.resolver.ts b/src/app/account-transfers/common-resolvers/standing-instructions-template.resolver.ts new file mode 100644 index 000000000..57c4696cf --- /dev/null +++ b/src/app/account-transfers/common-resolvers/standing-instructions-template.resolver.ts @@ -0,0 +1,46 @@ +/** 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 StandingInstructionsTemplateResolver implements Resolve { + + accountTypeId: string; + + /** + * @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 officeId = route.queryParamMap.get('officeId'); + const accountType = route.queryParamMap.get('accountType'); + const clientId = route.parent.paramMap.get('clientId'); + switch (accountType) { + case 'fromloans': + this.accountTypeId = '1'; + break; + case 'fromsavings': + this.accountTypeId = '2'; + break; + default: + this.accountTypeId = '0'; + } + return this.accountTransfersService.getStandingInstructionsTemplate(clientId, officeId, this.accountTypeId); + } + +} diff --git a/src/app/account-transfers/create-standing-instructions/create-standing-instructions.component.html b/src/app/account-transfers/create-standing-instructions/create-standing-instructions.component.html new file mode 100644 index 000000000..d6d05dcd9 --- /dev/null +++ b/src/app/account-transfers/create-standing-instructions/create-standing-instructions.component.html @@ -0,0 +1,244 @@ +
+ + + +
+ + + +
+ + + Name + + + Name is required + + + + + Applicant + + + + + Type + + + {{ transferType.value }} + + + + Transfer Type is required + + + + + Priority + + + {{ priorityType.value }} + + + + Priority is required + + + + + Status + + + {{ statusType.value }} + + + + Status is required + + + + + From Account Type + + + {{ fromAccountType.value }} + + + + From Account Type is required + + + + + From Account + + + {{ fromAccount.productName }} - {{ fromAccount.accountNo }} + + + + From Account is required + + + + + Destination + + + {{ destinationType.value }} + + + + Destination is required + + + + + To Office + + + {{ toOfficeType.name }} + + + + To Office is required + + + + + Beneficiary + + + {{ toClientType.displayName }} + + + + Beneficiary is required + + + + + To Account Type + + + {{ toAccountType.value }} + + + + To Account Type is required + + + + + To Account + + + {{ toAccount.productName }} - {{ toAccount.accountNo }} + + + + To Account is required + + + + + Standing Instruction Type + + + {{ instructionsType.value }} + + + + Standing Instruction Type is required + + + + + Amount + + + Amount is required + + + + + Validity From + + + + + Valid From Date is required + + + + + Validity To + + + + + Valid Till Date is required + + + + + Recurrence Type + + + {{ recurrenceType.value }} + + + + Recurrence Type is required + + + + + Interval + + + Recurrence Interval is required + + + + + Recurrence Frequency + + + {{ recurrenceFrequencyType.value }} + + + + Recurrence Frequency is required + + + + + On Month Day + + + + + On Month Day is required + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/account-transfers/create-standing-instructions/create-standing-instructions.component.scss b/src/app/account-transfers/create-standing-instructions/create-standing-instructions.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/account-transfers/create-standing-instructions/create-standing-instructions.component.spec.ts b/src/app/account-transfers/create-standing-instructions/create-standing-instructions.component.spec.ts new file mode 100644 index 000000000..aead9ad2b --- /dev/null +++ b/src/app/account-transfers/create-standing-instructions/create-standing-instructions.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CreateStandingInstructionsComponent } from './create-standing-instructions.component'; + +describe('CreateStandingInstructionsComponent', () => { + let component: CreateStandingInstructionsComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CreateStandingInstructionsComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CreateStandingInstructionsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/account-transfers/create-standing-instructions/create-standing-instructions.component.ts b/src/app/account-transfers/create-standing-instructions/create-standing-instructions.component.ts new file mode 100644 index 000000000..6a4ef5841 --- /dev/null +++ b/src/app/account-transfers/create-standing-instructions/create-standing-instructions.component.ts @@ -0,0 +1,224 @@ +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-create-standing-instructions', + templateUrl: './create-standing-instructions.component.html', + styleUrls: ['./create-standing-instructions.component.scss'] +}) +export class CreateStandingInstructionsComponent implements OnInit { + + /** Standing Instructions Data */ + standingIntructionsTemplate: any; + /** Minimum date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum date allowed. */ + maxDate = new Date(2100, 0, 1); + /** Allow Client Edit */ + allowclientedit = true; + /** Edit Standing Instructions form. */ + createStandingInstructionsForm: 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; + /** Transfer Type Data */ + transferTypeData: any; + /** From Account Type Data */ + fromAccountTypeData: any; + /** From Account Data */ + fromAccountData: any; + /** Destination Type Data */ + destinationTypeData: { id: number; value: string; }[]; + /** To Office Type Data */ + toOfficeTypeData: any; + /** To Client Type Data */ + toClientTypeData: any; + /** To Account Type Data */ + toAccountTypeData: any; + /** To Account Data */ + toAccountData: any; + /** Account Type Id */ + accountTypeId: any; + /** Office Id */ + officeId: any; + /** Account Type */ + accountType: any; + /** Client Id */ + clientId: any; + + /** + * Retrieves the standing instructions template from `resolve`. + * @param {ActivatedRoute} route Activated Route. + * @param {FormBuilder} formBuilder Form Builder + * @param {Router} router Router + * @param {AccountTransfersService} accountTransfersService Account Transfers Service + * @param {DatePipe} datePipe Date Pipe + */ + constructor(private formBuilder: FormBuilder, + private route: ActivatedRoute, + private router: Router, + private accountTransfersService: AccountTransfersService, + private datePipe: DatePipe) { + this.route.data.subscribe((data: { standingIntructionsTemplate: any }) => { + this.standingIntructionsTemplate = data.standingIntructionsTemplate; + this.setParams(); + this.setOptions(); + }); + } + /** Sets the value from the URL */ + setParams() { + this.officeId = this.route.snapshot.queryParams['officeId']; + this.accountType = this.route.snapshot.queryParams['accountType']; + this.clientId = this.route.parent.snapshot.params['clientId']; + switch (this.accountType) { + case 'fromloans': + this.accountTypeId = '1'; + break; + case 'fromsavings': + this.accountTypeId = '2'; + break; + default: + this.accountTypeId = '0'; + } + } + + /** + * Creates and sets the create standing instructions form. + */ + ngOnInit() { + this.createCreateStandingInstructionsForm(); + this.buildDependencies(); + this.createStandingInstructionsForm.patchValue({ + 'applicant': this.standingIntructionsTemplate.fromClient.displayName + }); + } + + /** + * Creates the standing instruction form. + */ + createCreateStandingInstructionsForm() { + this.createStandingInstructionsForm = this.formBuilder.group({ + 'name': ['', Validators.required], + 'applicant': [{value: '', disabled: true}], + 'transferType': ['', Validators.required], + 'priority': ['', Validators.required], + 'status': ['', Validators.required], + 'fromAccountType': ['', Validators.required], + 'fromAccountId': ['', Validators.required], + 'destination': ['', Validators.required], + 'toOfficeId': ['', Validators.required], + 'toClientId': ['', Validators.required], + 'toAccountType': ['', Validators.required], + 'toAccountId': ['', Validators.required], + 'instructionType': ['', Validators.required], + 'amount': ['', Validators.required], + 'validFrom': ['', Validators.required], + 'validTill': ['', Validators.required], + 'recurrenceType': ['', Validators.required], + 'recurrenceInterval': ['', Validators.required], + 'recurrenceFrequency': ['', Validators.required], + 'recurrenceOnMonthDay': ['', Validators.required] + }); + } + + /** Sets options value */ + setOptions() { + this.transferTypeData = this.standingIntructionsTemplate.transferTypeOptions; + this.priorityTypeData = this.standingIntructionsTemplate.priorityOptions; + this.statusTypeData = this.standingIntructionsTemplate.statusOptions; + this.fromAccountTypeData = this.standingIntructionsTemplate.fromAccountTypeOptions; + this.fromAccountData = this.standingIntructionsTemplate.fromAccountOptions; + this.destinationTypeData = [{ id: 1, value: 'own account' }, { id: 2, value: 'with in bank' }]; + this.toOfficeTypeData = this.standingIntructionsTemplate.toOfficeOptions; + this.toClientTypeData = this.standingIntructionsTemplate.toClientOptions; + this.toAccountTypeData = this.standingIntructionsTemplate.toAccountTypeOptions; + this.toAccountData = this.standingIntructionsTemplate.toAccountOptions; + this.instructionTypeData = this.standingIntructionsTemplate.instructionTypeOptions; + this.recurrenceTypeData = this.standingIntructionsTemplate.recurrenceTypeOptions; + this.recurrenceFrequencyTypeData = this.standingIntructionsTemplate.recurrenceFrequencyOptions; + } + + /** + * Changes the value on change of destination value + */ + buildDependencies() { + this.createStandingInstructionsForm.get('destination').valueChanges.subscribe((destination: any) => { + if (destination === 1) { + this.allowclientedit = false; + this.createStandingInstructionsForm.patchValue({ + 'toOfficeId': this.officeId, + 'toClientId': this.clientId + }); + this.createStandingInstructionsForm.controls['toOfficeId'].disable(); + this.createStandingInstructionsForm.controls['toClientId'].disable(); + this.changeEvent(); + } else { + this.allowclientedit = true; + this.createStandingInstructionsForm.patchValue({ + 'toOfficeId': '', + 'toClientId': '' + }); + this.createStandingInstructionsForm.controls['toOfficeId'].enable(); + this.createStandingInstructionsForm.controls['toClientId'].enable(); + } + }); + + } + + /** Executes on change of various select options */ + changeEvent() { + const formValue = this.refineObject(this.createStandingInstructionsForm.value); + this.accountTransfersService.getStandingInstructionsTemplate(this.clientId, this.officeId, this.accountTypeId, formValue).subscribe((response: any) => { + this.standingIntructionsTemplate = response; + this.setOptions(); + }); + } + + /** Refine Object + * Removes the object param with null or '' values + */ + refineObject(dataObj: Object) { + const propNames = Object.getOwnPropertyNames(dataObj); + for (let i = 0; i < propNames.length; i++) { + const propName = propNames[i]; + if (dataObj[propName] === null || dataObj[propName] === undefined || dataObj[propName] === '') { + delete dataObj[propName]; + } + } + return dataObj; + } + + /** + * Submits the standing instructions form + */ + submit() { + const dateFormat = 'dd MMMM yyyy'; + const standingInstructionData = { + ... this.createStandingInstructionsForm.value, + dateFormat: dateFormat, + locale: 'en', + monthDayFormat: 'dd MMMM', + fromClientId: this.clientId, + fromOfficeId: this.officeId, + validFrom: this.datePipe.transform(this.createStandingInstructionsForm.value.validFrom, dateFormat), + validTill: this.datePipe.transform(this.createStandingInstructionsForm.value.validTill, dateFormat), + recurrenceOnMonthDay: this.datePipe.transform(this.createStandingInstructionsForm.value.recurrenceOnMonthDay, 'dd MMMM'), + }; + delete standingInstructionData['destination']; + delete standingInstructionData['applicant']; + this.accountTransfersService.createStandingInstructions(standingInstructionData).subscribe((response: any) => { + this.router.navigate(['../../'], { relativeTo: this.route }); + }); + } + +} 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 index 326453a51..e754626b3 100644 --- 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 @@ -94,7 +94,7 @@ Amount - + 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 index cba72aa45..8d90fe15d 100644 --- 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 @@ -86,7 +86,7 @@ export class EditStandingInstructionsComponent implements OnInit { } /** - * Creates the group form. + * Creates the standing instructions form. */ createEditStandingInstructionsForm() { this.editStandingInstructionsForm = this.formBuilder.group({ diff --git a/src/app/clients/clients-routing.module.ts b/src/app/clients/clients-routing.module.ts index acba0db6a..7f760420b 100644 --- a/src/app/clients/clients-routing.module.ts +++ b/src/app/clients/clients-routing.module.ts @@ -229,6 +229,10 @@ const routes: Routes = [ path: 'sharesaccounts', loadChildren: '../shares/shares.module#SharesModule' }, + { + path: 'standing-instructions', + loadChildren: '../account-transfers/account-transfers.module#AccountTransfersModule' + }, ] } ] diff --git a/src/app/clients/clients-view/clients-view.component.html b/src/app/clients/clients-view/clients-view.component.html index e20526ffa..077661e4a 100644 --- a/src/app/clients/clients-view/clients-view.component.html +++ b/src/app/clients/clients-view/clients-view.component.html @@ -37,6 +37,7 @@ + diff --git a/src/app/clients/clients-view/clients-view.component.ts b/src/app/clients/clients-view/clients-view.component.ts index 5bf695670..ccfd79b69 100644 --- a/src/app/clients/clients-view/clients-view.component.ts +++ b/src/app/clients/clients-view/clients-view.component.ts @@ -95,6 +95,10 @@ export class ClientsViewComponent implements OnInit { case 'Delete Image': this.deleteProfileImage(); break; + case 'Create Standing Instructions': + const queryParams: any = { officeId: this.clientViewData.officeId, accountType: 'fromsavings' }; + this.router.navigate(['standing-instructions/create-standing-instructions'], { relativeTo: this.route, queryParams: queryParams }); + break; } } diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/recurring-deposits-account-view.component.html b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/recurring-deposits-account-view.component.html index 861428542..d8e00e274 100644 --- a/src/app/deposits/recurring-deposits/recurring-deposits-account-view/recurring-deposits-account-view.component.html +++ b/src/app/deposits/recurring-deposits/recurring-deposits-account-view/recurring-deposits-account-view.component.html @@ -211,7 +211,7 @@ Charges - Standing Instructions diff --git a/src/app/deposits/recurring-deposits/recurring-deposits-routing.module.ts b/src/app/deposits/recurring-deposits/recurring-deposits-routing.module.ts index 207a7ba7f..7e4a026ff 100644 --- a/src/app/deposits/recurring-deposits/recurring-deposits-routing.module.ts +++ b/src/app/deposits/recurring-deposits/recurring-deposits-routing.module.ts @@ -76,7 +76,7 @@ const routes: Routes = [ data: { title: extract('Recurring Deposit Account Charges'), breadcrumb: 'Charges', routeParamBreadcrumb: false } }, { - path: 'standing-instructions', + path: 'standing-instructions-tab', component: StandingInstructionsTabComponent, data: { title: extract('Recurring Deposit Account Standing Instructions'), breadcrumb: 'Standing Instructions', routeParamBreadcrumb: false }, resolve: { @@ -158,7 +158,6 @@ const routes: Routes = [ children: [ { path: 'standing-instructions', - data: { title: extract('Standing Instructions'), breadcrumb: 'standing-instructions', routeParamBreadcrumb: false }, loadChildren: '../../account-transfers/account-transfers.module#AccountTransfersModule' }, ]