Cashier checkout should now work
This commit is contained in:
@ -5,6 +5,10 @@ import {LogoutComponent} from './auth/logout/logout.component';
|
||||
import {HomeComponent} from './home/home.component';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path: 'checkout',
|
||||
loadChildren: () => import('./cashier-checkout/cashier-checkout.module').then(mod => mod.CashierCheckoutModule)
|
||||
},
|
||||
{
|
||||
path: 'devices',
|
||||
loadChildren: () => import('./devices/devices.module').then(mod => mod.DevicesModule)
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {ActiveCashiersResolver} from './active-cashiers-resolver.service';
|
||||
|
||||
describe('ActiveCashiersResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ActiveCashiersResolver]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([ActiveCashiersResolver], (service: ActiveCashiersResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
@ -0,0 +1,20 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { CashierCheckoutService } from './cashier-checkout.service';
|
||||
import { User } from "../core/user";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ActiveCashiersResolver implements Resolve<User[]> {
|
||||
|
||||
constructor(private ser: CashierCheckoutService) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<User[]> {
|
||||
const startDate = route.queryParamMap.get('startDate') || null;
|
||||
const finishDate = route.queryParamMap.get('finishDate') || null;
|
||||
return this.ser.activeCashiers(startDate, finishDate);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { CashierCheckoutDisplayItem } from './cashier-checkout';
|
||||
|
||||
|
||||
export class CashierCheckoutDataSource extends DataSource<CashierCheckoutDisplayItem> {
|
||||
|
||||
constructor(public data: CashierCheckoutDisplayItem[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<CashierCheckoutDisplayItem[]> {
|
||||
return observableOf(this.data);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {CashierCheckoutResolver} from './cashier-checkout-resolver.service';
|
||||
|
||||
describe('CashierCheckoutResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [CashierCheckoutResolver]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([CashierCheckoutResolver], (service: CashierCheckoutResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
@ -0,0 +1,21 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {CashierCheckout} from './cashier-checkout';
|
||||
import {CashierCheckoutService} from './cashier-checkout.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CashierCheckoutResolver implements Resolve<CashierCheckout> {
|
||||
|
||||
constructor(private ser: CashierCheckoutService) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<CashierCheckout> {
|
||||
const id = route.paramMap.get('id');
|
||||
const startDate = route.queryParamMap.get('startDate') || null;
|
||||
const finishDate = route.queryParamMap.get('finishDate') || null;
|
||||
return this.ser.list(id, startDate, finishDate);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
import {CashierCheckoutRoutingModule} from './cashier-checkout-routing.module';
|
||||
|
||||
describe('CashierCheckoutRoutingModule', () => {
|
||||
let CashierCheckoutRoutingModule: CashierCheckoutRoutingModule;
|
||||
|
||||
beforeEach(() => {
|
||||
CashierCheckoutRoutingModule = new CashierCheckoutRoutingModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(CashierCheckoutRoutingModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,52 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
import { CashierCheckoutResolver } from './cashier-checkout-resolver.service';
|
||||
import { AuthGuard } from '../auth/auth-guard.service';
|
||||
import { CashierCheckoutComponent } from './cashier-checkout.component';
|
||||
import { ActiveCashiersResolver } from "./active-cashiers-resolver.service";
|
||||
|
||||
const CashierCheckoutRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: CashierCheckoutComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Cashier Checkout'
|
||||
},
|
||||
resolve: {
|
||||
info: CashierCheckoutResolver,
|
||||
cashiers: ActiveCashiersResolver
|
||||
},
|
||||
runGuardsAndResolvers: 'always'
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: CashierCheckoutComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Cashier Checkout'
|
||||
},
|
||||
resolve: {
|
||||
info: CashierCheckoutResolver,
|
||||
cashiers: ActiveCashiersResolver
|
||||
},
|
||||
runGuardsAndResolvers: 'always'
|
||||
}
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterModule.forChild(CashierCheckoutRoutes)
|
||||
|
||||
],
|
||||
exports: [
|
||||
RouterModule
|
||||
],
|
||||
providers: [
|
||||
CashierCheckoutResolver
|
||||
]
|
||||
})
|
||||
export class CashierCheckoutRoutingModule {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
.right {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
<mat-card>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>cashier-checkout</mat-card-title>
|
||||
<button mat-button mat-icon-button (click)="exportCsv()">
|
||||
<mat-icon>save_alt</mat-icon>
|
||||
</button>
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
<form [formGroup]="form" fxLayout="column">
|
||||
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="20px" fxLayoutGap.lt-md="0px"
|
||||
fxLayoutAlign="space-around start">
|
||||
<mat-form-field fxFlex>
|
||||
<input matInput [matDatepicker]="startDate" (focus)="startDate.open()" placeholder="Start Date"
|
||||
formControlName="startDate" autocomplete="off">
|
||||
<mat-datepicker-toggle matSuffix [for]="startDate"></mat-datepicker-toggle>
|
||||
<mat-datepicker #startDate></mat-datepicker>
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex>
|
||||
<input matInput [matDatepicker]="finishDate" (focus)="finishDate.open()" placeholder="Finish Date"
|
||||
formControlName="finishDate" autocomplete="off">
|
||||
<mat-datepicker-toggle matSuffix [for]="finishDate"></mat-datepicker-toggle>
|
||||
<mat-datepicker #finishDate></mat-datepicker>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="20px" fxLayoutGap.lt-md="0px"
|
||||
fxLayoutAlign="space-around start">
|
||||
<mat-form-field fxFlex="80">
|
||||
<mat-label>Cashier</mat-label>
|
||||
<mat-select placeholder="Cashier" formControlName="cashier">
|
||||
<mat-option>-- Cashier --</mat-option>
|
||||
<mat-option *ngFor="let ac of activeCashiers" [value]="ac.id">
|
||||
{{ ac.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<button fxFlex="20" mat-raised-button color="primary" (click)="show()">Show</button>
|
||||
</div>
|
||||
</form>
|
||||
<mat-table #table [dataSource]="dataSource" aria-label="Elements">
|
||||
|
||||
<!-- Name Column -->
|
||||
<ng-container matColumnDef="name">
|
||||
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row"><a [href]="row.url">{{row.name}}</a></mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Amount Column -->
|
||||
<ng-container matColumnDef="amount">
|
||||
<mat-header-cell *matHeaderCellDef class="right">Amount</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row" class="right">{{row.amount | currency:'INR'}}</mat-cell>
|
||||
</ng-container>
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
|
||||
</mat-table>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
@ -0,0 +1,25 @@
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {CashierCheckoutComponent} from './cashier-checkout.component';
|
||||
|
||||
describe('CashierCheckoutComponent', () => {
|
||||
let component: CashierCheckoutComponent;
|
||||
let fixture: ComponentFixture<CashierCheckoutComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [CashierCheckoutComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(CashierCheckoutComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,96 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import * as moment from 'moment';
|
||||
import { CashierCheckoutDataSource } from './cashier-checkout-datasource';
|
||||
import { CashierCheckout } from './cashier-checkout';
|
||||
import { ToCsvService } from '../shared/to-csv.service';
|
||||
import { User } from "../core/user";
|
||||
|
||||
@Component({
|
||||
selector: 'app-cashier-checkout',
|
||||
templateUrl: './cashier-checkout.component.html',
|
||||
styleUrls: ['./cashier-checkout.component.css']
|
||||
})
|
||||
export class CashierCheckoutComponent implements OnInit {
|
||||
dataSource: CashierCheckoutDataSource;
|
||||
form: FormGroup;
|
||||
activeCashiers: User[];
|
||||
info: CashierCheckout;
|
||||
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'amount'];
|
||||
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private fb: FormBuilder,
|
||||
private toCsv: ToCsvService
|
||||
) {
|
||||
this.createForm();
|
||||
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { cashiers: User[], info: CashierCheckout }) => {
|
||||
this.activeCashiers = data.cashiers;
|
||||
this.info = data.info;
|
||||
this.form.setValue({
|
||||
cashier: this.info.user.id,
|
||||
startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(),
|
||||
finishDate: moment(this.info.finishDate, 'DD-MMM-YYYY').toDate()
|
||||
});
|
||||
this.dataSource = new CashierCheckoutDataSource(this.info.amounts);
|
||||
});
|
||||
}
|
||||
|
||||
show() {
|
||||
const info = this.getInfo();
|
||||
this.router.navigate(['checkout', this.form.value.cashier], {
|
||||
queryParams: {
|
||||
startDate: info.startDate,
|
||||
finishDate: info.finishDate
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
startDate: '',
|
||||
finishDate: '',
|
||||
cashier: ''
|
||||
});
|
||||
}
|
||||
|
||||
getInfo(): CashierCheckout {
|
||||
const formModel = this.form.value;
|
||||
|
||||
return {
|
||||
user: formModel.cashier,
|
||||
startDate: moment(formModel.startDate).format('DD-MMM-YYYY'),
|
||||
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY')
|
||||
};
|
||||
}
|
||||
|
||||
exportCsv() {
|
||||
const headers = {
|
||||
Date: 'date',
|
||||
Name: 'name',
|
||||
Type: 'type',
|
||||
Narration: 'narration',
|
||||
Debit: 'debit',
|
||||
Credit: 'credit',
|
||||
Running: 'running',
|
||||
Posted: 'posted'
|
||||
};
|
||||
const csvData = new Blob([this.toCsv.toCsv(headers, this.dataSource.data)], {type: 'text/csv;charset=utf-8;'});
|
||||
const link = document.createElement('a');
|
||||
link.href = window.URL.createObjectURL(csvData);
|
||||
link.setAttribute('download', 'cashier-checkout.csv');
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
import {CashierCheckoutModule} from './cashier-checkout.module';
|
||||
|
||||
describe('CashierCheckoutModule', () => {
|
||||
let CashierCheckoutModule: CashierCheckoutModule;
|
||||
|
||||
beforeEach(() => {
|
||||
CashierCheckoutModule = new CashierCheckoutModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(CashierCheckoutModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
71
bookie/src/app/cashier-checkout/cashier-checkout.module.ts
Normal file
71
bookie/src/app/cashier-checkout/cashier-checkout.module.ts
Normal file
@ -0,0 +1,71 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { MatAutocompleteModule } from '@angular/material/autocomplete';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE, MatNativeDateModule } from '@angular/material/core';
|
||||
import { MatDatepickerModule } from '@angular/material/datepicker';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatPaginatorModule } from '@angular/material/paginator';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatSortModule } from '@angular/material/sort';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { SharedModule} from '../shared/shared.module';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { CdkTableModule } from '@angular/cdk/table';
|
||||
import { CashierCheckoutRoutingModule } from './cashier-checkout-routing.module';
|
||||
import { CashierCheckoutComponent } from './cashier-checkout.component';
|
||||
import { MomentDateAdapter } from '@angular/material-moment-adapter';
|
||||
import { A11yModule } from '@angular/cdk/a11y';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
import { MatSelectModule } from "@angular/material";
|
||||
|
||||
export const MY_FORMATS = {
|
||||
parse: {
|
||||
dateInput: 'DD-MMM-YYYY',
|
||||
},
|
||||
display: {
|
||||
dateInput: 'DD-MMM-YYYY',
|
||||
monthYearLabel: 'MMM YYYY',
|
||||
dateA11yLabel: 'DD-MMM-YYYY',
|
||||
monthYearA11yLabel: 'MMM YYYY',
|
||||
},
|
||||
};
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
A11yModule,
|
||||
CommonModule,
|
||||
CdkTableModule,
|
||||
FlexLayoutModule,
|
||||
MatAutocompleteModule,
|
||||
MatButtonModule,
|
||||
MatCardModule,
|
||||
MatCheckboxModule,
|
||||
MatDatepickerModule,
|
||||
MatFormFieldModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatNativeDateModule,
|
||||
MatPaginatorModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatSelectModule,
|
||||
MatSortModule,
|
||||
MatTableModule,
|
||||
ReactiveFormsModule,
|
||||
SharedModule,
|
||||
CashierCheckoutRoutingModule
|
||||
],
|
||||
declarations: [
|
||||
CashierCheckoutComponent
|
||||
],
|
||||
providers: [
|
||||
{provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]},
|
||||
{provide: MAT_DATE_FORMATS, useValue: MY_FORMATS},
|
||||
]
|
||||
})
|
||||
export class CashierCheckoutModule {
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {CashierCheckoutService} from './cashier-checkout.service';
|
||||
|
||||
describe('CashierCheckoutService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [CashierCheckoutService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([CashierCheckoutService], (service: CashierCheckoutService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
55
bookie/src/app/cashier-checkout/cashier-checkout.service.ts
Normal file
55
bookie/src/app/cashier-checkout/cashier-checkout.service.ts
Normal file
@ -0,0 +1,55 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { CashierCheckout } from './cashier-checkout';
|
||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||
import {User} from "../core/user";
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
};
|
||||
|
||||
const url = '/v1/checkout';
|
||||
const urlActiveCashiers = '/v1/active-cashiers';
|
||||
const serviceName = 'CashierCheckoutService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CashierCheckoutService {
|
||||
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
|
||||
list(id: string, startDate: string, finishDate): Observable<CashierCheckout> {
|
||||
const listUrl = (id === null) ? url : `${url}/${id}`;
|
||||
const options = {params: new HttpParams()};
|
||||
if (startDate !== null) {
|
||||
options.params = options.params.set('s', startDate);
|
||||
}
|
||||
if (finishDate !== null) {
|
||||
options.params = options.params.set('f', finishDate);
|
||||
}
|
||||
return <Observable<CashierCheckout>>this.http.get<CashierCheckout>(listUrl, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
}
|
||||
|
||||
activeCashiers(startDate: string, finishDate): Observable<User[]> {
|
||||
const options = {params: new HttpParams()};
|
||||
if (startDate !== null) {
|
||||
options.params = options.params.set('s', startDate);
|
||||
}
|
||||
if (finishDate !== null) {
|
||||
options.params = options.params.set('f', finishDate);
|
||||
}
|
||||
return <Observable<User[]>>this.http.get<User[]>(urlActiveCashiers, options)
|
||||
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'activeCashiers'))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
21
bookie/src/app/cashier-checkout/cashier-checkout.ts
Normal file
21
bookie/src/app/cashier-checkout/cashier-checkout.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import {User} from "../core/user";
|
||||
|
||||
export class CashierCheckoutPrintItem {
|
||||
date: string;
|
||||
billId: string;
|
||||
customer: string;
|
||||
amount: number;
|
||||
}
|
||||
|
||||
export class CashierCheckoutDisplayItem {
|
||||
name: string;
|
||||
amount: number;
|
||||
}
|
||||
|
||||
export class CashierCheckout {
|
||||
startDate: string;
|
||||
finishDate: string;
|
||||
user: User;
|
||||
amounts?: CashierCheckoutDisplayItem[];
|
||||
info?: CashierCheckoutPrintItem[];
|
||||
}
|
||||
@ -11,6 +11,9 @@
|
||||
<mat-card fxLayout="column" class="square-button" matRipple [routerLink]="['/', 'sales']">
|
||||
<h3 class="item-name">Sales</h3>
|
||||
</mat-card>
|
||||
<mat-card fxLayout="column" class="square-button" matRipple [routerLink]="['/', 'checkout']">
|
||||
<h3 class="item-name">Cashier Checkout</h3>
|
||||
</mat-card>
|
||||
<mat-card fxLayout="column" class="square-button" matRipple [routerLink]="['/', 'tables']">
|
||||
<h3 class="item-name">Tables</h3>
|
||||
</mat-card>
|
||||
|
||||
Reference in New Issue
Block a user