From ed429b2d4bfe24e2123e80c1d6390fab0b8061ec Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 14 Dec 2017 16:40:29 +0630 Subject: [PATCH] change checkout time and free time --- .../api/check_in_process_controller.rb | 18 +++++------- .../origami/check_in_process_controller.rb | 19 +++++-------- app/models/dining_facility.rb | 28 ++++++++++++++++--- app/models/sale.rb | 2 +- 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/app/controllers/api/check_in_process_controller.rb b/app/controllers/api/check_in_process_controller.rb index cfce827f..46ac5f17 100644 --- a/app/controllers/api/check_in_process_controller.rb +++ b/app/controllers/api/check_in_process_controller.rb @@ -18,20 +18,16 @@ class Api::CheckInProcessController < Api::ApiController if params[:dining_id] dining_facility = DiningFacility.find(params[:dining_id]) if dining_facility.status == "available" - dining_charge = DiningCharge.select('charge_type','charge_block') - .where('dining_facility_id = ?',params[:dining_id]) - .first() + lookup_checkout_time = Lookup.collection_of("checkout_time") checkout_at = Time.now.utc - if !dining_charge.nil? - hr = (dining_charge.charge_block.utc.strftime("%H").to_i).to_int - min = (dining_charge.charge_block.utc.strftime("%M").to_i).to_int - # if dining_charge.charge_type == 'hr' - checkout_at = checkout_at + hr.hour + min.minutes - # else - - # end + if !lookup_checkout_time.nil? + if lookup_checkout_time[0][0] == 'hr' + checkout_at = checkout_at + (lookup_checkout_time[0][1]).to_i.hour + else + checkout_at = checkout_at + (lookup_checkout_time[0][1]).to_i.minutes + end end dining_facility.status = "occupied" diff --git a/app/controllers/origami/check_in_process_controller.rb b/app/controllers/origami/check_in_process_controller.rb index bc77e51c..37f58d8f 100644 --- a/app/controllers/origami/check_in_process_controller.rb +++ b/app/controllers/origami/check_in_process_controller.rb @@ -1,20 +1,15 @@ class Origami::CheckInProcessController < BaseOrigamiController def check_in_process - dining_charge = DiningCharge.select('charge_type','charge_block') - .where('dining_facility_id = ?',params[:dining_id]) - .first() - + lookup_checkout_time = Lookup.collection_of("checkout_time") checkout_at = Time.now.utc - if !dining_charge.nil? - hr = (dining_charge.charge_block.utc.strftime("%H").to_i).to_int - min = (dining_charge.charge_block.utc.strftime("%M").to_i).to_int - # if dining_charge.charge_type == 'hr' - checkout_at = checkout_at + hr.hour + min.minutes - # else - - # end + if !lookup_checkout_time.nil? + if lookup_checkout_time[0][0] == 'hr' + checkout_at = checkout_at + (lookup_checkout_time[0][1]).to_i.hour + else + checkout_at = checkout_at + (lookup_checkout_time[0][1]).to_i.minutes + end end @dining_facility = DiningFacility.find(params[:dining_id]) @dining_facility.status = "occupied" diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index 595f0e0f..c547a3c4 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -78,6 +78,16 @@ class DiningFacility < ApplicationRecord def get_checkout_booking booking = self.get_current_checkout_booking if booking + lookup_checkout_time = Lookup.collection_of("checkout_alert_time") + free_time_min = 0 + if !lookup_checkout_time.nil? + if lookup_checkout_time[0][0] == 'min' + free_time_min = (lookup_checkout_time[0][1]).to_i + else + free_time_min = 15 + end + end + now = Time.now.utc hr = (now.strftime("%H").to_i).to_int min = (now.strftime("%M").to_i).to_int @@ -88,7 +98,7 @@ class DiningFacility < ApplicationRecord checkout_at_min -= min if (checkout_at_hr < hr) return booking - elsif (checkout_at_hr == hr && checkout_at_min <= 15) + elsif (checkout_at_hr == hr && checkout_at_min <= free_time_min) return booking else return nil @@ -103,18 +113,28 @@ class DiningFacility < ApplicationRecord bookings = Booking.where("booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null") arr_booking = Array.new if bookings + lookup_checkout_time = Lookup.collection_of("checkout_alert_time") + free_time_min = 0 + if !lookup_checkout_time.nil? + if lookup_checkout_time[0][0] == 'min' + free_time_min = (lookup_checkout_time[0][1]).to_i + else + free_time_min = 15 + end + end + bookings.each do |booking| - now = Time.now.utc.getlocal + now = Time.now.utc hr = (now.strftime("%H").to_i).to_int min = (now.strftime("%M").to_i).to_int if !booking.checkout_at.nil? - checkout_at = booking.checkout_at.utc.getlocal + checkout_at = booking.checkout_at.utc checkout_at_hr = (checkout_at.strftime("%H").to_i).to_int checkout_at_min = (checkout_at.strftime("%M").to_i).to_int checkout_at_min -= min if (checkout_at_hr < hr) arr_booking.push({'table_id' => booking.dining_facility_id}) - elsif (checkout_at_hr == hr && checkout_at_min <= 15) + elsif (checkout_at_hr == hr && checkout_at_min <= free_time_min) arr_booking.push({'table_id' => booking.dining_facility_id}) end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 5816dc96..1598563f 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1076,7 +1076,7 @@ end end def self.total_other_customer(today) - query = Sale.select("count(distinct sales.customer_id) as total_cus") + query = Sale.select("count(sales.customer_id) as total_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today) .first()