feat: add allocate cash component (#878)

Fixes: #758
This commit is contained in:
Benura Abeywardena
2020-07-12 12:11:43 +05:30
committed by GitHub
parent 5ef7465ce5
commit 1b0aa6c28e
7 changed files with 207 additions and 2 deletions
@@ -0,0 +1,82 @@
<div class="container">
<mat-card>
<form [formGroup]="allocateCashForm" (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="allocateCashForm.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="allocateCashForm.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="allocateCashForm.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="allocateCashForm.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]="!allocateCashForm.valid">Submit</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AllocateCashComponent } from './allocate-cash.component';
describe('AllocateCashComponent', () => {
let component: AllocateCashComponent;
let fixture: ComponentFixture<AllocateCashComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AllocateCashComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AllocateCashComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,84 @@
/** Angular Imports. */
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { DatePipe } from '@angular/common';
/** Custom Services. */
import { OrganizationService } from 'app/organization/organization.service';
/**
* Allocate Cash component.
*/
@Component({
selector: 'mifosx-allocate-cash',
templateUrl: './allocate-cash.component.html',
styleUrls: ['./allocate-cash.component.scss']
})
export class AllocateCashComponent implements OnInit {
/** Minimum Date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum Date allowed. */
maxDate = new Date();
/** Cashier data. */
cashierData: any;
/** Cashier Form. */
allocateCashForm: 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.allocateCashForm = 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 Allocate Cash form.
*/
submit() {
const dateFormat = 'dd MMMM yyyy';
const txnDate = this.allocateCashForm.value.txnDate;
this.allocateCashForm.patchValue({
txnDate: this.datePipe.transform(txnDate, dateFormat)
});
const allocateCashForm = this.allocateCashForm.value;
allocateCashForm.dateFormat = dateFormat;
allocateCashForm.locale = 'en';
this.organizationService.allocateCash(this.cashierData.tellerId, this.cashierData.cashierId, allocateCashForm).subscribe((response: any) => {
this.router.navigate(['../'], {relativeTo: this.route});
});
}
}