From 69b786a91dcb37184dcaac77dca2c57dcc41cadc Mon Sep 17 00:00:00 2001 From: Yan Date: Thu, 7 Dec 2017 12:07:06 +0630 Subject: [PATCH] shift update --- app/controllers/api/bill_controller.rb | 10 +++++++++- app/controllers/api/check_in_process_controller.rb | 2 +- app/models/sale.rb | 2 +- app/models/sale_payment.rb | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 5e7a3195..387b7bf8 100755 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -5,7 +5,8 @@ class Api::BillController < Api::ApiController def create @status = false @error_message = "Order ID or Booking ID is require to request for a bill." - if ShiftSale.current_shift + + if shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0].id) #create Bill by Booking ID table = 0 if (params[:booking_id]) @@ -22,9 +23,11 @@ class Api::BillController < Api::ApiController if booking.sale_id.nil? @sale = Sale.new @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee, get_cashier_by_terminal) + @sale_data = Sale.find_by_sale_id(@sale_id) else @status = true @sale_id = booking.sale_id + @sale_data = Sale.find_by_sale_id(@sale_id) end end @@ -36,6 +39,11 @@ class Api::BillController < Api::ApiController booking = Booking.find_by_sale_id(@sale_id) table = DiningFacility.find(booking.dining_facility_id) end + + # Bind shift sale id to sale + @sale_data.shift_sale_id = shift_by_terminal.id + @sale_data.save + Promotion.promo_activate(@sale) BillBroadcastJob.perform_later(table) diff --git a/app/controllers/api/check_in_process_controller.rb b/app/controllers/api/check_in_process_controller.rb index 5360db5b..694c8794 100644 --- a/app/controllers/api/check_in_process_controller.rb +++ b/app/controllers/api/check_in_process_controller.rb @@ -3,7 +3,7 @@ class Api::CheckInProcessController < Api::ApiController def check_in_time if params[:dining_id] dining_facility = DiningFacility.find(params[:dining_id]) - booking = dining_facility.get_current_checkout_booking + booking = dining_facility.get_current_booking if !booking.nil? check_in_time = booking.checkin_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") check_out_time = booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") diff --git a/app/models/sale.rb b/app/models/sale.rb index 4b60cc94..a2d94dee 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -115,7 +115,7 @@ class Sale < ApplicationRecord booking.sale_id = self.id booking.checkout_at = Time.now.utc.getlocal - booking.checkout_by = requested_by.name + # booking.checkout_by = requested_by.name booking.save InventoryJob.perform_now(self.id) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 7840817e..b71bf733 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -282,7 +282,7 @@ class SalePayment < ApplicationRecord end - def sale_update_payment_status(paid_amount) + def sale_update_payment_status(paid_amount) #update amount_outstanding self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f self.sale.save!