diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index ece423c7..f72bc2ec 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -62,21 +62,23 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController def create Rails.logger.debug "Order Source - " + params[:order_source].to_s Rails.logger.debug "Table ID - " + params[:table_id].to_s - extra_time = false - time = '' + is_extra_time = false + extra_time = '' items_arr = [] JSON.parse(params[:order_items]).each { |i| if i["item_instance_code"] == 'Exti60' || i["item_instance_code"] == 'Exti30' - extra_time = true + is_extra_time = true if i["item_instance_code"] == 'Exti30' t = Time.now - time = 30*i["quantity"] + time = 30*60*i["quantity"].to_i + extra_time = Time.at(time).utc.strftime("%H:%M:%S") puts time puts "timmmmmmmmmmmmmmmmmmm" else t = Time.now - time = 1*i["quantity"] + time = 60*60*i["quantity"].to_i + extra_time = Time.at(time).utc.strftime("%H:%M:%S") puts time puts "timmmmmmmmmmmmmmmmmmm" end @@ -94,20 +96,20 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController @order.guest = params[:guest_info] @order.table_id = params[:table_id] # this is dining facilities's id @order.new_booking = true - @order.extra_time = true @order.waiters = current_login_employee.name @order.employee_name = current_login_employee.name + + @order.is_extra_time = is_extra_time + @order.extra_time = extra_time #Create Table Booking or Room Booking if !params["booking_id"].nil? # check booking id is already completed. booking = Booking.find(params[:booking_id]) - puts "ssssssssssssssssssss" + if booking if booking.dining_facility_id.to_i == params[:table_id].to_i && booking.booking_status != 'moved' if !booking.sale_id.nil? sale_status = check_order_with_booking(booking) - puts "WWwwWWWWWWww" - puts sale_status if sale_status return return_json_status_with_code(400, "bill requested") end @@ -117,18 +119,13 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController end else sale_status = check_order_with_table(params[:table_id]) - puts "OOOOOOOOO" - puts sale_status if sale_status return return_json_status_with_code(400, "bill requested") end end end #booking exists else - puts "seeeeeeeeeeeeeeeeee" sale_status = check_order_with_table(params[:table_id]) - # puts "MMMMMMMM" - # puts sale_status if sale_status # return false , @message = "bill requested" return return_json_status_with_code(400, "bill requested") diff --git a/app/models/order.rb b/app/models/order.rb index 676c129f..e4d58051 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -10,7 +10,7 @@ class Order < ApplicationRecord has_many :assigned_order_items #internal references attributes for business logic control - attr_accessor :items, :guest, :table_id, :new_booking, :booking_type, :employee_name, :booking_id, :extra_time + attr_accessor :items, :guest, :table_id, :new_booking, :booking_type, :employee_name, :booking_id, :extra_time, :is_extra_time scope :active, -> { where("date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") } #Main Controller method to create new order - validate all inputs and generate new order # order_item : { @@ -28,11 +28,28 @@ class Order < ApplicationRecord booking = Booking.create({:dining_facility_id => self.table_id,:type => "TableBooking", :checkin_at => Time.now.utc, :checkin_by => self.employee_name, :booking_status => "assign" }) + table = DiningFacility.find(self.table_id) table.status = "occupied" table.save else booking = Booking.find(self.booking_id) + if self.is_extra_time + if !booking.checkout_at.nil? + puts "sssssssssss" + date = booking.checkout_at.strftime("%Y-%m-%d") + time = Time.at(booking.checkout_at).utc.strftime("%H:%M:%S") + extra_time = self.extra_time + new_time = time.strftime("%H") + extra_time.strftime("%H") + + puts time + puts extra_time + puts new_time + + # booking.update_attributes(checkout_at: ) + end + + end end booking.save!