2017-03-14 12:56:57 +00:00
|
|
|
import uuid
|
|
|
|
|
|
|
|
import transaction
|
|
|
|
from pyramid.view import view_config
|
|
|
|
|
2019-06-13 19:02:34 +00:00
|
|
|
from barker.models import Kot, Voucher, Overview
|
2017-03-14 12:56:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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'])
|
|
|
|
|
|
|
|
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)
|
|
|
|
def move_kot(request):
|
|
|
|
json = request.json_body
|
|
|
|
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)
|
|
|
|
request.dbsession.add(item)
|
|
|
|
item.kots.append(kot)
|
|
|
|
status = "printed" if item.is_printed else "running"
|
2019-06-13 19:02:34 +00:00
|
|
|
item.status = Overview(voucher_id=None, food_table_id=item.food_table_id, status=status)
|
2017-03-14 12:56:57 +00:00
|
|
|
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)
|
|
|
|
def move_table(request):
|
|
|
|
json = request.json_body
|
|
|
|
voucher_id = uuid.UUID(json['VoucherID'])
|
|
|
|
food_table_id = uuid.UUID(json['FoodTableID'])
|
|
|
|
|
|
|
|
request.dbsession.query(
|
2019-06-13 19:02:34 +00:00
|
|
|
Overview
|
2017-03-14 12:56:57 +00:00
|
|
|
).filter(
|
2019-06-13 19:02:34 +00:00
|
|
|
Overview.voucher_id == voucher_id
|
|
|
|
).update({Overview.food_table_id: food_table_id})
|
2017-03-14 12:56:57 +00:00
|
|
|
|
|
|
|
request.dbsession.query(
|
|
|
|
Voucher
|
|
|
|
).filter(
|
|
|
|
Voucher.id == voucher_id
|
|
|
|
).update({Voucher.food_table_id: food_table_id})
|
|
|
|
|
|
|
|
transaction.commit()
|
|
|
|
|
|
|
|
|
|
|
|
@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'])
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
# 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;
|