parent
bf09471e9e
commit
cf34c2b855
|
@ -26,7 +26,7 @@ from .routers.reports import (
|
|||
sale_report,
|
||||
tax_report
|
||||
)
|
||||
from .routers.voucher import show, save, update, receive_payment, void
|
||||
from .routers.voucher import show, save, update, receive_payment, void, merge_move
|
||||
|
||||
from .db.base_class import Base
|
||||
from .core.config import settings
|
||||
|
@ -74,6 +74,7 @@ app.include_router(save.router, prefix="/api/voucher", tags=["voucher"])
|
|||
app.include_router(update.router, prefix="/api/voucher", tags=["voucher"])
|
||||
app.include_router(receive_payment.router, prefix="/api/voucher", tags=["voucher"])
|
||||
app.include_router(void.router, prefix="/api/voucher", tags=["voucher"])
|
||||
app.include_router(merge_move.router, prefix="/api", tags=["voucher"])
|
||||
|
||||
# app.include_router(issue_grid.router, prefix="/api/issue-grid", tags=["vouchers"])
|
||||
# app.include_router(batch.router, prefix="/api/batch", tags=["vouchers"])
|
||||
|
|
|
@ -1,127 +1,136 @@
|
|||
import uuid
|
||||
|
||||
import transaction
|
||||
from datetime import datetime
|
||||
from pyramid.view import view_config
|
||||
from typing import List
|
||||
|
||||
from fastapi import APIRouter, HTTPException, status, Depends, Security
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from barker.models import Kot, Voucher, Overview
|
||||
from barker.views.voucher import get_bill_id, do_update_table
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="POST",
|
||||
route_name="v1_move_kot",
|
||||
renderer="json",
|
||||
request_param="merge",
|
||||
permission="Merge Kots",
|
||||
trans=True,
|
||||
from ...schemas.auth import UserToken
|
||||
import barker.schemas.merge_move as schemas
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...db.session import SessionLocal
|
||||
from ...models import Voucher, Kot, Overview, Settlement
|
||||
from ...routers.voucher import (
|
||||
do_update_settlements,
|
||||
get_bill_id,
|
||||
do_update_table,
|
||||
)
|
||||
def merge_kot(request):
|
||||
json = request.json_body
|
||||
kot_id = uuid.UUID(json["kot"]["id"])
|
||||
new_voucher_id = uuid.UUID(json["newVoucher"]["id"])
|
||||
|
||||
request.dbsession.query(Kot).filter(Kot.id == kot_id).update({Kot.voucher_id: new_voucher_id})
|
||||
transaction.commit()
|
||||
return True
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="POST",
|
||||
route_name="v1_move_kot",
|
||||
renderer="json",
|
||||
request_param="move",
|
||||
permission="Move Kot to New Table",
|
||||
trans=True,
|
||||
)
|
||||
def move_kot(request):
|
||||
json = request.json_body
|
||||
now = datetime.now()
|
||||
kot_id = uuid.UUID(json["kot"]["id"])
|
||||
table_id = uuid.UUID(json["table"]["id"])
|
||||
|
||||
kot = request.dbsession.query(Kot).filter(Kot.id == kot_id).first()
|
||||
bill_id = get_bill_id(kot.voucher.voucher_type, request.dbsession)
|
||||
kot_id = request.dbsession.query(func.coalesce(func.max(Voucher.kot_id), 0) + 1).scalar()
|
||||
|
||||
item = Voucher(
|
||||
now,
|
||||
kot.voucher.pax,
|
||||
bill_id,
|
||||
kot_id,
|
||||
table_id,
|
||||
kot.voucher.customer_id,
|
||||
kot.voucher.voucher_type,
|
||||
uuid.UUID(request.authenticated_userid),
|
||||
)
|
||||
request.dbsession.add(item)
|
||||
item.kots.append(kot)
|
||||
do_update_table(item, None, request.dbsession)
|
||||
request.dbsession.add(item.status)
|
||||
transaction.commit()
|
||||
return True
|
||||
# Dependency
|
||||
def get_db():
|
||||
try:
|
||||
db = SessionLocal()
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="POST",
|
||||
route_name="v1_move_table",
|
||||
request_param="move",
|
||||
renderer="json",
|
||||
permission="Move Table",
|
||||
trans=True,
|
||||
)
|
||||
def move_table(request):
|
||||
id_ = uuid.UUID(request.json_body["voucher"]["id"])
|
||||
table_id = uuid.UUID(request.json_body["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 == id_).update({Voucher.food_table_id: table_id})
|
||||
|
||||
transaction.commit()
|
||||
return True
|
||||
@router.post("/move-kot/merge")
|
||||
def merge_kot(
|
||||
data: schemas.MergeKot, db: Session = Depends(get_db), user: UserToken = Security(get_user, scopes=["merge-kots"]),
|
||||
):
|
||||
try:
|
||||
db.query(Kot).filter(Kot.id == data.kot_id).update({Kot.voucher_id: data.new_voucher_id})
|
||||
update_vouchers([data.voucher_id, data.new_voucher_id], db)
|
||||
db.commit()
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e),
|
||||
)
|
||||
except Exception:
|
||||
db.rollback()
|
||||
raise
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="POST",
|
||||
route_name="v1_move_table",
|
||||
request_param="merge",
|
||||
renderer="json",
|
||||
permission="Merge Tables",
|
||||
trans=True,
|
||||
)
|
||||
def merge_table(request):
|
||||
json = request.json_body
|
||||
@router.post("/move-kot/move")
|
||||
def move_kot(
|
||||
data: schemas.MoveKot,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["move-kot-to-new-table"]),
|
||||
):
|
||||
try:
|
||||
now = datetime.now()
|
||||
table_id = data.table_id
|
||||
|
||||
id_ = uuid.UUID(json["oldVoucher"]["id"])
|
||||
# table_id = uuid.UUID(json["table"]["id"])
|
||||
new_voucher_id = uuid.UUID(json["newVoucher"]["id"])
|
||||
kot = db.query(Kot).filter(Kot.id == data.kot_id).first()
|
||||
bill_id = get_bill_id(kot.voucher.voucher_type, db)
|
||||
kot_id = db.query(func.coalesce(func.max(Voucher.kot_id), 0) + 1).scalar()
|
||||
|
||||
request.dbsession.query(Kot).filter(Kot.voucher_id == id_).update({Kot.voucher_id: new_voucher_id})
|
||||
request.dbsession.query(Voucher).filter(Voucher.id == id_).delete()
|
||||
transaction.commit()
|
||||
return True
|
||||
item = Voucher(
|
||||
now,
|
||||
kot.voucher.pax,
|
||||
bill_id,
|
||||
kot_id,
|
||||
table_id,
|
||||
kot.voucher.customer_id if kot.voucher.customer is not None else None,
|
||||
kot.voucher.voucher_type,
|
||||
user.id_,
|
||||
)
|
||||
db.add(item)
|
||||
item.kots.append(kot)
|
||||
do_update_table(item, None, db)
|
||||
update_vouchers([data.voucher_id, item.id], db)
|
||||
db.commit()
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e),
|
||||
)
|
||||
except Exception:
|
||||
db.rollback()
|
||||
raise
|
||||
|
||||
# VoucherBI.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && x.VoucherID == _voucher.VoucherID, null, null);
|
||||
# throw new NotImplementedException();
|
||||
# var newTable = _session.QueryOver<FoodTable>().Where(x => x.Name == tableName).SingleOrDefault();
|
||||
# var newVoucher = _session.Get<Voucher>(newTable.VoucherID);
|
||||
# var oldVoucher = _session.Get<Voucher>(voucherID);
|
||||
# for (var i = oldVoucher.Kots.Count - 1; i >= 0; i--)
|
||||
# {
|
||||
# var kot = oldVoucher.Kots[i];
|
||||
# oldVoucher.Kots.Remove(kot);
|
||||
# kot.Voucher = newVoucher;
|
||||
# newVoucher.Kots.Add(kot);
|
||||
# _session.Update(kot);
|
||||
# }
|
||||
# _session.Update(newVoucher);
|
||||
#
|
||||
#
|
||||
# foreach (var item in oldVoucher.Settlements)
|
||||
# {
|
||||
# _session.Delete(item);
|
||||
# }
|
||||
# _session.Delete(oldVoucher);
|
||||
# return newVoucher.VoucherID;
|
||||
|
||||
@router.post("/move-table/move")
|
||||
def move_table(
|
||||
data: schemas.MoveTable, db: Session = Depends(get_db), user: UserToken = Security(get_user, scopes=["move-table"]),
|
||||
):
|
||||
try:
|
||||
db.query(Overview).filter(Overview.voucher_id == data.voucher_id).update(
|
||||
{Overview.food_table_id: data.table_id}
|
||||
)
|
||||
db.query(Voucher).filter(Voucher.id == data.voucher_id).update({Voucher.food_table_id: data.table_id})
|
||||
db.commit()
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e),
|
||||
)
|
||||
except Exception:
|
||||
db.rollback()
|
||||
raise
|
||||
|
||||
|
||||
@router.post("/move-table/merge")
|
||||
def merge_table(
|
||||
data: schemas.MergeTable,
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["merge-tables"]),
|
||||
):
|
||||
try:
|
||||
db.query(Kot).filter(Kot.voucher_id == data.voucher_id).update({Kot.voucher_id: data.new_voucher_id})
|
||||
db.query(Overview).filter(Overview.voucher_id == data.voucher_id).delete()
|
||||
db.query(Settlement).filter(Settlement.voucher_id == data.voucher_id).delete()
|
||||
db.query(Voucher).filter(Voucher.id == data.voucher_id).delete()
|
||||
update_vouchers([data.new_voucher_id], db)
|
||||
db.commit()
|
||||
except SQLAlchemyError as e:
|
||||
db.rollback()
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e),
|
||||
)
|
||||
except Exception:
|
||||
db.rollback()
|
||||
raise
|
||||
|
||||
|
||||
def update_vouchers(vouchers: List[uuid.UUID], db: Session):
|
||||
for v in vouchers:
|
||||
voucher: Voucher = db.query(Voucher).filter(Voucher.id == v).first()
|
||||
do_update_settlements(voucher, [], db)
|
||||
|
|
|
@ -26,7 +26,7 @@ def get_db():
|
|||
def from_id(
|
||||
id_: str, db: Session = Depends(get_db), user: UserToken = Security(get_user),
|
||||
):
|
||||
item = db.query(Voucher).filter(Voucher.id == id_).first()
|
||||
item: Voucher = db.query(Voucher).filter(Voucher.id == id_).first()
|
||||
return voucher_info(item)
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
import uuid
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from barker.schemas import to_camel
|
||||
|
||||
|
||||
class MergeKot(BaseModel):
|
||||
voucher_id: uuid.UUID
|
||||
kot_id: uuid.UUID
|
||||
table_id: uuid.UUID
|
||||
new_voucher_id: uuid.UUID
|
||||
|
||||
class Config:
|
||||
alias_generator = to_camel
|
||||
fields = {"id_": "id"}
|
||||
|
||||
|
||||
class MoveKot(BaseModel):
|
||||
voucher_id: uuid.UUID
|
||||
kot_id: uuid.UUID
|
||||
table_id: uuid.UUID
|
||||
|
||||
class Config:
|
||||
alias_generator = to_camel
|
||||
fields = {"id_": "id"}
|
||||
|
||||
|
||||
class MergeTable(BaseModel):
|
||||
voucher_id: uuid.UUID
|
||||
table_id: uuid.UUID
|
||||
new_voucher_id: uuid.UUID
|
||||
|
||||
class Config:
|
||||
alias_generator = to_camel
|
||||
fields = {"id_": "id"}
|
||||
|
||||
|
||||
class MoveTable(BaseModel):
|
||||
voucher_id: uuid.UUID
|
||||
table_id: uuid.UUID
|
||||
|
||||
class Config:
|
||||
alias_generator = to_camel
|
||||
fields = {"id_": "id"}
|
|
@ -133,7 +133,7 @@ export class BillsComponent implements OnInit {
|
|||
}
|
||||
|
||||
moveKot(kot: Kot) {
|
||||
const canMergeTables = (this.auth.user.perms.indexOf('merge-tables') === -1);
|
||||
const canMergeTables = (this.auth.user.perms.indexOf('merge-tables') !== -1);
|
||||
this.dialog.open(TablesDialogComponent, {
|
||||
// width: '750px',
|
||||
data: {
|
||||
|
|
|
@ -100,45 +100,41 @@ export class VoucherService {
|
|||
}
|
||||
|
||||
moveTable(id: string, table: Table): Observable<boolean> {
|
||||
const options = {params: new HttpParams().set('move', '')};
|
||||
return <Observable<boolean>>this.http.post<boolean>(urlMoveTable, {
|
||||
voucher: {id: id},
|
||||
table: {id: table.id}
|
||||
}, options).pipe(
|
||||
return <Observable<boolean>>this.http.post<boolean>(`${urlMoveTable}/move`, {
|
||||
voucherId: id,
|
||||
tableId: table.id
|
||||
}).pipe(
|
||||
catchError(this.log.handleError(serviceName, 'moveTable'))
|
||||
);
|
||||
}
|
||||
|
||||
mergeTable(id: string, table: Table): Observable<boolean> {
|
||||
const options = {params: new HttpParams().set('merge', '')};
|
||||
return <Observable<boolean>>this.http.post<boolean>(urlMoveTable, {
|
||||
voucher: {id: id},
|
||||
table: {id: table.id},
|
||||
newVoucher: {id: table.voucherId}
|
||||
}, options).pipe(
|
||||
return <Observable<boolean>>this.http.post<boolean>(`${urlMoveTable}/merge`, {
|
||||
voucherId: id,
|
||||
tableId: table.id,
|
||||
newVoucherId: table.voucherId
|
||||
}).pipe(
|
||||
catchError(this.log.handleError(serviceName, 'mergeTable'))
|
||||
);
|
||||
}
|
||||
|
||||
moveKotToNewTable(id: string, kotId: string, table: Table): Observable<boolean> {
|
||||
const options = {params: new HttpParams().set('move', '')};
|
||||
return <Observable<boolean>>this.http.post<boolean>(urlMoveKot, {
|
||||
voucher: {id: id},
|
||||
kot: {id: kotId},
|
||||
table: {id: table.id}
|
||||
}, options).pipe(
|
||||
return <Observable<boolean>>this.http.post<boolean>(`${urlMoveKot}/move`, {
|
||||
voucherId: id,
|
||||
kotId: kotId,
|
||||
tableId: table.id
|
||||
}).pipe(
|
||||
catchError(this.log.handleError(serviceName, 'moveKotToNewTable'))
|
||||
);
|
||||
}
|
||||
|
||||
mergeKotWithOldBill(id: string, kotId: string, table: Table): Observable<boolean> {
|
||||
const options = {params: new HttpParams().set('merge', '')};
|
||||
return <Observable<boolean>>this.http.post<boolean>(urlMoveKot, {
|
||||
voucher: {id: id},
|
||||
kot: {id: kotId},
|
||||
table: {id: table.id},
|
||||
newVoucher: {id: table.voucherId}
|
||||
}, options).pipe(
|
||||
return <Observable<boolean>>this.http.post<boolean>(`${urlMoveKot}/merge`, {
|
||||
voucherId: id,
|
||||
kotId: kotId,
|
||||
tableId: table.id,
|
||||
newVoucherId: table.voucherId
|
||||
}).pipe(
|
||||
catchError(this.log.handleError(serviceName, 'mergeKotWithOldBill'))
|
||||
);
|
||||
}
|
||||
|
|
|
@ -265,7 +265,7 @@ export class SalesHomeComponent implements OnInit {
|
|||
if (!this.moveTableAllowed()) {
|
||||
return;
|
||||
}
|
||||
const canMergeTables = (this.auth.user.perms.indexOf('merge-tables') === -1);
|
||||
const canMergeTables = (this.auth.user.perms.indexOf('merge-tables') !== -1);
|
||||
this.dialog.open(TablesDialogComponent, {
|
||||
// width: '750px',
|
||||
data: {
|
||||
|
|
Loading…
Reference in New Issue