No automatic signout
Voucher basic working running tables shifted to cards from buttons, this gives us immense styling oportunities
This commit is contained in:
52
DB/db.cmd
52
DB/db.cmd
@ -1,28 +1,28 @@
|
|||||||
"\Program Files\PostgreSQL\10\bin\dropdb.exe" -U postgres petty
|
"\Program Files\PostgreSQL\11\bin\dropdb.exe" -U postgres petty
|
||||||
"\Program Files\PostgreSQL\10\bin\createdb.exe" -U postgres petty
|
"\Program Files\PostgreSQL\11\bin\createdb.exe" -U postgres petty
|
||||||
..\env\Scripts\initdb.exe ..\development.ini
|
..\env\Scripts\initdb.exe ..\development.ini
|
||||||
..\env\Scripts\fixtures.exe ..\development.ini
|
..\env\Scripts\fixtures.exe ..\development.ini
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < a-Roles.sql
|
rem "\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < a-Roles.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < b-Permissions.sql
|
rem "\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < b-Permissions.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < c-RolePermissions.sql
|
rem "\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < c-RolePermissions.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < d-Users.sql
|
rem "\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < d-Users.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < e-UserRoles.sql
|
rem "\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < e-UserRoles.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < f-Customers.sql
|
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < f-Customers.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < g-FoodTables.sql
|
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < g-FoodTables.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < h-Taxes.sql
|
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < h-Taxes.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < i-ProductGroups.sql
|
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < i-MenuCategories.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < j-Products.sql
|
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < j-SaleCategories.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < k-Vouchers.sql
|
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < k-Products.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < l-Voucher-Food-Table.sql
|
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < l-Modifiers.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < m-Kots.sql
|
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < m-Sections.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < n-Inventories.sql
|
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < n-Printers.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < o-Modifiers.sql
|
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < o-SectionPrinters.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < p-InventoryModifiers.sql
|
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < p-Vouchers.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < q-Locations.sql
|
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < q-Kots.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < r-MachineLocations.sql
|
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < r-Inventories.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < s-Printers.sql
|
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < s-InventoryModifiers.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < t-PrintLocations.sql
|
"\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < t-Overview.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < u-ProductGroupModifiers.sql
|
REM "\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < u-ProductGroupModifiers.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < v-Reprints.sql
|
REM "\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < v-Reprints.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < w-Settings.sql
|
REM "\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < w-Settings.sql
|
||||||
"\Program Files\PostgreSQL\10\bin\psql.exe" -U postgres petty < x-VoucherSettlements.sql
|
REM "\Program Files\PostgreSQL\11\bin\psql.exe" -U postgres petty < x-VoucherSettlements.sql
|
||||||
@ -4,22 +4,24 @@ call:copyQuery b-Permissions "SELECT 'INSERT INTO permissions(id, name) VALUES (
|
|||||||
call:copyQuery c-RolePermissions "SELECT 'INSERT INTO role_permissions(id, permission_id, role_id) VALUES (''' + CAST(RoleGroupID AS Nvarchar(36)) + ''', ''' + CAST(RoleID AS Nvarchar(36)) + ''', ''' + CAST(GroupID AS Nvarchar(36)) + ''');' FROM Test.dbo.Auth_RoleGroups;"
|
call:copyQuery c-RolePermissions "SELECT 'INSERT INTO role_permissions(id, permission_id, role_id) VALUES (''' + CAST(RoleGroupID AS Nvarchar(36)) + ''', ''' + CAST(RoleID AS Nvarchar(36)) + ''', ''' + CAST(GroupID AS Nvarchar(36)) + ''');' FROM Test.dbo.Auth_RoleGroups;"
|
||||||
call:copyQuery d-Users "SELECT 'INSERT INTO users(id, name, msr_string, password, locked_out) VALUES (''' + CAST(UserID AS Nvarchar(36)) + ''', ''' + Name + ''', ' + COALESCE('''' + MsrString + '''','null') + ', ''' + Password + ''', ' + CASE WHEN LockedOut = 1 THEN 'true' ELSE 'false' END + ');' FROM Test.dbo.Auth_Users;"
|
call:copyQuery d-Users "SELECT 'INSERT INTO users(id, name, msr_string, password, locked_out) VALUES (''' + CAST(UserID AS Nvarchar(36)) + ''', ''' + Name + ''', ' + COALESCE('''' + MsrString + '''','null') + ', ''' + Password + ''', ' + CASE WHEN LockedOut = 1 THEN 'true' ELSE 'false' END + ');' FROM Test.dbo.Auth_Users;"
|
||||||
call:copyQuery e-UserRoles "SELECT 'INSERT INTO user_roles(id, user_id, role_id) VALUES (''' + CAST(UserGroupID AS Nvarchar(36)) + ''', ''' + CAST(UserID AS Nvarchar(36)) + ''', ''' + CAST(GroupID AS Nvarchar(36)) + ''');' FROM Test.dbo.Auth_UserGroups;"
|
call:copyQuery e-UserRoles "SELECT 'INSERT INTO user_roles(id, user_id, role_id) VALUES (''' + CAST(UserGroupID AS Nvarchar(36)) + ''', ''' + CAST(UserID AS Nvarchar(36)) + ''', ''' + CAST(GroupID AS Nvarchar(36)) + ''');' FROM Test.dbo.Auth_UserGroups;"
|
||||||
call:copyQuery f-Customers "SELECT 'INSERT INTO customers(id, name, address, is_important, phone) VALUES (''' + CAST(CustomerID AS Nvarchar(36)) + ''', ''' + REPLACE(Name, '''', '''''') + ''', ''' + COALESCE(Address, 'null') + ''', ' + CASE WHEN Important = 1 THEN 'true' ELSE 'false' END + ', ''' + COALESCE(Phone, 'null') + ''');' FROM Test.dbo.Customers;"
|
|
||||||
call:copyQuery g-FoodTables "SELECT 'INSERT INTO food_tables(id, name, is_active, location, sort_order) VALUES (''' + CAST(FoodTableID AS Nvarchar(36)) + ''', ''' + Name + ''', ' + CASE WHEN IsActive = 1 THEN 'true' ELSE 'false' END + ', ''' + COALESCE(Location, 'null') + ''', ' + CAST(SortOrder AS Nvarchar(36)) + ');' FROM Test.dbo.FoodTables;"
|
call:copyQuery f-Customers "SELECT 'INSERT INTO customers(id, name, address, company, phone) VALUES (''' + CAST(CustomerID AS Nvarchar(36)) + ''', ''' + REPLACE(Name, '''', '''''') + ''', ''' + COALESCE(Address, 'null') + ''', '''', ''' + COALESCE(Phone, Name) + ''');' FROM Test.dbo.Customers WHERE CustomerID != '2c716f4b-0736-429a-ad51-610d7c47cb5e';"
|
||||||
|
call:copyQuery g-FoodTables "SELECT 'INSERT INTO food_tables(id, name, seats, is_active, section_id, sort_order) VALUES (''' + CAST(FoodTableID AS Nvarchar(36)) + ''', ''' + Name + ''', 0, ' + CASE WHEN IsActive = 1 THEN 'true' ELSE 'false' END + ', ''3f13f6e7-dc76-4fca-8fdb-b2bbf29b35df'', ' + CAST(SortOrder AS Nvarchar(36)) + ');' FROM Test.dbo.FoodTables;"
|
||||||
call:copyQuery h-Taxes "SELECT 'INSERT INTO taxes(id, name, rate, is_fixture) VALUES ('''+ CAST(TaxID AS Nvarchar(36)) + ''', ' + '''' + REPLACE(Name, '''', '''''') + '''' + ', ' + CAST(Rate AS Nvarchar(36)) + ', false);' FROM Test.dbo.Taxes;"
|
call:copyQuery h-Taxes "SELECT 'INSERT INTO taxes(id, name, rate, is_fixture) VALUES ('''+ CAST(TaxID AS Nvarchar(36)) + ''', ' + '''' + REPLACE(Name, '''', '''''') + '''' + ', ' + CAST(Rate AS Nvarchar(36)) + ', false);' FROM Test.dbo.Taxes;"
|
||||||
call:copyQuery i-ProductGroups "SELECT 'INSERT INTO menu_categories(id, name, discount_limit, is_active, is_fixture, sort_order) VALUES (''' + CAST(ProductGroupID AS Nvarchar(36)) + ''', ''' + REPLACE(Name, '''', '''''') + ''', ' + CAST(DiscountLimit AS nvarchar(36)) + ', ' + CASE WHEN IsActive = 1 THEN 'true' ELSE 'false' END + ', false, ' + CAST(SortOrder AS Nvarchar(36)) + ');' FROM Test.dbo.ProductGroups;"
|
call:copyQuery i-MenuCategories "SELECT 'INSERT INTO menu_categories(id, name, discount_limit, is_active, is_fixture, sort_order) VALUES (''' + CAST(ProductGroupID AS Nvarchar(36)) + ''', ''' + REPLACE(Name, '''', '''''') + ''', ' + CAST(DiscountLimit AS nvarchar(36)) + ', ' + CASE WHEN IsActive = 1 THEN 'true' ELSE 'false' END + ', false, ' + CAST(SortOrder AS Nvarchar(36)) + ');' FROM Test.dbo.ProductGroups;"
|
||||||
call:copyQuery i-SaleCategories "SELECT 'INSERT INTO sale_categories(id, name, tax_id) VALUES (''' + CAST(newid() AS Nvarchar(36)) + ''', ''' + REPLACE(pgo.GroupType, '''', '''''') + ''', ''' + CAST((select top 1 t.TaxID from Test.dbo.Taxes t inner join Test.dbo.Products p on t.TaxID = p.VatID inner join Test.dbo.ProductGroups pg on p.ProductGroupID = pg.ProductGroupID where pg.GroupType = pgo.GroupType) AS Nvarchar(36)) + ''');' from (select distinct pgx.GroupType from Test.dbo.ProductGroups pgx) as pgo;"
|
call:copyQuery j-SaleCategories "SELECT 'INSERT INTO sale_categories(id, name, tax_id) VALUES (''' + CAST(newid() AS Nvarchar(36)) + ''', ''' + REPLACE(pgo.GroupType, '''', '''''') + ''', ''' + CAST((select top 1 t.TaxID from Test.dbo.Taxes t inner join Test.dbo.Products p on t.TaxID = p.VatID inner join Test.dbo.ProductGroups pg on p.ProductGroupID = pg.ProductGroupID where pg.GroupType = pgo.GroupType) AS Nvarchar(36)) + ''');' from (select distinct pgx.GroupType from Test.dbo.ProductGroups pgx) as pgo;"
|
||||||
call:copyQuery j-Products "SELECT 'INSERT INTO products(id, name, units, menu_category_id, sale_category_id, price, has_happy_hour, is_active, is_not_available, sort_order, quantity) VALUES (''' + CAST(ProductID AS Nvarchar(36)) + ''', ' + '''' + REPLACE(Name, '''', '''''') + '''' + ', ' + '''' + Units + '''' + ', ' + '''' + CAST(ProductGroupID AS Nvarchar(36)) + '''' + ', ' + '(select id from sale_categories where name = ''' + (SELECT GroupType FROM Test.dbo.ProductGroups pgs WHERE pgs.ProductGroupID = Products.ProductGroupID) + ''')' + ', ' + CAST(Price AS Nvarchar(36)) + ', ' + CASE WHEN HasHappyHour = 1 THEN 'true' ELSE 'false' END + ', ' + CASE WHEN IsActive = 1 THEN 'true' ELSE 'false' END + ', ' + CASE WHEN IsNotAvailable = 1 THEN 'true' ELSE 'false' END + ', ' + CAST(SortOrder AS Nvarchar(36)) + ', ' + CAST(Quantity AS Nvarchar(36)) + ');' FROM Test.dbo.Products;"
|
call:copyQuery k-Products "SELECT 'INSERT INTO products(id, name, units, menu_category_id, sale_category_id, price, has_happy_hour, is_active, is_not_available, sort_order, quantity) VALUES (''' + CAST(ProductID AS Nvarchar(36)) + ''', ' + '''' + REPLACE(Name, '''', '''''') + '''' + ', ' + '''' + Units + '''' + ', ' + '''' + CAST(ProductGroupID AS Nvarchar(36)) + '''' + ', ' + '(select id from sale_categories where name = ''' + (SELECT GroupType FROM Test.dbo.ProductGroups pgs WHERE pgs.ProductGroupID = Products.ProductGroupID) + ''')' + ', ' + CAST(Price AS Nvarchar(36)) + ', ' + CASE WHEN HasHappyHour = 1 THEN 'true' ELSE 'false' END + ', ' + CASE WHEN IsActive = 1 THEN 'true' ELSE 'false' END + ', ' + CASE WHEN IsNotAvailable = 1 THEN 'true' ELSE 'false' END + ', ' + CAST(SortOrder AS Nvarchar(36)) + ', ' + CAST(Quantity AS Nvarchar(36)) + ');' FROM Test.dbo.Products;"
|
||||||
call:copyQuery k-Vouchers "SELECT 'INSERT INTO vouchers(id, date, pax, user_id, creation_date, last_edit_date, bill_id, food_table_id, customer_id, narration, is_void, void_reason, is_printed, voucher_type, kot_id) VALUES (''' + CAST(VoucherID AS Nvarchar(36)) + ''', ' + '''' + CONVERT(Nvarchar(36), Date, 126) + ''', ' + COALESCE(CAST(Pax AS Nvarchar(36)), 'null') + ', ' + '''' + CAST(UserID AS Nvarchar(36)) + ''', ' + '''' + CONVERT(Nvarchar(36), CreationDate, 126) + ''', ' + '''' + CONVERT(Nvarchar(36), LastEditDate, 126) + ''', ' + COALESCE(CAST(BillID AS Nvarchar(36)), 'null') + ', ' + '''' + CAST(TableID AS Nvarchar(36)) + ''', ' + '''' + CAST(CustomerID AS Nvarchar(36)) + ''', ' + COALESCE('''' + REPLACE(Narration, '''', '''''') + '''', 'null') + ', ' + CASE WHEN Void = 1 THEN 'true' ELSE 'false' END + ', ' + COALESCE('''' + REPLACE(VoidReason, '''', '''''') + '''', 'null') + ', ' + CASE WHEN Printed = 1 THEN 'true' ELSE 'false' END + ', ' + CAST(VoucherType AS Nvarchar(36)) + ', ' + CAST(KotID AS Nvarchar(36)) + ');' FROM Test.dbo.Vouchers;"
|
call:copyQuery l-Modifiers "SELECT 'INSERT INTO modifiers(id, name, show_in_bill, is_active, modifier_category_id, price) VALUES (''' + CAST(ModifierID AS Nvarchar(36)) + ''', ' + '''' + REPLACE(Name, '''', '''''') + '''' + ', ' + CASE WHEN ShowInBill = 1 THEN 'true' ELSE 'false' END + ', true, {ID}, ' + CAST(Price AS Nvarchar(36)) + ');' FROM Test.dbo.Modifiers;"
|
||||||
call:copyQuery l-Voucher-Food-Table "SELECT 'INSERT INTO voucher_food_table(id, voucher_id, food_table_id, status) VALUES (''' + CAST(newid() AS Nvarchar(36)) + ''', ' + '''' + CAST(VoucherID AS Nvarchar(36)) + ''', ' + '''' + CAST(FoodTableID AS Nvarchar(36)) + ''', ' + '''' + Status + ''');' FROM Test.dbo.FoodTables WHERE VoucherID IS NOT NULL;"
|
call:copyQuery m-Sections "SELECT 'INSERT INTO sections(id, name) VALUES (''' + CAST(NewID() AS Nvarchar(36)) + ''', ''' + Location + ''');' FROM Test.dbo.PrintLocations GROUP BY Location;"
|
||||||
call:copyQuery m-Kots "SELECT 'INSERT INTO kots(id, voucher_id, code, food_table_id, date, user_id) VALUES (''' + CAST(KotID AS Nvarchar(36)) + ''', ' + '''' + CAST(VoucherID AS Nvarchar(36)) + '''' + ', ' + CAST(Code AS Nvarchar(36)) + ', ' + '''' + CAST(TableID AS Nvarchar(36)) + '''' + ', ' + '''' + CONVERT(Nvarchar(36), Date, 126) + ''', ' + '''' + CAST(UserID AS Nvarchar(36)) + '''' + ');' FROM Test.dbo.Kots;"
|
call:copyQuery n-Printers "SELECT 'INSERT INTO printers(id, name, address, cut_code) VALUES (''' + CAST(NewID() AS Nvarchar(36)) + ''', ''' + Printer + ''', ''' + Printer + ''', ''' + CutCode + ''');' FROM Test.dbo.PrintLocations GROUP BY Printer, CutCode;"
|
||||||
call:copyQuery n-Inventories "SELECT 'INSERT INTO inventories(id, kot_id, product_id, sort_order, quantity, price, is_happy_hour, service_charge, is_sc_taxable, service_tax_rate, vat_rate, service_tax_id, vat_id, discount) VALUES (''' + CAST(InventoryID AS Nvarchar(36)) + ''', ' + '''' + CAST(KotID AS Nvarchar(36)) + '''' + ', ' + '''' + CAST(ProductID AS Nvarchar(36)) + '''' + ', ' + CAST(SortOrder AS Nvarchar(36)) + ', ' + CAST(Quantity AS Nvarchar(36)) + ', ' + CAST(Price AS Nvarchar(36)) + ', ' + CASE WHEN IsHappyHour = 1 THEN 'true' ELSE 'false' END + ', ' + CAST(ServiceCharge AS Nvarchar(36)) + ', ' + CASE WHEN IsScTaxable = 1 THEN 'true' ELSE 'false' END + ', ' + CAST(ServiceTaxRate AS Nvarchar(36)) + ', ' + CAST(VatRate AS Nvarchar(36)) + ', ' + '''' + CAST(ServiceTaxID AS Nvarchar(36)) + '''' + ', ' + '''' + CAST(VatID AS Nvarchar(36)) + '''' + ', ' + CAST(Discount AS Nvarchar(36)) + ');' FROM Test.dbo.Inventories;"
|
call:copyQuery o-SectionPrinters "SELECT 'INSERT INTO section_printers(id, menu_category_id, section_id, printer_id, copies) VALUES (''' + CAST(PrintLocationID AS Nvarchar(36)) + ''', ' + COALESCE('''' + CAST(ProductGroupID AS Nvarchar(36)) + '''','null') + ', ' + '(select id from sections where name = ''' + Location + ''')' + ', ' + '(select id from printers where name = ''' + Printer + ''')' + ', ' + CAST(Copies AS nvarchar(36)) + ');' FROM Test.dbo.PrintLocations;"
|
||||||
call:copyQuery o-Modifiers "SELECT 'INSERT INTO modifiers(id, name, show_in_bill, is_active, modifier_category_id, price) VALUES (''' + CAST(ModifierID AS Nvarchar(36)) + ''', ' + '''' + REPLACE(Name, '''', '''''') + '''' + ', ' + CASE WHEN ShowInBill = 1 THEN 'true' ELSE 'false' END + ', true, {ID}, ' + CAST(Price AS Nvarchar(36)) + ');' FROM Test.dbo.Modifiers;"
|
|
||||||
call:copyQuery p-InventoryModifiers "SELECT 'INSERT INTO inventory_modifiers(id, inventory_id, modifier_id, price) VALUES (''' + CAST(InventoryModifierID AS Nvarchar(36)) + ''', ' + '''' + CAST(InventoryID AS Nvarchar(36)) + '''' + ', ' + '''' + CAST(ModifierID AS Nvarchar(36)) + '''' + ', 0);' FROM Test.dbo.InventoryModifiers;"
|
call:copyQuery p-Vouchers "SELECT 'INSERT INTO vouchers(id, date, pax, user_id, creation_date, last_edit_date, bill_id, food_table_id, customer_id, narration, is_void, void_reason, is_printed, voucher_type, kot_id) VALUES (''' + CAST(VoucherID AS Nvarchar(36)) + ''', ' + '''' + CONVERT(Nvarchar(36), Date, 126) + ''', ' + COALESCE(CAST(Pax AS Nvarchar(36)), 'null') + ', (SELECT id from users limit 1), ' + '''' + CONVERT(Nvarchar(36), CreationDate, 126) + ''', ' + '''' + CONVERT(Nvarchar(36), LastEditDate, 126) + ''', ' + COALESCE(CAST(BillID AS Nvarchar(36)), 'null') + ', ' + '''' + CAST(TableID AS Nvarchar(36)) + ''', ' + '''' + CAST(CustomerID AS Nvarchar(36)) + ''', ' + COALESCE('''' + REPLACE(Narration, '''', '''''') + '''', 'null') + ', ' + CASE WHEN Void = 1 THEN 'true' ELSE 'false' END + ', ' + COALESCE('''' + REPLACE(VoidReason, '''', '''''') + '''', 'null') + ', ' + CASE WHEN Printed = 1 THEN 'true' ELSE 'false' END + ', ' + CAST(VoucherType AS Nvarchar(36)) + ', ' + CAST(KotID AS Nvarchar(36)) + ');' FROM Test.dbo.Vouchers;"
|
||||||
call:copyQuery q-Sections "SELECT 'INSERT INTO sections(id, name) VALUES (''' + CAST(NewID() AS Nvarchar(36)) + ''', ''' + Location + ''');' FROM Test.dbo.PrintLocations GROUP BY Location;"
|
call:copyQuery q-Kots "SELECT 'INSERT INTO kots(id, voucher_id, code, food_table_id, date, user_id) VALUES (''' + CAST(KotID AS Nvarchar(36)) + ''', ' + '''' + CAST(VoucherID AS Nvarchar(36)) + '''' + ', ' + CAST(Code AS Nvarchar(36)) + ', ' + '''' + CAST(TableID AS Nvarchar(36)) + '''' + ', ' + '''' + CONVERT(Nvarchar(36), Date, 126) + ''', (SELECT id from users limit 1));' FROM Test.dbo.Kots;"
|
||||||
call:copyQuery r-MachineLocations "SELECT 'INSERT INTO machine_locations(id, machine_name, location_id) SELECT ''' + CAST(MachineLocationID AS Nvarchar(36)) + ''', ' + '''' + REPLACE(Machine, '''', '''''') + '''' + ', id from locations where name = ' + '''' + REPLACE(Location, '''', '''''') + '''' + ';' FROM Test.dbo.MachineLocations;"
|
call:copyQuery r-Inventories "SELECT 'INSERT INTO inventories(id, kot_id, product_id, sort_order, quantity, price, is_happy_hour, tax_rate, tax_id, discount) VALUES (''' + CAST(InventoryID AS Nvarchar(36)) + ''', ' + '''' + CAST(KotID AS Nvarchar(36)) + '''' + ', ' + '''' + CAST(ProductID AS Nvarchar(36)) + '''' + ', ' + CAST(SortOrder AS Nvarchar(36)) + ', ' + CAST(Quantity AS Nvarchar(36)) + ', ' + CAST(Price AS Nvarchar(36)) + ', ' + CASE WHEN IsHappyHour = 1 THEN 'true' ELSE 'false' END + ', ' + CAST(VatRate AS Nvarchar(36)) + ', ' + '''' + CAST(VatID AS Nvarchar(36)) + '''' + ', ' + CAST(Discount AS Nvarchar(36)) + ');' FROM Test.dbo.Inventories;"
|
||||||
call:copyQuery s-Printers "SELECT 'INSERT INTO printers(id, name, address, cut_code) VALUES (''' + CAST(NewID() AS Nvarchar(36)) + ''', ''' + Printer + ''', ''' + ''' + Printer + ''', ''' + CutCode + ''');' FROM Test.dbo.PrintLocations GROUP BY Printer, CutCode;"
|
call:copyQuery s-InventoryModifiers "SELECT 'INSERT INTO inventory_modifiers(id, inventory_id, modifier_id, price) VALUES (''' + CAST(InventoryModifierID AS Nvarchar(36)) + ''', ' + '''' + CAST(InventoryID AS Nvarchar(36)) + '''' + ', ' + '''' + CAST(ModifierID AS Nvarchar(36)) + '''' + ', 0);' FROM Test.dbo.InventoryModifiers;"
|
||||||
call:copyQuery t-SectionPrinters "SELECT 'INSERT INTO section_printers(id, menu_category_id, section_id, printer_id, copies) VALUES (''' + CAST(PrintLocationID AS Nvarchar(36)) + ''', ' + COALESCE('''' + CAST(ProductGroupID AS Nvarchar(36)) + '''','null') + ', ' + '(select id from sections where name = ''' + Location + ''')' + ', ' + '(select id from printers where name = ''' + Printer + ''')' + ', ' + CAST(Copies AS nvarchar(36)) + ');' FROM Test.dbo.PrintLocations;"
|
call:copyQuery t-Overview "SELECT 'INSERT INTO overview(id, voucher_id, food_table_id, status) VALUES (''' + CAST(newid() AS Nvarchar(36)) + ''', ' + '''' + CAST(VoucherID AS Nvarchar(36)) + ''', ' + '''' + CAST(FoodTableID AS Nvarchar(36)) + ''', ' + '''' + Status + ''');' FROM Test.dbo.FoodTables WHERE VoucherID IS NOT NULL;"
|
||||||
|
|
||||||
call:copyQuery u-ProductGroupModifiers "SELECT 'INSERT INTO product_group_modifiers(id, product_group_id, modifier_id, show_automatically) VALUES (''' + CAST(ProductGroupModifierID AS Nvarchar(36)) + ''', ' + COALESCE('''' + CAST(ProductGroupID AS Nvarchar(36)) + '''','null') + ', ' + COALESCE('''' + CAST(ModifierID AS Nvarchar(36)) + '''','null') + ', ' + CASE WHEN ShowAutomatically = 1 THEN 'true' ELSE 'false' END + ');' FROM Test.dbo.ProductGroupModifiers;"
|
call:copyQuery u-ProductGroupModifiers "SELECT 'INSERT INTO product_group_modifiers(id, product_group_id, modifier_id, show_automatically) VALUES (''' + CAST(ProductGroupModifierID AS Nvarchar(36)) + ''', ' + COALESCE('''' + CAST(ProductGroupID AS Nvarchar(36)) + '''','null') + ', ' + COALESCE('''' + CAST(ModifierID AS Nvarchar(36)) + '''','null') + ', ' + CASE WHEN ShowAutomatically = 1 THEN 'true' ELSE 'false' END + ');' FROM Test.dbo.ProductGroupModifiers;"
|
||||||
call:copyQuery v-Reprints "SELECT 'INSERT INTO reprints(id, user_id, date, voucher_id) VALUES (''' + CAST(ReprintID AS Nvarchar(36)) + ''', ' + '''' + CAST(UserID AS Nvarchar(36)) + '''' + ', ' + '''' + CONVERT(Nvarchar(36), Date, 126) + '''' + ', ' + '''' + CAST(VoucherID AS Nvarchar(36)) + '''' + ');' FROM Test.dbo.Reprints;"
|
call:copyQuery v-Reprints "SELECT 'INSERT INTO reprints(id, user_id, date, voucher_id) VALUES (''' + CAST(ReprintID AS Nvarchar(36)) + ''', ' + '''' + CAST(UserID AS Nvarchar(36)) + '''' + ', ' + '''' + CONVERT(Nvarchar(36), Date, 126) + '''' + ', ' + '''' + CAST(VoucherID AS Nvarchar(36)) + '''' + ');' FROM Test.dbo.Reprints;"
|
||||||
call:copyQuery w-Settings "SELECT 'INSERT INTO public.settings(id, name, data) VALUES (''' + CAST(SettingID AS Nvarchar(36)) + ''', ' + '''' + REPLACE(Name, '''', '''''') + '''' + ', ' + '''' + REPLACE(Details, '''', '''''') + '''' + ');' FROM Test.dbo.Settings;"
|
call:copyQuery w-Settings "SELECT 'INSERT INTO public.settings(id, name, data) VALUES (''' + CAST(SettingID AS Nvarchar(36)) + ''', ' + '''' + REPLACE(Name, '''', '''''') + '''' + ', ' + '''' + REPLACE(Details, '''', '''''') + '''' + ');' FROM Test.dbo.Settings;"
|
||||||
@ -30,5 +32,5 @@ goto:eof
|
|||||||
:copyQuery - here starts my function identified by it's label
|
:copyQuery - here starts my function identified by it's label
|
||||||
echo.
|
echo.
|
||||||
echo. Copying %~1
|
echo. Copying %~1
|
||||||
bcp "%~2" queryout Data\%~1.sql -c -t',' -S sovereign -U sa -P 123456
|
bcp "%~2" queryout Data\%~1.sql -c -t',' -S . -U sa -P 123456
|
||||||
goto:eof
|
goto:eof
|
||||||
@ -19,7 +19,7 @@ def main(global_config, **settings):
|
|||||||
settings['sqlalchemy.url'] = DB_URI
|
settings['sqlalchemy.url'] = DB_URI
|
||||||
|
|
||||||
SECRET_KEY = os.environ.get('SECRET_KEY', settings.get('secret_key', ''))
|
SECRET_KEY = os.environ.get('SECRET_KEY', settings.get('secret_key', ''))
|
||||||
session_factory = SignedCookieSessionFactory(SECRET_KEY)
|
session_factory = SignedCookieSessionFactory(SECRET_KEY, timeout=None)
|
||||||
|
|
||||||
config = Configurator(
|
config = Configurator(
|
||||||
settings=settings,
|
settings=settings,
|
||||||
|
|||||||
@ -347,6 +347,9 @@ def includeme(config):
|
|||||||
permission="Authenticated",
|
permission="Authenticated",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
config.add_route("v1_vouchers_new", "/v1/vouchers/new")
|
||||||
|
config.add_route("v1_vouchers_id", "/v1/vouchers/{id}")
|
||||||
|
|
||||||
# Done till here
|
# Done till here
|
||||||
|
|
||||||
config.add_route("customer", "/Customer.json")
|
config.add_route("customer", "/Customer.json")
|
||||||
@ -390,8 +393,6 @@ def includeme(config):
|
|||||||
config.add_route("sa_st", "/SaleAnalysis/ServiceTax.json")
|
config.add_route("sa_st", "/SaleAnalysis/ServiceTax.json")
|
||||||
config.add_route("sa_vat", "/SaleAnalysis/Vat.json")
|
config.add_route("sa_vat", "/SaleAnalysis/Vat.json")
|
||||||
|
|
||||||
config.add_route("voucher", "/Voucher.json")
|
|
||||||
config.add_route("voucher_id", "/Voucher/{id}.json")
|
|
||||||
config.add_route("voucher_reprint", "/ReprintVoucher/{id}.json")
|
config.add_route("voucher_reprint", "/ReprintVoucher/{id}.json")
|
||||||
config.add_route("voucher_settle", "/Settle/{id}.json")
|
config.add_route("voucher_settle", "/Settle/{id}.json")
|
||||||
config.add_route("voucher_split", "/Split/{id}.json")
|
config.add_route("voucher_split", "/Split/{id}.json")
|
||||||
|
|||||||
@ -3,10 +3,7 @@ import sys
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import transaction
|
import transaction
|
||||||
from pyramid.paster import (
|
from pyramid.paster import get_appsettings, setup_logging
|
||||||
get_appsettings,
|
|
||||||
setup_logging,
|
|
||||||
)
|
|
||||||
from pyramid.scripts.common import parse_vars
|
from pyramid.scripts.common import parse_vars
|
||||||
|
|
||||||
from barker.models import (
|
from barker.models import (
|
||||||
@ -19,13 +16,18 @@ from barker.models import (
|
|||||||
get_session_factory,
|
get_session_factory,
|
||||||
get_tm_session,
|
get_tm_session,
|
||||||
SettleOption,
|
SettleOption,
|
||||||
Role, Section, ModifierCategory)
|
Role,
|
||||||
|
Section,
|
||||||
|
ModifierCategory,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def usage(argv):
|
def usage(argv):
|
||||||
cmd = os.path.basename(argv[0])
|
cmd = os.path.basename(argv[0])
|
||||||
print('usage: %s <config_uri> [var=value]\n'
|
print(
|
||||||
'(example: "%s development.ini")' % (cmd, cmd))
|
"usage: %s <config_uri> [var=value]\n"
|
||||||
|
'(example: "%s development.ini")' % (cmd, cmd)
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@ -43,64 +45,108 @@ def main(argv=sys.argv):
|
|||||||
with transaction.manager:
|
with transaction.manager:
|
||||||
dbsession = get_tm_session(session_factory, transaction.manager)
|
dbsession = get_tm_session(session_factory, transaction.manager)
|
||||||
|
|
||||||
permissions = [Permission('Accounts Audit', uuid.UUID('f30fd1fb-df09-46f5-8c5d-181fd46f38de')),
|
permissions = [
|
||||||
Permission('Beer Consumption', uuid.UUID('efbb8f31-9631-4491-92f4-17cc98e6a0c0')),
|
Permission(
|
||||||
Permission('Bill Details', uuid.UUID('612bb529-b50d-4653-a1c0-ebb725c7d728')),
|
"Accounts Audit", uuid.UUID("f30fd1fb-df09-46f5-8c5d-181fd46f38de")
|
||||||
Permission('Cashier Checkout', uuid.UUID('a86f8bcf-66f4-4c44-89e1-b714488b8331')),
|
),
|
||||||
Permission('Change Rate', uuid.UUID('10c63aae-0e48-4e54-b3b8-dd8a80b88fbf')),
|
Permission(
|
||||||
Permission('Customers', uuid.UUID('e5fef133-cdbe-441f-bb54-1f0db0c5db79')),
|
"Beer Consumption", uuid.UUID("efbb8f31-9631-4491-92f4-17cc98e6a0c0")
|
||||||
Permission('Discount', uuid.UUID('1f66f131-0105-4466-8f8e-21e0ccc2ac27')),
|
),
|
||||||
Permission('Discount Report', uuid.UUID('0d8ba1d5-6731-417c-ab0e-be03cfdc96db')),
|
Permission(
|
||||||
Permission('Edit Printed Bill', uuid.UUID('4ff6cb0f-93cb-4760-8219-4de280eaa957')),
|
"Bill Details", uuid.UUID("612bb529-b50d-4653-a1c0-ebb725c7d728")
|
||||||
Permission('Edit Printed Product', uuid.UUID('959713be-d753-4e14-8ecd-e27f33587499')),
|
),
|
||||||
Permission('Guest Book', uuid.UUID('7669dfc9-cc75-4e48-b267-145c8832a83c')),
|
Permission(
|
||||||
Permission('Machines', uuid.UUID('f12b573f-edcb-490d-91c3-fa76f6502ffd')),
|
"Cashier Checkout", uuid.UUID("a86f8bcf-66f4-4c44-89e1-b714488b8331")
|
||||||
Permission('Merge Kots', uuid.UUID('bed774e9-4857-43b0-a4af-40230c9eb5db')),
|
),
|
||||||
Permission('Merge Tables', uuid.UUID('dfc493fb-ac14-4602-8596-f93f47b617de')),
|
Permission(
|
||||||
Permission('Modifiers', uuid.UUID('9dc82529-1e86-41b4-a152-eaea9f775fea')),
|
"Change Rate", uuid.UUID("10c63aae-0e48-4e54-b3b8-dd8a80b88fbf")
|
||||||
Permission('Move Kot to New Table', uuid.UUID('5ed5796a-ca99-437f-8f67-483b1ade81ed')),
|
),
|
||||||
Permission('Move Table', uuid.UUID('cfdb69c9-d37a-40af-bef2-e29c04602543')),
|
Permission("Customers", uuid.UUID("e5fef133-cdbe-441f-bb54-1f0db0c5db79")),
|
||||||
Permission('NC Product', uuid.UUID('54263587-773e-4cbb-b1e4-4e814141158e')),
|
Permission("Discount", uuid.UUID("1f66f131-0105-4466-8f8e-21e0ccc2ac27")),
|
||||||
Permission('Open Bill', uuid.UUID('5811d233-a1ae-4d32-af52-cebbf46d274a')),
|
Permission(
|
||||||
Permission('Owner', uuid.UUID('6d109b66-8452-42aa-bbe9-d4cef440b7a1')),
|
"Discount Report", uuid.UUID("0d8ba1d5-6731-417c-ab0e-be03cfdc96db")
|
||||||
Permission('Print Bill', uuid.UUID('92242eae-bd38-4223-829b-2f981933b7f2')),
|
),
|
||||||
Permission('Print Kot', uuid.UUID('0eef56fb-7741-49fd-8b84-5069cccae767')),
|
Permission(
|
||||||
Permission('Products', uuid.UUID('f1f892ed-34aa-4c50-be12-dbaf48be7d4c')),
|
"Edit Printed Bill", uuid.UUID("4ff6cb0f-93cb-4760-8219-4de280eaa957")
|
||||||
Permission('Roles', uuid.UUID('d39f86f6-14e4-4fc3-b07e-01e2501a6f65')),
|
),
|
||||||
Permission('Sales', uuid.UUID('92ba45c4-2d34-4cbd-b5b8-d9164c3595d5')),
|
Permission(
|
||||||
Permission('Sales Analysis', uuid.UUID('0c1acb7c-9116-46e2-a3be-9d632e811330')),
|
"Edit Printed Product",
|
||||||
Permission('Sales Detail', uuid.UUID('e6476396-ef83-4c47-bc20-9f3b936813f9')),
|
uuid.UUID("959713be-d753-4e14-8ecd-e27f33587499"),
|
||||||
Permission('Settle Bill', uuid.UUID('9f7b658a-25bc-4a53-8560-2dde1c7a188a')),
|
),
|
||||||
Permission('Split Bill', uuid.UUID('0a8cfaf4-624e-478f-be65-c3b6392078c7')),
|
Permission("Guest Book", uuid.UUID("7669dfc9-cc75-4e48-b267-145c8832a83c")),
|
||||||
Permission('Tables', uuid.UUID('ac4512e8-efdd-429e-a7ae-a34d18782663')),
|
Permission("Machines", uuid.UUID("f12b573f-edcb-490d-91c3-fa76f6502ffd")),
|
||||||
Permission('Tax Analysis', uuid.UUID('bab36396-53dd-44ea-ab3c-426efa7830c8')),
|
Permission("Merge Kots", uuid.UUID("bed774e9-4857-43b0-a4af-40230c9eb5db")),
|
||||||
Permission('Taxes', uuid.UUID('5c8fcdde-460d-4047-810f-e34fb899fadc')),
|
Permission(
|
||||||
Permission('Users', uuid.UUID('243447b8-b403-47e6-8b3d-8e76f4df44a9')),
|
"Merge Tables", uuid.UUID("dfc493fb-ac14-4602-8596-f93f47b617de")
|
||||||
Permission('Void Bill', uuid.UUID('e3c76262-adc0-4936-8b4d-217c6292298b')),
|
),
|
||||||
Permission('Void or Reprinted Bill Report', uuid.UUID('30c8e743-c710-42d7-843a-0b75543b3516')),
|
Permission("Modifiers", uuid.UUID("9dc82529-1e86-41b4-a152-eaea9f775fea")),
|
||||||
Permission('Printers', uuid.UUID('5b66c6f6-003a-4ef8-ba28-49b8ff1ac33c')),
|
Permission(
|
||||||
Permission('Sections', uuid.UUID('c973f32c-a37b-496a-8dc5-60d2e4c39e97'))]
|
"Move Kot to New Table",
|
||||||
|
uuid.UUID("5ed5796a-ca99-437f-8f67-483b1ade81ed"),
|
||||||
|
),
|
||||||
|
Permission("Move Table", uuid.UUID("cfdb69c9-d37a-40af-bef2-e29c04602543")),
|
||||||
|
Permission("NC Product", uuid.UUID("54263587-773e-4cbb-b1e4-4e814141158e")),
|
||||||
|
Permission("Open Bill", uuid.UUID("5811d233-a1ae-4d32-af52-cebbf46d274a")),
|
||||||
|
Permission("Owner", uuid.UUID("6d109b66-8452-42aa-bbe9-d4cef440b7a1")),
|
||||||
|
Permission("Print Bill", uuid.UUID("92242eae-bd38-4223-829b-2f981933b7f2")),
|
||||||
|
Permission("Print Kot", uuid.UUID("0eef56fb-7741-49fd-8b84-5069cccae767")),
|
||||||
|
Permission("Products", uuid.UUID("f1f892ed-34aa-4c50-be12-dbaf48be7d4c")),
|
||||||
|
Permission("Roles", uuid.UUID("d39f86f6-14e4-4fc3-b07e-01e2501a6f65")),
|
||||||
|
Permission("Sales", uuid.UUID("92ba45c4-2d34-4cbd-b5b8-d9164c3595d5")),
|
||||||
|
Permission(
|
||||||
|
"Sales Analysis", uuid.UUID("0c1acb7c-9116-46e2-a3be-9d632e811330")
|
||||||
|
),
|
||||||
|
Permission(
|
||||||
|
"Sales Detail", uuid.UUID("e6476396-ef83-4c47-bc20-9f3b936813f9")
|
||||||
|
),
|
||||||
|
Permission(
|
||||||
|
"Settle Bill", uuid.UUID("9f7b658a-25bc-4a53-8560-2dde1c7a188a")
|
||||||
|
),
|
||||||
|
Permission("Split Bill", uuid.UUID("0a8cfaf4-624e-478f-be65-c3b6392078c7")),
|
||||||
|
Permission("Tables", uuid.UUID("ac4512e8-efdd-429e-a7ae-a34d18782663")),
|
||||||
|
Permission(
|
||||||
|
"Tax Analysis", uuid.UUID("bab36396-53dd-44ea-ab3c-426efa7830c8")
|
||||||
|
),
|
||||||
|
Permission("Taxes", uuid.UUID("5c8fcdde-460d-4047-810f-e34fb899fadc")),
|
||||||
|
Permission("Users", uuid.UUID("243447b8-b403-47e6-8b3d-8e76f4df44a9")),
|
||||||
|
Permission("Void Bill", uuid.UUID("e3c76262-adc0-4936-8b4d-217c6292298b")),
|
||||||
|
Permission(
|
||||||
|
"Void or Reprinted Bill Report",
|
||||||
|
uuid.UUID("30c8e743-c710-42d7-843a-0b75543b3516"),
|
||||||
|
),
|
||||||
|
Permission("Printers", uuid.UUID("5b66c6f6-003a-4ef8-ba28-49b8ff1ac33c")),
|
||||||
|
Permission("Sections", uuid.UUID("c973f32c-a37b-496a-8dc5-60d2e4c39e97")),
|
||||||
|
]
|
||||||
|
|
||||||
for permission in permissions:
|
for permission in permissions:
|
||||||
dbsession.add(permission)
|
dbsession.add(permission)
|
||||||
|
|
||||||
roles = [Role('Owner', uuid.UUID('06ec0ddb-949c-4357-aefb-65e5e55a9ae7')),
|
roles = [
|
||||||
Role('Accountant', uuid.UUID('57d4538c-257a-4bf4-9a42-342992cb6af3')),
|
Role("Owner", uuid.UUID("06ec0ddb-949c-4357-aefb-65e5e55a9ae7")),
|
||||||
Role('Bar Captain', uuid.UUID('5a8ebb05-4817-45a5-866f-e523c30bfa25')),
|
Role("Accountant", uuid.UUID("57d4538c-257a-4bf4-9a42-342992cb6af3")),
|
||||||
Role('Captain', uuid.UUID('8db7001f-0964-4607-84f5-b6f4d9183fef')),
|
Role("Bar Captain", uuid.UUID("5a8ebb05-4817-45a5-866f-e523c30bfa25")),
|
||||||
Role('Cashier', uuid.UUID('f1f0b112-1404-4b55-b121-f07ee6e08d12')),
|
Role("Captain", uuid.UUID("8db7001f-0964-4607-84f5-b6f4d9183fef")),
|
||||||
Role('Controller', uuid.UUID('d9a5a478-1fe4-4847-84da-63cfba1a094a')),
|
Role("Cashier", uuid.UUID("f1f0b112-1404-4b55-b121-f07ee6e08d12")),
|
||||||
Role('Manager', uuid.UUID('90ea7b14-9057-4bfd-a7cf-0ee7a3bb2463')),
|
Role("Controller", uuid.UUID("d9a5a478-1fe4-4847-84da-63cfba1a094a")),
|
||||||
Role('Senior Captain', uuid.UUID('d9b1b433-1ed5-4109-8ab2-cbd48ff010cd')),
|
Role("Manager", uuid.UUID("90ea7b14-9057-4bfd-a7cf-0ee7a3bb2463")),
|
||||||
Role('Server', uuid.UUID('6b378b71-f091-4485-a589-8db94ff1d6a4'))]
|
Role("Senior Captain", uuid.UUID("d9b1b433-1ed5-4109-8ab2-cbd48ff010cd")),
|
||||||
|
Role("Server", uuid.UUID("6b378b71-f091-4485-a589-8db94ff1d6a4")),
|
||||||
|
]
|
||||||
|
|
||||||
roles[0].permissions = permissions
|
roles[0].permissions = permissions
|
||||||
roles[1].permissions = list(permissions[i] for i in [2, 3, 11, 18, 24, 25, 26, 30, 34])
|
roles[1].permissions = list(
|
||||||
|
permissions[i] for i in [2, 3, 11, 18, 24, 25, 26, 30, 34]
|
||||||
|
)
|
||||||
roles[2].permissions = list(permissions[i] for i in [26])
|
roles[2].permissions = list(permissions[i] for i in [26])
|
||||||
roles[3].permissions = list(permissions[i] for i in [16])
|
roles[3].permissions = list(permissions[i] for i in [16])
|
||||||
roles[4].permissions = list(permissions[i] for i in [20, 24, 27])
|
roles[4].permissions = list(permissions[i] for i in [20, 24, 27])
|
||||||
roles[5].permissions = list(permissions[i] for i in [0, 2, 7, 11, 18, 22, 24, 25, 26, 34])
|
roles[5].permissions = list(
|
||||||
roles[6].permissions = list(permissions[i] for i in [2, 3, 4, 5, 6, 8, 11, 14, 18, 22, 25, 26, 28, 29, 33, 34])
|
permissions[i] for i in [0, 2, 7, 11, 18, 22, 24, 25, 26, 34]
|
||||||
|
)
|
||||||
|
roles[6].permissions = list(
|
||||||
|
permissions[i]
|
||||||
|
for i in [2, 3, 4, 5, 6, 8, 11, 14, 18, 22, 25, 26, 28, 29, 33, 34]
|
||||||
|
)
|
||||||
roles[7].permissions = list(permissions[i] for i in [9, 12, 13, 15, 16])
|
roles[7].permissions = list(permissions[i] for i in [9, 12, 13, 15, 16])
|
||||||
roles[8].permissions = list(permissions[i] for i in [21, 24])
|
roles[8].permissions = list(permissions[i] for i in [21, 24])
|
||||||
|
|
||||||
@ -111,40 +157,80 @@ def main(argv=sys.argv):
|
|||||||
admin.roles.append(roles[0])
|
admin.roles.append(roles[0])
|
||||||
dbsession.add(admin)
|
dbsession.add(admin)
|
||||||
|
|
||||||
main_section = Section("Main")
|
main_section = Section(
|
||||||
|
"Main", uuid.UUID("3f13f6e7-dc76-4fca-8fdb-b2bbf29b35df")
|
||||||
|
)
|
||||||
dbsession.add(main_section)
|
dbsession.add(main_section)
|
||||||
mcs = [ModifierCategory("Bar Instructions", 0, 0, True, 0, uuid.UUID("b572f401-3c2f-48b9-8973-ada5a6e4d3a6")),
|
mcs = [
|
||||||
ModifierCategory("Delivery", 0, 0, True, 0, uuid.UUID("caa72832-5034-405e-8442-68a8cc12ace9")),
|
ModifierCategory(
|
||||||
ModifierCategory("Kitchen Instructions", 0, 0, True, 0, uuid.UUID("d6a0595f-e209-42e4-bb12-b7499f9a9c4d")),
|
"Bar Instructions",
|
||||||
ModifierCategory("Mixers", 0, 0, True, 0, uuid.UUID("60ca9122-adc5-463b-ad5f-33a68df8c3ae")),
|
0,
|
||||||
ModifierCategory("Pasta Sauce", 0, 0, True, 0, uuid.UUID("ef5b1a0b-5eb1-45ff-bd82-3209c8b888df"))]
|
0,
|
||||||
|
True,
|
||||||
|
0,
|
||||||
|
uuid.UUID("b572f401-3c2f-48b9-8973-ada5a6e4d3a6"),
|
||||||
|
),
|
||||||
|
ModifierCategory(
|
||||||
|
"Delivery",
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
True,
|
||||||
|
0,
|
||||||
|
uuid.UUID("caa72832-5034-405e-8442-68a8cc12ace9"),
|
||||||
|
),
|
||||||
|
ModifierCategory(
|
||||||
|
"Kitchen Instructions",
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
True,
|
||||||
|
0,
|
||||||
|
uuid.UUID("d6a0595f-e209-42e4-bb12-b7499f9a9c4d"),
|
||||||
|
),
|
||||||
|
ModifierCategory(
|
||||||
|
"Mixers",
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
True,
|
||||||
|
0,
|
||||||
|
uuid.UUID("60ca9122-adc5-463b-ad5f-33a68df8c3ae"),
|
||||||
|
),
|
||||||
|
ModifierCategory(
|
||||||
|
"Pasta Sauce",
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
True,
|
||||||
|
0,
|
||||||
|
uuid.UUID("ef5b1a0b-5eb1-45ff-bd82-3209c8b888df"),
|
||||||
|
),
|
||||||
|
]
|
||||||
for item in mcs:
|
for item in mcs:
|
||||||
dbsession.add(item)
|
dbsession.add(item)
|
||||||
|
|
||||||
for name in range(1, 20):
|
|
||||||
ft = FoodTable(str(name), 0, main_section.id, True)
|
|
||||||
ft.section = main_section
|
|
||||||
dbsession.add(ft)
|
|
||||||
|
|
||||||
options = [
|
options = [
|
||||||
SettleOption('Unsettled', False, 1, True, 1),
|
SettleOption("Unsettled", False, 1, True, 1),
|
||||||
SettleOption('Cash', True, 2, False, 2),
|
SettleOption("Cash", True, 2, False, 2),
|
||||||
SettleOption('Credit Card', True, 2, True, 3),
|
SettleOption("Credit Card", True, 2, True, 3),
|
||||||
SettleOption('No Charge', True, 3, True, 4),
|
SettleOption("No Charge", True, 3, True, 4),
|
||||||
SettleOption('Bill To Company', True, 2, True, 5),
|
SettleOption("Bill To Company", True, 2, True, 5),
|
||||||
SettleOption('Tip', True, 2, True, 6),
|
SettleOption("Tip", True, 2, True, 6),
|
||||||
SettleOption('Round Off', False, 1, False, 7),
|
SettleOption("Round Off", False, 1, False, 7),
|
||||||
SettleOption('Amount', False, 1, False, 8),
|
SettleOption("Amount", False, 1, False, 8),
|
||||||
SettleOption('Void', True, 1, True, 9),
|
SettleOption("Void", True, 1, True, 9),
|
||||||
SettleOption('Staff', True, 4, True, 10),
|
SettleOption("Staff", True, 4, True, 10),
|
||||||
]
|
]
|
||||||
for option in options:
|
for option in options:
|
||||||
dbsession.add(option)
|
dbsession.add(option)
|
||||||
dbsession.add(Customer("", "Cash", "", "", uuid.UUID('2c716f4b-0736-429a-ad51-610d7c47cb5e')))
|
dbsession.add(
|
||||||
dbsession.add(DbSetting(
|
Customer(
|
||||||
uuid.UUID('fb738ba2-a3c9-40ed-891c-b930e6454974'),
|
"", "Cash", "", "", uuid.UUID("2c716f4b-0736-429a-ad51-610d7c47cb5e")
|
||||||
'Header',
|
)
|
||||||
{'Text': """ Hops n Grains
|
)
|
||||||
|
dbsession.add(
|
||||||
|
DbSetting(
|
||||||
|
uuid.UUID("fb738ba2-a3c9-40ed-891c-b930e6454974"),
|
||||||
|
"Header",
|
||||||
|
{
|
||||||
|
"Text": """ Hops n Grains
|
||||||
The Microbrewery
|
The Microbrewery
|
||||||
SCO 358, Sector 9, Panchkula
|
SCO 358, Sector 9, Panchkula
|
||||||
A Unit of Peitho Foods Pvt. Ltd.
|
A Unit of Peitho Foods Pvt. Ltd.
|
||||||
@ -152,10 +238,14 @@ def main(argv=sys.argv):
|
|||||||
(Reg Add: Plot No. 907, Indl Area II, Chd)
|
(Reg Add: Plot No. 907, Indl Area II, Chd)
|
||||||
TIN: 06592507323
|
TIN: 06592507323
|
||||||
Service Tax: AAFCP5097GSD001
|
Service Tax: AAFCP5097GSD001
|
||||||
"""}
|
"""
|
||||||
))
|
},
|
||||||
dbsession.add(DbSetting(
|
)
|
||||||
uuid.UUID('f7799871-d16e-4c4d-9b57-2299a5839acb'),
|
)
|
||||||
'Footer',
|
dbsession.add(
|
||||||
{'Text': "Call: 0172-4026666, 8054923853, 8054923856"}
|
DbSetting(
|
||||||
))
|
uuid.UUID("f7799871-d16e-4c4d-9b57-2299a5839acb"),
|
||||||
|
"Footer",
|
||||||
|
{"Text": "Call: 0172-4026666, 8054923853, 8054923856"},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|||||||
@ -9,15 +9,15 @@ class PermissionAuthorizationPolicy(object):
|
|||||||
if isinstance(permission, str):
|
if isinstance(permission, str):
|
||||||
return self.check(principals, permission)
|
return self.check(principals, permission)
|
||||||
for p in permission:
|
for p in permission:
|
||||||
if self.check(principals,p):
|
if self.check(principals, p):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def check(self, principals, permission):
|
def check(self, principals, permission):
|
||||||
if permission == 'Authenticated':
|
if permission == "Authenticated":
|
||||||
permission = 'system.Authenticated'
|
permission = "system.Authenticated"
|
||||||
if permission == 'Everyone':
|
if permission == "Everyone":
|
||||||
permission = 'system.Everyone'
|
permission = "system.Everyone"
|
||||||
allowed = permission in principals
|
allowed = permission in principals
|
||||||
return allowed
|
return allowed
|
||||||
|
|
||||||
|
|||||||
@ -128,23 +128,32 @@ def show_list(request):
|
|||||||
active = request.GET.get("a", None)
|
active = request.GET.get("a", None)
|
||||||
list_ = request.dbsession.query(FoodTable)
|
list_ = request.dbsession.query(FoodTable)
|
||||||
if active is not None:
|
if active is not None:
|
||||||
|
active = active == "true"
|
||||||
list_ = list_.filter(FoodTable.is_active == active)
|
list_ = list_.filter(FoodTable.is_active == active)
|
||||||
list_ = list_.order_by(FoodTable.sort_order).all()
|
list_ = list_.order_by(FoodTable.sort_order).all()
|
||||||
|
|
||||||
food_tables = []
|
food_tables = []
|
||||||
for item in list_:
|
for item in list_:
|
||||||
food_tables.append(
|
ft = {
|
||||||
{
|
|
||||||
"id": item.id,
|
"id": item.id,
|
||||||
"name": item.name,
|
"name": item.name,
|
||||||
"seats": item.seats,
|
"seats": item.seats,
|
||||||
"section": {"id": item.section_id, "name": item.section.name},
|
"section": {"id": item.section_id, "name": item.section.name},
|
||||||
"isActive": item.is_active,
|
"isActive": item.is_active,
|
||||||
"sortOrder": item.sort_order,
|
"sortOrder": item.sort_order
|
||||||
"status": "" if item.status is None else item.status.status,
|
|
||||||
"voucherId": None if item.status is None else item.status.voucher_id,
|
|
||||||
}
|
}
|
||||||
)
|
if item.status is None:
|
||||||
|
ft["status"] = ""
|
||||||
|
else:
|
||||||
|
ft["status"] = item.status.status
|
||||||
|
if item.status.voucher is not None:
|
||||||
|
ft["voucherId"] = item.status.voucher_id
|
||||||
|
ft["pax"] = item.status.voucher.pax
|
||||||
|
ft["date"] = item.status.voucher.date.strftime("%d-%b-%Y %H:%M")
|
||||||
|
ft["amount"] = 12345
|
||||||
|
if item.status.guest is not None:
|
||||||
|
ft["name"] = item.status.guest.customer.name
|
||||||
|
food_tables.append(ft)
|
||||||
return food_tables
|
return food_tables
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -185,7 +185,7 @@ def show_list(request):
|
|||||||
request_param="p",
|
request_param="p",
|
||||||
permission="Authenticated",
|
permission="Authenticated",
|
||||||
)
|
)
|
||||||
def show_for_pg(request):
|
def show_for_product(request):
|
||||||
product_id = uuid.UUID(request.GET["p"])
|
product_id = uuid.UUID(request.GET["p"])
|
||||||
product = request.dbsession.query(Product).filter(Product.id == product_id).first()
|
product = request.dbsession.query(Product).filter(Product.id == product_id).first()
|
||||||
|
|
||||||
@ -197,7 +197,7 @@ def show_for_pg(request):
|
|||||||
"maximum": item.maximum,
|
"maximum": item.maximum,
|
||||||
"isActive": item.is_active,
|
"isActive": item.is_active,
|
||||||
"modifiers": [
|
"modifiers": [
|
||||||
{"id": m.id, "name": m.name, "prince": m.price}
|
{"id": m.id, "name": m.name, "price": m.price}
|
||||||
for m in item.modifiers
|
for m in item.modifiers
|
||||||
if m.is_active == True
|
if m.is_active == True
|
||||||
],
|
],
|
||||||
|
|||||||
@ -1,509 +0,0 @@
|
|||||||
import re
|
|
||||||
import uuid
|
|
||||||
from datetime import datetime
|
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
import transaction
|
|
||||||
from pyramid.httpexceptions import HTTPForbidden
|
|
||||||
from pyramid.view import view_config
|
|
||||||
from sqlalchemy import func
|
|
||||||
|
|
||||||
from barker.exceptions import ValidationFailure
|
|
||||||
from barker.models import (
|
|
||||||
Inventory,
|
|
||||||
InventoryModifier,
|
|
||||||
Kot,
|
|
||||||
Settlement,
|
|
||||||
SettleOption,
|
|
||||||
Voucher,
|
|
||||||
Overview,
|
|
||||||
VoucherType,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@view_config(request_method="PUT", route_name="voucher", renderer="json", trans=True)
|
|
||||||
def save(request):
|
|
||||||
update_table = request.GET["u"]
|
|
||||||
json = request.json_body
|
|
||||||
|
|
||||||
if not json["Printed"] and "Print Kot" not in request.effective_principals:
|
|
||||||
raise HTTPForbidden("You are not allowed to print a kot")
|
|
||||||
|
|
||||||
if json["Printed"] and "Print Bill" not in request.effective_principals:
|
|
||||||
raise HTTPForbidden("You are not allowed to print bill")
|
|
||||||
|
|
||||||
item = save_voucher(json, request.dbsession)
|
|
||||||
if update_table:
|
|
||||||
status = "printed" if item.is_printed else "running"
|
|
||||||
item.status = Overview(
|
|
||||||
voucher_id=None, food_table_id=item.food_table_id, status=status
|
|
||||||
)
|
|
||||||
request.dbsession.add(item.status)
|
|
||||||
transaction.commit()
|
|
||||||
item = request.dbsession.query(Voucher).filter(Voucher.id == item.id).first()
|
|
||||||
return voucher_info(item)
|
|
||||||
|
|
||||||
|
|
||||||
@view_config(
|
|
||||||
request_method="POST", route_name="voucher_id", renderer="json", trans=True
|
|
||||||
)
|
|
||||||
def update(request):
|
|
||||||
now = datetime.now()
|
|
||||||
update_table = request.GET["u"]
|
|
||||||
json = request.json_body
|
|
||||||
id = uuid.UUID(request.matchdict["id"])
|
|
||||||
item = request.dbsession.query(Voucher).filter(Voucher.id == id).first()
|
|
||||||
|
|
||||||
if not json["Printed"] and "Print Kot" not in request.effective_principals:
|
|
||||||
raise HTTPForbidden("You are not allowed to print a kot")
|
|
||||||
|
|
||||||
if json["Printed"] and "Print Bill" not in request.effective_principals:
|
|
||||||
raise HTTPForbidden("You are not allowed to print bill")
|
|
||||||
|
|
||||||
if item.is_printed and "Edit Printed Bill" not in request.effective_principals:
|
|
||||||
raise HTTPForbidden("You are not allowed to edit a printed bill")
|
|
||||||
|
|
||||||
if item.is_printed and not json["Printed"]:
|
|
||||||
transaction.abort()
|
|
||||||
raise ValidationFailure("This Bill is already printed\nCannot add a Kot to it.")
|
|
||||||
|
|
||||||
if item.is_void:
|
|
||||||
transaction.abort()
|
|
||||||
raise ValidationFailure(
|
|
||||||
"This Bill is already void.\nReason: {0}".format(item.void_reason)
|
|
||||||
)
|
|
||||||
|
|
||||||
if item.is_printed and not json["Printed"]:
|
|
||||||
transaction.abort()
|
|
||||||
raise ValidationFailure("This Bill is already printed\nCannot add a Kot to it.")
|
|
||||||
|
|
||||||
item.pax = json["Pax"]
|
|
||||||
item.food_table_id = json["Table"]["FoodTableID"]
|
|
||||||
item.customer_id = json["Customer"]["CustomerID"]
|
|
||||||
item.voucher_type = json["VoucherType"]
|
|
||||||
if not item.is_printed and json["Printed"]:
|
|
||||||
item.date = now
|
|
||||||
type = [1, 3] if item.voucher_type in [1, 3] else [item.voucher_type]
|
|
||||||
item.bill_id = (
|
|
||||||
request.dbsession.query(func.coalesce(func.max(Voucher.bill_id), 0) + 1)
|
|
||||||
.filter(Voucher.voucher_type.in_(type))
|
|
||||||
.scalar()
|
|
||||||
)
|
|
||||||
|
|
||||||
item.is_printed = item.is_printed or json["Printed"]
|
|
||||||
item.user_id = json["User"]["UserID"]
|
|
||||||
item.last_edit_date = now
|
|
||||||
for k in item.kots:
|
|
||||||
for i in k.inventories:
|
|
||||||
i.service_tax_rate, i.vat_rate = get_st_vat(
|
|
||||||
i.service_tax_rate, i.vat_rate, item.voucher_type
|
|
||||||
)
|
|
||||||
i.discount = next(
|
|
||||||
Decimal(inv["Discount"])
|
|
||||||
for ko in json["Kots"]
|
|
||||||
for inv in ko["Inventories"]
|
|
||||||
if uuid.UUID(inv["InventoryID"]) == i.id
|
|
||||||
)
|
|
||||||
for k in (
|
|
||||||
k for k in json["Kots"] if k["KotID"] == "00000000-0000-0000-0000-000000000000"
|
|
||||||
):
|
|
||||||
kot = Kot(
|
|
||||||
item.id,
|
|
||||||
item.food_table_id,
|
|
||||||
item.date,
|
|
||||||
item.user_id,
|
|
||||||
dbsession=request.dbsession,
|
|
||||||
)
|
|
||||||
item.kots.append(kot)
|
|
||||||
request.dbsession.add(kot)
|
|
||||||
for index, i in enumerate(k["Inventories"]):
|
|
||||||
st, vat = get_st_vat(i["ServiceTaxRate"], i["VatRate"], json["VoucherType"])
|
|
||||||
inv = Inventory(
|
|
||||||
kot.id,
|
|
||||||
uuid.UUID(i["ProductID"]),
|
|
||||||
i["Quantity"],
|
|
||||||
i["Price"],
|
|
||||||
i["Discount"],
|
|
||||||
i["IsHappyHour"],
|
|
||||||
i["ServiceTaxID"],
|
|
||||||
st,
|
|
||||||
i["VatID"],
|
|
||||||
vat,
|
|
||||||
index,
|
|
||||||
)
|
|
||||||
kot.inventories.append(inv)
|
|
||||||
request.dbsession.add(inv)
|
|
||||||
for m in i["Modifiers"]:
|
|
||||||
mod = InventoryModifier(None, uuid.UUID(m["ModifierID"]), 0)
|
|
||||||
inv.modifiers.append(mod)
|
|
||||||
request.dbsession.add(mod)
|
|
||||||
get_settlements(item, request.dbsession)
|
|
||||||
if update_table:
|
|
||||||
vft = (
|
|
||||||
request.dbsession.query(Overview)
|
|
||||||
.filter(Overview.voucher_id == item.id)
|
|
||||||
.first()
|
|
||||||
)
|
|
||||||
status = "printed" if item.is_printed else "running"
|
|
||||||
if vft is None:
|
|
||||||
item.status = Overview(
|
|
||||||
voucher_id=None, food_table_id=item.food_table_id, status=status
|
|
||||||
)
|
|
||||||
request.dbsession.add(item.status)
|
|
||||||
else:
|
|
||||||
vft.status = status
|
|
||||||
vft.food_table_id = item.food_table_id
|
|
||||||
transaction.commit()
|
|
||||||
item = request.dbsession.query(Voucher).filter(Voucher.id == item.id).first()
|
|
||||||
return voucher_info(item)
|
|
||||||
|
|
||||||
|
|
||||||
@view_config(
|
|
||||||
request_method="POST",
|
|
||||||
route_name="voucher_settle",
|
|
||||||
renderer="json",
|
|
||||||
permission="Settle Bill",
|
|
||||||
trans=False,
|
|
||||||
)
|
|
||||||
def settle_voucher(request):
|
|
||||||
update_table = request.GET["u"]
|
|
||||||
json = request.json_body
|
|
||||||
id_ = uuid.UUID(request.matchdict["id"])
|
|
||||||
item = request.dbsession.query(Voucher).filter(Voucher.id == id_).first()
|
|
||||||
|
|
||||||
allowed = [
|
|
||||||
SettleOption.AMOUNT(),
|
|
||||||
SettleOption.ROUND_OFF(),
|
|
||||||
SettleOption.UNSETTLED(),
|
|
||||||
]
|
|
||||||
for i in (j for j in json if j["Amount"] != 0):
|
|
||||||
amount = i["Amount"]
|
|
||||||
so = i["Settled"]
|
|
||||||
so_settled = [s for s in item.settlements if s.settled == so]
|
|
||||||
if len(so_settled) == 1:
|
|
||||||
so_settled[0].amount = amount
|
|
||||||
else:
|
|
||||||
s = Settlement(item.id, so, amount)
|
|
||||||
item.settlements.append(s)
|
|
||||||
request.dbsession.add(s)
|
|
||||||
allowed.append(so)
|
|
||||||
for i in (s for s in item.settlements if s.settled not in allowed):
|
|
||||||
item.settlements.remove(i)
|
|
||||||
request.dbsession.delete(i)
|
|
||||||
unsettled = get_settlements(item, request.dbsession)
|
|
||||||
|
|
||||||
if unsettled == 0 and update_table:
|
|
||||||
request.dbsession.query(Overview).filter(
|
|
||||||
Overview.voucher_id == item.id
|
|
||||||
).delete()
|
|
||||||
transaction.commit()
|
|
||||||
item = request.dbsession.query(Voucher).filter(Voucher.id == item.id).first()
|
|
||||||
return voucher_info(item)
|
|
||||||
|
|
||||||
|
|
||||||
@view_config(
|
|
||||||
request_method="POST",
|
|
||||||
route_name="voucher_reprint",
|
|
||||||
renderer="json",
|
|
||||||
permission="Edit Printed Bill",
|
|
||||||
trans=True,
|
|
||||||
) # Permission error
|
|
||||||
def voucher_change(request):
|
|
||||||
json = request.json_body
|
|
||||||
id_ = uuid.UUID(request.matchdict["id"])
|
|
||||||
item = save_voucher(json, request.dbsession)
|
|
||||||
old = request.dbsession.query(Voucher).filter(Voucher.id == id_).first()
|
|
||||||
old.void = True
|
|
||||||
old.void_reason = "Bill Discounted / Changed. New Bill ID is {0}".format(
|
|
||||||
item.full_bill_id
|
|
||||||
)
|
|
||||||
# TODO: Set the Void Settlement
|
|
||||||
|
|
||||||
if old.status is None:
|
|
||||||
item.status = Overview(
|
|
||||||
voucher_id=None, food_table_id=item.food_table_id, status="printed"
|
|
||||||
)
|
|
||||||
request.dbsession.add(item.status)
|
|
||||||
else:
|
|
||||||
request.dbsession.query(Overview).filter(Overview.voucher_id == old.id).update(
|
|
||||||
{Overview.voucher_id: item.id}
|
|
||||||
)
|
|
||||||
transaction.commit()
|
|
||||||
item = request.dbsession.query(Voucher).filter(Voucher.id == item.id).first()
|
|
||||||
return voucher_info(item)
|
|
||||||
|
|
||||||
|
|
||||||
@view_config(
|
|
||||||
request_method="POST",
|
|
||||||
route_name="voucher_void",
|
|
||||||
renderer="json",
|
|
||||||
permission="Void Bill",
|
|
||||||
trans=True,
|
|
||||||
)
|
|
||||||
def void_voucher(request):
|
|
||||||
update_table = request.GET["u"]
|
|
||||||
json = request.json_body
|
|
||||||
id_ = uuid.UUID(request.matchdict["id"])
|
|
||||||
item = request.dbsession.query(Voucher).filter(Voucher.id == id_).first()
|
|
||||||
|
|
||||||
item.void = True
|
|
||||||
item.void_reason = json["Reason"]
|
|
||||||
|
|
||||||
amount = round(-1 * sum(i.amount for k in item.kots for i in k.inventories), 5) * -1
|
|
||||||
s = Settlement(item.id, SettleOption.VOID(), amount)
|
|
||||||
item.settlements.append(s)
|
|
||||||
request.dbsession.add(s)
|
|
||||||
allowed = [
|
|
||||||
SettleOption.AMOUNT(),
|
|
||||||
SettleOption.ROUND_OFF(),
|
|
||||||
SettleOption.UNSETTLED(),
|
|
||||||
SettleOption.VOID(),
|
|
||||||
]
|
|
||||||
for i in (s for s in item.settlements if s.settled not in allowed):
|
|
||||||
item.settlements.remove(i)
|
|
||||||
request.dbsession.delete(i)
|
|
||||||
get_settlements(item, request.dbsession)
|
|
||||||
|
|
||||||
if update_table:
|
|
||||||
request.dbsession.delete(item.status)
|
|
||||||
transaction.commit()
|
|
||||||
item = request.dbsession.query(Voucher).filter(Voucher.id == item.id).first()
|
|
||||||
return voucher_info(item)
|
|
||||||
|
|
||||||
|
|
||||||
@view_config(
|
|
||||||
request_method="POST",
|
|
||||||
route_name="voucher_split",
|
|
||||||
renderer="json",
|
|
||||||
permission="Split Bill",
|
|
||||||
trans=True,
|
|
||||||
)
|
|
||||||
def split_voucher(request):
|
|
||||||
json = request.json_body
|
|
||||||
id_ = uuid.UUID(request.matchdict["id"])
|
|
||||||
item = request.dbsession.query(Voucher).filter(Voucher.id == id_).first()
|
|
||||||
item.void = True
|
|
||||||
item.void_reason = "Bill Split"
|
|
||||||
# TODO: Set the Void Settlement
|
|
||||||
|
|
||||||
new_one = save_voucher(json["One"], request.dbsession)
|
|
||||||
new_two = save_voucher(json["Two"], request.dbsession)
|
|
||||||
|
|
||||||
status = "printed" if item.is_printed else "running"
|
|
||||||
new_one.status = Overview(
|
|
||||||
voucher_id=None, food_table_id=new_one.food_table_id, status=status
|
|
||||||
)
|
|
||||||
|
|
||||||
request.dbsession.add(new_one.status)
|
|
||||||
request.dbsession.query(Overview).filter(Overview.voucher_id == item.id).update(
|
|
||||||
{Overview.voucher_id: new_two.id}
|
|
||||||
)
|
|
||||||
|
|
||||||
transaction.commit()
|
|
||||||
|
|
||||||
|
|
||||||
@view_config(
|
|
||||||
request_method="GET",
|
|
||||||
route_name="voucher_id",
|
|
||||||
renderer="json",
|
|
||||||
permission="Authenticated",
|
|
||||||
)
|
|
||||||
def show_id(request):
|
|
||||||
id_ = uuid.UUID(request.matchdict["id"])
|
|
||||||
item = request.dbsession.query(Voucher).filter(Voucher.id == id_).first()
|
|
||||||
return voucher_info(item)
|
|
||||||
|
|
||||||
|
|
||||||
@view_config(
|
|
||||||
request_method="GET",
|
|
||||||
route_name="voucher",
|
|
||||||
request_param="b",
|
|
||||||
renderer="json",
|
|
||||||
permission="Authenticated",
|
|
||||||
)
|
|
||||||
def show(request):
|
|
||||||
bill_id = request.GET["b"]
|
|
||||||
item = request.dbsession.query(Voucher)
|
|
||||||
if re.compile("^\d{2,}-\d{4}$").match(bill_id):
|
|
||||||
item = item.filter(
|
|
||||||
Voucher.bill_id == int(bill_id.replace("-", "")),
|
|
||||||
Voucher.voucher_type.in_([1, 3]),
|
|
||||||
)
|
|
||||||
elif re.compile("^NC-\d+$").match(bill_id):
|
|
||||||
item = item.filter(
|
|
||||||
Voucher.bill_id == int(bill_id.replace("NC-", "")),
|
|
||||||
Voucher.voucher_type == 2,
|
|
||||||
)
|
|
||||||
elif re.compile("^ST-\d+$").match(bill_id):
|
|
||||||
item = item.filter(
|
|
||||||
Voucher.bill_id == int(bill_id.replace("ST-", "")),
|
|
||||||
Voucher.voucher_type == 4,
|
|
||||||
)
|
|
||||||
item = item.first()
|
|
||||||
if item is None:
|
|
||||||
return {}
|
|
||||||
return voucher_info(item)
|
|
||||||
|
|
||||||
|
|
||||||
def voucher_info(item):
|
|
||||||
return {
|
|
||||||
"id": item.id,
|
|
||||||
"date": item.date.strftime("%d-%b-%Y %H:%M:%S"),
|
|
||||||
"pax": item.pax,
|
|
||||||
"user": {"id": item.user_id, "name": item.user.name},
|
|
||||||
"creationDate": item.creation_date.strftime("%d-%b-%Y %H:%M:%S"),
|
|
||||||
"lastEditDate": item.last_edit_date.strftime("%d-%b-%Y %H:%M:%S"),
|
|
||||||
"billId": item.bill_id,
|
|
||||||
"table": {"id": item.food_table_id, "name": item.food_table.name},
|
|
||||||
"customer": {"id": item.customer_id, "name": item.customer.name},
|
|
||||||
"settlements": [],
|
|
||||||
"narration": item.narration,
|
|
||||||
"void": item.is_void,
|
|
||||||
"voidReason": item.void_reason,
|
|
||||||
"printed": item.is_printed,
|
|
||||||
"voucherType": item.voucher_type,
|
|
||||||
"kotId": item.kot_id,
|
|
||||||
"kots": [
|
|
||||||
{
|
|
||||||
"id": k.id,
|
|
||||||
"code": k.code,
|
|
||||||
"date": k.date.strftime("%d-%b-%Y %H:%M:%S"),
|
|
||||||
"user": {"id": k.user_id, "name": k.user.name},
|
|
||||||
"inventories": [
|
|
||||||
{
|
|
||||||
"id": i.id,
|
|
||||||
"sortOrder": i.sort_order,
|
|
||||||
"product": {
|
|
||||||
"id": i.product_id,
|
|
||||||
"name": i.product.name,
|
|
||||||
"units": i.product.units,
|
|
||||||
"menuCategory": {
|
|
||||||
"id": i.product.menu_category_id,
|
|
||||||
"name": i.product.menu_category.name,
|
|
||||||
"discountLimit": i.product.menu_category.discount_limit,
|
|
||||||
},
|
|
||||||
"saleCategory": {
|
|
||||||
"id": i.product.sale_category_id,
|
|
||||||
"name": i.product.sale_category.name
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"quantity": i.quantity,
|
|
||||||
"price": i.price,
|
|
||||||
"isHappyHour": i.is_happy_hour,
|
|
||||||
"taxRate": i.tax_rate,
|
|
||||||
"tax": {"id": i.vat_id, "name": i.vat.name},
|
|
||||||
"discount": i.discount,
|
|
||||||
"inventoryModifier": [
|
|
||||||
{
|
|
||||||
"modifier": {
|
|
||||||
"id": m.modifier.id,
|
|
||||||
"name": m.modifier.name,
|
|
||||||
"showInBill": m.modifier.show_in_bill,
|
|
||||||
},
|
|
||||||
"price": m.price,
|
|
||||||
}
|
|
||||||
for m in i.modifiers
|
|
||||||
],
|
|
||||||
}
|
|
||||||
for i in k.inventories
|
|
||||||
],
|
|
||||||
}
|
|
||||||
for k in item.kots
|
|
||||||
],
|
|
||||||
"reprints": [],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def get_st_vat(st, vat, voucher_type):
|
|
||||||
if voucher_type == VoucherType.STAFF.value:
|
|
||||||
return 0, 0
|
|
||||||
elif voucher_type == VoucherType.NO_CHARGE.value:
|
|
||||||
return 0, 0
|
|
||||||
else: # voucher_type in [REGULAR_BILL, TAKE_AWAY]:
|
|
||||||
return st, vat
|
|
||||||
|
|
||||||
|
|
||||||
def get_settlements(voucher, dbsession):
|
|
||||||
amount = round(
|
|
||||||
-1 * sum(sum(i.amount for i in k.inventories) for k in voucher.kots), 5
|
|
||||||
)
|
|
||||||
so_amount = [s for s in voucher.settlements if s.settled == SettleOption.AMOUNT()]
|
|
||||||
if len(so_amount) == 1:
|
|
||||||
so_amount[0].amount = amount
|
|
||||||
else:
|
|
||||||
s = Settlement(voucher.id, SettleOption.AMOUNT(), amount)
|
|
||||||
voucher.settlements.append(s)
|
|
||||||
dbsession.add(s)
|
|
||||||
|
|
||||||
round_off = round(amount) - amount
|
|
||||||
so_round_off = [
|
|
||||||
s for s in voucher.settlements if s.settled == SettleOption.ROUND_OFF()
|
|
||||||
]
|
|
||||||
if len(so_round_off) == 1 and round_off != 0:
|
|
||||||
so_round_off[0].amount = round_off
|
|
||||||
elif len(so_round_off) == 1 and round_off == 0:
|
|
||||||
voucher.settlements.remove(so_round_off[0])
|
|
||||||
dbsession.delete(so_round_off[0])
|
|
||||||
elif len(so_round_off) == 0 and round_off != 0:
|
|
||||||
s = Settlement(voucher.id, SettleOption.ROUND_OFF(), round_off)
|
|
||||||
voucher.settlements.append(s)
|
|
||||||
dbsession.add(s)
|
|
||||||
|
|
||||||
unsettled = sum(
|
|
||||||
s.amount for s in voucher.settlements if s.settled != SettleOption.UNSETTLED()
|
|
||||||
)
|
|
||||||
so_unsettled = [
|
|
||||||
s for s in voucher.settlements if s.settled == SettleOption.UNSETTLED()
|
|
||||||
]
|
|
||||||
if len(so_unsettled) == 1 and unsettled != 0:
|
|
||||||
so_unsettled[0].amount = unsettled
|
|
||||||
elif len(so_unsettled) == 1 and unsettled == 0:
|
|
||||||
voucher.settlements.remove(so_unsettled[0])
|
|
||||||
dbsession.delete(so_unsettled[0])
|
|
||||||
elif len(so_unsettled) == 0 and unsettled != 0:
|
|
||||||
s = Settlement(voucher.id, SettleOption.UNSETTLED(), unsettled)
|
|
||||||
voucher.settlements.append(s)
|
|
||||||
dbsession.add(s)
|
|
||||||
return unsettled
|
|
||||||
|
|
||||||
|
|
||||||
def save_voucher(json, dbsession):
|
|
||||||
item = Voucher(
|
|
||||||
json["Pax"],
|
|
||||||
json["Table"]["FoodTableID"],
|
|
||||||
json["Customer"]["CustomerID"],
|
|
||||||
json["Printed"],
|
|
||||||
json["VoucherType"],
|
|
||||||
json["User"]["UserID"],
|
|
||||||
dbsession,
|
|
||||||
)
|
|
||||||
dbsession.add(item)
|
|
||||||
for k in json["Kots"]:
|
|
||||||
kot = Kot(
|
|
||||||
item.id, item.food_table_id, item.date, item.user_id, dbsession=dbsession
|
|
||||||
)
|
|
||||||
item.kots.append(kot)
|
|
||||||
dbsession.add(kot)
|
|
||||||
for index, i in enumerate(k["Inventories"]):
|
|
||||||
st, vat = get_st_vat(i["ServiceTaxRate"], i["VatRate"], json["VoucherType"])
|
|
||||||
inv = Inventory(
|
|
||||||
kot.id,
|
|
||||||
uuid.UUID(i["ProductID"]),
|
|
||||||
i["Quantity"],
|
|
||||||
i["Price"],
|
|
||||||
i["Discount"],
|
|
||||||
i["IsHappyHour"],
|
|
||||||
i["ServiceTaxID"],
|
|
||||||
st,
|
|
||||||
i["VatID"],
|
|
||||||
vat,
|
|
||||||
index,
|
|
||||||
)
|
|
||||||
kot.inventories.append(inv)
|
|
||||||
dbsession.add(inv)
|
|
||||||
for m in i["Modifiers"]:
|
|
||||||
mod = InventoryModifier(None, uuid.UUID(m["ModifierID"]), 0)
|
|
||||||
inv.modifiers.append(mod)
|
|
||||||
dbsession.add(mod)
|
|
||||||
get_settlements(item, dbsession)
|
|
||||||
return item
|
|
||||||
77
barker/views/voucher/__init__.py
Normal file
77
barker/views/voucher/__init__.py
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
# import re
|
||||||
|
# import uuid
|
||||||
|
# from datetime import datetime
|
||||||
|
# from decimal import Decimal
|
||||||
|
#
|
||||||
|
# import transaction
|
||||||
|
# from pyramid.httpexceptions import HTTPForbidden
|
||||||
|
# from pyramid.view import view_config
|
||||||
|
# from sqlalchemy import func
|
||||||
|
#
|
||||||
|
# from barker.exceptions import ValidationFailure
|
||||||
|
# from barker.models import (
|
||||||
|
# Inventory,
|
||||||
|
# InventoryModifier,
|
||||||
|
# Kot,
|
||||||
|
# Settlement,
|
||||||
|
# SettleOption,
|
||||||
|
# Voucher,
|
||||||
|
# Overview,
|
||||||
|
# VoucherType,
|
||||||
|
# )
|
||||||
|
from barker.models import VoucherType, Settlement, SettleOption
|
||||||
|
|
||||||
|
|
||||||
|
def get_st_vat(st, vat, voucher_type):
|
||||||
|
if voucher_type == VoucherType.STAFF.value:
|
||||||
|
return 0, 0
|
||||||
|
elif voucher_type == VoucherType.NO_CHARGE.value:
|
||||||
|
return 0, 0
|
||||||
|
else: # voucher_type in [REGULAR_BILL, TAKE_AWAY]:
|
||||||
|
return st, vat
|
||||||
|
|
||||||
|
|
||||||
|
def get_settlements(voucher, dbsession):
|
||||||
|
amount = round(
|
||||||
|
-1 * sum(sum(i.amount for i in k.inventories) for k in voucher.kots), 5
|
||||||
|
)
|
||||||
|
so_amount = [s for s in voucher.settlements if s.settled == SettleOption.AMOUNT()]
|
||||||
|
if len(so_amount) == 1:
|
||||||
|
so_amount[0].amount = amount
|
||||||
|
else:
|
||||||
|
s = Settlement(voucher.id, SettleOption.AMOUNT(), amount)
|
||||||
|
voucher.settlements.append(s)
|
||||||
|
dbsession.add(s)
|
||||||
|
|
||||||
|
round_off = round(amount) - amount
|
||||||
|
so_round_off = [
|
||||||
|
s for s in voucher.settlements if s.settled == SettleOption.ROUND_OFF()
|
||||||
|
]
|
||||||
|
if len(so_round_off) == 1 and round_off != 0:
|
||||||
|
so_round_off[0].amount = round_off
|
||||||
|
elif len(so_round_off) == 1 and round_off == 0:
|
||||||
|
voucher.settlements.remove(so_round_off[0])
|
||||||
|
dbsession.delete(so_round_off[0])
|
||||||
|
elif len(so_round_off) == 0 and round_off != 0:
|
||||||
|
s = Settlement(voucher.id, SettleOption.ROUND_OFF(), round_off)
|
||||||
|
voucher.settlements.append(s)
|
||||||
|
dbsession.add(s)
|
||||||
|
|
||||||
|
unsettled = sum(
|
||||||
|
s.amount for s in voucher.settlements if s.settled != SettleOption.UNSETTLED()
|
||||||
|
)
|
||||||
|
so_unsettled = [
|
||||||
|
s for s in voucher.settlements if s.settled == SettleOption.UNSETTLED()
|
||||||
|
]
|
||||||
|
if len(so_unsettled) == 1 and unsettled != 0:
|
||||||
|
so_unsettled[0].amount = unsettled
|
||||||
|
elif len(so_unsettled) == 1 and unsettled == 0:
|
||||||
|
voucher.settlements.remove(so_unsettled[0])
|
||||||
|
dbsession.delete(so_unsettled[0])
|
||||||
|
elif len(so_unsettled) == 0 and unsettled != 0:
|
||||||
|
s = Settlement(voucher.id, SettleOption.UNSETTLED(), unsettled)
|
||||||
|
voucher.settlements.append(s)
|
||||||
|
dbsession.add(s)
|
||||||
|
return unsettled
|
||||||
|
|
||||||
|
|
||||||
42
barker/views/voucher/change.py
Normal file
42
barker/views/voucher/change.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
|
import transaction
|
||||||
|
from pyramid.view import view_config
|
||||||
|
|
||||||
|
from barker.models import Voucher, Overview
|
||||||
|
from barker.views.voucher.save import save_voucher
|
||||||
|
from barker.views.voucher.show import voucher_info
|
||||||
|
|
||||||
|
|
||||||
|
@view_config(
|
||||||
|
request_method="POST",
|
||||||
|
route_name="voucher_reprint",
|
||||||
|
renderer="json",
|
||||||
|
permission="Edit Printed Bill",
|
||||||
|
trans=True,
|
||||||
|
) # Permission error
|
||||||
|
def voucher_change(request):
|
||||||
|
json = request.json_body
|
||||||
|
id_ = uuid.UUID(request.matchdict["id"])
|
||||||
|
item = save_voucher(json, request.dbsession)
|
||||||
|
old = request.dbsession.query(Voucher).filter(Voucher.id == id_).first()
|
||||||
|
old.void = True
|
||||||
|
old.void_reason = "Bill Discounted / Changed. New Bill ID is {0}".format(
|
||||||
|
item.full_bill_id
|
||||||
|
)
|
||||||
|
# TODO: Set the Void Settlement
|
||||||
|
|
||||||
|
if old.status is None:
|
||||||
|
item.status = Overview(
|
||||||
|
voucher_id=None, food_table_id=item.food_table_id, status="printed"
|
||||||
|
)
|
||||||
|
request.dbsession.add(item.status)
|
||||||
|
else:
|
||||||
|
request.dbsession.query(Overview).filter(Overview.voucher_id == old.id).update(
|
||||||
|
{Overview.voucher_id: item.id}
|
||||||
|
)
|
||||||
|
transaction.commit()
|
||||||
|
item = request.dbsession.query(Voucher).filter(Voucher.id == item.id).first()
|
||||||
|
return voucher_info(item)
|
||||||
|
|
||||||
|
|
||||||
74
barker/views/voucher/save.py
Normal file
74
barker/views/voucher/save.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
|
import transaction
|
||||||
|
from pyramid.httpexceptions import HTTPForbidden
|
||||||
|
from pyramid.view import view_config
|
||||||
|
|
||||||
|
from barker.models import Overview, Voucher, Kot, Inventory, InventoryModifier
|
||||||
|
from barker.views.voucher import get_st_vat, get_settlements
|
||||||
|
from barker.views.voucher.show import voucher_info
|
||||||
|
|
||||||
|
|
||||||
|
@view_config(request_method="PUT", route_name="v1_vouchers_new", renderer="json", trans=True)
|
||||||
|
def save(request):
|
||||||
|
update_table = request.GET["u"]
|
||||||
|
json = request.json_body
|
||||||
|
|
||||||
|
if not json["Printed"] and "Print Kot" not in request.effective_principals:
|
||||||
|
raise HTTPForbidden("You are not allowed to print a kot")
|
||||||
|
|
||||||
|
if json["Printed"] and "Print Bill" not in request.effective_principals:
|
||||||
|
raise HTTPForbidden("You are not allowed to print bill")
|
||||||
|
|
||||||
|
item = save_voucher(json, request.dbsession)
|
||||||
|
if update_table:
|
||||||
|
status = "printed" if item.is_printed else "running"
|
||||||
|
item.status = Overview(
|
||||||
|
voucher_id=None, food_table_id=item.food_table_id, status=status
|
||||||
|
)
|
||||||
|
request.dbsession.add(item.status)
|
||||||
|
transaction.commit()
|
||||||
|
item = request.dbsession.query(Voucher).filter(Voucher.id == item.id).first()
|
||||||
|
return voucher_info(item)
|
||||||
|
|
||||||
|
|
||||||
|
def save_voucher(json, dbsession):
|
||||||
|
item = Voucher(
|
||||||
|
json["Pax"],
|
||||||
|
json["Table"]["FoodTableID"],
|
||||||
|
json["Customer"]["CustomerID"],
|
||||||
|
json["Printed"],
|
||||||
|
json["VoucherType"],
|
||||||
|
json["User"]["UserID"],
|
||||||
|
dbsession,
|
||||||
|
)
|
||||||
|
dbsession.add(item)
|
||||||
|
for k in json["Kots"]:
|
||||||
|
kot = Kot(
|
||||||
|
item.id, item.food_table_id, item.date, item.user_id, dbsession=dbsession
|
||||||
|
)
|
||||||
|
item.kots.append(kot)
|
||||||
|
dbsession.add(kot)
|
||||||
|
for index, i in enumerate(k["Inventories"]):
|
||||||
|
st, vat = get_st_vat(i["ServiceTaxRate"], i["VatRate"], json["VoucherType"])
|
||||||
|
inv = Inventory(
|
||||||
|
kot.id,
|
||||||
|
uuid.UUID(i["ProductID"]),
|
||||||
|
i["Quantity"],
|
||||||
|
i["Price"],
|
||||||
|
i["Discount"],
|
||||||
|
i["IsHappyHour"],
|
||||||
|
i["ServiceTaxID"],
|
||||||
|
st,
|
||||||
|
i["VatID"],
|
||||||
|
vat,
|
||||||
|
index,
|
||||||
|
)
|
||||||
|
kot.inventories.append(inv)
|
||||||
|
dbsession.add(inv)
|
||||||
|
for m in i["Modifiers"]:
|
||||||
|
mod = InventoryModifier(None, uuid.UUID(m["ModifierID"]), 0)
|
||||||
|
inv.modifiers.append(mod)
|
||||||
|
dbsession.add(mod)
|
||||||
|
get_settlements(item, dbsession)
|
||||||
|
return item
|
||||||
53
barker/views/voucher/settle.py
Normal file
53
barker/views/voucher/settle.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
|
import transaction
|
||||||
|
from pyramid.view import view_config
|
||||||
|
|
||||||
|
from barker.models import SettleOption, Voucher, Settlement, Overview
|
||||||
|
from barker.views.voucher import get_settlements
|
||||||
|
from barker.views.voucher.show import voucher_info
|
||||||
|
|
||||||
|
|
||||||
|
@view_config(
|
||||||
|
request_method="POST",
|
||||||
|
route_name="voucher_settle",
|
||||||
|
renderer="json",
|
||||||
|
permission="Settle Bill",
|
||||||
|
trans=False,
|
||||||
|
)
|
||||||
|
def settle_voucher(request):
|
||||||
|
update_table = request.GET["u"]
|
||||||
|
json = request.json_body
|
||||||
|
id_ = uuid.UUID(request.matchdict["id"])
|
||||||
|
item = request.dbsession.query(Voucher).filter(Voucher.id == id_).first()
|
||||||
|
|
||||||
|
allowed = [
|
||||||
|
SettleOption.AMOUNT(),
|
||||||
|
SettleOption.ROUND_OFF(),
|
||||||
|
SettleOption.UNSETTLED(),
|
||||||
|
]
|
||||||
|
for i in (j for j in json if j["Amount"] != 0):
|
||||||
|
amount = i["Amount"]
|
||||||
|
so = i["Settled"]
|
||||||
|
so_settled = [s for s in item.settlements if s.settled == so]
|
||||||
|
if len(so_settled) == 1:
|
||||||
|
so_settled[0].amount = amount
|
||||||
|
else:
|
||||||
|
s = Settlement(item.id, so, amount)
|
||||||
|
item.settlements.append(s)
|
||||||
|
request.dbsession.add(s)
|
||||||
|
allowed.append(so)
|
||||||
|
for i in (s for s in item.settlements if s.settled not in allowed):
|
||||||
|
item.settlements.remove(i)
|
||||||
|
request.dbsession.delete(i)
|
||||||
|
unsettled = get_settlements(item, request.dbsession)
|
||||||
|
|
||||||
|
if unsettled == 0 and update_table:
|
||||||
|
request.dbsession.query(Overview).filter(
|
||||||
|
Overview.voucher_id == item.id
|
||||||
|
).delete()
|
||||||
|
transaction.commit()
|
||||||
|
item = request.dbsession.query(Voucher).filter(Voucher.id == item.id).first()
|
||||||
|
return voucher_info(item)
|
||||||
|
|
||||||
|
|
||||||
160
barker/views/voucher/show.py
Normal file
160
barker/views/voucher/show.py
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
import re
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from pyramid.view import view_config
|
||||||
|
|
||||||
|
from barker.exceptions import ValidationFailure
|
||||||
|
from barker.models import Voucher, Overview, FoodTable, GuestBook
|
||||||
|
|
||||||
|
|
||||||
|
@view_config(
|
||||||
|
request_method="GET",
|
||||||
|
route_name="v1_vouchers_id",
|
||||||
|
renderer="json",
|
||||||
|
permission="Authenticated",
|
||||||
|
)
|
||||||
|
def show_id(request):
|
||||||
|
id_ = uuid.UUID(request.matchdict["id"])
|
||||||
|
item = request.dbsession.query(Voucher).filter(Voucher.id == id_).first()
|
||||||
|
return voucher_info(item)
|
||||||
|
|
||||||
|
|
||||||
|
@view_config(
|
||||||
|
request_method="GET",
|
||||||
|
route_name="v1_vouchers_new",
|
||||||
|
request_param="b",
|
||||||
|
renderer="json",
|
||||||
|
permission="Authenticated",
|
||||||
|
)
|
||||||
|
def show(request):
|
||||||
|
bill_id = request.GET["b"]
|
||||||
|
item = request.dbsession.query(Voucher)
|
||||||
|
if re.compile("^\d{2,}-\d{4}$").match(bill_id):
|
||||||
|
item = item.filter(
|
||||||
|
Voucher.bill_id == int(bill_id.replace("-", "")),
|
||||||
|
Voucher.voucher_type.in_([1, 3]),
|
||||||
|
)
|
||||||
|
elif re.compile("^NC-\d+$").match(bill_id):
|
||||||
|
item = item.filter(
|
||||||
|
Voucher.bill_id == int(bill_id.replace("NC-", "")),
|
||||||
|
Voucher.voucher_type == 2,
|
||||||
|
)
|
||||||
|
elif re.compile("^ST-\d+$").match(bill_id):
|
||||||
|
item = item.filter(
|
||||||
|
Voucher.bill_id == int(bill_id.replace("ST-", "")),
|
||||||
|
Voucher.voucher_type == 4,
|
||||||
|
)
|
||||||
|
item = item.first()
|
||||||
|
if item is None:
|
||||||
|
return {}
|
||||||
|
return voucher_info(item)
|
||||||
|
|
||||||
|
|
||||||
|
@view_config(
|
||||||
|
request_method="GET",
|
||||||
|
route_name="v1_vouchers_new",
|
||||||
|
request_param="t",
|
||||||
|
renderer="json",
|
||||||
|
permission="Authenticated",
|
||||||
|
)
|
||||||
|
def show_for_table(request):
|
||||||
|
table_id = uuid.UUID(request.GET["t"])
|
||||||
|
voucher_id = request.GET.get("v", None)
|
||||||
|
guest_id = request.GET.get("g", None)
|
||||||
|
if voucher_id is not None:
|
||||||
|
item = (
|
||||||
|
request.dbsession.query(Overview)
|
||||||
|
.filter(
|
||||||
|
Overview.voucher_id == uuid.UUID(voucher_id),
|
||||||
|
Overview.food_table_id == table_id,
|
||||||
|
)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
if item is None:
|
||||||
|
raise ValidationFailure("Bill Not Found")
|
||||||
|
else:
|
||||||
|
return voucher_info(item.voucher)
|
||||||
|
table = request.dbsession.query(FoodTable).filter(FoodTable.id == table_id).first()
|
||||||
|
if guest_id is not None:
|
||||||
|
guest = request.dbsession.query(GuestBook).filter(GuestBook.id == guest_id).first()
|
||||||
|
return voucher_blank(table, guest)
|
||||||
|
|
||||||
|
|
||||||
|
def voucher_info(item):
|
||||||
|
return {
|
||||||
|
"id": item.id,
|
||||||
|
"date": item.date.strftime("%d-%b-%Y %H:%M:%S"),
|
||||||
|
"pax": item.pax,
|
||||||
|
"user": {"id": item.user_id, "name": item.user.name},
|
||||||
|
"creationDate": item.creation_date.strftime("%d-%b-%Y %H:%M:%S"),
|
||||||
|
"lastEditDate": item.last_edit_date.strftime("%d-%b-%Y %H:%M:%S"),
|
||||||
|
"billId": item.bill_id,
|
||||||
|
"table": {"id": item.food_table_id, "name": item.food_table.name},
|
||||||
|
"customer": {"id": item.customer_id, "name": item.customer.name},
|
||||||
|
"settlements": [],
|
||||||
|
"narration": item.narration,
|
||||||
|
"void": item.is_void,
|
||||||
|
"voidReason": item.void_reason,
|
||||||
|
"printed": item.is_printed,
|
||||||
|
"voucherType": item.voucher_type,
|
||||||
|
"kotId": item.kot_id,
|
||||||
|
"kots": [
|
||||||
|
{
|
||||||
|
"id": k.id,
|
||||||
|
"code": k.code,
|
||||||
|
"date": k.date.strftime("%d-%b-%Y %H:%M:%S"),
|
||||||
|
"user": {"id": k.user_id, "name": k.user.name},
|
||||||
|
"inventories": [
|
||||||
|
{
|
||||||
|
"id": i.id,
|
||||||
|
"sortOrder": i.sort_order,
|
||||||
|
"product": {
|
||||||
|
"id": i.product_id,
|
||||||
|
"name": i.product.name,
|
||||||
|
"units": i.product.units,
|
||||||
|
"menuCategory": {
|
||||||
|
"id": i.product.menu_category_id,
|
||||||
|
"name": i.product.menu_category.name,
|
||||||
|
"discountLimit": i.product.menu_category.discount_limit,
|
||||||
|
},
|
||||||
|
"saleCategory": {
|
||||||
|
"id": i.product.sale_category_id,
|
||||||
|
"name": i.product.sale_category.name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"quantity": i.quantity,
|
||||||
|
"price": i.price,
|
||||||
|
"isHappyHour": i.is_happy_hour,
|
||||||
|
"taxRate": i.tax_rate,
|
||||||
|
"tax": {"id": i.tax_id, "name": i.tax.name},
|
||||||
|
"discount": i.discount,
|
||||||
|
"inventoryModifier": [
|
||||||
|
{
|
||||||
|
"modifier": {
|
||||||
|
"id": m.modifier.id,
|
||||||
|
"name": m.modifier.name,
|
||||||
|
"showInBill": m.modifier.show_in_bill,
|
||||||
|
},
|
||||||
|
"price": m.price,
|
||||||
|
}
|
||||||
|
for m in i.modifiers
|
||||||
|
],
|
||||||
|
}
|
||||||
|
for i in k.inventories
|
||||||
|
],
|
||||||
|
}
|
||||||
|
for k in item.kots
|
||||||
|
],
|
||||||
|
"reprints": [],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def voucher_blank(table, guest):
|
||||||
|
return {
|
||||||
|
"pax": table.seats if guest is None else guest.pax,
|
||||||
|
"table": {"id": table.id, "name": table.name},
|
||||||
|
"customer": {"id": guest.customer_id, "name": guest.customer.name},
|
||||||
|
"kots": []
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
40
barker/views/voucher/split.py
Normal file
40
barker/views/voucher/split.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
|
import transaction
|
||||||
|
from pyramid.view import view_config
|
||||||
|
|
||||||
|
from barker.models import Voucher, Overview
|
||||||
|
from barker.views.voucher.save import save_voucher
|
||||||
|
|
||||||
|
|
||||||
|
@view_config(
|
||||||
|
request_method="POST",
|
||||||
|
route_name="voucher_split",
|
||||||
|
renderer="json",
|
||||||
|
permission="Split Bill",
|
||||||
|
trans=True,
|
||||||
|
)
|
||||||
|
def split_voucher(request):
|
||||||
|
json = request.json_body
|
||||||
|
id_ = uuid.UUID(request.matchdict["id"])
|
||||||
|
item = request.dbsession.query(Voucher).filter(Voucher.id == id_).first()
|
||||||
|
item.void = True
|
||||||
|
item.void_reason = "Bill Split"
|
||||||
|
# TODO: Set the Void Settlement
|
||||||
|
|
||||||
|
new_one = save_voucher(json["One"], request.dbsession)
|
||||||
|
new_two = save_voucher(json["Two"], request.dbsession)
|
||||||
|
|
||||||
|
status = "printed" if item.is_printed else "running"
|
||||||
|
new_one.status = Overview(
|
||||||
|
voucher_id=None, food_table_id=new_one.food_table_id, status=status
|
||||||
|
)
|
||||||
|
|
||||||
|
request.dbsession.add(new_one.status)
|
||||||
|
request.dbsession.query(Overview).filter(Overview.voucher_id == item.id).update(
|
||||||
|
{Overview.voucher_id: new_two.id}
|
||||||
|
)
|
||||||
|
|
||||||
|
transaction.commit()
|
||||||
|
|
||||||
|
|
||||||
129
barker/views/voucher/update.py
Normal file
129
barker/views/voucher/update.py
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
import datetime
|
||||||
|
import uuid
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
|
import transaction
|
||||||
|
from pyramid.httpexceptions import HTTPForbidden
|
||||||
|
from pyramid.view import view_config
|
||||||
|
from sqlalchemy import func
|
||||||
|
|
||||||
|
from barker.exceptions import ValidationFailure
|
||||||
|
from barker.models import Voucher, Kot, Inventory, InventoryModifier, Overview
|
||||||
|
from barker.views.voucher import get_st_vat, get_settlements
|
||||||
|
from barker.views.voucher.show import voucher_info
|
||||||
|
|
||||||
|
|
||||||
|
@view_config(
|
||||||
|
request_method="POST", route_name="v1_vouchers_id", renderer="json", trans=True
|
||||||
|
)
|
||||||
|
def update(request):
|
||||||
|
now = datetime.now()
|
||||||
|
update_table = request.GET["u"]
|
||||||
|
json = request.json_body
|
||||||
|
id = uuid.UUID(request.matchdict["id"])
|
||||||
|
item = request.dbsession.query(Voucher).filter(Voucher.id == id).first()
|
||||||
|
|
||||||
|
if not json["Printed"] and "Print Kot" not in request.effective_principals:
|
||||||
|
raise HTTPForbidden("You are not allowed to print a kot")
|
||||||
|
|
||||||
|
if json["Printed"] and "Print Bill" not in request.effective_principals:
|
||||||
|
raise HTTPForbidden("You are not allowed to print bill")
|
||||||
|
|
||||||
|
if item.is_printed and "Edit Printed Bill" not in request.effective_principals:
|
||||||
|
raise HTTPForbidden("You are not allowed to edit a printed bill")
|
||||||
|
|
||||||
|
if item.is_printed and not json["Printed"]:
|
||||||
|
transaction.abort()
|
||||||
|
raise ValidationFailure("This Bill is already printed\nCannot add a Kot to it.")
|
||||||
|
|
||||||
|
if item.is_void:
|
||||||
|
transaction.abort()
|
||||||
|
raise ValidationFailure(
|
||||||
|
"This Bill is already void.\nReason: {0}".format(item.void_reason)
|
||||||
|
)
|
||||||
|
|
||||||
|
if item.is_printed and not json["Printed"]:
|
||||||
|
transaction.abort()
|
||||||
|
raise ValidationFailure("This Bill is already printed\nCannot add a Kot to it.")
|
||||||
|
|
||||||
|
item.pax = json["Pax"]
|
||||||
|
item.food_table_id = json["Table"]["FoodTableID"]
|
||||||
|
item.customer_id = json["Customer"]["CustomerID"]
|
||||||
|
item.voucher_type = json["VoucherType"]
|
||||||
|
if not item.is_printed and json["Printed"]:
|
||||||
|
item.date = now
|
||||||
|
type = [1, 3] if item.voucher_type in [1, 3] else [item.voucher_type]
|
||||||
|
item.bill_id = (
|
||||||
|
request.dbsession.query(func.coalesce(func.max(Voucher.bill_id), 0) + 1)
|
||||||
|
.filter(Voucher.voucher_type.in_(type))
|
||||||
|
.scalar()
|
||||||
|
)
|
||||||
|
|
||||||
|
item.is_printed = item.is_printed or json["Printed"]
|
||||||
|
item.user_id = json["User"]["UserID"]
|
||||||
|
item.last_edit_date = now
|
||||||
|
for k in item.kots:
|
||||||
|
for i in k.inventories:
|
||||||
|
i.service_tax_rate, i.vat_rate = get_st_vat(
|
||||||
|
i.service_tax_rate, i.vat_rate, item.voucher_type
|
||||||
|
)
|
||||||
|
i.discount = next(
|
||||||
|
Decimal(inv["Discount"])
|
||||||
|
for ko in json["Kots"]
|
||||||
|
for inv in ko["Inventories"]
|
||||||
|
if uuid.UUID(inv["InventoryID"]) == i.id
|
||||||
|
)
|
||||||
|
for k in (
|
||||||
|
k for k in json["Kots"] if k["KotID"] == "00000000-0000-0000-0000-000000000000"
|
||||||
|
):
|
||||||
|
kot = Kot(
|
||||||
|
item.id,
|
||||||
|
item.food_table_id,
|
||||||
|
item.date,
|
||||||
|
item.user_id,
|
||||||
|
dbsession=request.dbsession,
|
||||||
|
)
|
||||||
|
item.kots.append(kot)
|
||||||
|
request.dbsession.add(kot)
|
||||||
|
for index, i in enumerate(k["Inventories"]):
|
||||||
|
st, vat = get_st_vat(i["ServiceTaxRate"], i["VatRate"], json["VoucherType"])
|
||||||
|
inv = Inventory(
|
||||||
|
kot.id,
|
||||||
|
uuid.UUID(i["ProductID"]),
|
||||||
|
i["Quantity"],
|
||||||
|
i["Price"],
|
||||||
|
i["Discount"],
|
||||||
|
i["IsHappyHour"],
|
||||||
|
i["ServiceTaxID"],
|
||||||
|
st,
|
||||||
|
i["VatID"],
|
||||||
|
vat,
|
||||||
|
index,
|
||||||
|
)
|
||||||
|
kot.inventories.append(inv)
|
||||||
|
request.dbsession.add(inv)
|
||||||
|
for m in i["Modifiers"]:
|
||||||
|
mod = InventoryModifier(None, uuid.UUID(m["ModifierID"]), 0)
|
||||||
|
inv.modifiers.append(mod)
|
||||||
|
request.dbsession.add(mod)
|
||||||
|
get_settlements(item, request.dbsession)
|
||||||
|
if update_table:
|
||||||
|
vft = (
|
||||||
|
request.dbsession.query(Overview)
|
||||||
|
.filter(Overview.voucher_id == item.id)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
status = "printed" if item.is_printed else "running"
|
||||||
|
if vft is None:
|
||||||
|
item.status = Overview(
|
||||||
|
voucher_id=None, food_table_id=item.food_table_id, status=status
|
||||||
|
)
|
||||||
|
request.dbsession.add(item.status)
|
||||||
|
else:
|
||||||
|
vft.status = status
|
||||||
|
vft.food_table_id = item.food_table_id
|
||||||
|
transaction.commit()
|
||||||
|
item = request.dbsession.query(Voucher).filter(Voucher.id == item.id).first()
|
||||||
|
return voucher_info(item)
|
||||||
|
|
||||||
|
|
||||||
48
barker/views/voucher/void.py
Normal file
48
barker/views/voucher/void.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
|
import transaction
|
||||||
|
from pyramid.view import view_config
|
||||||
|
|
||||||
|
from barker.models import Voucher, SettleOption, Settlement
|
||||||
|
from barker.views.voucher import get_settlements
|
||||||
|
from barker.views.voucher.show import voucher_info
|
||||||
|
|
||||||
|
|
||||||
|
@view_config(
|
||||||
|
request_method="POST",
|
||||||
|
route_name="voucher_void",
|
||||||
|
renderer="json",
|
||||||
|
permission="Void Bill",
|
||||||
|
trans=True,
|
||||||
|
)
|
||||||
|
def void_voucher(request):
|
||||||
|
update_table = request.GET["u"]
|
||||||
|
json = request.json_body
|
||||||
|
id_ = uuid.UUID(request.matchdict["id"])
|
||||||
|
item = request.dbsession.query(Voucher).filter(Voucher.id == id_).first()
|
||||||
|
|
||||||
|
item.void = True
|
||||||
|
item.void_reason = json["Reason"]
|
||||||
|
|
||||||
|
amount = round(-1 * sum(i.amount for k in item.kots for i in k.inventories), 5) * -1
|
||||||
|
s = Settlement(item.id, SettleOption.VOID(), amount)
|
||||||
|
item.settlements.append(s)
|
||||||
|
request.dbsession.add(s)
|
||||||
|
allowed = [
|
||||||
|
SettleOption.AMOUNT(),
|
||||||
|
SettleOption.ROUND_OFF(),
|
||||||
|
SettleOption.UNSETTLED(),
|
||||||
|
SettleOption.VOID(),
|
||||||
|
]
|
||||||
|
for i in (s for s in item.settlements if s.settled not in allowed):
|
||||||
|
item.settlements.remove(i)
|
||||||
|
request.dbsession.delete(i)
|
||||||
|
get_settlements(item, request.dbsession)
|
||||||
|
|
||||||
|
if update_table:
|
||||||
|
request.dbsession.delete(item.status)
|
||||||
|
transaction.commit()
|
||||||
|
item = request.dbsession.query(Voucher).filter(Voucher.id == item.id).first()
|
||||||
|
return voucher_info(item)
|
||||||
|
|
||||||
|
|
||||||
@ -6,4 +6,5 @@ export class Table {
|
|||||||
seats: number;
|
seats: number;
|
||||||
section: Section;
|
section: Section;
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
|
voucherId?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,37 +1,54 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import { MatDialog } from '@angular/material';
|
||||||
|
import { BehaviorSubject } from "rxjs";
|
||||||
import { Product } from '../core/product';
|
import { Product } from '../core/product';
|
||||||
import { ModifiersComponent } from './modifiers/modifiers.component';
|
import { ModifiersComponent } from './modifiers/modifiers.component';
|
||||||
import { MatDialog } from '@angular/material';
|
|
||||||
import { ModifierCategoryService } from '../modifier-categories/modifier-category.service';
|
import { ModifierCategoryService } from '../modifier-categories/modifier-category.service';
|
||||||
import {Subject} from "rxjs";
|
import { ModifierCategory } from "../core/modifier-category";
|
||||||
import {Modifier} from "../core/modifier";
|
|
||||||
import {ModifierCategory} from "../core/modifier-category";
|
|
||||||
import {isNotNullOrUndefined} from "codelyzer/util/isNotNullOrUndefined";
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BillService {
|
export class BillService {
|
||||||
public dataObs = new Subject<any[]>();
|
public dataObs;
|
||||||
public data = [];
|
public data;
|
||||||
constructor(
|
|
||||||
private dialog: MatDialog,
|
|
||||||
private modifierCategoryService: ModifierCategoryService
|
|
||||||
) { }
|
|
||||||
|
|
||||||
addProduct(product: Product) {
|
constructor(
|
||||||
let item = {
|
private dialog: MatDialog,
|
||||||
isKot: false,
|
private modifierCategoryService: ModifierCategoryService
|
||||||
product: product,
|
) {
|
||||||
productId: product.id,
|
this.data = [];
|
||||||
info: `${product.name} (${product.units}) @ ${product.price}`,
|
this.dataObs = new BehaviorSubject<any[]>(this.data);
|
||||||
quantity: 1,
|
}
|
||||||
modifiers: []
|
|
||||||
};
|
loadData(d: any): void {
|
||||||
this.data.push(item);
|
console.log("data loaded");
|
||||||
this.modifierCategoryService.listIsActiveOfProduct(product.id).subscribe(result => {
|
this.data = d;
|
||||||
if (result.reduce((a: any, c: ModifierCategory) => {return a + c.minimum}, 0)) {
|
this.data.push({isKot: true, newKot: true, info: "== New Kot =="})
|
||||||
this.showModifier(item);
|
this.dataObs.next(this.data);
|
||||||
}
|
|
||||||
});
|
}
|
||||||
|
addProduct(product: Product): void {
|
||||||
|
let old = this.data.find(x=> !x.isKot && x.productId == product.id && x.isHappyHour == product.hasHappyHour);
|
||||||
|
if (old !== undefined) {
|
||||||
|
old.quantity += 1;
|
||||||
|
} else {
|
||||||
|
let item = {
|
||||||
|
isKot: false,
|
||||||
|
product: product,
|
||||||
|
productId: product.id,
|
||||||
|
isHappyHour: product.hasHappyHour,
|
||||||
|
info: `${product.name} (${product.units}) @ ${product.price}`,
|
||||||
|
quantity: 1,
|
||||||
|
modifiers: []
|
||||||
|
};
|
||||||
|
this.data.push(item);
|
||||||
|
this.modifierCategoryService.listIsActiveOfProduct(product.id).subscribe(result => {
|
||||||
|
if (result.reduce((a: any, c: ModifierCategory) => {
|
||||||
|
return a + c.minimum
|
||||||
|
}, 0)) {
|
||||||
|
this.showModifier(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
this.dataObs.next(this.data);
|
this.dataObs.next(this.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +65,7 @@ export class BillService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
dialogRef.afterClosed().subscribe(result => {
|
dialogRef.afterClosed().subscribe(result => {
|
||||||
if (isNotNullOrUndefined(result)) {
|
if (result !== undefined) {
|
||||||
item.modifiers = result;
|
item.modifiers = result;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,19 +1,21 @@
|
|||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router';
|
||||||
import {Observable} from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
import {TableService} from '../../tables/table.service';
|
import { VoucherService } from "./voucher.service";
|
||||||
|
import { Bill } from "./bill";
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class BillResolver implements Resolve<any[]> {
|
export class BillResolver implements Resolve<Bill> {
|
||||||
|
|
||||||
constructor(private ser: TableService, private router: Router) {
|
constructor(private ser: VoucherService, private router: Router) {
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any[]> {
|
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Bill> {
|
||||||
const tableId = route.queryParamMap.get('table');
|
const tableId = route.queryParamMap.get('table');
|
||||||
const guestId = route.queryParamMap.get('guest');
|
const guestId = route.queryParamMap.get('guest');
|
||||||
return this.ser.list();
|
const voucherId = route.queryParamMap.get('voucher');
|
||||||
|
return this.ser.getFromTable(tableId, voucherId, guestId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@ export class Inventory {
|
|||||||
taxRate: number;
|
taxRate: number;
|
||||||
tax: Tax;
|
tax: Tax;
|
||||||
discount: number;
|
discount: number;
|
||||||
modifiers: Modifier;
|
modifiers: Modifier[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Kot {
|
export class Kot {
|
||||||
|
|||||||
@ -1,6 +1,11 @@
|
|||||||
.kot {
|
.kot {
|
||||||
background-color: red;
|
background-color: hotpink;
|
||||||
font-weight: bold;
|
}
|
||||||
|
.printed {
|
||||||
|
background-color: lightpink;
|
||||||
|
}
|
||||||
|
.new-kot {
|
||||||
|
background-color: lightblue;
|
||||||
}
|
}
|
||||||
|
|
||||||
.square-button {
|
.square-button {
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
<mat-table #table [dataSource]="dataSource" aria-label="Elements">
|
<mat-table #table [dataSource]="dataSource" aria-label="Elements">
|
||||||
<!-- Info Column -->
|
<!-- Info Column -->
|
||||||
<ng-container matColumnDef="info">
|
<ng-container matColumnDef="info">
|
||||||
<mat-cell *matCellDef="let row" fxLayout="column" fxLayoutAlign="space-around start" [class.kot]="row.isKot">
|
<mat-cell *matCellDef="let row" fxLayout="column" fxLayoutAlign="start space-between end">
|
||||||
<span>
|
<span>
|
||||||
{{row.info}}
|
{{row.info}}
|
||||||
</span>
|
</span>
|
||||||
@ -19,26 +19,27 @@
|
|||||||
<ng-container matColumnDef="quantity">
|
<ng-container matColumnDef="quantity">
|
||||||
<mat-header-cell *matHeaderCellDef>Quantity</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef>Quantity</mat-header-cell>
|
||||||
<mat-cell *matCellDef="let row">
|
<mat-cell *matCellDef="let row">
|
||||||
<button mat-icon-button (click)="subtractOne(row)">
|
<button mat-icon-button (click)="subtractOne(row)" [disabled]="row.isPrinted" *ngIf="!row.isKot">
|
||||||
<mat-icon class="del">indeterminate_check_box</mat-icon>
|
<mat-icon class="del">indeterminate_check_box</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<button mat-icon-button (click)="quantity(row)">
|
<button mat-icon-button (click)="quantity(row)" [disabled]="row.isPrinted" *ngIf="!row.isKot">
|
||||||
{{row.quantity}}
|
{{row.quantity}}
|
||||||
</button>
|
</button>
|
||||||
<button mat-icon-button (click)="addOne(row)">
|
<button mat-icon-button (click)="addOne(row)" [disabled]="row.isPrinted" *ngIf="!row.isKot">
|
||||||
<mat-icon class="del">control_point</mat-icon>
|
<mat-icon class="del">control_point</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<button mat-icon-button (click)="removeItem(row)">
|
<button mat-icon-button (click)="removeItem(row)" [disabled]="row.isPrinted" *ngIf="!row.isKot">
|
||||||
<mat-icon class="del">cancel</mat-icon>
|
<mat-icon class="del">cancel</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<button mat-icon-button (click)="modifier(row)">
|
<button mat-icon-button (click)="modifier(row)" [disabled]="row.isPrinted" *ngIf="!row.isKot">
|
||||||
<mat-icon class="del">assignment</mat-icon>
|
<mat-icon class="del">assignment</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
</mat-cell>
|
</mat-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
|
|
||||||
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
|
<mat-row *matRowDef="let row; columns: displayedColumns;" [class.kot]="row.isKot" [class.new-kot]="row.newKot"
|
||||||
|
[class.printed]="row.isPrinted"></mat-row>
|
||||||
</mat-table>
|
</mat-table>
|
||||||
</mat-card-content>
|
</mat-card-content>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { ActivatedRoute } from '@angular/router';
|
import { ActivatedRoute } from '@angular/router';
|
||||||
import {Bill, Inventory, Kot} from './bill';
|
import {Bill, Inventory, Kot} from './bill';
|
||||||
import {ModifierCategoryListDatasource} from '../../modifier-categories/modifier-category-list/modifier-category-list-datasource';
|
|
||||||
import {BillsDataSource} from './bills-datasource';
|
import {BillsDataSource} from './bills-datasource';
|
||||||
import {BillService} from "../bill.service";
|
import {BillService} from "../bill.service";
|
||||||
|
|
||||||
@ -13,7 +12,6 @@ import {BillService} from "../bill.service";
|
|||||||
export class BillsComponent implements OnInit {
|
export class BillsComponent implements OnInit {
|
||||||
dataSource: BillsDataSource;
|
dataSource: BillsDataSource;
|
||||||
item: Bill;
|
item: Bill;
|
||||||
view: any[];
|
|
||||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||||
displayedColumns: string[] = ['info', 'quantity'];
|
displayedColumns: string[] = ['info', 'quantity'];
|
||||||
|
|
||||||
@ -24,18 +22,35 @@ export class BillsComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
console.log("ds set")
|
||||||
|
this.dataSource = new BillsDataSource(this.bs.dataObs);
|
||||||
this.route.data
|
this.route.data
|
||||||
.subscribe((data: { item: Bill }) => {
|
.subscribe((data: { item: Bill }) => {
|
||||||
this.updateView(data.item);
|
this.updateView(data.item);
|
||||||
});
|
});
|
||||||
this.dataSource = new BillsDataSource(this.bs.dataObs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateView(item) {
|
updateView(item) {
|
||||||
this.item = item;
|
this.item = item;
|
||||||
// this.view = item.kots.reduce((p: Kot, c:Kot) => {
|
let view = item.kots.map(k => {
|
||||||
//
|
return [{
|
||||||
// }, [])
|
isKot: true,
|
||||||
|
}, ...k.inventories.map(i => {
|
||||||
|
return {
|
||||||
|
id: i.id,
|
||||||
|
isKot: false,
|
||||||
|
product: i.product,
|
||||||
|
productId: i.product.id,
|
||||||
|
isHappyHour: i.isHappyHour,
|
||||||
|
isPrinted: true,
|
||||||
|
info: `${i.product.name} (${i.product.units}) @ ${i.price}`,
|
||||||
|
quantity: 1,
|
||||||
|
modifiers: i.modifiers
|
||||||
|
}
|
||||||
|
})]
|
||||||
|
});
|
||||||
|
view = view.reduce((a, c) => {return a.concat(c)} , []);
|
||||||
|
this.bs.loadData(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
addOne(item: any): void {
|
addOne(item: any): void {
|
||||||
|
|||||||
70
bookie/src/app/sales/bills/voucher.service.ts
Normal file
70
bookie/src/app/sales/bills/voucher.service.ts
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
|
import { catchError } from 'rxjs/operators';
|
||||||
|
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||||
|
import { ErrorLoggerService } from '../../core/error-logger.service';
|
||||||
|
import {Bill} from "./bill";
|
||||||
|
|
||||||
|
const httpOptions = {
|
||||||
|
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||||
|
};
|
||||||
|
|
||||||
|
const url = '/v1/vouchers';
|
||||||
|
const serviceName = 'VoucherService';
|
||||||
|
|
||||||
|
@Injectable({providedIn: 'root'})
|
||||||
|
export class VoucherService {
|
||||||
|
|
||||||
|
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
get(id: string): Observable<Bill> {
|
||||||
|
return <Observable<Bill>>this.http.get<Bill>(`${url}/${id}`)
|
||||||
|
.pipe(
|
||||||
|
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
getFromTable(tableId: string, voucherId: string, guestId: string): Observable<Bill> {
|
||||||
|
let params = new HttpParams();
|
||||||
|
if (tableId !== null) {
|
||||||
|
params = params.set('t', tableId);
|
||||||
|
}
|
||||||
|
if (voucherId !== null) {
|
||||||
|
params = params.set('v', voucherId);
|
||||||
|
}
|
||||||
|
if (guestId !== null) {
|
||||||
|
params = params.set('g', guestId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Observable<Bill>>this.http.get<Bill>(`${url}/new`, {params: params})
|
||||||
|
.pipe(
|
||||||
|
catchError(this.log.handleError(
|
||||||
|
serviceName,
|
||||||
|
`getFromTable tableId=${tableId} voucherId=${voucherId} guestId=${guestId}`
|
||||||
|
))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
save(voucher: Bill): Observable<Bill> {
|
||||||
|
return <Observable<Bill>>this.http.post<Bill>(`${url}/new`, voucher, httpOptions)
|
||||||
|
.pipe(
|
||||||
|
catchError(this.log.handleError(serviceName, 'save'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
update(voucher: Bill): Observable<Bill> {
|
||||||
|
return <Observable<Bill>>this.http.put<Bill>(`${url}/${voucher.id}`, voucher, httpOptions)
|
||||||
|
.pipe(
|
||||||
|
catchError(this.log.handleError(serviceName, 'update'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
saveOrUpdate(voucher: Bill): Observable<Bill> {
|
||||||
|
if (!voucher.id) {
|
||||||
|
return this.save(voucher);
|
||||||
|
} else {
|
||||||
|
return this.update(voucher);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -13,6 +13,6 @@ export class RunningTablesResolver implements Resolve<Table[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Table[]> {
|
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Table[]> {
|
||||||
return this.ser.list();
|
return this.ser.running();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,23 @@
|
|||||||
|
.running {
|
||||||
|
background-color: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
.printed {
|
||||||
|
background-color: firebrick;
|
||||||
|
}
|
||||||
|
|
||||||
.square-button {
|
.square-button {
|
||||||
min-width: 150px;
|
min-width: 150px;
|
||||||
max-width: 150px;
|
max-width: 150px;
|
||||||
min-height: 150px;
|
min-height: 150px;
|
||||||
|
max-height: 150px;
|
||||||
|
margin: 20px;
|
||||||
|
}
|
||||||
|
.item-name {
|
||||||
|
text-align: center;
|
||||||
|
padding: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.center {
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,13 @@
|
|||||||
<mat-card-title>Running Tables</mat-card-title>
|
<mat-card-title>Running Tables</mat-card-title>
|
||||||
</mat-card-title-group>
|
</mat-card-title-group>
|
||||||
<mat-card-content fxLayout="row wrap" fxLayoutGap="grid 20px">
|
<mat-card-content fxLayout="row wrap" fxLayoutGap="grid 20px">
|
||||||
<button mat-raised-button class="square-button"
|
<mat-card fxLayout="column" class="square-button"
|
||||||
*ngFor="let table of list" [routerLink]="['../bill']" [queryParams]="{table: table.id}" queryParamsHandling="merge">{{table.name}}</button>
|
*ngFor="let table of list" (click)="navigateToBill(table)"
|
||||||
|
[class.running]="table.status === 'running'" [class.printed]="table.status === 'printed'">
|
||||||
|
<h3 class="item-name">{{table.name}}</h3>
|
||||||
|
<span class="center">{{table.pax || 0}} / {{table.seats}} Seats</span>
|
||||||
|
<span class="center" *ngIf="table.date">{{table.date}}</span>
|
||||||
|
<span class="center" *ngIf="table.amount">{{table.amount}}</span>
|
||||||
|
</mat-card>
|
||||||
</mat-card-content>
|
</mat-card-content>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { ActivatedRoute } from '@angular/router';
|
import { ActivatedRoute, NavigationExtras, Router } from '@angular/router';
|
||||||
import { Table } from '../../core/table';
|
import { Table } from '../../core/table';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -10,7 +10,7 @@ import { Table } from '../../core/table';
|
|||||||
export class RunningTablesComponent implements OnInit {
|
export class RunningTablesComponent implements OnInit {
|
||||||
list: Table[];
|
list: Table[];
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute) {
|
constructor(private router: Router, private route: ActivatedRoute) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@ -19,4 +19,17 @@ export class RunningTablesComponent implements OnInit {
|
|||||||
this.list = data.list;
|
this.list = data.list;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
navigateToBill(table: Table): void {
|
||||||
|
let qp = {table: table.id};
|
||||||
|
if (table.voucherId) {
|
||||||
|
qp["voucher"] = table.voucherId;
|
||||||
|
}
|
||||||
|
let navigationExtras: NavigationExtras = {
|
||||||
|
queryParams: qp,
|
||||||
|
queryParamsHandling: 'merge',
|
||||||
|
preserveFragment: true
|
||||||
|
};
|
||||||
|
this.router.navigate(['/sales', 'bill'], navigationExtras);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,7 +43,7 @@ const routes: Routes = [
|
|||||||
permission: 'Guest Book'
|
permission: 'Guest Book'
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
list: BillResolver
|
item: BillResolver
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
|
|||||||
@ -34,6 +34,14 @@ export class TableService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
running(): Observable<Table[]> {
|
||||||
|
const options = {params: new HttpParams().set('a', 'true')};
|
||||||
|
return <Observable<Table[]>>this.http.get<Table[]>(url, options)
|
||||||
|
.pipe(
|
||||||
|
catchError(this.log.handleError(serviceName, 'running'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
save(tables: Table): Observable<Table> {
|
save(tables: Table): Observable<Table> {
|
||||||
return <Observable<Table>>this.http.post<Table>(`${url}/new`, tables, httpOptions)
|
return <Observable<Table>>this.http.post<Table>(`${url}/new`, tables, httpOptions)
|
||||||
.pipe(
|
.pipe(
|
||||||
|
|||||||
Reference in New Issue
Block a user