Save Bill Works
This commit is contained in:
@ -1,15 +1,15 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router';
|
||||
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { VoucherService } from "./voucher.service";
|
||||
import { Bill } from "./bill";
|
||||
import { VoucherService } from './voucher.service';
|
||||
import { Bill } from './bill';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class BillResolver implements Resolve<Bill> {
|
||||
|
||||
constructor(private ser: VoucherService, private router: Router) {
|
||||
constructor(private ser: VoucherService) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Bill> {
|
||||
|
||||
@ -7,7 +7,6 @@ import {Modifier} from '../../core/modifier';
|
||||
|
||||
export class Inventory {
|
||||
id: string;
|
||||
sortOrder: number;
|
||||
product: Product;
|
||||
quantity: number;
|
||||
price: number;
|
||||
@ -16,14 +15,23 @@ export class Inventory {
|
||||
tax: Tax;
|
||||
discount: number;
|
||||
modifiers: Modifier[];
|
||||
sortOrder: number;
|
||||
|
||||
public constructor(init?: Partial<Inventory>) {
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
export class Kot {
|
||||
id: string;
|
||||
serial: number;
|
||||
code: number;
|
||||
date: string;
|
||||
user: User;
|
||||
inventories: Inventory[];
|
||||
|
||||
public constructor(init?: Partial<Kot>) {
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
export class Bill {
|
||||
@ -43,4 +51,16 @@ export class Bill {
|
||||
serial: number;
|
||||
kots: Kot[];
|
||||
reprints: any[];
|
||||
|
||||
public constructor(init?: Partial<Bill>) {
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
export enum PrintType {
|
||||
Kot = 'KOT',
|
||||
Bill = 'BILL',
|
||||
NoCharge = 'NO_CHARGE',
|
||||
Staff = 'STAFF'
|
||||
}
|
||||
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
.kot {
|
||||
background-color: hotpink;
|
||||
background-color: lightblue;
|
||||
}
|
||||
|
||||
.printed {
|
||||
background-color: lightpink;
|
||||
}
|
||||
.new-kot {
|
||||
background-color: lightblue;
|
||||
}
|
||||
|
||||
.square-button {
|
||||
min-width: 150px;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
<mat-table #table [dataSource]="dataSource" aria-label="Elements">
|
||||
<!-- Info Column -->
|
||||
<ng-container matColumnDef="info">
|
||||
<mat-cell *matCellDef="let row" fxLayout="column" fxLayoutAlign="start space-between end">
|
||||
<mat-cell *matCellDef="let row" fxLayout="column" fxLayoutAlign="start">
|
||||
<span>
|
||||
{{row.info}}
|
||||
</span>
|
||||
@ -18,7 +18,7 @@
|
||||
<!-- Quantity Column -->
|
||||
<ng-container matColumnDef="quantity">
|
||||
<mat-header-cell *matHeaderCellDef>Quantity</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">
|
||||
<mat-cell *matCellDef="let row" fxLayoutAlign="end">
|
||||
<button mat-icon-button (click)="subtractOne(row)" [disabled]="row.isPrinted" *ngIf="!row.isKot">
|
||||
<mat-icon class="del">indeterminate_check_box</mat-icon>
|
||||
</button>
|
||||
@ -38,8 +38,7 @@
|
||||
</ng-container>
|
||||
|
||||
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns;" [class.kot]="row.isKot" [class.new-kot]="row.newKot"
|
||||
[class.printed]="row.isPrinted"></mat-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns;" [class.kot]="row.isKot"[class.printed]="row.isPrinted"></mat-row>
|
||||
</mat-table>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import {Bill, Inventory, Kot} from './bill';
|
||||
import {BillsDataSource} from './bills-datasource';
|
||||
import {BillService} from "../bill.service";
|
||||
import { Bill } from './bill';
|
||||
import { BillsDataSource } from './bills-datasource';
|
||||
import { BillService } from '../bill.service';
|
||||
import { QuantityComponent } from '../quantity/quantity.component';
|
||||
import { MatDialog } from '@angular/material';
|
||||
|
||||
@Component({
|
||||
selector: 'app-bills',
|
||||
@ -17,40 +19,18 @@ export class BillsComponent implements OnInit {
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private dialog: MatDialog,
|
||||
private bs: BillService
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
console.log("ds set")
|
||||
this.dataSource = new BillsDataSource(this.bs.dataObs);
|
||||
this.route.data
|
||||
.subscribe((data: { item: Bill }) => {
|
||||
this.updateView(data.item);
|
||||
this.item = data.item;
|
||||
this.bs.loadData(data.item);
|
||||
});
|
||||
}
|
||||
|
||||
updateView(item) {
|
||||
this.item = item;
|
||||
let view = item.kots.map(k => {
|
||||
return [{
|
||||
isKot: true,
|
||||
}, ...k.inventories.map(i => {
|
||||
return {
|
||||
id: i.id,
|
||||
isKot: false,
|
||||
product: i.product,
|
||||
productId: i.product.id,
|
||||
isHappyHour: i.isHappyHour,
|
||||
isPrinted: true,
|
||||
info: `${i.product.name} (${i.product.units}) @ ${i.price}`,
|
||||
quantity: 1,
|
||||
modifiers: i.modifiers
|
||||
}
|
||||
})]
|
||||
});
|
||||
view = view.reduce((a, c) => {return a.concat(c)} , []);
|
||||
this.bs.loadData(view);
|
||||
this.dataSource = new BillsDataSource(this.bs.dataObs);
|
||||
}
|
||||
|
||||
addOne(item: any): void {
|
||||
@ -58,7 +38,17 @@ export class BillsComponent implements OnInit {
|
||||
}
|
||||
|
||||
quantity(item: any): void {
|
||||
this.bs.quantity(item);
|
||||
const dialogRef = this.dialog.open(QuantityComponent, {
|
||||
// width: '750px',
|
||||
data: item.quantity
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean | number) => {
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
this.bs.quantity(item, result as number);
|
||||
});
|
||||
}
|
||||
|
||||
subtractOne(item: any): void {
|
||||
|
||||
@ -3,7 +3,7 @@ import { Observable } from 'rxjs/internal/Observable';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { ErrorLoggerService } from '../../core/error-logger.service';
|
||||
import {Bill} from "./bill";
|
||||
import { Bill, PrintType } from './bill';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
@ -46,25 +46,33 @@ export class VoucherService {
|
||||
);
|
||||
}
|
||||
|
||||
save(voucher: Bill): Observable<Bill> {
|
||||
return <Observable<Bill>>this.http.post<Bill>(`${url}/new`, voucher, httpOptions)
|
||||
save(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<Bill> {
|
||||
const options = {params: new HttpParams().set('p', printType).set('u', updateTable.toString())};
|
||||
if (guest_book_id !== null) {
|
||||
options.params = options.params.set('g', guest_book_id)
|
||||
}
|
||||
return <Observable<Bill>>this.http.post<Bill>(`${url}/new`, voucher, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
}
|
||||
|
||||
update(voucher: Bill): Observable<Bill> {
|
||||
return <Observable<Bill>>this.http.put<Bill>(`${url}/${voucher.id}`, voucher, httpOptions)
|
||||
update(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<Bill> {
|
||||
const options = {params: new HttpParams().set('p', printType).set('u', updateTable.toString())};
|
||||
if (guest_book_id !== null) {
|
||||
options.params = options.params.set('g', guest_book_id)
|
||||
}
|
||||
return <Observable<Bill>>this.http.put<Bill>(`${url}/${voucher.id}`, voucher, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'update'))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(voucher: Bill): Observable<Bill> {
|
||||
saveOrUpdate(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<Bill> {
|
||||
if (!voucher.id) {
|
||||
return this.save(voucher);
|
||||
return this.save(voucher, printType, guest_book_id, updateTable);
|
||||
} else {
|
||||
return this.update(voucher);
|
||||
return this.update(voucher, printType, guest_book_id, updateTable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user