From f9e784b12fbfdbcde60716cbecbb2c3bae61e15a Mon Sep 17 00:00:00 2001 From: Amritanshu Date: Mon, 19 Aug 2019 15:58:02 +0530 Subject: [PATCH] Cashier checkout should now work --- DB/migrate.cmd | 8 +- barker/models/master.py | 2 +- barker/models/voucher.py | 4 +- barker/routes.py | 6 +- barker/scripts/fixtures.py | 240 ++++++++++-------- barker/views/reports/checkout.py | 154 ++++++----- barker/views/voucher/void.py | 3 +- bookie/src/app/app-routing.module.ts | 4 + .../active-cashiers-resolver.service.spec.ts | 15 ++ .../active-cashiers-resolver.service.ts | 20 ++ .../cashier-checkout-datasource.ts | 18 ++ .../cashier-checkout-resolver.service.spec.ts | 15 ++ .../cashier-checkout-resolver.service.ts | 21 ++ .../cashier-checkout-routing.module.spec.ts | 13 + .../cashier-checkout-routing.module.ts | 52 ++++ .../cashier-checkout.component.css | 4 + .../cashier-checkout.component.html | 56 ++++ .../cashier-checkout.component.spec.ts | 25 ++ .../cashier-checkout.component.ts | 96 +++++++ .../cashier-checkout.module.spec.ts | 13 + .../cashier-checkout.module.ts | 71 ++++++ .../cashier-checkout.service.spec.ts | 15 ++ .../cashier-checkout.service.ts | 55 ++++ .../app/cashier-checkout/cashier-checkout.ts | 21 ++ bookie/src/app/home/home.component.html | 3 + 25 files changed, 753 insertions(+), 181 deletions(-) create mode 100644 bookie/src/app/cashier-checkout/active-cashiers-resolver.service.spec.ts create mode 100644 bookie/src/app/cashier-checkout/active-cashiers-resolver.service.ts create mode 100644 bookie/src/app/cashier-checkout/cashier-checkout-datasource.ts create mode 100644 bookie/src/app/cashier-checkout/cashier-checkout-resolver.service.spec.ts create mode 100644 bookie/src/app/cashier-checkout/cashier-checkout-resolver.service.ts create mode 100644 bookie/src/app/cashier-checkout/cashier-checkout-routing.module.spec.ts create mode 100644 bookie/src/app/cashier-checkout/cashier-checkout-routing.module.ts create mode 100644 bookie/src/app/cashier-checkout/cashier-checkout.component.css create mode 100644 bookie/src/app/cashier-checkout/cashier-checkout.component.html create mode 100644 bookie/src/app/cashier-checkout/cashier-checkout.component.spec.ts create mode 100644 bookie/src/app/cashier-checkout/cashier-checkout.component.ts create mode 100644 bookie/src/app/cashier-checkout/cashier-checkout.module.spec.ts create mode 100644 bookie/src/app/cashier-checkout/cashier-checkout.module.ts create mode 100644 bookie/src/app/cashier-checkout/cashier-checkout.service.spec.ts create mode 100644 bookie/src/app/cashier-checkout/cashier-checkout.service.ts create mode 100644 bookie/src/app/cashier-checkout/cashier-checkout.ts diff --git a/DB/migrate.cmd b/DB/migrate.cmd index 400235d..be6a9be 100644 --- a/DB/migrate.cmd +++ b/DB/migrate.cmd @@ -2,10 +2,10 @@ call:copyQuery a-Roles "SELECT 'INSERT INTO roles(id, name) VALUES (''' + CAST(GroupID AS Nvarchar(36)) + ''', ''' + Name + ''');' FROM Test.dbo.Auth_Groups;" call:copyQuery b-Permissions "SELECT 'INSERT INTO permissions(id, name) VALUES (''' + CAST(RoleID AS Nvarchar(36)) + ''', ''' + Name + ''');' FROM Test.dbo.Auth_Roles;" 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, password, locked_out) VALUES (''' + CAST(UserID AS Nvarchar(36)) + ''', ''' + Name + ''', ''' + 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 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 f-Customers "SELECT 'INSERT INTO customers(id, name, address, company, phone) VALUES (''' + CAST(CustomerID AS Nvarchar(36)) + ''', ''' + REPLACE(Name, '''', '''''') + ''', ''' + COALESCE(Address, 'null') + ''', '''', ' + CASE WHEN Phone = '' THEN 'null' ELSE '''' + COALESCE(Phone, Name) + '''' END + ');' 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 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;" @@ -16,7 +16,7 @@ call:copyQuery m-Sections "SELECT 'INSERT INTO sections(id, name) VALUES (''' + 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 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 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, 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 = 0 THEN '0' ELSE CAST(VoucherType AS Nvarchar(36)) END + ', ' + CAST(KotID AS Nvarchar(36)) + ');' FROM Test.dbo.Vouchers;" +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, 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 = 0 THEN '0' WHEN Void = 1 THEN '5' ELSE CAST(VoucherType AS Nvarchar(36)) END + ', ' + CAST(KotID AS Nvarchar(36)) + ');' FROM Test.dbo.Vouchers;" 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-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-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;" @@ -33,4 +33,4 @@ goto:eof echo. echo. Copying %~1 bcp "%~2" queryout Data\%~1.sql -c -t',' -S . -U sa -P 123456 -goto:eof \ No newline at end of file +goto:eof diff --git a/barker/models/master.py b/barker/models/master.py index ed5dd2f..eb640f6 100644 --- a/barker/models/master.py +++ b/barker/models/master.py @@ -24,7 +24,7 @@ class Customer(Base): id = Column("id", GUID(), primary_key=True, default=uuid.uuid4) company = Column("company", Unicode(255), nullable=False) name = Column("name", Unicode(255), nullable=False) - phone = Column("phone", Unicode(255), nullable=False, unique=True) + phone = Column("phone", Unicode(255), nullable=True, unique=True) address = Column("address", Unicode(255), nullable=False) @property diff --git a/barker/models/voucher.py b/barker/models/voucher.py index b8f886d..3da255d 100644 --- a/barker/models/voucher.py +++ b/barker/models/voucher.py @@ -13,7 +13,6 @@ from sqlalchemy import ( Numeric, ForeignKey, UniqueConstraint, - func, case, ) from sqlalchemy.orm import relationship, backref, synonym @@ -26,6 +25,7 @@ class VoucherType(Enum): REGULAR_BILL = 1 NO_CHARGE = 2 STAFF = 4 + VOID = 5 class GuestBook(Base): @@ -186,6 +186,8 @@ class Voucher(Base): return "ST-" + str(self.bill_id) if self.voucher_type == VoucherType.REGULAR_BILL: return str(self.bill_id // 10000) + "-" + str(self.bill_id % 10000) + if self.voucher_type == VoucherType.VOID: + return "K-" + str(self.kot_id) else: raise Exception diff --git a/barker/routes.py b/barker/routes.py index 490b90b..92dce57 100644 --- a/barker/routes.py +++ b/barker/routes.py @@ -353,6 +353,10 @@ def includeme(config): config.add_route("v1_move_table", "/v1/move-table") config.add_route("v1_move_kot", "/v1/move-kot") + config.add_route("v1_active_cashiers", "/v1/active-cashiers") + config.add_route("v1_checkout_id", "/v1/checkout/{id}") + config.add_route("v1_checkout_blank", "/v1/checkout") + # Done till here config.add_route("customer", "/Customer.json") @@ -393,8 +397,6 @@ def includeme(config): config.add_route("api_lock_info", "/api/LockInfo") config.add_route("api_maintenance", "/api/Maintenance") - config.add_route("active_cashiers", "/Cashiers.json") - config.add_route("checkout", "/Checkout/{id}.json") # config.add_route('customer_id', '/Customer/{id}.json') config.add_route("beer_consumption", "/BeerConsumption.json") diff --git a/barker/scripts/fixtures.py b/barker/scripts/fixtures.py index 371a880..bd92aaa 100644 --- a/barker/scripts/fixtures.py +++ b/barker/scripts/fixtures.py @@ -11,7 +11,6 @@ from barker.models import ( DbSetting, Permission, User, - FoodTable, get_engine, get_session_factory, get_tm_session, @@ -45,123 +44,27 @@ def main(argv=sys.argv): with transaction.manager: dbsession = get_tm_session(session_factory, transaction.manager) - permissions = [ - Permission( - "Accounts Audit", uuid.UUID("f30fd1fb-df09-46f5-8c5d-181fd46f38de") - ), - Permission( - "Beer Consumption", uuid.UUID("efbb8f31-9631-4491-92f4-17cc98e6a0c0") - ), - Permission( - "Bill Details", uuid.UUID("612bb529-b50d-4653-a1c0-ebb725c7d728") - ), - Permission( - "Cashier Checkout", uuid.UUID("a86f8bcf-66f4-4c44-89e1-b714488b8331") - ), - Permission( - "Change Rate", uuid.UUID("10c63aae-0e48-4e54-b3b8-dd8a80b88fbf") - ), - Permission("Customers", uuid.UUID("e5fef133-cdbe-441f-bb54-1f0db0c5db79")), - Permission("Discount", uuid.UUID("1f66f131-0105-4466-8f8e-21e0ccc2ac27")), - Permission( - "Discount Report", uuid.UUID("0d8ba1d5-6731-417c-ab0e-be03cfdc96db") - ), - Permission( - "Edit Printed Bill", uuid.UUID("4ff6cb0f-93cb-4760-8219-4de280eaa957") - ), - Permission( - "Edit Printed Product", - uuid.UUID("959713be-d753-4e14-8ecd-e27f33587499"), - ), - Permission("Guest Book", uuid.UUID("7669dfc9-cc75-4e48-b267-145c8832a83c")), - Permission("Machines", uuid.UUID("f12b573f-edcb-490d-91c3-fa76f6502ffd")), - Permission("Merge Kots", uuid.UUID("bed774e9-4857-43b0-a4af-40230c9eb5db")), - Permission( - "Merge Tables", uuid.UUID("dfc493fb-ac14-4602-8596-f93f47b617de") - ), - Permission("Modifiers", uuid.UUID("9dc82529-1e86-41b4-a152-eaea9f775fea")), - Permission( - "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: - dbsession.add(permission) - - roles = [ - Role("Owner", uuid.UUID("06ec0ddb-949c-4357-aefb-65e5e55a9ae7")), - Role("Accountant", uuid.UUID("57d4538c-257a-4bf4-9a42-342992cb6af3")), - Role("Bar Captain", uuid.UUID("5a8ebb05-4817-45a5-866f-e523c30bfa25")), - Role("Captain", uuid.UUID("8db7001f-0964-4607-84f5-b6f4d9183fef")), - Role("Cashier", uuid.UUID("f1f0b112-1404-4b55-b121-f07ee6e08d12")), - Role("Controller", uuid.UUID("d9a5a478-1fe4-4847-84da-63cfba1a094a")), - Role("Manager", uuid.UUID("90ea7b14-9057-4bfd-a7cf-0ee7a3bb2463")), - Role("Senior Captain", uuid.UUID("d9b1b433-1ed5-4109-8ab2-cbd48ff010cd")), - Role("Server", uuid.UUID("6b378b71-f091-4485-a589-8db94ff1d6a4")), - ] - - roles[0].permissions = permissions - 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[3].permissions = list(permissions[i] for i in [16]) - 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[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[8].permissions = list(permissions[i] for i in [21, 24]) - - for role in roles: - dbsession.add(role) - - admin = User("Admin", "123456", False) - admin.roles.append(roles[0]) - dbsession.add(admin) + prod = True + if prod: + dbsession.add(Permission("Guest Book", uuid.UUID("7669dfc9-cc75-4e48-b267-145c8832a83c"))) + dbsession.add(Permission("Printers", uuid.UUID("5b66c6f6-003a-4ef8-ba28-49b8ff1ac33c"))) + dbsession.add(Permission("Sections", uuid.UUID("c973f32c-a37b-496a-8dc5-60d2e4c39e97"))) + else: + add_permissions(dbsession) main_section = Section( "Main", uuid.UUID("3f13f6e7-dc76-4fca-8fdb-b2bbf29b35df") ) dbsession.add(main_section) mcs = [ + ModifierCategory( + "Old Modifiers", + 0, + 0, + True, + 0, + uuid.UUID("e046ad33-dc65-4c78-8833-c3d3538d44c0"), + ), ModifierCategory( "Bar Instructions", 0, @@ -249,3 +152,116 @@ def main(argv=sys.argv): {"Text": "Call: 0172-4026666, 8054923853, 8054923856"}, ) ) + +def add_permissions(dbsession): + permissions = [ + Permission( + "Accounts Audit", uuid.UUID("f30fd1fb-df09-46f5-8c5d-181fd46f38de") + ), + Permission( + "Beer Consumption", uuid.UUID("efbb8f31-9631-4491-92f4-17cc98e6a0c0") + ), + Permission( + "Bill Details", uuid.UUID("612bb529-b50d-4653-a1c0-ebb725c7d728") + ), + Permission( + "Cashier Checkout", uuid.UUID("a86f8bcf-66f4-4c44-89e1-b714488b8331") + ), + Permission( + "Change Rate", uuid.UUID("10c63aae-0e48-4e54-b3b8-dd8a80b88fbf") + ), + Permission("Customers", uuid.UUID("e5fef133-cdbe-441f-bb54-1f0db0c5db79")), + Permission("Discount", uuid.UUID("1f66f131-0105-4466-8f8e-21e0ccc2ac27")), + Permission( + "Discount Report", uuid.UUID("0d8ba1d5-6731-417c-ab0e-be03cfdc96db") + ), + Permission( + "Edit Printed Bill", uuid.UUID("4ff6cb0f-93cb-4760-8219-4de280eaa957") + ), + Permission( + "Edit Printed Product", + uuid.UUID("959713be-d753-4e14-8ecd-e27f33587499"), + ), + Permission("Guest Book", uuid.UUID("7669dfc9-cc75-4e48-b267-145c8832a83c")), + Permission("Machines", uuid.UUID("f12b573f-edcb-490d-91c3-fa76f6502ffd")), + Permission("Merge Kots", uuid.UUID("bed774e9-4857-43b0-a4af-40230c9eb5db")), + Permission( + "Merge Tables", uuid.UUID("dfc493fb-ac14-4602-8596-f93f47b617de") + ), + Permission("Modifiers", uuid.UUID("9dc82529-1e86-41b4-a152-eaea9f775fea")), + Permission( + "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: + dbsession.add(permission) + + roles = [ + Role("Owner", uuid.UUID("06ec0ddb-949c-4357-aefb-65e5e55a9ae7")), + Role("Accountant", uuid.UUID("57d4538c-257a-4bf4-9a42-342992cb6af3")), + Role("Bar Captain", uuid.UUID("5a8ebb05-4817-45a5-866f-e523c30bfa25")), + Role("Captain", uuid.UUID("8db7001f-0964-4607-84f5-b6f4d9183fef")), + Role("Cashier", uuid.UUID("f1f0b112-1404-4b55-b121-f07ee6e08d12")), + Role("Controller", uuid.UUID("d9a5a478-1fe4-4847-84da-63cfba1a094a")), + Role("Manager", uuid.UUID("90ea7b14-9057-4bfd-a7cf-0ee7a3bb2463")), + Role("Senior Captain", uuid.UUID("d9b1b433-1ed5-4109-8ab2-cbd48ff010cd")), + Role("Server", uuid.UUID("6b378b71-f091-4485-a589-8db94ff1d6a4")), + ] + + roles[0].permissions = permissions + 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[3].permissions = list(permissions[i] for i in [16]) + 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[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[8].permissions = list(permissions[i] for i in [21, 24]) + + for role in roles: + dbsession.add(role) + + admin = User("Admin", "123456", False) + admin.roles.append(roles[0]) + dbsession.add(admin) diff --git a/barker/views/reports/checkout.py b/barker/views/reports/checkout.py index 03683eb..fa3bbfc 100644 --- a/barker/views/reports/checkout.py +++ b/barker/views/reports/checkout.py @@ -1,78 +1,112 @@ -import datetime import uuid -from barker.models import Voucher, User, Settlement -from barker.models.master import SettleOption +from datetime import datetime, timedelta +from barker.models import Voucher, User, Settlement, VoucherType from pyramid.view import view_config from sqlalchemy.orm import joinedload -__author__ = 'tanshu' +__author__ = "tanshu" -@view_config(request_method='GET', route_name='active_cashiers', renderer='json', permission='Cashier Checkout', - request_param=('s', 'f')) +@view_config( + request_method="GET", + route_name="v1_active_cashiers", + renderer="json", + permission="Cashier Checkout" +) def active_cashiers(request): - start_date = datetime.datetime.strptime(request.GET['s'], '%d-%b-%Y %H:%M') - finish_date = datetime.datetime.strptime(request.GET['f'], '%d-%b-%Y %H:%M') + start_date = request.GET.get("s", None) + if not start_date: + start_date = datetime.today().replace(hour=7, minute=0) + else: + start_date = datetime.strptime(start_date, "%d-%b-%Y").replace(hour=7, minute=0) - user_ids = request.dbsession.query(Voucher.user_id).filter( - Voucher.date >= start_date, - Voucher.date <= finish_date - ).distinct() + finish_date = request.GET.get("f", None) + if not finish_date: + finish_date = datetime.today().replace(hour=7, minute=0) + timedelta(days=1) + else: + finish_date = datetime.strptime(finish_date, "%d-%b-%Y").replace(hour=7, minute=0) + timedelta(days=1) - users = request.dbsession.query( - User - ).filter( - User.id.in_(user_ids) - ).order_by( - User.name - ).all() + user_ids = ( + request.dbsession.query(Voucher.user_id) + .filter(Voucher.date >= start_date, Voucher.date <= finish_date) + .distinct() + ) - return [{'UserID': u.id, 'Name': u.name} for u in users] + users = ( + request.dbsession.query(User) + .filter(User.id.in_(user_ids)) + .order_by(User.name) + .all() + ) + + return [{"id": u.id, "name": u.name} for u in users] -@view_config(request_method='GET', route_name='checkout', renderer='json', permission='Cashier Checkout', - request_param=('s', 'f')) +@view_config( + request_method="GET", + route_name="v1_checkout_blank", + renderer="json", + permission="Cashier Checkout" +) +def blank_out(request): + return { + "startDate": datetime.today().strftime("%d-%b-%Y"), + "finishDate": datetime.today().strftime("%d-%b-%Y"), + "user": {"id": ''}, + "amounts": [], + "info": [] + } + + +@view_config( + request_method="GET", + route_name="v1_checkout_id", + renderer="json", + permission="Cashier Checkout", + request_param=("s", "f"), +) def check_me_out(request): - id = uuid.UUID(request.matchdict['id']) - start_date = datetime.datetime.strptime(request.GET['s'], '%d-%b-%Y %H:%M') - finish_date = datetime.datetime.strptime(request.GET['f'], '%d-%b-%Y %H:%M') + id_ = uuid.UUID(request.matchdict["id"]) + start_date = datetime.strptime(request.GET["s"], "%d-%b-%Y").replace(hour=7, minute=0) + finish_date = datetime.strptime(request.GET["f"], "%d-%b-%Y").replace(hour=7, minute=0) + timedelta(days=1) - vouchers = request.dbsession.query( - Voucher - ).options( - joinedload(Voucher.settlements, innerjoin=True).joinedload(Settlement.settle_option, innerjoin=True), - joinedload(Voucher.customer, innerjoin=True) - ).filter( - Voucher.date >= start_date, - Voucher.date <= finish_date, - Voucher.user_id == id - ).order_by( - Voucher.voucher_type - ).order_by( - Voucher.bill_id - ).all() + vouchers = ( + request.dbsession.query(Voucher) + .options( + joinedload(Voucher.settlements, innerjoin=True).joinedload( + Settlement.settle_option, innerjoin=True + ) + ) + .filter( + Voucher.date >= start_date, + Voucher.date <= finish_date, + Voucher.user_id == id_, + ) + .order_by(Voucher.voucher_type) + .order_by(Voucher.bill_id) + .all() + ) info = {} + amounts = {} for item in vouchers: - if item.is_void: - if SettleOption.VOID() not in info: - info[SettleOption.VOID()] = [] - amount = next(s.amount * -1 for s in item.settlements if s.settled == SettleOption.AMOUNT()) - info[SettleOption.VOID()].append({ - 'Date': item.date.strftime('%d-%b-%Y %H:%M:%S'), - 'BillID': item.full_bill_id, - 'Customer': item.customer.name, - 'Amount': amount - }) - else: - for so in (so for so in item.settlements if so.settle_option.show_in_choices): - if so.settled not in info: - info[so.settled] = [] - info[so.settled].append({ - 'Date': item.date.strftime('%d-%b-%Y %H:%M:%S'), - 'BillID': item.full_bill_id, - 'Customer': item.customer.name, - 'Amount': so.amount - }) - return info + for so in (so for so in item.settlements if so.settle_option.show_in_choices): + if so.settled not in info: + info[so.settled] = [] + amounts[so.settle_option.name] = 0 + info[so.settled].append( + { + "date": item.date.strftime("%d-%b-%Y %H:%M:%S"), + "billId": item.full_bill_id, + "customer": item.customer.name if item.customer is not None else "", + "amount": so.amount, + } + ) + amounts[so.settle_option.name] += so.amount + return { + "startDate": start_date.strftime("%d-%b-%Y"), + "finishDate": finish_date.strftime("%d-%b-%Y"), + "user": {"id": id_}, + "amounts": [{'name': key, 'amount': value} for key, value in amounts.items()], "info": info + } diff --git a/barker/views/voucher/void.py b/barker/views/voucher/void.py index 92f1f62..ba75846 100644 --- a/barker/views/voucher/void.py +++ b/barker/views/voucher/void.py @@ -3,7 +3,7 @@ import uuid import transaction from pyramid.view import view_config -from barker.models import Voucher, SettleOption, Settlement, Overview +from barker.models import Voucher, SettleOption, Settlement, Overview, VoucherType @view_config( @@ -23,6 +23,7 @@ def void_voucher(request): item.void = True item.void_reason = reason + item.voucher_type = VoucherType.VOID do_void_settlements(item, request.dbsession) diff --git a/bookie/src/app/app-routing.module.ts b/bookie/src/app/app-routing.module.ts index f02e956..dcc0c7f 100644 --- a/bookie/src/app/app-routing.module.ts +++ b/bookie/src/app/app-routing.module.ts @@ -5,6 +5,10 @@ import {LogoutComponent} from './auth/logout/logout.component'; import {HomeComponent} from './home/home.component'; const routes: Routes = [ + { + path: 'checkout', + loadChildren: () => import('./cashier-checkout/cashier-checkout.module').then(mod => mod.CashierCheckoutModule) + }, { path: 'devices', loadChildren: () => import('./devices/devices.module').then(mod => mod.DevicesModule) diff --git a/bookie/src/app/cashier-checkout/active-cashiers-resolver.service.spec.ts b/bookie/src/app/cashier-checkout/active-cashiers-resolver.service.spec.ts new file mode 100644 index 0000000..12b5d1d --- /dev/null +++ b/bookie/src/app/cashier-checkout/active-cashiers-resolver.service.spec.ts @@ -0,0 +1,15 @@ +import {inject, TestBed} from '@angular/core/testing'; + +import {ActiveCashiersResolver} from './active-cashiers-resolver.service'; + +describe('ActiveCashiersResolver', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [ActiveCashiersResolver] + }); + }); + + it('should be created', inject([ActiveCashiersResolver], (service: ActiveCashiersResolver) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/bookie/src/app/cashier-checkout/active-cashiers-resolver.service.ts b/bookie/src/app/cashier-checkout/active-cashiers-resolver.service.ts new file mode 100644 index 0000000..318c185 --- /dev/null +++ b/bookie/src/app/cashier-checkout/active-cashiers-resolver.service.ts @@ -0,0 +1,20 @@ +import { Injectable } from '@angular/core'; +import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router'; +import { Observable } from 'rxjs/internal/Observable'; +import { CashierCheckoutService } from './cashier-checkout.service'; +import { User } from "../core/user"; + +@Injectable({ + providedIn: 'root' +}) +export class ActiveCashiersResolver implements Resolve { + + constructor(private ser: CashierCheckoutService) { + } + + resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { + const startDate = route.queryParamMap.get('startDate') || null; + const finishDate = route.queryParamMap.get('finishDate') || null; + return this.ser.activeCashiers(startDate, finishDate); + } +} diff --git a/bookie/src/app/cashier-checkout/cashier-checkout-datasource.ts b/bookie/src/app/cashier-checkout/cashier-checkout-datasource.ts new file mode 100644 index 0000000..9f3defe --- /dev/null +++ b/bookie/src/app/cashier-checkout/cashier-checkout-datasource.ts @@ -0,0 +1,18 @@ +import { DataSource } from '@angular/cdk/collections'; +import { Observable, of as observableOf } from 'rxjs'; +import { CashierCheckoutDisplayItem } from './cashier-checkout'; + + +export class CashierCheckoutDataSource extends DataSource { + + constructor(public data: CashierCheckoutDisplayItem[]) { + super(); + } + + connect(): Observable { + return observableOf(this.data); + } + + disconnect() { + } +} diff --git a/bookie/src/app/cashier-checkout/cashier-checkout-resolver.service.spec.ts b/bookie/src/app/cashier-checkout/cashier-checkout-resolver.service.spec.ts new file mode 100644 index 0000000..2f8501b --- /dev/null +++ b/bookie/src/app/cashier-checkout/cashier-checkout-resolver.service.spec.ts @@ -0,0 +1,15 @@ +import {inject, TestBed} from '@angular/core/testing'; + +import {CashierCheckoutResolver} from './cashier-checkout-resolver.service'; + +describe('CashierCheckoutResolver', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [CashierCheckoutResolver] + }); + }); + + it('should be created', inject([CashierCheckoutResolver], (service: CashierCheckoutResolver) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/bookie/src/app/cashier-checkout/cashier-checkout-resolver.service.ts b/bookie/src/app/cashier-checkout/cashier-checkout-resolver.service.ts new file mode 100644 index 0000000..2f46040 --- /dev/null +++ b/bookie/src/app/cashier-checkout/cashier-checkout-resolver.service.ts @@ -0,0 +1,21 @@ +import {Injectable} from '@angular/core'; +import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router'; +import {Observable} from 'rxjs/internal/Observable'; +import {CashierCheckout} from './cashier-checkout'; +import {CashierCheckoutService} from './cashier-checkout.service'; + +@Injectable({ + providedIn: 'root' +}) +export class CashierCheckoutResolver implements Resolve { + + constructor(private ser: CashierCheckoutService) { + } + + resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { + const id = route.paramMap.get('id'); + const startDate = route.queryParamMap.get('startDate') || null; + const finishDate = route.queryParamMap.get('finishDate') || null; + return this.ser.list(id, startDate, finishDate); + } +} diff --git a/bookie/src/app/cashier-checkout/cashier-checkout-routing.module.spec.ts b/bookie/src/app/cashier-checkout/cashier-checkout-routing.module.spec.ts new file mode 100644 index 0000000..3ca2e0a --- /dev/null +++ b/bookie/src/app/cashier-checkout/cashier-checkout-routing.module.spec.ts @@ -0,0 +1,13 @@ +import {CashierCheckoutRoutingModule} from './cashier-checkout-routing.module'; + +describe('CashierCheckoutRoutingModule', () => { + let CashierCheckoutRoutingModule: CashierCheckoutRoutingModule; + + beforeEach(() => { + CashierCheckoutRoutingModule = new CashierCheckoutRoutingModule(); + }); + + it('should create an instance', () => { + expect(CashierCheckoutRoutingModule).toBeTruthy(); + }); +}); diff --git a/bookie/src/app/cashier-checkout/cashier-checkout-routing.module.ts b/bookie/src/app/cashier-checkout/cashier-checkout-routing.module.ts new file mode 100644 index 0000000..0024520 --- /dev/null +++ b/bookie/src/app/cashier-checkout/cashier-checkout-routing.module.ts @@ -0,0 +1,52 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { RouterModule, Routes } from '@angular/router'; +import { CashierCheckoutResolver } from './cashier-checkout-resolver.service'; +import { AuthGuard } from '../auth/auth-guard.service'; +import { CashierCheckoutComponent } from './cashier-checkout.component'; +import { ActiveCashiersResolver } from "./active-cashiers-resolver.service"; + +const CashierCheckoutRoutes: Routes = [ + { + path: '', + component: CashierCheckoutComponent, + canActivate: [AuthGuard], + data: { + permission: 'Cashier Checkout' + }, + resolve: { + info: CashierCheckoutResolver, + cashiers: ActiveCashiersResolver + }, + runGuardsAndResolvers: 'always' + }, + { + path: ':id', + component: CashierCheckoutComponent, + canActivate: [AuthGuard], + data: { + permission: 'Cashier Checkout' + }, + resolve: { + info: CashierCheckoutResolver, + cashiers: ActiveCashiersResolver + }, + runGuardsAndResolvers: 'always' + } +]; + +@NgModule({ + imports: [ + CommonModule, + RouterModule.forChild(CashierCheckoutRoutes) + + ], + exports: [ + RouterModule + ], + providers: [ + CashierCheckoutResolver + ] +}) +export class CashierCheckoutRoutingModule { +} diff --git a/bookie/src/app/cashier-checkout/cashier-checkout.component.css b/bookie/src/app/cashier-checkout/cashier-checkout.component.css new file mode 100644 index 0000000..a9626b3 --- /dev/null +++ b/bookie/src/app/cashier-checkout/cashier-checkout.component.css @@ -0,0 +1,4 @@ +.right { + display: flex; + justify-content: flex-end; +} diff --git a/bookie/src/app/cashier-checkout/cashier-checkout.component.html b/bookie/src/app/cashier-checkout/cashier-checkout.component.html new file mode 100644 index 0000000..8151f5b --- /dev/null +++ b/bookie/src/app/cashier-checkout/cashier-checkout.component.html @@ -0,0 +1,56 @@ + + + cashier-checkout + + + +
+
+ + + + + + + + + + +
+
+ + Cashier + + -- Cashier -- + + {{ ac.name }} + + + + +
+
+ + + + + Name + {{row.name}} + + + + + Amount + {{row.amount | currency:'INR'}} + + + + +
+
diff --git a/bookie/src/app/cashier-checkout/cashier-checkout.component.spec.ts b/bookie/src/app/cashier-checkout/cashier-checkout.component.spec.ts new file mode 100644 index 0000000..128d651 --- /dev/null +++ b/bookie/src/app/cashier-checkout/cashier-checkout.component.spec.ts @@ -0,0 +1,25 @@ +import {async, ComponentFixture, TestBed} from '@angular/core/testing'; + +import {CashierCheckoutComponent} from './cashier-checkout.component'; + +describe('CashierCheckoutComponent', () => { + let component: CashierCheckoutComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [CashierCheckoutComponent] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CashierCheckoutComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/bookie/src/app/cashier-checkout/cashier-checkout.component.ts b/bookie/src/app/cashier-checkout/cashier-checkout.component.ts new file mode 100644 index 0000000..1390985 --- /dev/null +++ b/bookie/src/app/cashier-checkout/cashier-checkout.component.ts @@ -0,0 +1,96 @@ +import { Component, OnInit } from '@angular/core'; +import { FormBuilder, FormGroup } from '@angular/forms'; +import { ActivatedRoute, Router } from '@angular/router'; +import * as moment from 'moment'; +import { CashierCheckoutDataSource } from './cashier-checkout-datasource'; +import { CashierCheckout } from './cashier-checkout'; +import { ToCsvService } from '../shared/to-csv.service'; +import { User } from "../core/user"; + +@Component({ + selector: 'app-cashier-checkout', + templateUrl: './cashier-checkout.component.html', + styleUrls: ['./cashier-checkout.component.css'] +}) +export class CashierCheckoutComponent implements OnInit { + dataSource: CashierCheckoutDataSource; + form: FormGroup; + activeCashiers: User[]; + info: CashierCheckout; + + /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */ + displayedColumns = ['name', 'amount']; + + + constructor( + private route: ActivatedRoute, + private router: Router, + private fb: FormBuilder, + private toCsv: ToCsvService + ) { + this.createForm(); + + } + + ngOnInit() { + this.route.data + .subscribe((data: { cashiers: User[], info: CashierCheckout }) => { + this.activeCashiers = data.cashiers; + this.info = data.info; + this.form.setValue({ + cashier: this.info.user.id, + startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(), + finishDate: moment(this.info.finishDate, 'DD-MMM-YYYY').toDate() + }); + this.dataSource = new CashierCheckoutDataSource(this.info.amounts); + }); + } + + show() { + const info = this.getInfo(); + this.router.navigate(['checkout', this.form.value.cashier], { + queryParams: { + startDate: info.startDate, + finishDate: info.finishDate + } + }); + } + + createForm() { + this.form = this.fb.group({ + startDate: '', + finishDate: '', + cashier: '' + }); + } + + getInfo(): CashierCheckout { + const formModel = this.form.value; + + return { + user: formModel.cashier, + startDate: moment(formModel.startDate).format('DD-MMM-YYYY'), + finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY') + }; + } + + exportCsv() { + const headers = { + Date: 'date', + Name: 'name', + Type: 'type', + Narration: 'narration', + Debit: 'debit', + Credit: 'credit', + Running: 'running', + Posted: 'posted' + }; + const csvData = new Blob([this.toCsv.toCsv(headers, this.dataSource.data)], {type: 'text/csv;charset=utf-8;'}); + const link = document.createElement('a'); + link.href = window.URL.createObjectURL(csvData); + link.setAttribute('download', 'cashier-checkout.csv'); + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + } +} diff --git a/bookie/src/app/cashier-checkout/cashier-checkout.module.spec.ts b/bookie/src/app/cashier-checkout/cashier-checkout.module.spec.ts new file mode 100644 index 0000000..f7e4543 --- /dev/null +++ b/bookie/src/app/cashier-checkout/cashier-checkout.module.spec.ts @@ -0,0 +1,13 @@ +import {CashierCheckoutModule} from './cashier-checkout.module'; + +describe('CashierCheckoutModule', () => { + let CashierCheckoutModule: CashierCheckoutModule; + + beforeEach(() => { + CashierCheckoutModule = new CashierCheckoutModule(); + }); + + it('should create an instance', () => { + expect(CashierCheckoutModule).toBeTruthy(); + }); +}); diff --git a/bookie/src/app/cashier-checkout/cashier-checkout.module.ts b/bookie/src/app/cashier-checkout/cashier-checkout.module.ts new file mode 100644 index 0000000..0fee144 --- /dev/null +++ b/bookie/src/app/cashier-checkout/cashier-checkout.module.ts @@ -0,0 +1,71 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { MatAutocompleteModule } from '@angular/material/autocomplete'; +import { MatButtonModule } from '@angular/material/button'; +import { MatCardModule } from '@angular/material/card'; +import { MatCheckboxModule } from '@angular/material/checkbox'; +import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE, MatNativeDateModule } from '@angular/material/core'; +import { MatDatepickerModule } from '@angular/material/datepicker'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatIconModule } from '@angular/material/icon'; +import { MatInputModule } from '@angular/material/input'; +import { MatPaginatorModule } from '@angular/material/paginator'; +import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; +import { MatSortModule } from '@angular/material/sort'; +import { MatTableModule } from '@angular/material/table'; +import { SharedModule} from '../shared/shared.module'; +import { ReactiveFormsModule } from '@angular/forms'; +import { CdkTableModule } from '@angular/cdk/table'; +import { CashierCheckoutRoutingModule } from './cashier-checkout-routing.module'; +import { CashierCheckoutComponent } from './cashier-checkout.component'; +import { MomentDateAdapter } from '@angular/material-moment-adapter'; +import { A11yModule } from '@angular/cdk/a11y'; +import { FlexLayoutModule } from '@angular/flex-layout'; +import { MatSelectModule } from "@angular/material"; + +export const MY_FORMATS = { + parse: { + dateInput: 'DD-MMM-YYYY', + }, + display: { + dateInput: 'DD-MMM-YYYY', + monthYearLabel: 'MMM YYYY', + dateA11yLabel: 'DD-MMM-YYYY', + monthYearA11yLabel: 'MMM YYYY', + }, +}; + +@NgModule({ + imports: [ + A11yModule, + CommonModule, + CdkTableModule, + FlexLayoutModule, + MatAutocompleteModule, + MatButtonModule, + MatCardModule, + MatCheckboxModule, + MatDatepickerModule, + MatFormFieldModule, + MatIconModule, + MatInputModule, + MatNativeDateModule, + MatPaginatorModule, + MatProgressSpinnerModule, + MatSelectModule, + MatSortModule, + MatTableModule, + ReactiveFormsModule, + SharedModule, + CashierCheckoutRoutingModule + ], + declarations: [ + CashierCheckoutComponent + ], + providers: [ + {provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]}, + {provide: MAT_DATE_FORMATS, useValue: MY_FORMATS}, + ] +}) +export class CashierCheckoutModule { +} diff --git a/bookie/src/app/cashier-checkout/cashier-checkout.service.spec.ts b/bookie/src/app/cashier-checkout/cashier-checkout.service.spec.ts new file mode 100644 index 0000000..46ec47d --- /dev/null +++ b/bookie/src/app/cashier-checkout/cashier-checkout.service.spec.ts @@ -0,0 +1,15 @@ +import {inject, TestBed} from '@angular/core/testing'; + +import {CashierCheckoutService} from './cashier-checkout.service'; + +describe('CashierCheckoutService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [CashierCheckoutService] + }); + }); + + it('should be created', inject([CashierCheckoutService], (service: CashierCheckoutService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/bookie/src/app/cashier-checkout/cashier-checkout.service.ts b/bookie/src/app/cashier-checkout/cashier-checkout.service.ts new file mode 100644 index 0000000..d699b02 --- /dev/null +++ b/bookie/src/app/cashier-checkout/cashier-checkout.service.ts @@ -0,0 +1,55 @@ +import { Injectable } from '@angular/core'; +import { catchError } from 'rxjs/operators'; +import { Observable } from 'rxjs/internal/Observable'; +import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; +import { CashierCheckout } from './cashier-checkout'; +import { ErrorLoggerService } from '../core/error-logger.service'; +import {User} from "../core/user"; + +const httpOptions = { + headers: new HttpHeaders({'Content-Type': 'application/json'}) +}; + +const url = '/v1/checkout'; +const urlActiveCashiers = '/v1/active-cashiers'; +const serviceName = 'CashierCheckoutService'; + +@Injectable({ + providedIn: 'root' +}) +export class CashierCheckoutService { + + constructor(private http: HttpClient, private log: ErrorLoggerService) { + } + + list(id: string, startDate: string, finishDate): Observable { + const listUrl = (id === null) ? url : `${url}/${id}`; + const options = {params: new HttpParams()}; + if (startDate !== null) { + options.params = options.params.set('s', startDate); + } + if (finishDate !== null) { + options.params = options.params.set('f', finishDate); + } + return >this.http.get(listUrl, options) + .pipe( + catchError(this.log.handleError(serviceName, 'list')) + ); + } + + activeCashiers(startDate: string, finishDate): Observable { + const options = {params: new HttpParams()}; + if (startDate !== null) { + options.params = options.params.set('s', startDate); + } + if (finishDate !== null) { + options.params = options.params.set('f', finishDate); + } + return >this.http.get(urlActiveCashiers, options) + + .pipe( + catchError(this.log.handleError(serviceName, 'activeCashiers')) + ); + } + +} diff --git a/bookie/src/app/cashier-checkout/cashier-checkout.ts b/bookie/src/app/cashier-checkout/cashier-checkout.ts new file mode 100644 index 0000000..095fe66 --- /dev/null +++ b/bookie/src/app/cashier-checkout/cashier-checkout.ts @@ -0,0 +1,21 @@ +import {User} from "../core/user"; + +export class CashierCheckoutPrintItem { + date: string; + billId: string; + customer: string; + amount: number; +} + +export class CashierCheckoutDisplayItem { + name: string; + amount: number; +} + +export class CashierCheckout { + startDate: string; + finishDate: string; + user: User; + amounts?: CashierCheckoutDisplayItem[]; + info?: CashierCheckoutPrintItem[]; +} diff --git a/bookie/src/app/home/home.component.html b/bookie/src/app/home/home.component.html index bdb566a..4d1e8d5 100644 --- a/bookie/src/app/home/home.component.html +++ b/bookie/src/app/home/home.component.html @@ -11,6 +11,9 @@

Sales

+ +

Cashier Checkout

+

Tables