From dcaf23b3901b6a5c703c85eda8b6e33db611520c Mon Sep 17 00:00:00 2001 From: Amritanshu Date: Sun, 11 Aug 2019 01:37:14 +0530 Subject: [PATCH] Tax is added directly to product for sale Auth guard and auth service simplified and fixed so that user is updated upon login Home component changed to use square buttons Fixed showing the totals in the bill ng linted the project --- barker/views/product.py | 56 +++++++-- bookie/src/app/app.module.ts | 2 + bookie/src/app/auth/auth-guard.service.ts | 18 ++- bookie/src/app/auth/auth.service.ts | 47 +++----- bookie/src/app/core/product.ts | 6 +- bookie/src/app/home/home.component.css | 17 +++ bookie/src/app/home/home.component.html | 112 +++++++++--------- bookie/src/app/home/home.component.ts | 20 ++-- .../sales/bill-type/bill-type.component.ts | 2 +- bookie/src/app/sales/bill.service.ts | 97 ++++++++------- .../src/app/sales/bills/bills.component.html | 11 +- bookie/src/app/sales/bills/bills.component.ts | 32 ++--- bookie/src/app/sales/bills/voucher.service.ts | 12 +- .../app/sales/discount/discount.component.ts | 6 +- .../app/sales/home/sales-home.component.ts | 82 ++++++------- .../app/sales/products/products.component.css | 5 + .../sales/products/products.component.html | 3 +- .../receive-payment.component.ts | 24 ++-- .../running-tables.component.css | 8 +- bookie/src/app/sales/sales.module.ts | 12 +- .../tables-dialog/tables-dialog.component.css | 8 +- .../tables-dialog/tables-dialog.component.ts | 2 +- .../void-reason/void-reason.component.ts | 18 +-- 23 files changed, 334 insertions(+), 266 deletions(-) diff --git a/barker/views/product.py b/barker/views/product.py index 938f272..c381260 100644 --- a/barker/views/product.py +++ b/barker/views/product.py @@ -1,6 +1,5 @@ import uuid from decimal import Decimal, InvalidOperation -from functools import reduce import transaction from pyramid.response import Response @@ -193,15 +192,49 @@ def show_list_sale(request): ) products = [] for item in list_: + products.append( + { + "id": item.id, + "name": item.name, + "units": item.units, + "saleCategory": { + "id": item.sale_category_id, + "name": item.sale_category.name, + }, + "tax": { + "id": item.sale_category.tax_id, + "name": item.sale_category.tax.name, + "rate": item.sale_category.tax.rate, + }, + "price": item.price, + "hasHappyHour": False, + "isNotAvailable": item.is_not_available, + "isActive": item.is_active, + "sortOrder": item.sort_order, + } + ) if item.has_happy_hour: - p = product_info(item, request.dbsession) - p["hasHappyHour"] = False - products.append(p) - i = product_info(item, request.dbsession) - i["name"] = "H + H " + i["name"] - products.append(i) - else: - products.append(product_info(item, request.dbsession)) + products.append( + { + "id": item.id, + "name": "H H " + item.name, + "units": item.units, + "saleCategory": { + "id": item.sale_category_id, + "name": item.sale_category.name, + }, + "tax": { + "id": item.sale_category.tax_id, + "name": item.sale_category.tax.name, + "rate": item.sale_category.tax.rate, + }, + "price": item.price, + "hasHappyHour": True, + "isNotAvailable": item.is_not_available, + "isActive": item.is_active, + "sortOrder": item.sort_order, + } + ) return products @@ -251,7 +284,10 @@ def product_info(item, dbsession): "saleCategory": { "id": item.sale_category_id, "name": item.sale_category.name, - "tax": {"id": item.sale_category.tax_id, "name": item.sale_category.name}, + "tax": { + "id": item.sale_category.tax_id, + "name": item.sale_category.tax.name, + }, }, "price": item.price, "hasHappyHour": item.has_happy_hour, diff --git a/bookie/src/app/app.module.ts b/bookie/src/app/app.module.ts index 4fe5c6d..6ed7ca0 100644 --- a/bookie/src/app/app.module.ts +++ b/bookie/src/app/app.module.ts @@ -23,6 +23,7 @@ import { HomeComponent } from './home/home.component'; import { CoreModule } from './core/core.module'; import { ReactiveFormsModule } from '@angular/forms'; import { SharedModule } from './shared/shared.module'; +import { FlexLayoutModule } from '@angular/flex-layout'; registerLocaleData(enIN); @@ -37,6 +38,7 @@ registerLocaleData(enIN); BrowserModule, AppRoutingModule, BrowserAnimationsModule, + FlexLayoutModule, MatGridListModule, MatCardModule, MatMenuModule, diff --git a/bookie/src/app/auth/auth-guard.service.ts b/bookie/src/app/auth/auth-guard.service.ts index ed3088b..a9519ff 100644 --- a/bookie/src/app/auth/auth-guard.service.ts +++ b/bookie/src/app/auth/auth-guard.service.ts @@ -20,7 +20,8 @@ export class AuthGuard implements CanActivate { this.toaster.show('Danger', 'User is not authenticated'); return false; } - const hasPermission = permission === undefined || user.perms.indexOf(permission) !== -1; + + const hasPermission = this.auth.hasPermission(permission); if (!hasPermission) { this.toaster.show('Danger', 'You do not have the permission to access this area.'); } @@ -28,14 +29,11 @@ export class AuthGuard implements CanActivate { } canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | boolean { - if (this.auth.user === undefined) { - return this.auth.userObservable - .pipe( - map((value: User) => this.checkUser( - next.data['permission'], value, state - )) - ); - } - return this.checkUser(next.data['permission'], this.auth.user, state); + return this.auth.userObservable + .pipe( + map((value: User) => this.checkUser( + next.data['permission'], value, state + )) + ); } } diff --git a/bookie/src/app/auth/auth.service.ts b/bookie/src/app/auth/auth.service.ts index 68ad3fb..7396383 100644 --- a/bookie/src/app/auth/auth.service.ts +++ b/bookie/src/app/auth/auth.service.ts @@ -1,10 +1,10 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs/internal/Observable'; -import { catchError, tap } from 'rxjs/operators'; -import { Subject } from 'rxjs/internal/Subject'; +import { catchError, map, tap } from 'rxjs/operators'; import { ErrorLoggerService } from '../core/error-logger.service'; import { User } from '../core/user'; +import { merge, Subject } from 'rxjs'; const httpOptions = { @@ -19,22 +19,18 @@ const checkUrl = '/v1/auth'; providedIn: 'root' }) export class AuthService { - public userObservable = new Subject(); - + private readonly userSubject: Subject; + private user: User; + public userObservable: Observable; constructor(private http: HttpClient, private log: ErrorLoggerService) { - this.check().subscribe(); + this.userSubject = new Subject(); + this.userObservable = merge(this.checkObserver(), this.userSubject).pipe( + tap(x => this.user = x) + ); } - private _user: User; - - get user() { - return this._user; - } - - set user(user: User) { - this._user = user; - this.log.handleError('AuthService', 'Set User', user); - this.userObservable.next(user); + checkObserver(): Observable { + return >this.http.get(checkUrl, httpOptions); } login(name: string, password: string, otp?: string, clientName?: string): Observable { @@ -49,29 +45,20 @@ export class AuthService { return this.http.post(loginUrl, data, httpOptions) .pipe( - tap((user: User) => this.user = user), + tap((user: User) => this.userSubject.next(user)), catchError(this.log.handleError('AuthService', 'login')) ); } - logout(): Observable { - return this.http.post(logoutUrl, {}, httpOptions) + logout(): Observable { + return >this.http.post(logoutUrl, {}, httpOptions) .pipe( - tap((user: User) => this.user = user), - catchError(this.log.handleError('AuthService', 'logout')) + tap((user: User) => this.userSubject.next(user)), + map(() => true) ); } - check(): Observable { - return this.http.get(checkUrl, httpOptions) - .pipe( - tap((user: User) => this.user = user), - catchError(this.log.handleError('AuthService', 'check')) - ); - } - - hasPermission(permission: string) : boolean { + hasPermission(permission: string): boolean { return this.user !== undefined && this.user.isAuthenticated && this.user.perms.indexOf(permission) !== -1; } - } diff --git a/bookie/src/app/core/product.ts b/bookie/src/app/core/product.ts index d93919f..3057df1 100644 --- a/bookie/src/app/core/product.ts +++ b/bookie/src/app/core/product.ts @@ -1,5 +1,6 @@ -import {MenuCategory} from './menu-category'; -import {SaleCategory} from './sale-category'; +import { MenuCategory } from './menu-category'; +import { SaleCategory } from './sale-category'; +import { Tax } from './tax'; export class Product { id: string; @@ -16,4 +17,5 @@ export class Product { sortOrder: number; enabled?: boolean; + tax?: Tax; } diff --git a/bookie/src/app/home/home.component.css b/bookie/src/app/home/home.component.css index e69de29..2c8bf6c 100644 --- a/bookie/src/app/home/home.component.css +++ b/bookie/src/app/home/home.component.css @@ -0,0 +1,17 @@ +.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; +} + diff --git a/bookie/src/app/home/home.component.html b/bookie/src/app/home/home.component.html index 0855567..bdb566a 100644 --- a/bookie/src/app/home/home.component.html +++ b/bookie/src/app/home/home.component.html @@ -1,53 +1,59 @@ -

