diff --git a/src/app/savings/saving-account-actions/saving-account-actions.component.html b/src/app/savings/saving-account-actions/saving-account-actions.component.html index 62b6ba688..b82edef58 100644 --- a/src/app/savings/saving-account-actions/saving-account-actions.component.html +++ b/src/app/savings/saving-account-actions/saving-account-actions.component.html @@ -3,4 +3,5 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/src/app/savings/saving-account-actions/saving-account-actions.component.ts b/src/app/savings/saving-account-actions/saving-account-actions.component.ts index d1f731f6d..7d6ac6a67 100644 --- a/src/app/savings/saving-account-actions/saving-account-actions.component.ts +++ b/src/app/savings/saving-account-actions/saving-account-actions.component.ts @@ -1,6 +1,7 @@ /** Angular Imports */ import { Component } from '@angular/core'; -import { Router, ActivatedRoute } from '@angular/router'; +import { ActivatedRoute } from '@angular/router'; +import { SavingsService } from '../savings.service'; /** * Savings account actions component. @@ -12,8 +13,8 @@ import { Router, ActivatedRoute } from '@angular/router'; }) export class SavingAccountActionsComponent { - /** Shares Account Data */ - sharesAccountData: any; + /** Savings Account Data */ + savingsAccountData: any; /** Flag object to store possible actions and render appropriate UI to the user */ actions: { 'Approve': boolean @@ -33,10 +34,16 @@ export class SavingAccountActionsComponent { /** * @param {ActivatedRoute} route Activated Route + * @param {SavingsService} savingsService Savings Service */ - constructor(private route: ActivatedRoute) { + constructor(private route: ActivatedRoute, + private savingsService: SavingsService) { const name = this.route.snapshot.params['name']; - this.actions[name] = true; + const accountId = this.route.parent.snapshot.params['savingAccountId']; + this.savingsService.getSavingsAccountAndTemplate(accountId, true).subscribe((response: any) => { + this.savingsAccountData = response; + this.actions[name] = true; + }); } } diff --git a/src/app/savings/saving-account-actions/savings-account-assign-staff/savings-account-assign-staff.component.html b/src/app/savings/saving-account-actions/savings-account-assign-staff/savings-account-assign-staff.component.html new file mode 100644 index 000000000..a86c4faf6 --- /dev/null +++ b/src/app/savings/saving-account-actions/savings-account-assign-staff/savings-account-assign-staff.component.html @@ -0,0 +1,43 @@ +
+ + + +
+ + + +
+ + + To Savings Officer + + + {{ officer.displayName }} + + + + + + Assignment Date + + + + + Assignment Date is required + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/savings/saving-account-actions/savings-account-assign-staff/savings-account-assign-staff.component.scss b/src/app/savings/saving-account-actions/savings-account-assign-staff/savings-account-assign-staff.component.scss new file mode 100644 index 000000000..d774f68da --- /dev/null +++ b/src/app/savings/saving-account-actions/savings-account-assign-staff/savings-account-assign-staff.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; +} diff --git a/src/app/savings/saving-account-actions/savings-account-assign-staff/savings-account-assign-staff.component.spec.ts b/src/app/savings/saving-account-actions/savings-account-assign-staff/savings-account-assign-staff.component.spec.ts new file mode 100644 index 000000000..887378fa8 --- /dev/null +++ b/src/app/savings/saving-account-actions/savings-account-assign-staff/savings-account-assign-staff.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { SavingsAccountAssignStaffComponent } from './savings-account-assign-staff.component'; + +describe('SavingsAccountAssignStaffComponent', () => { + let component: SavingsAccountAssignStaffComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ SavingsAccountAssignStaffComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(SavingsAccountAssignStaffComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/savings/saving-account-actions/savings-account-assign-staff/savings-account-assign-staff.component.ts b/src/app/savings/saving-account-actions/savings-account-assign-staff/savings-account-assign-staff.component.ts new file mode 100644 index 000000000..f4d3c3fe9 --- /dev/null +++ b/src/app/savings/saving-account-actions/savings-account-assign-staff/savings-account-assign-staff.component.ts @@ -0,0 +1,90 @@ +/** Angular Imports */ +import { Component, OnInit, Input } from '@angular/core'; +import { FormGroup, FormBuilder, Validators } from '@angular/forms'; +import { DatePipe } from '@angular/common'; +import { ActivatedRoute, Router } from '@angular/router'; + +/** Custom Services */ +import { SavingsService } from 'app/savings/savings.service'; + +/** + * Savings Account Assign Staff Component + */ +@Component({ + selector: 'mifosx-savings-account-assign-staff', + templateUrl: './savings-account-assign-staff.component.html', + styleUrls: ['./savings-account-assign-staff.component.scss'] +}) +export class SavingsAccountAssignStaffComponent implements OnInit { + + /** Savings Account Data */ + @Input() savingsAccountData: any; + + /** Minimum date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum date allowed. */ + maxDate = new Date(); + /** Savings Account Assign Staff form. */ + savingsAssignStaffForm: FormGroup; + /** Savings Account Id */ + accountId: any; + /** Field Officer Data */ + fieldOfficerData: any; + + /** + * @param {FormBuilder} formBuilder Form Builder + * @param {SavingsService} savingsService Savings Service + * @param {DatePipe} datePipe Date Pipe + * @param {ActivatedRoute} route Activated Route + * @param {Router} router Router + */ + constructor(private formBuilder: FormBuilder, + private savingsService: SavingsService, + private datePipe: DatePipe, + private route: ActivatedRoute, + private router: Router) { + this.accountId = this.route.parent.snapshot.params['savingAccountId']; + } + + /** + * Creates the savings account assign staff form. + */ + ngOnInit() { + this.fieldOfficerData = this.savingsAccountData.fieldOfficerOptions; + this.createSavingsAssignStaffForm(); + } + + /** + * Creates the savings account assign staff form. + */ + createSavingsAssignStaffForm() { + this.savingsAssignStaffForm = this.formBuilder.group({ + 'toSavingsOfficerId': [''], + 'assignmentDate': ['', Validators.required] + }); + } + + /** + * Submits the form and assigns staff the saving account, + * if successful redirects to the saving account. + */ + submit() { + // TODO: Update once language and date settings are setup + const locale = 'en'; + const dateFormat = 'dd MMMM yyyy'; + const prevAssignmentDate: Date = this.savingsAssignStaffForm.value.assignmentDate; + this.savingsAssignStaffForm.patchValue({ + assignmentDate: this.datePipe.transform(prevAssignmentDate, dateFormat), + }); + const data = { + ...this.savingsAssignStaffForm.value, + fromSavingsOfficerId: '', + dateFormat, + locale + }; + this.savingsService.executeSavingsAccountCommand(this.accountId, 'assignSavingsOfficer', data).subscribe(() => { + this.router.navigate(['../../'], { relativeTo: this.route }); + }); + } + +} diff --git a/src/app/savings/savings-account-view/savings-account-view.component.ts b/src/app/savings/savings-account-view/savings-account-view.component.ts index 2acce70b4..178116f27 100644 --- a/src/app/savings/savings-account-view/savings-account-view.component.ts +++ b/src/app/savings/savings-account-view/savings-account-view.component.ts @@ -104,6 +104,7 @@ export class SavingsAccountViewComponent implements OnInit { case 'Activate': case 'Undo Approval': case 'Post Interest As On': + case 'Assign Staff': this.router.navigate([`actions/${name}`], { relativeTo: this.route }); break; case 'Modify Application': diff --git a/src/app/savings/savings.module.ts b/src/app/savings/savings.module.ts index 4066af238..f4f4ae5fe 100644 --- a/src/app/savings/savings.module.ts +++ b/src/app/savings/savings.module.ts @@ -31,6 +31,7 @@ import { WithdrawSavingsAccountComponent } from './saving-account-actions/withdr import { ActivateSavingsAccountComponent } from './saving-account-actions/activate-savings-account/activate-savings-account.component'; import { UndoApprovalSavingsAccountComponent } from './saving-account-actions/undo-approval-savings-account/undo-approval-savings-account.component'; import { PostInterestAsOnSavingsAccountComponent } from './saving-account-actions/post-interest-as-on-savings-account/post-interest-as-on-savings-account.component'; +import { SavingsAccountAssignStaffComponent } from './saving-account-actions/savings-account-assign-staff/savings-account-assign-staff.component'; /** * Savings Module @@ -66,7 +67,8 @@ import { PostInterestAsOnSavingsAccountComponent } from './saving-account-action WithdrawSavingsAccountComponent, ActivateSavingsAccountComponent, UndoApprovalSavingsAccountComponent, - PostInterestAsOnSavingsAccountComponent + PostInterestAsOnSavingsAccountComponent, + SavingsAccountAssignStaffComponent ], providers: [DatePipe] })