Guest book now shows table status and link to open table
This commit is contained in:
@ -3,7 +3,7 @@ import uuid
|
|||||||
from datetime import date, datetime, timedelta
|
from datetime import date, datetime, timedelta
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import barker.schemas.master as schemas
|
import barker.schemas.guest_book as schemas
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||||
from sqlalchemy.exc import SQLAlchemyError
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
@ -34,7 +34,7 @@ def save(
|
|||||||
data: schemas.GuestBookIn,
|
data: schemas.GuestBookIn,
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
user: UserToken = Security(get_user, scopes=["guest-book"]),
|
user: UserToken = Security(get_user, scopes=["guest-book"]),
|
||||||
):
|
) -> schemas.GuestBook:
|
||||||
try:
|
try:
|
||||||
customer: Customer = db.query(Customer).filter(Customer.phone == data.phone).first()
|
customer: Customer = db.query(Customer).filter(Customer.phone == data.phone).first()
|
||||||
if customer is None:
|
if customer is None:
|
||||||
@ -68,7 +68,7 @@ def update(
|
|||||||
data: schemas.GuestBookIn,
|
data: schemas.GuestBookIn,
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
user: UserToken = Security(get_user, scopes=["guest-book"]),
|
user: UserToken = Security(get_user, scopes=["guest-book"]),
|
||||||
):
|
) -> schemas.GuestBook:
|
||||||
try:
|
try:
|
||||||
item: GuestBook = db.query(GuestBook).filter(GuestBook.id == id_).first()
|
item: GuestBook = db.query(GuestBook).filter(GuestBook.id == id_).first()
|
||||||
item.customer.name = data.name
|
item.customer.name = data.name
|
||||||
@ -88,17 +88,17 @@ def update(
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/{id_}")
|
@router.delete("/{id_}", response_model=schemas.GuestBookIn)
|
||||||
def delete(
|
def delete(
|
||||||
id_: uuid.UUID,
|
id_: uuid.UUID,
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
user: UserToken = Security(get_user, scopes=["guest-book"]),
|
user: UserToken = Security(get_user, scopes=["guest-book"]),
|
||||||
):
|
) -> schemas.GuestBookIn:
|
||||||
try:
|
try:
|
||||||
item: GuestBook = db.query(GuestBook).filter(GuestBook.id == id_).first()
|
item: GuestBook = db.query(GuestBook).filter(GuestBook.id == id_).first()
|
||||||
db.delete(item)
|
db.delete(item)
|
||||||
db.commit()
|
db.commit()
|
||||||
return guest_book_info(None)
|
return blank_guest_book_info()
|
||||||
except SQLAlchemyError as e:
|
except SQLAlchemyError as e:
|
||||||
db.rollback()
|
db.rollback()
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
@ -110,20 +110,20 @@ def delete(
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
@router.get("")
|
@router.get("", response_model=schemas.GuestBookIn)
|
||||||
def show_blank(
|
def show_blank(
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
user: UserToken = Security(get_user, scopes=["guest-book"]),
|
user: UserToken = Security(get_user, scopes=["guest-book"]),
|
||||||
):
|
) -> schemas.GuestBook:
|
||||||
return guest_book_info(None)
|
return blank_guest_book_info()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/list")
|
@router.get("/list", response_model=schemas.GuestBookList)
|
||||||
def show_list(
|
def show_list(
|
||||||
q: Optional[str] = None,
|
q: Optional[str] = None,
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
user: UserToken = Depends(get_user),
|
user: UserToken = Depends(get_user),
|
||||||
):
|
) -> schemas.GuestBookList:
|
||||||
if q is None or q == "":
|
if q is None or q == "":
|
||||||
q = date.today()
|
q = date.today()
|
||||||
else:
|
else:
|
||||||
@ -149,38 +149,42 @@ def show_list(
|
|||||||
for i, item in enumerate(list_):
|
for i, item in enumerate(list_):
|
||||||
guest_book.insert(
|
guest_book.insert(
|
||||||
0,
|
0,
|
||||||
{
|
schemas.GuestBookListItem(
|
||||||
"id": item.id,
|
id=item.id,
|
||||||
"serial": i + 1,
|
serial=i + 1,
|
||||||
"name": item.customer.name,
|
name=item.customer.name,
|
||||||
"phone": item.customer.phone,
|
phone=item.customer.phone,
|
||||||
"pax": item.pax,
|
pax=item.pax,
|
||||||
"date": item.date.strftime("%d-%b-%Y %H:%M"),
|
date=item.date,
|
||||||
"status": "" if item.status is None else item.status.status,
|
status=None if item.status is None else item.status.status,
|
||||||
},
|
tableId=None if item.status is None else item.status.food_table.id,
|
||||||
|
voucherId=None if item.status is None else item.status.voucher_id,
|
||||||
|
tableName=None if item.status is None else item.status.food_table.name,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
return {"date": q.strftime("%d-%b-%Y"), "list": guest_book}
|
return schemas.GuestBookList(date=q, list=guest_book)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{id_}")
|
@router.get("/{id_}", response_model=schemas.GuestBook)
|
||||||
def show_id(
|
def show_id(
|
||||||
id_: uuid.UUID,
|
id_: uuid.UUID,
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
user: UserToken = Security(get_user, scopes=["guest-book"]),
|
user: UserToken = Security(get_user, scopes=["guest-book"]),
|
||||||
):
|
) -> schemas.GuestBook:
|
||||||
item: GuestBook = db.query(GuestBook).filter(GuestBook.id == id_).first()
|
item: GuestBook = db.query(GuestBook).filter(GuestBook.id == id_).first()
|
||||||
return guest_book_info(item)
|
return guest_book_info(item)
|
||||||
|
|
||||||
|
|
||||||
def guest_book_info(item: Optional[GuestBook]):
|
def guest_book_info(item: GuestBook) -> schemas.GuestBook:
|
||||||
if item is not None:
|
return schemas.GuestBook(
|
||||||
return {
|
id=item.id,
|
||||||
"id": item.id,
|
name=item.customer.name,
|
||||||
"name": item.customer.name,
|
phone=item.customer.phone,
|
||||||
"phone": item.customer.phone,
|
pax=item.pax,
|
||||||
"pax": item.pax,
|
address=item.customer.address,
|
||||||
"address": item.customer.address,
|
date=item.date,
|
||||||
"date": item.date.strftime("%d-%b-%Y %H:%M"),
|
)
|
||||||
}
|
|
||||||
else:
|
|
||||||
return {"name": "", "phone": "", "pax": 0, "address": ""}
|
def blank_guest_book_info() -> schemas.GuestBookIn:
|
||||||
|
return schemas.GuestBookIn(name="", phone="", pax=0, address="")
|
||||||
|
|||||||
@ -1,12 +1,17 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from pydantic import Field
|
from datetime import date, datetime
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
from pydantic import BaseModel, Field, validator
|
||||||
|
|
||||||
from . import to_camel
|
from . import to_camel
|
||||||
from .customer import CustomerIn
|
|
||||||
|
|
||||||
|
|
||||||
class GuestBookIn(CustomerIn):
|
class GuestBookIn(BaseModel):
|
||||||
|
name: str
|
||||||
|
phone: str
|
||||||
|
address: str
|
||||||
pax: int = Field(ge=0)
|
pax: int = Field(ge=0)
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
@ -17,9 +22,58 @@ class GuestBookIn(CustomerIn):
|
|||||||
|
|
||||||
class GuestBook(GuestBookIn):
|
class GuestBook(GuestBookIn):
|
||||||
id_: uuid.UUID
|
id_: uuid.UUID
|
||||||
date: str
|
date_: datetime
|
||||||
|
|
||||||
|
@validator("date_", pre=True)
|
||||||
|
def parse_date(cls, value):
|
||||||
|
if isinstance(value, datetime):
|
||||||
|
return value
|
||||||
|
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
fields = {"id_": "id"}
|
fields = {"id_": "id"}
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
|
json_encoders = {datetime: lambda v: v.strftime("%d-%b-%Y %H:%M")}
|
||||||
|
|
||||||
|
|
||||||
|
class GuestBookListItem(BaseModel):
|
||||||
|
id_: uuid.UUID
|
||||||
|
serial: int
|
||||||
|
name: str
|
||||||
|
phone: str
|
||||||
|
pax: int
|
||||||
|
date_: datetime
|
||||||
|
status: Optional[str]
|
||||||
|
table_id: Optional[uuid.UUID]
|
||||||
|
voucher_id: Optional[uuid.UUID]
|
||||||
|
table_name: Optional[str]
|
||||||
|
|
||||||
|
@validator("date_", pre=True)
|
||||||
|
def parse_date(cls, value):
|
||||||
|
if isinstance(value, datetime):
|
||||||
|
return value
|
||||||
|
return datetime.strptime(value, "%d-%b-%Y %H:%M")
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
fields = {"id_": "id"}
|
||||||
|
anystr_strip_whitespace = True
|
||||||
|
alias_generator = to_camel
|
||||||
|
json_encoders = {datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"), date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|
||||||
|
|
||||||
|
class GuestBookList(BaseModel):
|
||||||
|
date_: date
|
||||||
|
list: List[GuestBookListItem]
|
||||||
|
|
||||||
|
@validator("date_", pre=True)
|
||||||
|
def parse_date(cls, value):
|
||||||
|
if isinstance(value, date):
|
||||||
|
return value
|
||||||
|
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
fields = {"id_": "id"}
|
||||||
|
anystr_strip_whitespace = True
|
||||||
|
alias_generator = to_camel
|
||||||
|
json_encoders = {datetime: lambda v: v.strftime("%d-%b-%Y %H:%M"), date: lambda v: v.strftime("%d-%b-%Y")}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ from pydantic import BaseModel, Field, validator
|
|||||||
from . import to_camel
|
from . import to_camel
|
||||||
from .customer import Customer, CustomerIn # noqa: F401
|
from .customer import Customer, CustomerIn # noqa: F401
|
||||||
from .device import Device, DeviceIn, DeviceLink # noqa: F401
|
from .device import Device, DeviceIn, DeviceLink # noqa: F401
|
||||||
from .guest_book import GuestBook, GuestBookIn # noqa: F401
|
from .guest_book import GuestBook, GuestBookIn, GuestBookListItem # noqa: F401
|
||||||
from .menu_category import MenuCategory, MenuCategoryIn, MenuCategoryLink # noqa: F401
|
from .menu_category import MenuCategory, MenuCategoryIn, MenuCategoryLink # noqa: F401
|
||||||
from .modifier import Modifier, ModifierIn, ModifierLink # noqa: F401
|
from .modifier import Modifier, ModifierIn, ModifierLink # noqa: F401
|
||||||
from .modifier_category import ( # noqa: F401
|
from .modifier_category import ( # noqa: F401
|
||||||
|
|||||||
@ -1,3 +1,15 @@
|
|||||||
.full-width-table {
|
.full-width-table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.running {
|
||||||
|
/* Red 900 */
|
||||||
|
background-color: #b71c1c;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.printed {
|
||||||
|
/* Green 900 */
|
||||||
|
background-color: #1b5e20;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|||||||
@ -33,7 +33,7 @@
|
|||||||
<!-- SNo Column -->
|
<!-- SNo Column -->
|
||||||
<ng-container matColumnDef="sno">
|
<ng-container matColumnDef="sno">
|
||||||
<mat-header-cell *matHeaderCellDef>S. No</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef>S. No</mat-header-cell>
|
||||||
<mat-cell *matCellDef="let row">{{ row.serial }}</mat-cell>
|
<mat-cell *matCellDef="let row">{{ row.serial }} {{ row.status }}</mat-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<!-- Name Column -->
|
<!-- Name Column -->
|
||||||
@ -64,9 +64,24 @@
|
|||||||
<ng-container matColumnDef="action">
|
<ng-container matColumnDef="action">
|
||||||
<mat-header-cell *matHeaderCellDef class="center">Action</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef class="center">Action</mat-header-cell>
|
||||||
<mat-cell *matCellDef="let row" class="center">
|
<mat-cell *matCellDef="let row" class="center">
|
||||||
<button mat-icon-button [routerLink]="['/sales']" [queryParams]="{ guest: row.id }">
|
<button
|
||||||
|
mat-raised-button
|
||||||
|
color="primary"
|
||||||
|
[routerLink]="['/sales']"
|
||||||
|
[queryParams]="{ guest: row.id }"
|
||||||
|
*ngIf="!row.tableId"
|
||||||
|
>
|
||||||
Seat
|
Seat
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
mat-raised-button
|
||||||
|
color="primary"
|
||||||
|
[routerLink]="['/sales', 'bill']"
|
||||||
|
[queryParams]="{ table: row.tableId, voucher: row.voucherId }"
|
||||||
|
*ngIf="row.tableId"
|
||||||
|
>
|
||||||
|
{{ row.tableName }}
|
||||||
|
</button>
|
||||||
<button mat-icon-button [routerLink]="['/guest-book/', row.id]">
|
<button mat-icon-button [routerLink]="['/guest-book/', row.id]">
|
||||||
<mat-icon>edit</mat-icon>
|
<mat-icon>edit</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
@ -77,7 +92,11 @@
|
|||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||||
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
|
<mat-row
|
||||||
|
*matRowDef="let row; columns: displayedColumns"
|
||||||
|
[class.running]="row.status === 'running'"
|
||||||
|
[class.printed]="row.status === 'printed'"
|
||||||
|
></mat-row>
|
||||||
</mat-table>
|
</mat-table>
|
||||||
</mat-card-content>
|
</mat-card-content>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
|
|||||||
@ -6,6 +6,10 @@ export class GuestBook {
|
|||||||
pax: number;
|
pax: number;
|
||||||
address: string;
|
address: string;
|
||||||
date: string;
|
date: string;
|
||||||
|
status?: string;
|
||||||
|
tableId?: string;
|
||||||
|
voucherId?: string;
|
||||||
|
tableName?: string;
|
||||||
|
|
||||||
public constructor(init?: Partial<GuestBook>) {
|
public constructor(init?: Partial<GuestBook>) {
|
||||||
Object.assign(this, init);
|
Object.assign(this, init);
|
||||||
|
|||||||
Reference in New Issue
Block a user