Guest book now shows table status and link to open table
This commit is contained in:
parent
ef1ee35b65
commit
2dd9f7d962
@ -3,7 +3,7 @@ import uuid
|
||||
from datetime import date, datetime, timedelta
|
||||
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 sqlalchemy.exc import SQLAlchemyError
|
||||
@ -34,7 +34,7 @@ def save(
|
||||
data: schemas.GuestBookIn,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["guest-book"]),
|
||||
):
|
||||
) -> schemas.GuestBook:
|
||||
try:
|
||||
customer: Customer = db.query(Customer).filter(Customer.phone == data.phone).first()
|
||||
if customer is None:
|
||||
@ -68,7 +68,7 @@ def update(
|
||||
data: schemas.GuestBookIn,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["guest-book"]),
|
||||
):
|
||||
) -> schemas.GuestBook:
|
||||
try:
|
||||
item: GuestBook = db.query(GuestBook).filter(GuestBook.id == id_).first()
|
||||
item.customer.name = data.name
|
||||
@ -88,17 +88,17 @@ def update(
|
||||
raise
|
||||
|
||||
|
||||
@router.delete("/{id_}")
|
||||
@router.delete("/{id_}", response_model=schemas.GuestBookIn)
|
||||
def delete(
|
||||
id_: uuid.UUID,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["guest-book"]),
|
||||
):
|
||||
) -> schemas.GuestBookIn:
|
||||
try:
|
||||
item: GuestBook = db.query(GuestBook).filter(GuestBook.id == id_).first()
|
||||
db.delete(item)
|
||||
db.commit()
|
||||
return guest_book_info(None)
|
||||
return blank_guest_book_info()
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
@ -110,20 +110,20 @@ def delete(
|
||||
raise
|
||||
|
||||
|
||||
@router.get("")
|
||||
@router.get("", response_model=schemas.GuestBookIn)
|
||||
def show_blank(
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["guest-book"]),
|
||||
):
|
||||
return guest_book_info(None)
|
||||
) -> schemas.GuestBook:
|
||||
return blank_guest_book_info()
|
||||
|
||||
|
||||
@router.get("/list")
|
||||
@router.get("/list", response_model=schemas.GuestBookList)
|
||||
def show_list(
|
||||
q: Optional[str] = None,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Depends(get_user),
|
||||
):
|
||||
) -> schemas.GuestBookList:
|
||||
if q is None or q == "":
|
||||
q = date.today()
|
||||
else:
|
||||
@ -149,38 +149,42 @@ def show_list(
|
||||
for i, item in enumerate(list_):
|
||||
guest_book.insert(
|
||||
0,
|
||||
{
|
||||
"id": item.id,
|
||||
"serial": i + 1,
|
||||
"name": item.customer.name,
|
||||
"phone": item.customer.phone,
|
||||
"pax": item.pax,
|
||||
"date": item.date.strftime("%d-%b-%Y %H:%M"),
|
||||
"status": "" if item.status is None else item.status.status,
|
||||
},
|
||||
schemas.GuestBookListItem(
|
||||
id=item.id,
|
||||
serial=i + 1,
|
||||
name=item.customer.name,
|
||||
phone=item.customer.phone,
|
||||
pax=item.pax,
|
||||
date=item.date,
|
||||
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(
|
||||
id_: uuid.UUID,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["guest-book"]),
|
||||
):
|
||||
) -> schemas.GuestBook:
|
||||
item: GuestBook = db.query(GuestBook).filter(GuestBook.id == id_).first()
|
||||
return guest_book_info(item)
|
||||
|
||||
|
||||
def guest_book_info(item: Optional[GuestBook]):
|
||||
if item is not None:
|
||||
return {
|
||||
"id": item.id,
|
||||
"name": item.customer.name,
|
||||
"phone": item.customer.phone,
|
||||
"pax": item.pax,
|
||||
"address": item.customer.address,
|
||||
"date": item.date.strftime("%d-%b-%Y %H:%M"),
|
||||
}
|
||||
else:
|
||||
return {"name": "", "phone": "", "pax": 0, "address": ""}
|
||||
def guest_book_info(item: GuestBook) -> schemas.GuestBook:
|
||||
return schemas.GuestBook(
|
||||
id=item.id,
|
||||
name=item.customer.name,
|
||||
phone=item.customer.phone,
|
||||
pax=item.pax,
|
||||
address=item.customer.address,
|
||||
date=item.date,
|
||||
)
|
||||
|
||||
|
||||
def blank_guest_book_info() -> schemas.GuestBookIn:
|
||||
return schemas.GuestBookIn(name="", phone="", pax=0, address="")
|
||||
|
@ -1,12 +1,17 @@
|
||||
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 .customer import CustomerIn
|
||||
|
||||
|
||||
class GuestBookIn(CustomerIn):
|
||||
class GuestBookIn(BaseModel):
|
||||
name: str
|
||||
phone: str
|
||||
address: str
|
||||
pax: int = Field(ge=0)
|
||||
|
||||
class Config:
|
||||
@ -17,9 +22,58 @@ class GuestBookIn(CustomerIn):
|
||||
|
||||
class GuestBook(GuestBookIn):
|
||||
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:
|
||||
fields = {"id_": "id"}
|
||||
anystr_strip_whitespace = True
|
||||
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 .customer import Customer, CustomerIn # 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 .modifier import Modifier, ModifierIn, ModifierLink # noqa: F401
|
||||
from .modifier_category import ( # noqa: F401
|
||||
|
@ -1,3 +1,15 @@
|
||||
.full-width-table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.running {
|
||||
/* Red 900 */
|
||||
background-color: #b71c1c;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.printed {
|
||||
/* Green 900 */
|
||||
background-color: #1b5e20;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@
|
||||
<!-- SNo Column -->
|
||||
<ng-container matColumnDef="sno">
|
||||
<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>
|
||||
|
||||
<!-- Name Column -->
|
||||
@ -64,9 +64,24 @@
|
||||
<ng-container matColumnDef="action">
|
||||
<mat-header-cell *matHeaderCellDef class="center">Action</mat-header-cell>
|
||||
<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
|
||||
</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]">
|
||||
<mat-icon>edit</mat-icon>
|
||||
</button>
|
||||
@ -77,7 +92,11 @@
|
||||
</ng-container>
|
||||
|
||||
<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-card-content>
|
||||
</mat-card>
|
||||
|
@ -6,6 +6,10 @@ export class GuestBook {
|
||||
pax: number;
|
||||
address: string;
|
||||
date: string;
|
||||
status?: string;
|
||||
tableId?: string;
|
||||
voucherId?: string;
|
||||
tableName?: string;
|
||||
|
||||
public constructor(init?: Partial<GuestBook>) {
|
||||
Object.assign(this, init);
|
||||
|
Loading…
x
Reference in New Issue
Block a user