From 2fcff26e3405dca00796c3837f2bb6e038785e38 Mon Sep 17 00:00:00 2001 From: Amritanshu Date: Sat, 10 Aug 2019 14:21:40 +0530 Subject: [PATCH] Move Table with confirm --- barker/routes.py | 1 - barker/views/{ => voucher}/merge_move.py | 90 +++++++++++++------ bookie/src/app/core/table.ts | 5 ++ bookie/src/app/sales/bill.service.ts | 5 ++ bookie/src/app/sales/bills/voucher.service.ts | 9 ++ .../app/sales/home/sales-home.component.html | 2 +- .../app/sales/home/sales-home.component.ts | 53 ++++++++++- bookie/src/app/sales/sales.module.ts | 7 +- .../tables-dialog/tables-dialog.component.css | 27 ++++++ .../tables-dialog.component.html | 16 ++++ .../tables-dialog.component.spec.ts | 25 ++++++ .../tables-dialog/tables-dialog.component.ts | 41 +++++++++ 12 files changed, 248 insertions(+), 33 deletions(-) rename barker/views/{ => voucher}/merge_move.py (52%) create mode 100644 bookie/src/app/sales/tables-dialog/tables-dialog.component.css create mode 100644 bookie/src/app/sales/tables-dialog/tables-dialog.component.html create mode 100644 bookie/src/app/sales/tables-dialog/tables-dialog.component.spec.ts create mode 100644 bookie/src/app/sales/tables-dialog/tables-dialog.component.ts diff --git a/barker/routes.py b/barker/routes.py index 80b97fd..a0e3bf2 100644 --- a/barker/routes.py +++ b/barker/routes.py @@ -368,7 +368,6 @@ def includeme(config): config.add_route("merge_table", "/MergeTable.json") config.add_route("move_kot", "/MoveKot.json") - config.add_route("move_table", "/MoveTable.json") config.add_route("permission_list", "/Permissions.json") diff --git a/barker/views/merge_move.py b/barker/views/voucher/merge_move.py similarity index 52% rename from barker/views/merge_move.py rename to barker/views/voucher/merge_move.py index 6e4346f..3142bb8 100644 --- a/barker/views/merge_move.py +++ b/barker/views/voucher/merge_move.py @@ -6,64 +6,98 @@ from pyramid.view import view_config 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): json = request.json_body - kot_id = uuid.UUID(json['KotID']) - voucher_id = uuid.UUID(json['NewVoucherID']) + kot_id = uuid.UUID(json["KotID"]) + 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() 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): json = request.json_body - kot_id = uuid.UUID(json['KotID']) - food_table_id = uuid.UUID(json['FoodTableID']) + kot_id = uuid.UUID(json["KotID"]) + food_table_id = uuid.UUID(json["FoodTableID"]) 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, - kot.voucher.user_id, request.dbsession) + item = Voucher( + 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) item.kots.append(kot) 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) transaction.commit() 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): - json = request.json_body - voucher_id = uuid.UUID(json['VoucherID']) - food_table_id = uuid.UUID(json['FoodTableID']) + id_ = uuid.UUID(request.matchdict["id"]) + table_id = uuid.UUID(request.GET["m"]) - request.dbsession.query( - Overview - ).filter( - Overview.voucher_id == voucher_id - ).update({Overview.food_table_id: food_table_id}) + request.dbsession.query(Overview).filter(Overview.voucher_id == id_).update( + {Overview.food_table_id: table_id} + ) - request.dbsession.query( - Voucher - ).filter( - Voucher.id == voucher_id - ).update({Voucher.food_table_id: food_table_id}) + request.dbsession.query(Voucher).filter(Voucher.id == id_).update( + {Voucher.food_table_id: table_id} + ) 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): json = request.json_body - voucher_id = uuid.UUID(json['VoucherID']) - new_voucher_id = uuid.UUID(json['NewVoucherID']) + voucher_id = uuid.UUID(json["VoucherID"]) + 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() transaction.commit() return voucher_id diff --git a/bookie/src/app/core/table.ts b/bookie/src/app/core/table.ts index b820093..191a6da 100644 --- a/bookie/src/app/core/table.ts +++ b/bookie/src/app/core/table.ts @@ -7,4 +7,9 @@ export class Table { section: Section; isActive: boolean; voucherId?: string; + status?: string; + pax?: number; + guest?: string; + date?: string; + amount?: number; } diff --git a/bookie/src/app/sales/bill.service.ts b/bookie/src/app/sales/bill.service.ts index e49b1ba..0564620 100644 --- a/bookie/src/app/sales/bill.service.ts +++ b/bookie/src/app/sales/bill.service.ts @@ -11,6 +11,7 @@ import { Bill, Inventory, Kot, PrintType } from './bills/bill'; import { VoucherService } from './bills/voucher.service'; import { ToasterService } from "../core/toaster.service"; import { tap } from "rxjs/operators"; +import { Table } from "../core/table"; @Injectable() export class BillService { @@ -197,6 +198,10 @@ export class BillService { ); } + moveTable(table: Table): Observable { + return this.ser.moveTable(this.bill.id, table); + } + netAmount() { return math.round(this.bill.kots.reduce( (ka: number, k: Kot) => ka + k.inventories.reduce( diff --git a/bookie/src/app/sales/bills/voucher.service.ts b/bookie/src/app/sales/bills/voucher.service.ts index 6a339be..340ca0c 100644 --- a/bookie/src/app/sales/bills/voucher.service.ts +++ b/bookie/src/app/sales/bills/voucher.service.ts @@ -4,6 +4,7 @@ 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'}) @@ -83,4 +84,12 @@ export class VoucherService { catchError(this.log.handleError(serviceName, 'receivePayment')) ); } + + moveTable(id: string, table: Table): Observable { + const options = {params: new HttpParams().set('m', table.id)}; + return >this.http.post(`${url}/${id}`, {}, options) + .pipe( + catchError(this.log.handleError(serviceName, 'moveTable')) + ); + } } diff --git a/bookie/src/app/sales/home/sales-home.component.html b/bookie/src/app/sales/home/sales-home.component.html index 5198d59..6aa99ad 100644 --- a/bookie/src/app/sales/home/sales-home.component.html +++ b/bookie/src/app/sales/home/sales-home.component.html @@ -18,7 +18,7 @@

Receive Payment

- +

Move Table

diff --git a/bookie/src/app/sales/home/sales-home.component.ts b/bookie/src/app/sales/home/sales-home.component.ts index 0e357ac..09d0214 100644 --- a/bookie/src/app/sales/home/sales-home.component.ts +++ b/bookie/src/app/sales/home/sales-home.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from "@angular/router"; 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 { BillService } from '../bill.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 { AuthService } from "../../auth/auth.service"; 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({ selector: 'app-sales-home', @@ -26,6 +30,7 @@ export class SalesHomeComponent implements OnInit { private auth: AuthService, private toaster: ToasterService, private mcSer: SaleCategoryService, + private tSer: TableService, 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() { const canGiveDiscount = this.auth.hasPermission("Discount"); 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() { + + } } diff --git a/bookie/src/app/sales/sales.module.ts b/bookie/src/app/sales/sales.module.ts index 1f6f9b1..787f092 100644 --- a/bookie/src/app/sales/sales.module.ts +++ b/bookie/src/app/sales/sales.module.ts @@ -28,6 +28,7 @@ import { QuantityComponent } from './quantity/quantity.component'; import { DiscountComponent } from "./discount/discount.component"; import { BillTypeComponent } from "./bill-type/bill-type.component"; import { ReceivePaymentComponent } from "./receive-payment/receive-payment.component"; +import { TablesDialogComponent } from "./tables-dialog/tables-dialog.component"; @NgModule({ providers: [ @@ -43,7 +44,8 @@ import { ReceivePaymentComponent } from "./receive-payment/receive-payment.compo QuantityComponent, ReceivePaymentComponent, RunningTablesComponent, - SalesHomeComponent + SalesHomeComponent, + TablesDialogComponent ], imports: [ CommonModule, @@ -69,7 +71,8 @@ import { ReceivePaymentComponent } from "./receive-payment/receive-payment.compo DiscountComponent, ModifiersComponent, QuantityComponent, - ReceivePaymentComponent + ReceivePaymentComponent, + TablesDialogComponent ] }) export class SalesModule { } diff --git a/bookie/src/app/sales/tables-dialog/tables-dialog.component.css b/bookie/src/app/sales/tables-dialog/tables-dialog.component.css new file mode 100644 index 0000000..0bd1e4c --- /dev/null +++ b/bookie/src/app/sales/tables-dialog/tables-dialog.component.css @@ -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; +} diff --git a/bookie/src/app/sales/tables-dialog/tables-dialog.component.html b/bookie/src/app/sales/tables-dialog/tables-dialog.component.html new file mode 100644 index 0000000..73fec78 --- /dev/null +++ b/bookie/src/app/sales/tables-dialog/tables-dialog.component.html @@ -0,0 +1,16 @@ +

Tables

+ + +

{{table.name}}

+ {{table.guest}} + {{table.pax || 0}} / {{table.seats}} Seats + {{table.date}} + {{table.amount | currency:'INR'}} +
+
+ + + + diff --git a/bookie/src/app/sales/tables-dialog/tables-dialog.component.spec.ts b/bookie/src/app/sales/tables-dialog/tables-dialog.component.spec.ts new file mode 100644 index 0000000..da4a34f --- /dev/null +++ b/bookie/src/app/sales/tables-dialog/tables-dialog.component.spec.ts @@ -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; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ TablesDialogComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(TablesDialogComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/bookie/src/app/sales/tables-dialog/tables-dialog.component.ts b/bookie/src/app/sales/tables-dialog/tables-dialog.component.ts new file mode 100644 index 0000000..41dbe19 --- /dev/null +++ b/bookie/src/app/sales/tables-dialog/tables-dialog.component.ts @@ -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, + @Inject(MAT_DIALOG_DATA) public data: { list: Observable, 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); + } + } +}