From 5ef7465ce526d389064c0ac42bdab60727da050f Mon Sep 17 00:00:00 2001 From: Benura Abeywardena <43112139+BLasan@users.noreply.github.com> Date: Sun, 12 Jul 2020 11:33:12 +0530 Subject: [PATCH] feat: add settle cash component (#879) Fixes: #759 --- .../organization-routing.module.ts | 13 ++- src/app/organization/organization.module.ts | 4 +- src/app/organization/organization.service.ts | 21 +++++ .../settle-cash/settle-cash.component.html | 82 +++++++++++++++++++ .../settle-cash/settle-cash.component.scss | 0 .../settle-cash/settle-cash.component.spec.ts | 25 ++++++ .../settle-cash/settle-cash.component.ts | 78 ++++++++++++++++++ .../teller-transaction-template.resolver.ts | 32 ++++++++ 8 files changed, 253 insertions(+), 2 deletions(-) create mode 100644 src/app/organization/tellers/settle-cash/settle-cash.component.html create mode 100644 src/app/organization/tellers/settle-cash/settle-cash.component.scss create mode 100644 src/app/organization/tellers/settle-cash/settle-cash.component.spec.ts create mode 100644 src/app/organization/tellers/settle-cash/settle-cash.component.ts create mode 100644 src/app/organization/tellers/teller-transaction-template.resolver.ts diff --git a/src/app/organization/organization-routing.module.ts b/src/app/organization/organization-routing.module.ts index 2e871634c..af816c268 100644 --- a/src/app/organization/organization-routing.module.ts +++ b/src/app/organization/organization-routing.module.ts @@ -74,6 +74,8 @@ import { OfficeDatatableResolver } from './offices/common-resolvers/office-datat import { OfficeDatatablesResolver } from './offices/common-resolvers/office-datatables.resolver'; import { SmsCampaignResolver } from './sms-campaigns/common-resolvers/sms-campaign.resolver'; import { ManageFundsResolver } from './manage-funds/manage-funds.resolver'; +import { SettleCashComponent } from './tellers/settle-cash/settle-cash.component'; +import { CashierTransactionTemplateResolver } from './tellers/teller-transaction-template.resolver'; /** Organization Routes */ const routes: Routes = [ @@ -356,6 +358,14 @@ const routes: Routes = [ resolve: { currencies: CurrenciesResolver } + }, + { + path: 'settle', + component: SettleCashComponent, + data: { title: extract('Settle Cash'), breadcrumb: 'Settle Cash', routeParamBreadcrumb: false }, + resolve: { + cashierTemplate: CashierTransactionTemplateResolver + } } ] } @@ -499,7 +509,8 @@ const routes: Routes = [ OfficeResolver, OfficeDatatableResolver, OfficeDatatablesResolver, - ManageFundsResolver + ManageFundsResolver, + CashierTransactionTemplateResolver ] }) export class OrganizationRoutingModule { } diff --git a/src/app/organization/organization.module.ts b/src/app/organization/organization.module.ts index 968d474d1..b44c6fc79 100644 --- a/src/app/organization/organization.module.ts +++ b/src/app/organization/organization.module.ts @@ -46,6 +46,7 @@ import { ManageFundsComponent } from './manage-funds/manage-funds.component'; import { ManageCurrenciesComponent } from './currencies/manage-currencies/manage-currencies.component'; import { CashiersComponent } from './tellers/cashiers/cashiers.component'; import { TransactionsComponent } from './tellers/transactions/transactions.component'; +import { SettleCashComponent } from './tellers/settle-cash/settle-cash.component'; /** * Organization Module @@ -97,7 +98,8 @@ import { TransactionsComponent } from './tellers/transactions/transactions.compo ManageFundsComponent, ManageCurrenciesComponent, CashiersComponent, - TransactionsComponent + TransactionsComponent, + SettleCashComponent ] }) export class OrganizationModule { } diff --git a/src/app/organization/organization.service.ts b/src/app/organization/organization.service.ts index 457b1d849..a5859be6d 100644 --- a/src/app/organization/organization.service.ts +++ b/src/app/organization/organization.service.ts @@ -284,6 +284,27 @@ export class OrganizationService { return this.http.get(`/tellers/${tellerId}/cashiers/${cashierId}/summaryandtransactions`, { params: httpParams }); } + /** Get Cashier Transaction template. + * @param {string} tellerId Teller Id. + * @param {string} cashierId Cashier Id. + * @returns {Observable} Cashier Transaction data. + */ + getCashierTransactionTemplate(tellerId: string, cashierId: string): Observable { + return this.http.get(`/tellers/${tellerId}/cashiers/${cashierId}/transactions/template`); + } + + /** + * Settle Cash. + * @param {string} tellerId Teller Id. + * @param {string} cashierId Cashier Id. + * @param {string} cashData Cash Data. + * @returns {Observable} + */ + settleCash(tellerId: string, cashierId: string, cashData: any): Observable { + const httpParams = new HttpParams().set('command', 'settle'); + return this.http.post(`/tellers/${tellerId}/cashiers/${cashierId}/settle`, cashData, {params: httpParams}); + } + /** * @param {string} tellerId Teller ID of teller to be deleted. * @returns {Observable} diff --git a/src/app/organization/tellers/settle-cash/settle-cash.component.html b/src/app/organization/tellers/settle-cash/settle-cash.component.html new file mode 100644 index 000000000..cea6c168a --- /dev/null +++ b/src/app/organization/tellers/settle-cash/settle-cash.component.html @@ -0,0 +1,82 @@ +
+ + + +
+ + + +
+ + + Office + + + + + Teller Name + + + + + Cashier + + + + + Assignment Period + + + + + Date + + + + + Date is required + + + + + Currency + + + {{ currency.name }} + + + + Currency is required + + + + + Amount + + + Amount is required + + + + + Notes/Comments + + + Notes/Comments is required + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/organization/tellers/settle-cash/settle-cash.component.scss b/src/app/organization/tellers/settle-cash/settle-cash.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/organization/tellers/settle-cash/settle-cash.component.spec.ts b/src/app/organization/tellers/settle-cash/settle-cash.component.spec.ts new file mode 100644 index 000000000..1c732cc09 --- /dev/null +++ b/src/app/organization/tellers/settle-cash/settle-cash.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { SettleCashComponent } from './settle-cash.component'; + +describe('SettleCashComponent', () => { + let component: SettleCashComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ SettleCashComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(SettleCashComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/organization/tellers/settle-cash/settle-cash.component.ts b/src/app/organization/tellers/settle-cash/settle-cash.component.ts new file mode 100644 index 000000000..138cb3029 --- /dev/null +++ b/src/app/organization/tellers/settle-cash/settle-cash.component.ts @@ -0,0 +1,78 @@ +import { Component, OnInit } from '@angular/core'; +import { FormGroup, FormBuilder, Validators } from '@angular/forms'; +import { ActivatedRoute, Router } from '@angular/router'; +import { DatePipe } from '@angular/common'; +import { OrganizationService } from 'app/organization/organization.service'; + +@Component({ + selector: 'mifosx-settle-cash', + templateUrl: './settle-cash.component.html', + styleUrls: ['./settle-cash.component.scss'] +}) +export class SettleCashComponent implements OnInit { + + /** Minimum Date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum Date allowed. */ + maxDate = new Date(); + /** Cashier data. */ + cashierData: any; + /** Cashier Form. */ + settleCashForm: FormGroup; + + /** + * Get cashier data from `Resolver`. + * @param {FormBuilder} formBuilder Form Builder. + * @param {ActivatedRoute} route ActivateRoute. + * @param {DatePipe} datePipe Date Pipe. + * @param {OrganizationService} organizationService Organization Service. + * @param {Router} router Router. + */ + constructor(private formBuilder: FormBuilder, + private route: ActivatedRoute, + private datePipe: DatePipe, + private organizationService: OrganizationService, + private router: Router) { + this.route.data.subscribe((data: { cashierTemplate: any}) => { + this.cashierData = data.cashierTemplate; + }); + } + + ngOnInit() { + this.setCashierForm(); + } + + /** + * Set Cashier form. + */ + setCashierForm() { + this.settleCashForm = this.formBuilder.group({ + 'office': [{value: this.cashierData.officeName, disabled: true}], + 'tellerName': [{value: this.cashierData.tellerName, disabled: true}], + 'cashier': [{value: this.cashierData.cashierName, disabled: true}], + 'assignmentPeriod': [{value: this.datePipe.transform(this.cashierData.startDate, 'dd MMMM yyyy') + ' - ' + this.datePipe.transform(this.cashierData.endDate, 'dd MMMM yyyy'), disabled: true}], + 'txnDate': [new Date(), Validators.required], + 'currencyCode': ['', Validators.required], + 'txnAmount': ['', Validators.required], + 'txnNote': ['', Validators.required] + }); + } + + /** + * Submits Settle Cash form. + */ + submit() { + const dateFormat = 'dd MMMM yyyy'; + const txnDate = this.settleCashForm.value.txnDate; + this.settleCashForm.patchValue({ + txnDate: this.datePipe.transform(txnDate, dateFormat) + }); + const settleCashForm = this.settleCashForm.value; + settleCashForm.dateFormat = dateFormat; + settleCashForm.locale = 'en'; + this.organizationService.settleCash(this.cashierData.tellerId, this.cashierData.cashierId, settleCashForm).subscribe((response: any) => { + this.router.navigate(['../'], {relativeTo: this.route}); + }); + } + +} diff --git a/src/app/organization/tellers/teller-transaction-template.resolver.ts b/src/app/organization/tellers/teller-transaction-template.resolver.ts new file mode 100644 index 000000000..507b1771b --- /dev/null +++ b/src/app/organization/tellers/teller-transaction-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 { OrganizationService } from 'app/organization/organization.service'; + +/** + * Cashier transaction data resolver. + */ +@Injectable() +export class CashierTransactionTemplateResolver implements Resolve { + + /** + * @param {OrganizationService} organizationService Organization service. + */ + constructor(private organizationService: OrganizationService) {} + + /** + * Returns the cashier transaction data. + * @returns {Observable} + */ + resolve(route: ActivatedRouteSnapshot): Observable { + const cashierId = route.parent.paramMap.get('id'); + const tellerId = route.parent.parent.paramMap.get('id'); + return this.organizationService.getCashierTransactionTemplate(tellerId, cashierId); + } + +}