From 108415ed3f80df5e4a01be29a930b4216f483687 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Tue, 3 Dec 2019 10:02:49 +0630 Subject: [PATCH] update dine-in pay bill --- .../origami/payments_controller.rb | 4 +-- app/models/sale_payment.rb | 27 +++++-------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 401e231b..b6c3e5be 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -176,14 +176,14 @@ class Origami::PaymentsController < BaseOrigamiController # For Cashier by Zone # bookings = Booking.where("sale_id='#{sale_id}'") - bookings = Booking.find_by_sale_id(sale_id) + bookings = saleObj.bookings[0] shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) else if bookings.dining_facility_id.to_i > 0 - table = DiningFacility.find(bookings.dining_facility_id) + table = bookings.dining_facility cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index e0ad2383..c48b4a6b 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -87,7 +87,7 @@ class SalePayment < ApplicationRecord amount_due = amount_due - payment.payment_amount end end - if (amount_due >= 0) + if (amount_due > 0) payment_status = false membership_data = nil #route to payment type @@ -780,27 +780,14 @@ class SalePayment < ApplicationRecord def table_update_status(sale_obj) status = true sale_count = 0 - booking = Booking.find_by_sale_id(sale_obj.id) - if booking + if booking = sale_obj.bookings[0] if booking.dining_facility_id.to_i > 0 - table = DiningFacility.find(booking.dining_facility_id) - bookings = table.bookings - bookings.each do |tablebooking| - if tablebooking.booking_status != 'moved' - if tablebooking.sale_id - if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void' && tablebooking.sale.sale_status != 'spoile' && tablebooking.sale.sale_status != 'waste' - status = false - sale_count += 1 - else - status = true - end - else - status = false - sale_count += 1 - end - end + table = booking.dining_facility + if Booking.left_joins(:sale).where(dining_facility_id: booking.dining_facility_id).where.not(booking_status: 'moved').where("sales.sale_status NOT IN ('completed', 'void', 'spoile', 'waste') OR sales.sale_status IS NULL").exists? + status = false end - if status && sale_count == 0 + + if status table.update_attributes(status: "available") # table.status = "available" # table.save