feat: add settle cash component (#879)

Fixes: #759
This commit is contained in:
Benura Abeywardena
2020-07-12 11:33:12 +05:30
committed by GitHub
parent ff6ac7028e
commit 5ef7465ce5
8 changed files with 253 additions and 2 deletions
@@ -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 { }
+3 -1
View File
@@ -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 { }
@@ -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<any>} Cashier Transaction data.
*/
getCashierTransactionTemplate(tellerId: string, cashierId: string): Observable<any> {
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<any>}
*/
settleCash(tellerId: string, cashierId: string, cashData: any): Observable<any> {
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<any>}
@@ -0,0 +1,82 @@
<div class="container">
<mat-card>
<form [formGroup]="settleCashForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="row wrap" fxLayoutGap="2%" fxLayout.lt-md="column">
<mat-form-field fxFlex="48%">
<mat-label>Office</mat-label>
<input matInput required formControlName="office">
</mat-form-field>
<mat-form-field fxFlex="48%">
<mat-label>Teller Name</mat-label>
<input matInput required formControlName="tellerName">
</mat-form-field>
<mat-form-field fxFlex="48%">
<mat-label>Cashier</mat-label>
<input matInput required formControlName="cashier">
</mat-form-field>
<mat-form-field fxFlex="48%">
<mat-label>Assignment Period</mat-label>
<input matInput formControlName="assignmentPeriod">
</mat-form-field>
<mat-form-field fxFlex="48%">
<mat-label>Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="cashDatePicker" required formControlName="txnDate">
<mat-datepicker-toggle matSuffix [for]="cashDatePicker"></mat-datepicker-toggle>
<mat-datepicker #cashDatePicker></mat-datepicker>
<mat-error *ngIf="settleCashForm.controls.txnDate.hasError('required')">
Date <strong>is required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="48%">
<mat-label>Currency</mat-label>
<mat-select required formControlName="currencyCode">
<mat-option *ngFor="let currency of cashierData.currencyOptions" [value]="currency.code">
{{ currency.name }}
</mat-option>
</mat-select>
<mat-error *ngIf="settleCashForm.controls.currencyCode.hasError('required')">
Currency <strong>is required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="48%">
<mat-label>Amount</mat-label>
<input matInput required formControlName="txnAmount">
<mat-error *ngIf="settleCashForm.controls.txnAmount.hasError('required')">
Amount <strong>is required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="48%">
<mat-label>Notes/Comments</mat-label>
<input matInput required formControlName="txnNote">
<mat-error *ngIf="settleCashForm.controls.txnNote.hasError('required')">
Notes/Comments <strong>is required</strong>
</mat-error>
</mat-form-field>
</div>
</mat-card-content>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="!settleCashForm.valid">Settle Cash</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -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<SettleCashComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SettleCashComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SettleCashComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -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});
});
}
}
@@ -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<Object> {
/**
* @param {OrganizationService} organizationService Organization service.
*/
constructor(private organizationService: OrganizationService) {}
/**
* Returns the cashier transaction data.
* @returns {Observable<any>}
*/
resolve(route: ActivatedRouteSnapshot): Observable<any> {
const cashierId = route.parent.paramMap.get('id');
const tellerId = route.parent.parent.paramMap.get('id');
return this.organizationService.getCashierTransactionTemplate(tellerId, cashierId);
}
}