Move Table with confirm
This commit is contained in:
@ -368,7 +368,6 @@ def includeme(config):
|
|||||||
config.add_route("merge_table", "/MergeTable.json")
|
config.add_route("merge_table", "/MergeTable.json")
|
||||||
|
|
||||||
config.add_route("move_kot", "/MoveKot.json")
|
config.add_route("move_kot", "/MoveKot.json")
|
||||||
config.add_route("move_table", "/MoveTable.json")
|
|
||||||
|
|
||||||
config.add_route("permission_list", "/Permissions.json")
|
config.add_route("permission_list", "/Permissions.json")
|
||||||
|
|
||||||
|
|||||||
@ -6,64 +6,98 @@ from pyramid.view import view_config
|
|||||||
from barker.models import Kot, Voucher, Overview
|
from barker.models import Kot, Voucher, Overview
|
||||||
|
|
||||||
|
|
||||||
@view_config(request_method='POST', route_name='merge_kot', renderer='json', permission='Merge Kots', trans=True)
|
@view_config(
|
||||||
|
request_method="POST",
|
||||||
|
route_name="merge_kot",
|
||||||
|
renderer="json",
|
||||||
|
permission="Merge Kots",
|
||||||
|
trans=True,
|
||||||
|
)
|
||||||
def merge_kot(request):
|
def merge_kot(request):
|
||||||
json = request.json_body
|
json = request.json_body
|
||||||
kot_id = uuid.UUID(json['KotID'])
|
kot_id = uuid.UUID(json["KotID"])
|
||||||
voucher_id = uuid.UUID(json['NewVoucherID'])
|
voucher_id = uuid.UUID(json["NewVoucherID"])
|
||||||
|
|
||||||
request.dbsession.query(Kot).filter(Kot.id == kot_id).update({Kot.voucher_id: voucher_id})
|
request.dbsession.query(Kot).filter(Kot.id == kot_id).update(
|
||||||
|
{Kot.voucher_id: voucher_id}
|
||||||
|
)
|
||||||
transaction.commit()
|
transaction.commit()
|
||||||
return voucher_id
|
return voucher_id
|
||||||
|
|
||||||
|
|
||||||
@view_config(request_method='POST', route_name='move_kot', renderer='json', permission='Move Kot', trans=True)
|
@view_config(
|
||||||
|
request_method="POST",
|
||||||
|
route_name="move_kot",
|
||||||
|
renderer="json",
|
||||||
|
permission="Move Kot",
|
||||||
|
trans=True,
|
||||||
|
)
|
||||||
def move_kot(request):
|
def move_kot(request):
|
||||||
json = request.json_body
|
json = request.json_body
|
||||||
kot_id = uuid.UUID(json['KotID'])
|
kot_id = uuid.UUID(json["KotID"])
|
||||||
food_table_id = uuid.UUID(json['FoodTableID'])
|
food_table_id = uuid.UUID(json["FoodTableID"])
|
||||||
|
|
||||||
kot = request.dbsession.query(Kot).filter(Kot.id == kot_id).first()
|
kot = request.dbsession.query(Kot).filter(Kot.id == kot_id).first()
|
||||||
|
|
||||||
item = Voucher(kot.voucher.pax, food_table_id, kot.voucher.customer_id, False, kot.voucher.voucher_type,
|
item = Voucher(
|
||||||
kot.voucher.user_id, request.dbsession)
|
kot.voucher.pax,
|
||||||
|
food_table_id,
|
||||||
|
kot.voucher.customer_id,
|
||||||
|
False,
|
||||||
|
kot.voucher.voucher_type,
|
||||||
|
kot.voucher.user_id,
|
||||||
|
request.dbsession,
|
||||||
|
)
|
||||||
request.dbsession.add(item)
|
request.dbsession.add(item)
|
||||||
item.kots.append(kot)
|
item.kots.append(kot)
|
||||||
status = "printed" if item.is_printed else "running"
|
status = "printed" if item.is_printed else "running"
|
||||||
item.status = Overview(voucher_id=None, food_table_id=item.food_table_id, status=status)
|
item.status = Overview(
|
||||||
|
voucher_id=None, food_table_id=item.food_table_id, status=status
|
||||||
|
)
|
||||||
request.dbsession.add(item.status)
|
request.dbsession.add(item.status)
|
||||||
transaction.commit()
|
transaction.commit()
|
||||||
return item.id
|
return item.id
|
||||||
|
|
||||||
|
|
||||||
@view_config(request_method='POST', route_name='move_table', renderer='json', permission='Move Table', trans=True)
|
@view_config(
|
||||||
|
request_method="POST",
|
||||||
|
route_name="v1_vouchers_id",
|
||||||
|
request_param="m",
|
||||||
|
renderer="json",
|
||||||
|
permission="Move Table",
|
||||||
|
trans=True,
|
||||||
|
)
|
||||||
def move_table(request):
|
def move_table(request):
|
||||||
json = request.json_body
|
id_ = uuid.UUID(request.matchdict["id"])
|
||||||
voucher_id = uuid.UUID(json['VoucherID'])
|
table_id = uuid.UUID(request.GET["m"])
|
||||||
food_table_id = uuid.UUID(json['FoodTableID'])
|
|
||||||
|
|
||||||
request.dbsession.query(
|
request.dbsession.query(Overview).filter(Overview.voucher_id == id_).update(
|
||||||
Overview
|
{Overview.food_table_id: table_id}
|
||||||
).filter(
|
)
|
||||||
Overview.voucher_id == voucher_id
|
|
||||||
).update({Overview.food_table_id: food_table_id})
|
|
||||||
|
|
||||||
request.dbsession.query(
|
request.dbsession.query(Voucher).filter(Voucher.id == id_).update(
|
||||||
Voucher
|
{Voucher.food_table_id: table_id}
|
||||||
).filter(
|
)
|
||||||
Voucher.id == voucher_id
|
|
||||||
).update({Voucher.food_table_id: food_table_id})
|
|
||||||
|
|
||||||
transaction.commit()
|
transaction.commit()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
@view_config(request_method='POST', route_name='merge_table', renderer='json', permission='Merge Tables', trans=True)
|
@view_config(
|
||||||
|
request_method="POST",
|
||||||
|
route_name="merge_table",
|
||||||
|
renderer="json",
|
||||||
|
permission="Merge Tables",
|
||||||
|
trans=True,
|
||||||
|
)
|
||||||
def merge_table(request):
|
def merge_table(request):
|
||||||
json = request.json_body
|
json = request.json_body
|
||||||
voucher_id = uuid.UUID(json['VoucherID'])
|
voucher_id = uuid.UUID(json["VoucherID"])
|
||||||
new_voucher_id = uuid.UUID(json['NewVoucherID'])
|
new_voucher_id = uuid.UUID(json["NewVoucherID"])
|
||||||
|
|
||||||
request.dbsession.query(Kot).filter(Kot.voucher_id == voucher_id).update({Kot.voucher_id: new_voucher_id})
|
request.dbsession.query(Kot).filter(Kot.voucher_id == voucher_id).update(
|
||||||
|
{Kot.voucher_id: new_voucher_id}
|
||||||
|
)
|
||||||
request.dbsession.query(Voucher).filter(Voucher.id == voucher_id).delete()
|
request.dbsession.query(Voucher).filter(Voucher.id == voucher_id).delete()
|
||||||
transaction.commit()
|
transaction.commit()
|
||||||
return voucher_id
|
return voucher_id
|
||||||
@ -7,4 +7,9 @@ export class Table {
|
|||||||
section: Section;
|
section: Section;
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
voucherId?: string;
|
voucherId?: string;
|
||||||
|
status?: string;
|
||||||
|
pax?: number;
|
||||||
|
guest?: string;
|
||||||
|
date?: string;
|
||||||
|
amount?: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import { Bill, Inventory, Kot, PrintType } from './bills/bill';
|
|||||||
import { VoucherService } from './bills/voucher.service';
|
import { VoucherService } from './bills/voucher.service';
|
||||||
import { ToasterService } from "../core/toaster.service";
|
import { ToasterService } from "../core/toaster.service";
|
||||||
import { tap } from "rxjs/operators";
|
import { tap } from "rxjs/operators";
|
||||||
|
import { Table } from "../core/table";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BillService {
|
export class BillService {
|
||||||
@ -197,6 +198,10 @@ export class BillService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
moveTable(table: Table): Observable<boolean> {
|
||||||
|
return this.ser.moveTable(this.bill.id, table);
|
||||||
|
}
|
||||||
|
|
||||||
netAmount() {
|
netAmount() {
|
||||||
return math.round(this.bill.kots.reduce(
|
return math.round(this.bill.kots.reduce(
|
||||||
(ka: number, k: Kot) => ka + k.inventories.reduce(
|
(ka: number, k: Kot) => ka + k.inventories.reduce(
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { catchError } from 'rxjs/operators';
|
|||||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||||
import { ErrorLoggerService } from '../../core/error-logger.service';
|
import { ErrorLoggerService } from '../../core/error-logger.service';
|
||||||
import { Bill, PrintType } from './bill';
|
import { Bill, PrintType } from './bill';
|
||||||
|
import { Table } from "../../core/table";
|
||||||
|
|
||||||
const httpOptions = {
|
const httpOptions = {
|
||||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||||
@ -83,4 +84,12 @@ export class VoucherService {
|
|||||||
catchError(this.log.handleError(serviceName, 'receivePayment'))
|
catchError(this.log.handleError(serviceName, 'receivePayment'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
moveTable(id: string, table: Table): Observable<boolean> {
|
||||||
|
const options = {params: new HttpParams().set('m', table.id)};
|
||||||
|
return <Observable<boolean>>this.http.post<boolean>(`${url}/${id}`, {}, options)
|
||||||
|
.pipe(
|
||||||
|
catchError(this.log.handleError(serviceName, 'moveTable'))
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
<mat-card fxLayout="column" class="square-button" matRipple (click)="receivePayment()">
|
<mat-card fxLayout="column" class="square-button" matRipple (click)="receivePayment()">
|
||||||
<h3 class="item-name">Receive Payment</h3>
|
<h3 class="item-name">Receive Payment</h3>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
<mat-card fxLayout="column" class="square-button" matRipple [routerLink]="['../../tables']">
|
<mat-card fxLayout="column" class="square-button" matRipple (click)="moveTable()">
|
||||||
<h3 class="item-name">Move Table</h3>
|
<h3 class="item-name">Move Table</h3>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
<mat-card fxLayout="column" class="square-button" matRipple [routerLink]="['../../tables']">
|
<mat-card fxLayout="column" class="square-button" matRipple [routerLink]="['../../tables']">
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { ActivatedRoute, Router } from "@angular/router";
|
import { ActivatedRoute, Router } from "@angular/router";
|
||||||
import { MatDialog } from "@angular/material";
|
import { MatDialog } from "@angular/material";
|
||||||
import { concatMap, tap } from "rxjs/operators";
|
import { concatMap, map, switchMap, tap } from "rxjs/operators";
|
||||||
import { iif, Observable, of as observableOf, throwError} from "rxjs";
|
import { iif, Observable, of as observableOf, throwError} from "rxjs";
|
||||||
import { BillService } from '../bill.service';
|
import { BillService } from '../bill.service';
|
||||||
import { ToasterService } from "../../core/toaster.service";
|
import { ToasterService } from "../../core/toaster.service";
|
||||||
@ -11,6 +11,10 @@ import { BillTypeComponent } from "../bill-type/bill-type.component";
|
|||||||
import { PrintType } from "../bills/bill";
|
import { PrintType } from "../bills/bill";
|
||||||
import { AuthService } from "../../auth/auth.service";
|
import { AuthService } from "../../auth/auth.service";
|
||||||
import { ReceivePaymentComponent } from "../receive-payment/receive-payment.component";
|
import { ReceivePaymentComponent } from "../receive-payment/receive-payment.component";
|
||||||
|
import { TableService } from "../../tables/table.service";
|
||||||
|
import { Table } from "../../core/table";
|
||||||
|
import { TablesDialogComponent } from "../tables-dialog/tables-dialog.component";
|
||||||
|
import { ConfirmDialogComponent } from "../../shared/confirm-dialog/confirm-dialog.component";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-sales-home',
|
selector: 'app-sales-home',
|
||||||
@ -26,6 +30,7 @@ export class SalesHomeComponent implements OnInit {
|
|||||||
private auth: AuthService,
|
private auth: AuthService,
|
||||||
private toaster: ToasterService,
|
private toaster: ToasterService,
|
||||||
private mcSer: SaleCategoryService,
|
private mcSer: SaleCategoryService,
|
||||||
|
private tSer: TableService,
|
||||||
private bs: BillService) {
|
private bs: BillService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,6 +88,15 @@ export class SalesHomeComponent implements OnInit {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
confirmMoveTableDialog(table: Table): Observable<{table: Table, confirmed: boolean}> {
|
||||||
|
return this.dialog.open(ConfirmDialogComponent, {
|
||||||
|
width: '250px',
|
||||||
|
data: {title: 'Move Table?', content: 'Are you sure?'}
|
||||||
|
}).afterClosed().pipe(
|
||||||
|
map ((x: boolean) => ({table: table, confirmed: x}))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
printBill() {
|
printBill() {
|
||||||
const canGiveDiscount = this.auth.hasPermission("Discount");
|
const canGiveDiscount = this.auth.hasPermission("Discount");
|
||||||
let guestBookId = null;
|
let guestBookId = null;
|
||||||
@ -127,4 +141,41 @@ export class SalesHomeComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
moveTable() {
|
||||||
|
const dialogRef = this.dialog.open(TablesDialogComponent, {
|
||||||
|
// width: '750px',
|
||||||
|
data: {
|
||||||
|
list: this.tSer.running(),
|
||||||
|
canChooseRunning: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dialogRef.afterClosed().pipe(
|
||||||
|
switchMap((x: boolean | Table) => {
|
||||||
|
if (!!x) {
|
||||||
|
return this.confirmMoveTableDialog(x as Table)
|
||||||
|
} else {
|
||||||
|
return throwError("Please choose a table")
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
switchMap((value: { table: Table, confirmed: boolean }, index: number) => {
|
||||||
|
if (!!value.confirmed) {
|
||||||
|
return this.bs.moveTable(value.table)
|
||||||
|
} else {
|
||||||
|
return throwError("Please confirm move")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
).subscribe((x) => {
|
||||||
|
this.toaster.show('Success', '');
|
||||||
|
this.router.navigate(['/sales']);
|
||||||
|
},
|
||||||
|
x => {
|
||||||
|
this.toaster.show('Error', x)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
voidBill() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,7 @@ import { QuantityComponent } from './quantity/quantity.component';
|
|||||||
import { DiscountComponent } from "./discount/discount.component";
|
import { DiscountComponent } from "./discount/discount.component";
|
||||||
import { BillTypeComponent } from "./bill-type/bill-type.component";
|
import { BillTypeComponent } from "./bill-type/bill-type.component";
|
||||||
import { ReceivePaymentComponent } from "./receive-payment/receive-payment.component";
|
import { ReceivePaymentComponent } from "./receive-payment/receive-payment.component";
|
||||||
|
import { TablesDialogComponent } from "./tables-dialog/tables-dialog.component";
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
providers: [
|
providers: [
|
||||||
@ -43,7 +44,8 @@ import { ReceivePaymentComponent } from "./receive-payment/receive-payment.compo
|
|||||||
QuantityComponent,
|
QuantityComponent,
|
||||||
ReceivePaymentComponent,
|
ReceivePaymentComponent,
|
||||||
RunningTablesComponent,
|
RunningTablesComponent,
|
||||||
SalesHomeComponent
|
SalesHomeComponent,
|
||||||
|
TablesDialogComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
@ -69,7 +71,8 @@ import { ReceivePaymentComponent } from "./receive-payment/receive-payment.compo
|
|||||||
DiscountComponent,
|
DiscountComponent,
|
||||||
ModifiersComponent,
|
ModifiersComponent,
|
||||||
QuantityComponent,
|
QuantityComponent,
|
||||||
ReceivePaymentComponent
|
ReceivePaymentComponent,
|
||||||
|
TablesDialogComponent
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class SalesModule { }
|
export class SalesModule { }
|
||||||
|
|||||||
@ -0,0 +1,27 @@
|
|||||||
|
.running {
|
||||||
|
background-color: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
.printed {
|
||||||
|
background-color: firebrick;
|
||||||
|
}
|
||||||
|
|
||||||
|
.square-button {
|
||||||
|
min-width: 150px;
|
||||||
|
max-width: 150px;
|
||||||
|
min-height: 150px;
|
||||||
|
max-height: 150px;
|
||||||
|
cursor: pointer;
|
||||||
|
margin: 20px;
|
||||||
|
}
|
||||||
|
.item-name {
|
||||||
|
text-align: center;
|
||||||
|
padding: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.center {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.selected {
|
||||||
|
background-color: #dddddd;
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
<h2 mat-dialog-title>Tables</h2>
|
||||||
|
<mat-dialog-content fxLayout="row wrap" fxLayoutGap="grid 20px">
|
||||||
|
<mat-card fxLayout="column" class="square-button" matRipple *ngFor="let table of list" (click)="select(table)"
|
||||||
|
[class.running]="table.status === 'running'" [class.printed]="table.status === 'printed'"
|
||||||
|
[class.selected]="table === selected">
|
||||||
|
<h3 class="item-name">{{table.name}}</h3>
|
||||||
|
<mat-card-subtitle class="center">{{table.guest}}</mat-card-subtitle>
|
||||||
|
<span class="center">{{table.pax || 0}} / {{table.seats}} Seats</span>
|
||||||
|
<span class="center" *ngIf="table.date">{{table.date}}</span>
|
||||||
|
<span class="center" *ngIf="table.amount">{{table.amount | currency:'INR'}}</span>
|
||||||
|
</mat-card>
|
||||||
|
</mat-dialog-content>
|
||||||
|
<mat-dialog-actions align="end">
|
||||||
|
<button mat-button [mat-dialog-close]="false">Cancel</button>
|
||||||
|
<button mat-button (click)="accept()" color="primary">Ok</button>
|
||||||
|
</mat-dialog-actions>
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { TablesDialogComponent } from './tables-dialog.component';
|
||||||
|
|
||||||
|
describe('TablesDialogComponent', () => {
|
||||||
|
let component: TablesDialogComponent;
|
||||||
|
let fixture: ComponentFixture<TablesDialogComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ TablesDialogComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(TablesDialogComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -0,0 +1,41 @@
|
|||||||
|
import { Component, Inject } from '@angular/core';
|
||||||
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { Table } from "../../core/table";
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-tables-dialog',
|
||||||
|
templateUrl: './tables-dialog.component.html',
|
||||||
|
styleUrls: ['./tables-dialog.component.css']
|
||||||
|
})
|
||||||
|
export class TablesDialogComponent {
|
||||||
|
list: Table[];
|
||||||
|
canChooseRunning: boolean;
|
||||||
|
selected: Table;
|
||||||
|
constructor(
|
||||||
|
public dialogRef: MatDialogRef<TablesDialogComponent>,
|
||||||
|
@Inject(MAT_DIALOG_DATA) public data: { list: Observable<Table[]>, canChooseRunning: boolean }) {
|
||||||
|
this.data.list.subscribe((list: Table[]) => {
|
||||||
|
this.list = list;
|
||||||
|
});
|
||||||
|
this.canChooseRunning = data.canChooseRunning;
|
||||||
|
this.selected = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
select(t: Table) {
|
||||||
|
if (!this.canChooseRunning && t.status) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.selected === t) {
|
||||||
|
this.selected = null;
|
||||||
|
} else {
|
||||||
|
this.selected = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
accept(): void {
|
||||||
|
if (this.selected !== null) {
|
||||||
|
this.dialogRef.close(this.selected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user