From a977cb6e0c61778f8718c045dc15049a85b10a7c Mon Sep 17 00:00:00 2001 From: Benura Abeywardena <43112139+BLasan@users.noreply.github.com> Date: Sun, 12 Jul 2020 12:32:55 +0530 Subject: [PATCH] feat: add edit cashier component (#802) Fixes: #762 --- .../organization-routing.module.ts | 17 +++- src/app/organization/organization.module.ts | 4 +- src/app/organization/organization.service.ts | 19 ++++ .../edit-cashier/edit-cashier.component.html | 83 +++++++++++++++++ .../edit-cashier/edit-cashier.component.scss | 0 .../edit-cashier.component.spec.ts | 25 ++++++ .../edit-cashier/edit-cashier.component.ts | 88 +++++++++++++++++++ .../edit-cashier/edit-cashier.resolver.ts | 31 +++++++ .../view-cashier/view-cashier.component.html | 2 +- 9 files changed, 265 insertions(+), 4 deletions(-) create mode 100644 src/app/organization/tellers/edit-cashier/edit-cashier.component.html create mode 100644 src/app/organization/tellers/edit-cashier/edit-cashier.component.scss create mode 100644 src/app/organization/tellers/edit-cashier/edit-cashier.component.spec.ts create mode 100644 src/app/organization/tellers/edit-cashier/edit-cashier.component.ts create mode 100644 src/app/organization/tellers/edit-cashier/edit-cashier.resolver.ts diff --git a/src/app/organization/organization-routing.module.ts b/src/app/organization/organization-routing.module.ts index 324ed5473..ccddb2c31 100644 --- a/src/app/organization/organization-routing.module.ts +++ b/src/app/organization/organization-routing.module.ts @@ -45,6 +45,7 @@ import { CashiersComponent } from './tellers/cashiers/cashiers.component'; import { TransactionsComponent } from './tellers/transactions/transactions.component'; import { AllocateCashComponent } from './tellers/allocate-cash/allocate-cash.component'; import { SettleCashComponent } from './tellers/settle-cash/settle-cash.component'; +import { EditCashierComponent } from './tellers/edit-cashier/edit-cashier.component'; /** Custom Resolvers */ import { LoanProvisioningCriteriaResolver } from './loan-provisioning-criteria/loan-provisioning-criteria.resolver'; @@ -77,6 +78,7 @@ import { OfficeDatatablesResolver } from './offices/common-resolvers/office-data import { SmsCampaignResolver } from './sms-campaigns/common-resolvers/sms-campaign.resolver'; import { ManageFundsResolver } from './manage-funds/manage-funds.resolver'; import { CashierTransactionTemplateResolver } from './tellers/teller-transaction-template.resolver'; +import { EditCashierResolver } from './tellers/edit-cashier/edit-cashier.resolver'; /** Organization Routes */ const routes: Routes = [ @@ -332,7 +334,7 @@ const routes: Routes = [ }, { path: 'cashiers', - data: { title: extract('View Cashiers'), breadcrumb: 'View Cashiers', routeParamBreadcrumb: false }, + data: { title: extract('Cashiers'), breadcrumb: 'Cashiers', routeParamBreadcrumb: false }, children: [ { path: '', @@ -348,6 +350,7 @@ const routes: Routes = [ { path: '', component: ViewCashierComponent, + data: { title: extract('View Cashier'), breadcrumb: 'View Cashier', routeParamBreadcrumb: false }, resolve: { cashier: CashierResolver } @@ -372,6 +375,15 @@ const routes: Routes = [ resolve: { cashierTemplate: CashierTransactionTemplateResolver } + }, + { + path: 'edit', + component: EditCashierComponent, + data: { title: extract('Edit Cashier'), breadcrumb: 'Edit', routeParamBreadcrumb: false }, + resolve: { + cashier: CashierResolver, + cashierTemplate: EditCashierResolver + } } ] } @@ -516,7 +528,8 @@ const routes: Routes = [ OfficeDatatableResolver, OfficeDatatablesResolver, ManageFundsResolver, - CashierTransactionTemplateResolver + CashierTransactionTemplateResolver, + EditCashierResolver ] }) export class OrganizationRoutingModule { } diff --git a/src/app/organization/organization.module.ts b/src/app/organization/organization.module.ts index 247bffa7f..692e24439 100644 --- a/src/app/organization/organization.module.ts +++ b/src/app/organization/organization.module.ts @@ -48,6 +48,7 @@ import { CashiersComponent } from './tellers/cashiers/cashiers.component'; import { TransactionsComponent } from './tellers/transactions/transactions.component'; import { SettleCashComponent } from './tellers/settle-cash/settle-cash.component'; import { AllocateCashComponent } from './tellers/allocate-cash/allocate-cash.component'; +import { EditCashierComponent } from './tellers/edit-cashier/edit-cashier.component'; /** * Organization Module @@ -101,7 +102,8 @@ import { AllocateCashComponent } from './tellers/allocate-cash/allocate-cash.com CashiersComponent, TransactionsComponent, SettleCashComponent, - AllocateCashComponent + AllocateCashComponent, + EditCashierComponent ] }) export class OrganizationModule { } diff --git a/src/app/organization/organization.service.ts b/src/app/organization/organization.service.ts index 629e10939..9d4ece737 100644 --- a/src/app/organization/organization.service.ts +++ b/src/app/organization/organization.service.ts @@ -311,6 +311,25 @@ export class OrganizationService { return this.http.post(`/tellers/${tellerId}/cashiers/${cashierId}/allocate`, cashData, {params: httpParams}); } + /** Get Cashier Template. + * @param tellerId Teller ID. + * @returns {Observable} Cashier template. + */ + getCashierTemplate(tellerId: string): Observable { + return this.http.get(`/tellers/${tellerId}/cashiers/template`); + } + + /** + * Update Cashier. + * @param tellerId Teller Id. + * @param cashierId Cashier Id. + * @param cashierData Cashier data to be updated. + * @returns {Observable} + */ + updateCashier(tellerId: string, cashierId: string, cashierData: any): Observable { + return this.http.put(`/tellers/${tellerId}/cashiers/${cashierId}`, cashierData); + } + /** * @param {string} tellerId Teller ID of teller to be deleted. * @returns {Observable} diff --git a/src/app/organization/tellers/edit-cashier/edit-cashier.component.html b/src/app/organization/tellers/edit-cashier/edit-cashier.component.html new file mode 100644 index 000000000..f13fc735c --- /dev/null +++ b/src/app/organization/tellers/edit-cashier/edit-cashier.component.html @@ -0,0 +1,83 @@ +
+ + + +
+ + + +
+ + + Office + + + + + Teller Name + + + + + Cashier + + + {{ staff.displayName }} + + + + + + Cashier + + + Select Option + + + + + + Description/Notes + + + + + From + + + + + From Date is required + + + + + To + + + + + To Date is required + + + +
+ + Full Day? + +
+ +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/organization/tellers/edit-cashier/edit-cashier.component.scss b/src/app/organization/tellers/edit-cashier/edit-cashier.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/organization/tellers/edit-cashier/edit-cashier.component.spec.ts b/src/app/organization/tellers/edit-cashier/edit-cashier.component.spec.ts new file mode 100644 index 000000000..3d6afa46a --- /dev/null +++ b/src/app/organization/tellers/edit-cashier/edit-cashier.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { EditCashierComponent } from './edit-cashier.component'; + +describe('EditCashierComponent', () => { + let component: EditCashierComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ EditCashierComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(EditCashierComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/organization/tellers/edit-cashier/edit-cashier.component.ts b/src/app/organization/tellers/edit-cashier/edit-cashier.component.ts new file mode 100644 index 000000000..94afcc3aa --- /dev/null +++ b/src/app/organization/tellers/edit-cashier/edit-cashier.component.ts @@ -0,0 +1,88 @@ +/** Angular Imports. */ +import { Component, OnInit } from '@angular/core'; +import { FormGroup, FormBuilder, Validators } from '@angular/forms'; +import { ActivatedRoute, Router } from '@angular/router'; +import { DatePipe } from '@angular/common'; + +/** Custom Services. */ +import { OrganizationService } from 'app/organization/organization.service'; + +/** + * Edit Cashier component. + */ +@Component({ + selector: 'mifosx-edit-cashier', + templateUrl: './edit-cashier.component.html', + styleUrls: ['./edit-cashier.component.scss'] +}) +export class EditCashierComponent implements OnInit { + + /** Cashier Data. */ + cashierData: any = new Object(); + /** Edit cashier form. */ + editCashierForm: FormGroup; + /** Is Staff ID present. */ + isStaffId = true; + /** Minimum Date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum Date allowed. */ + maxDate = new Date(); + + /** + * + * @param {FormBuilder} formBuilder Form Builder. + * @param {ActivatedRoute} route Activated Route. + * @param {Router} router Router. + * @param {DatePipe} datePipe Date Pipe. + * @param {OrganizationService} organizationService Organization Service. + */ + constructor(private formBuilder: FormBuilder, + private route: ActivatedRoute, + private router: Router, + private datePipe: DatePipe, + private organizationService: OrganizationService ) { + this.route.data.subscribe((data: { cashier: any, cashierTemplate: any }) => { + this.cashierData.data = data.cashier; + this.cashierData.template = data.cashierTemplate; + this.isStaffId = this.cashierData.template.staffOptions.some((element: any) => element.id === this.cashierData.data.staffId); + }); + } + + ngOnInit() { + this.setEditChargeForm(); + } + + /** + * Sets Edit Charge Form. + */ + setEditChargeForm() { + this.editCashierForm = this.formBuilder.group({ + 'staffId': [{value: this.cashierData.data.staffId, disabled: true}], + 'description': [this.cashierData.data.description], + 'startDate': [this.cashierData.data.startDate && new Date(this.cashierData.data.startDate), Validators.required], + 'endDate': [this.cashierData.data.endDate && new Date(this.cashierData.data.endDate), Validators.required], + 'isFullDay': [this.cashierData.data.isFullDay, Validators.required] + }); + } + + /** + * Submits edit cashier form. + */ + submit() { + const dateFormat = 'yyyy-MM-dd'; + const startDate = this.editCashierForm.value.startDate; + const endDate = this.editCashierForm.value.endDate; + this.editCashierForm.patchValue({ + 'startDate': this.datePipe.transform(startDate, dateFormat), + 'endDate': this.datePipe.transform(endDate, dateFormat) + }); + const editCashierForm = this.editCashierForm.value; + editCashierForm.locale = 'en'; + editCashierForm.dateFormat = dateFormat; + editCashierForm.staffId = this.cashierData.data.staffId; + this.organizationService.updateCashier(this.cashierData.data.tellerId, this.cashierData.data.id, editCashierForm).subscribe((response: any) => { + this.router.navigate(['../'], {relativeTo: this.route}); + }); + } + +} diff --git a/src/app/organization/tellers/edit-cashier/edit-cashier.resolver.ts b/src/app/organization/tellers/edit-cashier/edit-cashier.resolver.ts new file mode 100644 index 000000000..d42f26e01 --- /dev/null +++ b/src/app/organization/tellers/edit-cashier/edit-cashier.resolver.ts @@ -0,0 +1,31 @@ +/** Angular Imports */ +import { Injectable } from '@angular/core'; +import { Resolve, ActivatedRouteSnapshot } from '@angular/router'; + +/** rxjs Imports */ +import { Observable } from 'rxjs'; + +/** Custom Services */ +import { OrganizationService } from 'app/organization/organization.service'; + +/** + * Cashier Template resolver. + */ +@Injectable() +export class EditCashierResolver implements Resolve { + + /** + * @param {OrganizationService} organizationService Organization service. + */ + constructor(private organizationService: OrganizationService) {} + + /** + * Returns the cashier template. + * @returns {Observable} + */ + resolve(route: ActivatedRouteSnapshot): Observable { + const tellerId = route.parent.paramMap.get('id'); + return this.organizationService.getCashierTemplate(tellerId); + } + +} diff --git a/src/app/organization/tellers/view-cashier/view-cashier.component.html b/src/app/organization/tellers/view-cashier/view-cashier.component.html index 9f6317fc6..d21bd647c 100644 --- a/src/app/organization/tellers/view-cashier/view-cashier.component.html +++ b/src/app/organization/tellers/view-cashier/view-cashier.component.html @@ -1,5 +1,5 @@
-