Welcome to bookie!

- - account_box - Login - - Guest Book - - - Sales - - - Tables - - - Sections - - - Menu Categories - - - Sale Categories - - - Products - - - Modifier Categories - - - Modifiers - - - Taxes - - - Devices - - - Section Printers - - - Printers - - - Roles - - - Users - - - account_box - Logout {{name}} - +
+ +

+ account_box + Login +

+
+ +

Guest Book

+
+ +

Sales

+
+ +

Tables

+
+ +

Sections

+
+ +

Menu Categories

+
+ +

Sale Categories

+
+ +

Products

+
+ +

Modifier Categories

+
+ +

Modifiers

+
+ +

Taxes

+
+ +

Devices

+
+ +

Section Printers

+
+ +

Printers

+
+ +

Roles

+
+ +

Users

+
+ +

+ account_box + Logout {{name}}

+
+
diff --git a/bookie/src/app/home/home.component.ts b/bookie/src/app/home/home.component.ts index 750cb35..cf3acaa 100644 --- a/bookie/src/app/home/home.component.ts +++ b/bookie/src/app/home/home.component.ts @@ -1,6 +1,7 @@ -import {Component, OnInit} from '@angular/core'; -import {Subject} from 'rxjs'; -import {AuthService} from '../auth/auth.service'; +import { Component, OnInit} from '@angular/core'; +import { AuthService} from '../auth/auth.service'; +import { Observable } from 'rxjs'; +import { map, share } from 'rxjs/operators'; @Component({ selector: 'app-home', @@ -8,18 +9,15 @@ import {AuthService} from '../auth/auth.service'; styleUrls: ['./home.component.css'] }) export class HomeComponent implements OnInit { - public nameObject = new Subject(); + public user: Observable; constructor(private auth: AuthService) { } ngOnInit() { - this.auth.userObservable.subscribe((user) => { - if (user.isAuthenticated) { - this.nameObject.next(user.name); - } else { - this.nameObject.next(null); - } - }); + this.user = this.auth.userObservable.pipe( + map (x => x.isAuthenticated ? x.name : null), + share() + ); } } diff --git a/bookie/src/app/sales/bill-type/bill-type.component.ts b/bookie/src/app/sales/bill-type/bill-type.component.ts index b3e7e47..4bea60b 100644 --- a/bookie/src/app/sales/bill-type/bill-type.component.ts +++ b/bookie/src/app/sales/bill-type/bill-type.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; import { MatDialogRef } from '@angular/material'; -import { PrintType } from "../bills/bill"; +import { PrintType } from '../bills/bill'; @Component({ selector: 'app-bill-type', diff --git a/bookie/src/app/sales/bill.service.ts b/bookie/src/app/sales/bill.service.ts index d7107de..d245cb8 100644 --- a/bookie/src/app/sales/bill.service.ts +++ b/bookie/src/app/sales/bill.service.ts @@ -9,16 +9,19 @@ import { ModifierCategoryService } from '../modifier-categories/modifier-categor import { ModifierCategory } from '../core/modifier-category'; 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"; -import {observableToBeFn} from "rxjs/internal/testing/TestScheduler"; +import { ToasterService } from '../core/toaster.service'; +import { tap } from 'rxjs/operators'; +import { Table } from '../core/table'; @Injectable() export class BillService { public dataObs; public data; private bill; + public netAmount: BehaviorSubject; + public discountAmount: BehaviorSubject; + public taxAmount: BehaviorSubject; + public amount: BehaviorSubject; constructor( private dialog: MatDialog, @@ -28,6 +31,10 @@ export class BillService { ) { this.data = []; this.dataObs = new BehaviorSubject(this.data); + this.netAmount = new BehaviorSubject(0); + this.discountAmount = new BehaviorSubject(0); + this.taxAmount = new BehaviorSubject(0); + this.amount = new BehaviorSubject(0); } loadData(bill: Bill): void { @@ -58,6 +65,7 @@ export class BillService { this.data = view.reduce((a, c) => a.concat(c) , []); this.data.push({isKot: true, newKot: true, info: '== New Kot =='}); this.dataObs.next(this.data); + this.updateAmounts(); } addProduct(product: Product): void { @@ -76,8 +84,8 @@ export class BillService { price: product.price, quantity: 1, discount: 0, - taxRate: product.saleCategory.tax.rate, - tax: product.saleCategory.tax, + taxRate: product.tax.rate, + tax: product.tax, modifiers: [] }; this.data.push(item); @@ -90,6 +98,7 @@ export class BillService { }); } this.dataObs.next(this.data); + this.updateAmounts(); } showModifier(item: any): void { @@ -114,17 +123,20 @@ export class BillService { addOne(item: any): void { item.quantity += 1; this.dataObs.next(this.data); + this.updateAmounts(); } quantity(item: any, quantity: number): void { item.quantity = quantity; this.dataObs.next(this.data); + this.updateAmounts(); } subtractOne(item: any): void { if (item.quantity > 1) { item.quantity -= 1; this.dataObs.next(this.data); + this.updateAmounts(); } else if (item.quantity === 0) { this.removeItem(item); } @@ -133,20 +145,22 @@ export class BillService { removeItem(item: any): void { this.data.splice(this.data.indexOf(item), 1); this.dataObs.next(this.data); + this.updateAmounts(); } modifier(item: any): void { this.showModifier(item); } - discount(discounts:{id: string, name: string, discount: number}[]): void { - this.data.forEach(x=> { + discount(discounts: {id: string, name: string, discount: number}[]): void { + this.data.forEach(x => { if (!x.isKot) { x.discount = discounts.find(d => d.id === x.product.saleCategory.id).discount / 100; x.info = `${x.product.name} (${x.product.units}) @ ${x.price} - ${math.round(x.discount * 100, 2)}%`; } }); this.dataObs.next(this.data); + this.updateAmounts(); } private getKot(): Kot { @@ -165,28 +179,24 @@ export class BillService { } printKot(guest_book_id: string): Observable { - let item = JSON.parse(JSON.stringify(this.bill)); - let newKot = this.getKot(); + const item = JSON.parse(JSON.stringify(this.bill)); + const newKot = this.getKot(); if (newKot.inventories.length == 0) { this.toaster.show('Error', 'Cannot print a blank KOT\nPlease add some products!'); } item.kots.push(newKot); - return this.ser.saveOrUpdate(item, PrintType.Kot, guest_book_id, true).pipe( - tap(x => console.log(x)) - ); + return this.ser.saveOrUpdate(item, PrintType.Kot, guest_book_id, true); } printBill(guest_book_id: string, printType: PrintType): Observable { - let item = JSON.parse(JSON.stringify(this.bill)); + const item = JSON.parse(JSON.stringify(this.bill)); item.kots.forEach(k => { k.inventories.forEach(i => { i.discount = this.data.find(x => !x.isKot && x.id === i.id).discount; - }) + }); }); item.kots.push(this.getKot()); - return this.ser.saveOrUpdate(item, printType, guest_book_id, true).pipe( - tap(x => console.log(x)) - ); + return this.ser.saveOrUpdate(item, printType, guest_book_id, true); } type() { @@ -194,48 +204,49 @@ export class BillService { } receivePayment(amounts: { id: string; name: string; amount: number }[]): Observable { - return this.ser.receivePayment(this.bill.id, amounts, true).pipe( - tap(x => console.log(x)) - ); + return this.ser.receivePayment(this.bill.id, amounts, true); } moveTable(table: Table): Observable { return this.ser.moveTable(this.bill.id, table); } + moveKot(id: string, table: Table): Observable { + return this.ser.moveKot(this.bill.id, id, table); + } + voidBill(reason: string): Observable { return this.ser.voidBill(this.bill.id, reason, true); } - netAmount() { - return math.round(this.bill.kots.reduce( - (ka: number, k: Kot) => ka + k.inventories.reduce( - (ca: number, c: Inventory) => ca + ((c.isHappyHour ? 0 : c.price) * c.quantity) - , 0) - , 0)) - } - - discountAmount() { - return math.round(this.bill.kots.reduce( - (ka: number, k: Kot) => ka + k.inventories.reduce( + updateAmounts() { + this.netAmount.next( + math.round(this.data.filter(x => !x.isKot).reduce( + (ca: number, c: any) => ca + ((c.isHappyHour ? 0 : c.price) * c.quantity) + , 0)) + ); + this.discountAmount.next( + math.round(this.data.filter(x => !x.isKot).reduce( (ca: number, c: Inventory) => ca + ((c.isHappyHour ? 0 : c.price) * c.quantity * c.discount) - , 0) - , 0)) - } - - taxAmount() { - return math.round(this.bill.kots.reduce( - (ka: number, k: Kot) => ka + k.inventories.reduce( + , 0)) + ); + this.taxAmount.next( + math.round(this.data.filter(x => !x.isKot).reduce( (ca: number, c: Inventory) => ca + ((c.isHappyHour ? 0 : c.price) * c.quantity * (1 - c.discount) * c.taxRate) - , 0) - , 0)) + , 0)) + ); + this.amount.next( + math.round(this.data.filter(x => !x.isKot).reduce( + (ca: number, c: Inventory) => ca + ((c.isHappyHour ? 0 : c.price) * c.quantity * (1 - c.discount) * (1 + c.taxRate)) + , 0)) + ); } - amount() { + amountVal(): number { return math.round(this.bill.kots.reduce( (ka: number, k: Kot) => ka + k.inventories.reduce( (ca: number, c: Inventory) => ca + ((c.isHappyHour ? 0 : c.price) * c.quantity * (1 - c.discount) * (1 + c.taxRate)) , 0) - , 0)) + , 0)); } } diff --git a/bookie/src/app/sales/bills/bills.component.html b/bookie/src/app/sales/bills/bills.component.html index 0a76d6e..5e43fd7 100644 --- a/bookie/src/app/sales/bills/bills.component.html +++ b/bookie/src/app/sales/bills/bills.component.html @@ -39,26 +39,29 @@ + - {{ amount() | currency: 'INR' }} + {{ bs.amount | async | currency: 'INR' }} Net - {{ netAmount() | currency: 'INR' }} + {{ bs.netAmount | async | currency: 'INR' }} Discount - {{ discountAmount() | currency: 'INR' }} + {{ bs.discountAmount | async | currency: 'INR' }} Tax - {{ taxAmount() | currency: 'INR' }} + {{ bs.taxAmount | async | currency: 'INR' }} { 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) + options.params = options.params.set('g', guest_book_id); } return >this.http.post(`${url}/new`, voucher, options) .pipe( @@ -61,7 +61,7 @@ export class VoucherService { update(voucher: Bill, printType: PrintType, guest_book_id: string, updateTable: boolean): Observable { 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) + options.params = options.params.set('g', guest_book_id); } return >this.http.put(`${url}/${voucher.id}`, voucher, options) .pipe( @@ -78,7 +78,7 @@ export class VoucherService { } receivePayment(id: string, amounts: { id: string; name: string; amount: number }[], updateTable: boolean): Observable { - const options = {params: new HttpParams().set('receive-payment', "").set('u', updateTable.toString())}; + const options = {params: new HttpParams().set('receive-payment', '').set('u', updateTable.toString())}; return >this.http.post(`${url}/${id}`, amounts, options) .pipe( catchError(this.log.handleError(serviceName, 'receivePayment')) @@ -87,14 +87,14 @@ export class VoucherService { moveTable(id: string, table: Table): Observable { const options = {params: new HttpParams().set('move-table', '')}; - return >this.http.post(`${url}/${id}`, {table:{id: table.id}}, options) + return >this.http.post(`${url}/${id}`, {table: {id: table.id}}, options) .pipe( catchError(this.log.handleError(serviceName, 'moveTable')) ); } voidBill(id: string, reason: string, updateTable: boolean): Observable { - const options = {params: new HttpParams().set('void-bill', "").set('u', updateTable.toString())}; + const options = {params: new HttpParams().set('void-bill', '').set('u', updateTable.toString())}; return >this.http.post(`${url}/${id}`, {reason: reason}, options) .pipe( catchError(this.log.handleError(serviceName, 'voidBill')) diff --git a/bookie/src/app/sales/discount/discount.component.ts b/bookie/src/app/sales/discount/discount.component.ts index a73236e..223ac92 100644 --- a/bookie/src/app/sales/discount/discount.component.ts +++ b/bookie/src/app/sales/discount/discount.component.ts @@ -1,8 +1,8 @@ import { Component, Inject } from '@angular/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material'; import { Observable } from 'rxjs'; -import { FormArray, FormBuilder, FormGroup, Validators } from "@angular/forms"; -import { DiscountDataSource } from "./discount-datasource"; +import { FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { DiscountDataSource } from './discount-datasource'; @Component({ selector: 'app-modifiers', @@ -28,7 +28,7 @@ export class DiscountComponent { this.list.map( x => this.fb.group({ name: [x.name], - discount: ["", [Validators.min(0), Validators.max(100)]] + discount: ['', [Validators.min(0), Validators.max(100)]] }) ) )); diff --git a/bookie/src/app/sales/home/sales-home.component.ts b/bookie/src/app/sales/home/sales-home.component.ts index 3d72402..6af3d77 100644 --- a/bookie/src/app/sales/home/sales-home.component.ts +++ b/bookie/src/app/sales/home/sales-home.component.ts @@ -1,21 +1,21 @@ import { Component, OnInit } from '@angular/core'; -import { ActivatedRoute, Router } from "@angular/router"; -import { MatDialog } from "@angular/material"; -import { concatMap, map, switchMap, tap } from "rxjs/operators"; -import { iif, Observable, of as observableOf, throwError } from "rxjs"; +import { ActivatedRoute, Router } from '@angular/router'; +import { MatDialog } from '@angular/material'; +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"; -import { DiscountComponent } from "../discount/discount.component"; -import { SaleCategoryService } from "../../sale-category/sale-category.service"; -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"; -import { VoidReasonComponent } from "../void-reason/void-reason.component"; +import { ToasterService } from '../../core/toaster.service'; +import { DiscountComponent } from '../discount/discount.component'; +import { SaleCategoryService } from '../../sale-category/sale-category.service'; +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'; +import { VoidReasonComponent } from '../void-reason/void-reason.component'; @Component({ selector: 'app-sales-home', @@ -40,8 +40,8 @@ export class SalesHomeComponent implements OnInit { printKot() { let guestBookId = null; - if (this.route.snapshot.queryParamMap.has("guest")) { - guestBookId = this.route.snapshot.queryParamMap.get("guest"); + if (this.route.snapshot.queryParamMap.has('guest')) { + guestBookId = this.route.snapshot.queryParamMap.get('guest'); } this.bs.printKot(guestBookId).subscribe(x => { this.toaster.show('Success', ''); @@ -50,7 +50,7 @@ export class SalesHomeComponent implements OnInit { } discount(): void { - if (this.auth.hasPermission("Discount")) { + if (this.auth.hasPermission('Discount')) { this.showDiscount().subscribe(); } } @@ -66,15 +66,15 @@ export class SalesHomeComponent implements OnInit { this.bs.discount(result as { id: string, name: string, discount: number }[]); } }) - ) + ); } - discountDialog (canGiveDiscount: boolean) : Observable { + discountDialog (canGiveDiscount: boolean): Observable { let discObs = null; if (canGiveDiscount) { return discObs = this.showDiscount(); } else { - return discObs = observableOf(""); + return discObs = observableOf(''); } } @@ -83,10 +83,10 @@ export class SalesHomeComponent implements OnInit { return this.dialog.open(BillTypeComponent).afterClosed().pipe( tap(x => { if (!x) { - throwError ("No Bill Type Chosen") + throwError ('No Bill Type Chosen'); } }) - ) + ); } confirmMoveTableDialog(table: Table): Observable<{table: Table, confirmed: boolean}> { @@ -108,10 +108,10 @@ export class SalesHomeComponent implements OnInit { } printBill() { - const canGiveDiscount = this.auth.hasPermission("Discount"); + const canGiveDiscount = this.auth.hasPermission('Discount'); let guestBookId = null; - if (this.route.snapshot.queryParamMap.has("guest")) { - guestBookId = this.route.snapshot.queryParamMap.get("guest"); + if (this.route.snapshot.queryParamMap.has('guest')) { + guestBookId = this.route.snapshot.queryParamMap.get('guest'); } this.discountDialog(canGiveDiscount).pipe( concatMap(() => this.billTypeDialog()) @@ -128,13 +128,13 @@ export class SalesHomeComponent implements OnInit { this.router.navigate(['/sales']); }, x => { - this.toaster.show('Error', "No Bill Type Chosen") + this.toaster.show('Error', 'No Bill Type Chosen'); }); } receivePayment() { - let amount = this.bs.amount(); - let type = this.bs.type(); + const amount = this.bs.amountVal(); + const type = this.bs.type(); const dialogRef = this.dialog.open(ReceivePaymentComponent, { // width: '750px', data: { @@ -149,7 +149,7 @@ export class SalesHomeComponent implements OnInit { this.router.navigate(['/sales']); }); } - }) + }); } moveTable() { @@ -164,14 +164,14 @@ export class SalesHomeComponent implements OnInit { if (!!x) { return this.confirmMoveTableDialog(x as Table); } else { - return throwError("Please choose a table"); + return throwError('Please choose a table'); } }), switchMap((value: { table: Table, confirmed: boolean }, index: number) => { if (!!value.confirmed) { - return this.bs.moveTable(value.table) + return this.bs.moveTable(value.table); } else { - return throwError("Please confirm move") + return throwError('Please confirm move'); } } ) @@ -180,8 +180,8 @@ export class SalesHomeComponent implements OnInit { this.router.navigate(['/sales']); }, x => { - this.toaster.show('Error', x) - }) + this.toaster.show('Error', x); + }); } voidBill() { @@ -192,14 +192,14 @@ export class SalesHomeComponent implements OnInit { if (!!x) { return this.confirmVoidDialog(x as string); } else { - return throwError("Please choose a reason to void the bill"); + return throwError('Please choose a reason to void the bill'); } }), switchMap((x: boolean | string) => { if (!!x) { - return this.bs.voidBill(x as string) + return this.bs.voidBill(x as string); } else { - return throwError("You chose not to void the bill") + return throwError('You chose not to void the bill'); } }) ).subscribe((x) => { @@ -207,7 +207,7 @@ export class SalesHomeComponent implements OnInit { this.router.navigate(['/sales']); }, x => { - this.toaster.show('Error', x) - }) + this.toaster.show('Error', x); + }); } } diff --git a/bookie/src/app/sales/products/products.component.css b/bookie/src/app/sales/products/products.component.css index ca1c92c..0d5d1b3 100644 --- a/bookie/src/app/sales/products/products.component.css +++ b/bookie/src/app/sales/products/products.component.css @@ -23,3 +23,8 @@ background-color: #d32f2f; color: #ffffff; } + +.grey800 { + background-color: #424242; + color: #ffffff; +} diff --git a/bookie/src/app/sales/products/products.component.html b/bookie/src/app/sales/products/products.component.html index d6f7cf9..651d275 100644 --- a/bookie/src/app/sales/products/products.component.html +++ b/bookie/src/app/sales/products/products.component.html @@ -1,6 +1,7 @@ - +

{{item.name}}

this.fb.group({ name: [x.name], - amount: [""] + amount: [''] }) ) )); @@ -91,7 +91,7 @@ export class ReceivePaymentComponent { (z, i) => array.controls[i].valueChanges.pipe( distinctUntilChanged() ).subscribe(x => { - this.choices[this.type].find(s => s.name == x.name).amount = (x.amount === "" ? 0 : parseInt(x.amount, 10)); + this.choices[this.type].find(s => s.name == x.name).amount = (x.amount === '' ? 0 : parseInt(x.amount, 10)); this.balance = this.amount - this.choices[this.type].reduce((a, c) => a + c.amount, 0); }) ); diff --git a/bookie/src/app/sales/running-tables/running-tables.component.css b/bookie/src/app/sales/running-tables/running-tables.component.css index f08b6b5..b46ac09 100644 --- a/bookie/src/app/sales/running-tables/running-tables.component.css +++ b/bookie/src/app/sales/running-tables/running-tables.component.css @@ -1,9 +1,13 @@ .running { - background-color: green; + /* Red 900 */ + background-color: #b71c1c; + color: #ffffff; } .printed { - background-color: firebrick; + /* Green 900 */ + background-color: #1b5e20; + color: #ffffff; } .square-button { diff --git a/bookie/src/app/sales/sales.module.ts b/bookie/src/app/sales/sales.module.ts index 8f5c375..51b7062 100644 --- a/bookie/src/app/sales/sales.module.ts +++ b/bookie/src/app/sales/sales.module.ts @@ -15,7 +15,7 @@ import { MatTableModule } from '@angular/material/table'; import { MatTabsModule } from '@angular/material/tabs'; import { FlexLayoutModule } from '@angular/flex-layout'; -import { SharedModule } from "../shared/shared.module"; +import { SharedModule } from '../shared/shared.module'; import { SalesRoutingModule } from './sales-routing.module'; import { RunningTablesComponent } from './running-tables/running-tables.component'; import { MenuCategoriesComponent } from './menu-categories/menu-categories.component'; @@ -25,11 +25,11 @@ import { BillsComponent } from './bills/bills.component'; import { SalesHomeComponent } from './home/sales-home.component'; import { BillService } from './bill.service'; 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"; -import { VoidReasonComponent } from "./void-reason/void-reason.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'; +import { VoidReasonComponent } from './void-reason/void-reason.component'; @NgModule({ providers: [ diff --git a/bookie/src/app/sales/tables-dialog/tables-dialog.component.css b/bookie/src/app/sales/tables-dialog/tables-dialog.component.css index 4159064..bfd69f5 100644 --- a/bookie/src/app/sales/tables-dialog/tables-dialog.component.css +++ b/bookie/src/app/sales/tables-dialog/tables-dialog.component.css @@ -1,9 +1,13 @@ .running { - background-color: green; + /* Red 900 */ + background-color: #b71c1c; + color: #ffffff; } .printed { - background-color: firebrick; + /* Green 900 */ + background-color: #1b5e20; + color: #ffffff; } .square-button { diff --git a/bookie/src/app/sales/tables-dialog/tables-dialog.component.ts b/bookie/src/app/sales/tables-dialog/tables-dialog.component.ts index 41dbe19..35c2697 100644 --- a/bookie/src/app/sales/tables-dialog/tables-dialog.component.ts +++ b/bookie/src/app/sales/tables-dialog/tables-dialog.component.ts @@ -1,7 +1,7 @@ import { Component, Inject } from '@angular/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material'; import { Observable } from 'rxjs'; -import { Table } from "../../core/table"; +import { Table } from '../../core/table'; @Component({ selector: 'app-tables-dialog', diff --git a/bookie/src/app/sales/void-reason/void-reason.component.ts b/bookie/src/app/sales/void-reason/void-reason.component.ts index 9f1842d..095d3a2 100644 --- a/bookie/src/app/sales/void-reason/void-reason.component.ts +++ b/bookie/src/app/sales/void-reason/void-reason.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; import { MatDialogRef } from '@angular/material'; -import { VoidReasonDatasource } from "./void-reason-datasource"; +import { VoidReasonDatasource } from './void-reason-datasource'; @Component({ selector: 'app-void-reason', @@ -11,14 +11,14 @@ export class VoidReasonComponent { dataSource: VoidReasonDatasource; selected: string; reasons = [ - "Discount", - "Printing fault", - "Item changed", - "Quantity reduced", - "Costing bill for party", - "Cashier mistake", - "Management free sale", - "Other" + 'Discount', + 'Printing fault', + 'Item changed', + 'Quantity reduced', + 'Costing bill for party', + 'Cashier mistake', + 'Management free sale', + 'Other' ]; displayedColumns = ['reason'];