Blacked and isorted the python files

Prettied and eslinted the typescript/html files
This commit is contained in:
2020-10-11 10:56:29 +05:30
parent b31db593c2
commit d677cfb1ea
505 changed files with 7560 additions and 5650 deletions

View File

@ -1,18 +1,17 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
import { Observable } from 'rxjs/internal/Observable';
import { VoucherService } from './voucher.service';
import { Bill } from './bill';
import { VoucherService } from './voucher.service';
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class BillResolver implements Resolve<Bill> {
constructor(private ser: VoucherService) {}
constructor(private ser: VoucherService) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Bill> {
resolve(route: ActivatedRouteSnapshot): Observable<Bill> {
const tableId = route.queryParamMap.get('table');
const guestId = route.queryParamMap.get('guest');
const voucherId = route.queryParamMap.get('voucher');

View File

@ -1,44 +1,14 @@
import {User} from '../../core/user';
import {Table} from '../../core/table';
import {GuestBook} from '../../guest-book/guest-book';
import {Product} from '../../core/product';
import {Tax} from '../../core/tax';
import {Modifier} from '../../core/modifier';
import { Table } from '../../core/table';
import { User } from '../../core/user';
import { GuestBook } from '../../guest-book/guest-book';
export class Inventory {
id: string;
product: Product;
quantity: number;
price: number;
isHappyHour: boolean;
taxRate: number;
tax: Tax;
discount: number;
modifiers: Modifier[];
sortOrder: number;
public constructor(init?: Partial<Inventory>) {
Object.assign(this, init);
}
}
export class Kot {
id: string;
code: number;
date: string;
user: User;
inventories: Inventory[];
public constructor(init?: Partial<Kot>) {
Object.assign(this, init);
}
}
import { Kot } from './kot';
export class Bill {
id: string;
date: string;
pax: number;
customer?: {id: string, name: string};
customer?: { id: string; name: string };
user: User;
creationDate: string;
lastEditDate: string;
@ -57,11 +27,3 @@ export class Bill {
Object.assign(this, init);
}
}
export enum PrintType {
Kot = 'KOT',
Bill = 'REGULAR_BILL',
NoCharge = 'NO_CHARGE',
Staff = 'STAFF'
}

View File

@ -2,9 +2,7 @@ import { DataSource } from '@angular/cdk/collections';
import { Observable } from 'rxjs';
export class BillsDataSource extends DataSource<any> {
constructor(private data: Observable<any[]>
) {
constructor(private data: Observable<any[]>) {
super();
}
@ -16,6 +14,5 @@ export class BillsDataSource extends DataSource<any> {
* Called when the table is being destroyed. Use this function, to clean up
* any open connections or free any held resources that were set up during connect.
*/
disconnect() {
}
disconnect() {}
}

View File

@ -13,8 +13,8 @@ table {
width: 100%;
}
.mat-column-select{
flex: 0 0 50px;
.mat-column-select {
flex: 0 0 50px;
}
.grey900 {

View File

@ -3,44 +3,68 @@
<mat-card-title>Bill</mat-card-title>
</mat-card-title-group>
<mat-card-content>
<table mat-table #table [dataSource]="dataSource" aria-label="Elements" class="mat-elevation-z8">
<table
mat-table
#table
[dataSource]="dataSource"
aria-label="Elements"
class="mat-elevation-z8"
>
<ng-container matColumnDef="bill-no-title">
<mat-header-cell *matHeaderCellDef class="deep-purple-200 bold">Bill / KOT number</mat-header-cell>
<mat-header-cell *matHeaderCellDef class="deep-purple-200 bold"
>Bill / KOT number</mat-header-cell
>
</ng-container>
<ng-container matColumnDef="bill-no-details">
<mat-header-cell *matHeaderCellDef class="deep-purple-200 bold right-align">{{ bs.bill.billId }} /
K-{{ bs.bill.kotId }}</mat-header-cell>
<mat-header-cell *matHeaderCellDef class="deep-purple-200 bold right-align"
>{{ bs.bill.billId }} / K-{{ bs.bill.kotId }}</mat-header-cell
>
</ng-container>
<ng-container matColumnDef="time-title">
<mat-header-cell *matHeaderCellDef class="deep-purple-100 bold">Time / Start Time / Last Edit Time
<mat-header-cell *matHeaderCellDef class="deep-purple-100 bold"
>Time / Start Time / Last Edit Time
</mat-header-cell>
</ng-container>
<ng-container matColumnDef="time-details">
<mat-header-cell *matHeaderCellDef class="deep-purple-100 bold right-align"><span
[matTooltip]="bs.bill.dateTip">{{ bs.bill.date }}</span>&nbsp;/&nbsp;<span
[matTooltip]="bs.bill.creationDateTip">{{ bs.bill.creationDate}}</span>&nbsp;/&nbsp;<span
[matTooltip]="bs.bill.lastEditDateTip">{{ bs.bill.lastEditDate }}</span></mat-header-cell>
<mat-header-cell *matHeaderCellDef class="deep-purple-100 bold right-align"
><span [matTooltip]="bs.bill.dateTip">{{ bs.bill.date }}</span
>&nbsp;/&nbsp;<span [matTooltip]="bs.bill.creationDateTip">{{
bs.bill.creationDate
}}</span
>&nbsp;/&nbsp;<span [matTooltip]="bs.bill.lastEditDateTip">{{
bs.bill.lastEditDate
}}</span></mat-header-cell
>
</ng-container>
<ng-container matColumnDef="table-title">
<mat-header-cell *matHeaderCellDef class="deep-purple-50 bold">Table / Pax / Customer</mat-header-cell>
<mat-header-cell *matHeaderCellDef class="deep-purple-50 bold"
>Table / Pax / Customer</mat-header-cell
>
</ng-container>
<ng-container matColumnDef="table-details">
<mat-header-cell *matHeaderCellDef class="deep-purple-50 bold right-align">{{ bs.bill.table.name }}
/ {{ bs.bill.pax }} / {{ bs.bill.customer?.name }}</mat-header-cell>
<mat-header-cell *matHeaderCellDef class="deep-purple-50 bold right-align"
>{{ bs.bill.table.name }} / {{ bs.bill.pax }} /
{{ bs.bill.customer?.name }}</mat-header-cell
>
</ng-container>
<!-- Checkbox Column -->
<ng-container matColumnDef="select">
<mat-cell *matCellDef="let row">
<mat-checkbox *ngIf="row.oldKot"
(change)="$event ? masterToggle(row) : null"
[checked]="bs.selection.hasValue() && isAllSelected(row)"
[indeterminate]="isAnySelected(row)">
<mat-checkbox
*ngIf="row.oldKot"
(change)="$event ? masterToggle(row) : null"
[checked]="bs.selection.hasValue() && isAllSelected(row)"
[indeterminate]="isAnySelected(row)"
>
</mat-checkbox>
<mat-checkbox *ngIf="!row.isKot" [disabled]="!row.id"
(click)="$event.stopPropagation()"
(change)="$event ? bs.selection.toggle(row) : null"
[checked]="bs.selection.isSelected(row)">
<mat-checkbox
*ngIf="!row.isKot"
[disabled]="!row.id"
(click)="$event.stopPropagation()"
(change)="$event ? bs.selection.toggle(row) : null"
[checked]="bs.selection.isSelected(row)"
>
</mat-checkbox>
</mat-cell>
</ng-container>
@ -48,10 +72,10 @@
<ng-container matColumnDef="info">
<mat-cell *matCellDef="let row" [class.blue800]="row.newKot">
<span>
{{row.info}}
{{ row.info }}
</span>
<ul>
<li *ngFor="let m of row.modifiers">{{m.name}}</li>
<li *ngFor="let m of row.modifiers">{{ m.name }}</li>
</ul>
</mat-cell>
</ng-container>
@ -59,19 +83,44 @@
<ng-container matColumnDef="quantity">
<mat-header-cell *matHeaderCellDef>Quantity</mat-header-cell>
<mat-cell *matCellDef="let row" class="right-align">
<button mat-icon-button (click)="subtractOne(row)" [disabled]="row.isPrinted" *ngIf="!row.isKot">
<button
mat-icon-button
(click)="subtractOne(row)"
[disabled]="row.isPrinted"
*ngIf="!row.isKot"
>
<mat-icon class="del">indeterminate_check_box</mat-icon>
</button>
<button mat-icon-button (click)="quantity(row)" [disabled]="row.isPrinted" *ngIf="!row.isKot">
{{row.quantity}}
<button
mat-icon-button
(click)="quantity(row)"
[disabled]="row.isPrinted"
*ngIf="!row.isKot"
>
{{ row.quantity }}
</button>
<button mat-icon-button (click)="addOne(row)" [disabled]="row.isPrinted" *ngIf="!row.isKot">
<button
mat-icon-button
(click)="addOne(row)"
[disabled]="row.isPrinted"
*ngIf="!row.isKot"
>
<mat-icon class="del">control_point</mat-icon>
</button>
<button mat-icon-button (click)="removeItem(row)" [disabled]="row.isPrinted" *ngIf="!row.isKot">
<button
mat-icon-button
(click)="removeItem(row)"
[disabled]="row.isPrinted"
*ngIf="!row.isKot"
>
<mat-icon class="del">cancel</mat-icon>
</button>
<button mat-icon-button (click)="modifier(row)" [disabled]="row.isPrinted" *ngIf="!row.isKot">
<button
mat-icon-button
(click)="modifier(row)"
[disabled]="row.isPrinted"
*ngIf="!row.isKot"
>
<mat-icon class="del">assignment</mat-icon>
</button>
<button mat-icon-button (click)="moveKot(row)" [disabled]="row.newKot" *ngIf="row.isKot">
@ -83,37 +132,44 @@
<mat-footer-cell *matFooterCellDef class="grey300 bold">Net</mat-footer-cell>
</ng-container>
<ng-container matColumnDef="net-amount">
<mat-footer-cell *matFooterCellDef
class="grey300 bold right-align">{{ bs.netAmount | async | currency: 'INR' }}</mat-footer-cell>
<mat-footer-cell *matFooterCellDef class="grey300 bold right-align">{{
bs.netAmount | async | currency: 'INR'
}}</mat-footer-cell>
</ng-container>
<ng-container matColumnDef="discount-title">
<mat-footer-cell *matFooterCellDef class="grey500 bold">Discount</mat-footer-cell>
</ng-container>
<ng-container matColumnDef="discount-amount">
<mat-footer-cell *matFooterCellDef
class="grey500 bold right-align">{{ bs.discountAmount | async | currency: 'INR' }}</mat-footer-cell>
<mat-footer-cell *matFooterCellDef class="grey500 bold right-align">{{
bs.discountAmount | async | currency: 'INR'
}}</mat-footer-cell>
</ng-container>
<ng-container matColumnDef="tax-title">
<mat-footer-cell *matFooterCellDef class="grey700 bold">Tax</mat-footer-cell>
</ng-container>
<ng-container matColumnDef="tax-amount">
<mat-footer-cell *matFooterCellDef
class="grey700 bold right-align">{{ bs.taxAmount | async | currency: 'INR' }}</mat-footer-cell>
<mat-footer-cell *matFooterCellDef class="grey700 bold right-align">{{
bs.taxAmount | async | currency: 'INR'
}}</mat-footer-cell>
</ng-container>
<ng-container matColumnDef="amount-title">
<mat-footer-cell *matFooterCellDef class="grey900">Amount</mat-footer-cell>
</ng-container>
<ng-container matColumnDef="amount-amount">
<mat-footer-cell *matFooterCellDef
class="grey900 bold right-align">{{ bs.amount | async | currency: 'INR' }}</mat-footer-cell>
<mat-footer-cell *matFooterCellDef class="grey900 bold right-align">{{
bs.amount | async | currency: 'INR'
}}</mat-footer-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="['bill-no-title', 'bill-no-details']"></mat-header-row>
<mat-header-row *matHeaderRowDef="['time-title', 'time-details']"></mat-header-row>
<mat-header-row *matHeaderRowDef="['table-title', 'table-details']"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;" [class.blue400]="row.oldKot"
[class.blue800]="row.newKot"
[class.red100]="row.isPrinted"></mat-row>
<mat-row
*matRowDef="let row; columns: displayedColumns"
[class.blue400]="row.oldKot"
[class.blue800]="row.newKot"
[class.red100]="row.isPrinted"
></mat-row>
<mat-footer-row *matFooterRowDef="['net-title', 'net-amount']"></mat-footer-row>
<mat-footer-row *matFooterRowDef="['discount-title', 'discount-amount']"></mat-footer-row>
<mat-footer-row *matFooterRowDef="['tax-title', 'tax-amount']"></mat-footer-row>

View File

@ -8,9 +8,8 @@ describe('BillsComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ BillsComponent ]
})
.compileComponents();
declarations: [BillsComponent],
}).compileComponents();
}));
beforeEach(() => {

View File

@ -1,24 +1,27 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Bill, Kot } from './bill';
import { BillsDataSource } from './bills-datasource';
import { BillService } from '../bill.service';
import { QuantityComponent } from '../quantity/quantity.component';
import { MatDialog } from '@angular/material/dialog';
import { Table } from '../../core/table';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable, throwError } from 'rxjs';
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
import { map, switchMap } from 'rxjs/operators';
import { TablesDialogComponent } from '../tables-dialog/tables-dialog.component';
import { TableService } from '../../tables/table.service';
import { ToasterService } from '../../core/toaster.service';
import { AuthService } from '../../auth/auth.service';
import { Table } from '../../core/table';
import { ToasterService } from '../../core/toaster.service';
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
import { TableService } from '../../tables/table.service';
import { BillService } from '../bill.service';
import { PaxComponent } from '../pax/pax.component';
import { QuantityComponent } from '../quantity/quantity.component';
import { TablesDialogComponent } from '../tables-dialog/tables-dialog.component';
import { Bill } from './bill';
import { BillsDataSource } from './bills-datasource';
import { Kot } from './kot';
@Component({
selector: 'app-bills',
templateUrl: './bills.component.html',
styleUrls: ['./bills.component.css']
styleUrls: ['./bills.component.css'],
})
export class BillsComponent implements OnInit {
dataSource: BillsDataSource;
@ -32,15 +35,13 @@ export class BillsComponent implements OnInit {
private toaster: ToasterService,
private auth: AuthService,
public bs: BillService,
private tSer: TableService
) {
}
private tSer: TableService,
) {}
ngOnInit() {
this.route.data
.subscribe((data: { item: Bill }) => {
this.bs.loadData(data.item);
});
this.route.data.subscribe((data: { item: Bill }) => {
this.bs.loadData(data.item);
});
this.getPax();
this.dataSource = new BillsDataSource(this.bs.dataObs);
}
@ -51,7 +52,7 @@ export class BillsComponent implements OnInit {
}
const dialogRef = this.dialog.open(PaxComponent, {
// width: '750px',
data: this.bs.bill.pax
data: this.bs.bill.pax,
});
dialogRef.afterClosed().subscribe((result: boolean | number) => {
@ -61,36 +62,34 @@ export class BillsComponent implements OnInit {
this.bs.bill.pax = result as number;
});
}
isAllSelected(kot: Kot) {
return this.bs.data.filter(
x => x.kotId === kot.id
).reduce(
(p: boolean, c: any) => p && this.bs.selection.isSelected(c)
, true
);
return this.bs.data
.filter((x) => x.kotId === kot.id)
.reduce((p: boolean, c: any) => p && this.bs.selection.isSelected(c), true);
}
isAnySelected(kot: Kot) {
let total = 0,
found = 0;
this.bs.data.filter(
x => x.kotId === kot.id
).forEach((c: any) => {
total += 1;
if (this.bs.selection.isSelected(c)) {
found += 1;
}
});
let total = 0;
let found = 0;
this.bs.data
.filter((x) => x.kotId === kot.id)
.forEach((c: any) => {
total += 1;
if (this.bs.selection.isSelected(c)) {
found += 1;
}
});
return found > 0 && found < total;
}
masterToggle(kot: Kot) {
const isAllSelected = this.isAllSelected(kot);
this.bs.data.filter(
x => x.kotId === kot.id
).forEach(
row => isAllSelected ? this.bs.selection.deselect(row) : this.bs.selection.select(row)
);
this.bs.data
.filter((x) => x.kotId === kot.id)
.forEach((row) =>
isAllSelected ? this.bs.selection.deselect(row) : this.bs.selection.select(row),
);
}
addOne(item: any): void {
@ -100,7 +99,7 @@ export class BillsComponent implements OnInit {
quantity(item: any): void {
const dialogRef = this.dialog.open(QuantityComponent, {
// width: '750px',
data: item.quantity
data: item.quantity,
});
dialogRef.afterClosed().subscribe((result: boolean | number) => {
@ -123,47 +122,53 @@ export class BillsComponent implements OnInit {
this.bs.modifier(item);
}
confirmMoveKotDialog(table: Table): Observable<{table: Table, confirmed: boolean}> {
return this.dialog.open(ConfirmDialogComponent, {
width: '250px',
data: {title: 'Move KOT?', content: 'Are you sure?'}
}).afterClosed().pipe(
map ((x: boolean) => ({table: table, confirmed: x}))
);
confirmMoveKotDialog(table: Table): Observable<{ table: Table; confirmed: boolean }> {
return this.dialog
.open(ConfirmDialogComponent, {
width: '250px',
data: { title: 'Move KOT?', content: 'Are you sure?' },
})
.afterClosed()
.pipe(map((x: boolean) => ({ table, confirmed: x })));
}
moveKot(kot: Kot) {
const canMergeTables = (this.auth.user.perms.indexOf('merge-tables') !== -1);
this.dialog.open(TablesDialogComponent, {
// width: '750px',
data: {
list: this.tSer.running(),
canChooseRunning: canMergeTables
}
}).afterClosed().pipe(
switchMap((x: boolean | Table) => {
if (!!x) {
return this.confirmMoveKotDialog(x as Table);
} else {
const canMergeTables = this.auth.user.perms.indexOf('merge-tables') !== -1;
this.dialog
.open(TablesDialogComponent, {
// width: '750px',
data: {
list: this.tSer.running(),
canChooseRunning: canMergeTables,
},
})
.afterClosed()
.pipe(
switchMap((x: boolean | Table) => {
if (x) {
return this.confirmMoveKotDialog(x as Table);
}
return throwError('Please choose a table');
}
}),
switchMap((value: { table: Table, confirmed: boolean }, index: number) => {
}),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
switchMap((value: { table: Table; confirmed: boolean }, index: number) => {
if (!value.confirmed) {
return throwError('Please confirm move');
} else if (value.table.status) {
return this.bs.mergeKot(kot.id, value.table);
} else {
return this.bs.moveKot(kot.id, value.table);
}
}
if (value.table.status) {
return this.bs.mergeKot(kot.id, value.table);
}
return this.bs.moveKot(kot.id, value.table);
}),
)
).subscribe((x) => {
this.toaster.show('Success', '');
this.router.navigate(['/sales']);
},
x => {
this.toaster.show('Error', x);
});
.subscribe(
() => {
this.toaster.show('Success', '');
this.router.navigate(['/sales']);
},
(x) => {
this.toaster.show('Error', x);
},
);
}
}

View File

@ -0,0 +1,20 @@
import { Modifier } from '../../core/modifier';
import { Product } from '../../core/product';
import { Tax } from '../../core/tax';
export class Inventory {
id: string;
product: Product;
quantity: number;
price: number;
isHappyHour: boolean;
taxRate: number;
tax: Tax;
discount: number;
modifiers: Modifier[];
sortOrder: number;
public constructor(init?: Partial<Inventory>) {
Object.assign(this, init);
}
}

View File

@ -0,0 +1,15 @@
import { User } from '../../core/user';
import { Inventory } from './inventory';
export class Kot {
id: string;
code: number;
date: string;
user: User;
inventories: Inventory[];
public constructor(init?: Partial<Kot>) {
Object.assign(this, init);
}
}

View File

@ -0,0 +1,6 @@
export enum PrintType {
Kot = 'KOT',
Bill = 'REGULAR_BILL',
NoCharge = 'NO_CHARGE',
Staff = 'STAFF',
}

View File

@ -1,14 +1,13 @@
import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
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, PrintType } from './bill';
import { Table } from '../../core/table';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
};
import { Bill } from './bill';
import { PrintType } from './print-type';
const url = '/api/voucher';
const urlMoveTable = '/api/move-table';
@ -16,17 +15,16 @@ const urlMoveKot = '/api/move-kot';
const urlSplitBill = '/api/split-bill';
const serviceName = 'VoucherService';
@Injectable({providedIn: 'root'})
@Injectable({ providedIn: 'root' })
export class VoucherService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {
}
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
get(id: string): Observable<Bill> {
return <Observable<Bill>>this.http.get<Bill>(`${url}/from-id/${id}`)
.pipe(
catchError(this.log.handleError(serviceName, `get id=${id}`))
);
return <Observable<Bill>>(
this.http
.get<Bill>(`${url}/from-id/${id}`)
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`)))
);
}
getFromTable(tableId: string, voucherId: string, guestId: string): Observable<Bill> {
@ -38,128 +36,164 @@ export class VoucherService {
params = params.set('g', guestId);
}
return <Observable<Bill>>this.http.get<Bill>(`${url}/from-table/${tableId}`, {params: params})
return <Observable<Bill>>this.http
.get<Bill>(`${url}/from-table/${tableId}`, { params })
.pipe(
catchError(this.log.handleError(
serviceName,
`getFromTable tableId=${tableId} voucherId=${voucherId} guestId=${guestId}`
))
catchError(
this.log.handleError(
serviceName,
`getFromTable tableId=${tableId} voucherId=${voucherId} guestId=${guestId}`,
),
),
);
}
save(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<boolean> {
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<boolean>>this.http.post<boolean>(`${url}/save`, voucher, options)
.pipe(
catchError(this.log.handleError(serviceName, 'save'))
);
save(
voucher: Bill,
printType: PrintType,
guest_book_id: string,
updateTable: boolean,
): Observable<boolean> {
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<boolean>>(
this.http
.post<boolean>(`${url}/save`, voucher, options)
.pipe(catchError(this.log.handleError(serviceName, 'save')))
);
}
update(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<boolean> {
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<boolean>>this.http.put<boolean>(`${url}/update/${voucher.id}`, voucher, options)
.pipe(
catchError(this.log.handleError(serviceName, 'update'))
);
update(
voucher: Bill,
printType: PrintType,
guest_book_id: string,
updateTable: boolean,
): Observable<boolean> {
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<boolean>>(
this.http
.put<boolean>(`${url}/update/${voucher.id}`, voucher, options)
.pipe(catchError(this.log.handleError(serviceName, 'update')))
);
}
change(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<boolean> {
const options = {params: new HttpParams().set('u', updateTable.toString())};
if (guest_book_id !== null) {
options.params = options.params.set('g', guest_book_id);
}
return <Observable<boolean>>this.http.put<boolean>(`${url}/change/${voucher.id}`, voucher, options)
.pipe(
catchError(this.log.handleError(serviceName, 'change'))
);
change(
voucher: Bill,
printType: PrintType,
guest_book_id: string,
updateTable: boolean,
): Observable<boolean> {
const options = { params: new HttpParams().set('u', updateTable.toString()) };
if (guest_book_id !== null) {
options.params = options.params.set('g', guest_book_id);
}
return <Observable<boolean>>(
this.http
.put<boolean>(`${url}/change/${voucher.id}`, voucher, options)
.pipe(catchError(this.log.handleError(serviceName, 'change')))
);
}
saveOrUpdate(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable<boolean> {
saveOrUpdate(
voucher: Bill,
printType: PrintType,
guest_book_id: string,
updateTable: boolean,
): Observable<boolean> {
if (!voucher.id) {
return this.save(voucher, printType, guest_book_id, updateTable);
} else if (voucher.voucherType === PrintType.Kot) {
return this.update(voucher, printType, guest_book_id, updateTable);
} else {
return this.change(voucher, printType, guest_book_id, updateTable);
}
if (voucher.voucherType === PrintType.Kot) {
return this.update(voucher, printType, guest_book_id, updateTable);
}
return this.change(voucher, printType, guest_book_id, updateTable);
}
receivePayment(
id: string,
amounts: { id: number; name: string; amount: number }[],
name: string,
updateTable: boolean
updateTable: boolean,
): Observable<boolean> {
const options = {params: new HttpParams().set('u', updateTable.toString())};
return <Observable<boolean>>this.http.post<boolean>(
`${url}/receive-payment/${id}`, {name: name, amounts: amounts}, options
).pipe(
catchError(this.log.handleError(serviceName, 'receivePayment'))
const options = { params: new HttpParams().set('u', updateTable.toString()) };
return <Observable<boolean>>(
this.http
.post<boolean>(`${url}/receive-payment/${id}`, { name, amounts }, options)
.pipe(catchError(this.log.handleError(serviceName, 'receivePayment')))
);
}
voidBill(id: string, reason: string, updateTable: boolean): Observable<boolean> {
const options = {params: new HttpParams().set('reason', reason).set('u', updateTable.toString())};
return <Observable<boolean>>this.http.post<boolean>(
`${url}/void-bill/${id}`, {}, options
).pipe(
catchError(this.log.handleError(serviceName, 'voidBill'))
const options = {
params: new HttpParams().set('reason', reason).set('u', updateTable.toString()),
};
return <Observable<boolean>>(
this.http
.post<boolean>(`${url}/void-bill/${id}`, {}, options)
.pipe(catchError(this.log.handleError(serviceName, 'voidBill')))
);
}
moveTable(id: string, table: Table): Observable<boolean> {
return <Observable<boolean>>this.http.post<boolean>(`${urlMoveTable}/move`, {
voucherId: id,
tableId: table.id
}).pipe(
catchError(this.log.handleError(serviceName, 'moveTable'))
);
return <Observable<boolean>>this.http
.post<boolean>(`${urlMoveTable}/move`, {
voucherId: id,
tableId: table.id,
})
.pipe(catchError(this.log.handleError(serviceName, 'moveTable')));
}
mergeTable(id: string, table: Table): Observable<boolean> {
return <Observable<boolean>>this.http.post<boolean>(`${urlMoveTable}/merge`, {
voucherId: id,
tableId: table.id,
newVoucherId: table.voucherId
}).pipe(
catchError(this.log.handleError(serviceName, 'mergeTable'))
);
return <Observable<boolean>>this.http
.post<boolean>(`${urlMoveTable}/merge`, {
voucherId: id,
tableId: table.id,
newVoucherId: table.voucherId,
})
.pipe(catchError(this.log.handleError(serviceName, 'mergeTable')));
}
moveKotToNewTable(id: string, kotId: string, table: Table): Observable<boolean> {
return <Observable<boolean>>this.http.post<boolean>(`${urlMoveKot}/move`, {
voucherId: id,
kotId: kotId,
tableId: table.id
}).pipe(
catchError(this.log.handleError(serviceName, 'moveKotToNewTable'))
);
return <Observable<boolean>>this.http
.post<boolean>(`${urlMoveKot}/move`, {
voucherId: id,
kotId,
tableId: table.id,
})
.pipe(catchError(this.log.handleError(serviceName, 'moveKotToNewTable')));
}
mergeKotWithOldBill(id: string, kotId: string, table: Table): Observable<boolean> {
return <Observable<boolean>>this.http.post<boolean>(`${urlMoveKot}/merge`, {
voucherId: id,
kotId: kotId,
tableId: table.id,
newVoucherId: table.voucherId
}).pipe(
catchError(this.log.handleError(serviceName, 'mergeKotWithOldBill'))
);
return <Observable<boolean>>this.http
.post<boolean>(`${urlMoveKot}/merge`, {
voucherId: id,
kotId,
tableId: table.id,
newVoucherId: table.voucherId,
})
.pipe(catchError(this.log.handleError(serviceName, 'mergeKotWithOldBill')));
}
splitBill(id: string, inventoriesToMove: string[], table: Table) {
const options = {params: new HttpParams().set('u', 'true')};
return <Observable<boolean>>this.http.post<boolean>(`${urlSplitBill}/${id}`, {
inventories: inventoriesToMove,
tableId: table.id
}, options).pipe(
catchError(this.log.handleError(serviceName, 'splitBill'))
);
const options = { params: new HttpParams().set('u', 'true') };
return <Observable<boolean>>this.http
.post<boolean>(
`${urlSplitBill}/${id}`,
{
inventories: inventoriesToMove,
tableId: table.id,
},
options,
)
.pipe(catchError(this.log.handleError(serviceName, 'splitBill')));
}
}