diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index db6dd039..dd27197c 100755 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -49,7 +49,25 @@ class Api::OrdersController < Api::ApiController def create Rails.logger.debug "Order Source - " + params[:order_source].to_s Rails.logger.debug "Table ID - " + params[:table_id].to_s +#for extratime + is_extra_time = false + extra_time = '' + params[:order_items].each { |i| + if i["item_instance_code"] == 'Exti60' || i["item_instance_code"] == 'Exti30' + is_extra_time = true + if i["item_instance_code"] == 'Exti30' + t = Time.now + time = 30*60*i["quantity"].to_i + extra_time = Time.at(time) + else + t = Time.now + time = 60*60*i["quantity"].to_i + extra_time = Time.at(time) + end + end + } +#end extra time # begin @order = Order.new @order.source = params[:order_source] @@ -61,6 +79,9 @@ class Api::OrdersController < Api::ApiController @order.new_booking = 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. diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index f72bc2ec..5aedca8c 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -70,17 +70,11 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController if i["item_instance_code"] == 'Exti60' || i["item_instance_code"] == 'Exti30' is_extra_time = true if i["item_instance_code"] == 'Exti30' - t = Time.now time = 30*60*i["quantity"].to_i - extra_time = Time.at(time).utc.strftime("%H:%M:%S") - puts time - puts "timmmmmmmmmmmmmmmmmmm" + extra_time = Time.at(time) else - t = Time.now time = 60*60*i["quantity"].to_i - extra_time = Time.at(time).utc.strftime("%H:%M:%S") - puts time - puts "timmmmmmmmmmmmmmmmmmm" + extra_time = Time.at(time) end end items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": i["options"]} diff --git a/app/controllers/origami/sales_controller.rb b/app/controllers/origami/sales_controller.rb index e5350706..bdf481c2 100755 --- a/app/controllers/origami/sales_controller.rb +++ b/app/controllers/origami/sales_controller.rb @@ -15,9 +15,14 @@ class Origami::SalesController < BaseOrigamiController dining = params[:dining_id] sale_id = params[:sale_id] table = DiningFacility.find(dining) + existing_booking = Booking.find_by_sale_id(sale_id) table.bookings.each do |booking| + # if !booking.checkout_at.nil? + # existing_booking.update_attributes(checkout_at: checkout_at) + # end if booking.sale_id.nil? booking.booking_orders.each do |booking_order| + booking.booking_status = 'moved' order = Order.find(booking_order.order_id) order.status = 'billed' @@ -36,7 +41,7 @@ class Origami::SalesController < BaseOrigamiController order.save booking.save end - existing_booking = Booking.find_by_sale_id(sale_id) + booking_order = BookingOrder.where('booking_id=?',booking) booking_order.each do |bo| bo.booking_id = existing_booking.booking_id diff --git a/app/models/order.rb b/app/models/order.rb index e4d58051..318e8e91 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -25,31 +25,33 @@ class Order < ApplicationRecord booking = nil if self.new_booking - booking = Booking.create({:dining_facility_id => self.table_id,:type => "TableBooking", + #add extra time + if self.is_extra_time && self.extra_time + booking = Booking.create({:dining_facility_id => self.table_id,:type => "TableBooking", + :checkin_at => Time.now.utc,:checkout_at => Time.now.utc + self.extra_time.to_i, + :checkin_by => self.employee_name, + :booking_status => "assign" }) + else + booking = Booking.create({:dining_facility_id => self.table_id,:type => "TableBooking", :checkin_at => Time.now.utc, :checkin_by => self.employee_name, :booking_status => "assign" }) + end + #end extra time + table = DiningFacility.find(self.table_id) table.status = "occupied" table.save else booking = Booking.find(self.booking_id) + #add extra time 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 - + new_time = booking.checkout_at + self.extra_time.to_i + booking.update_attributes(checkout_at: new_time) + end end + #end extra time end booking.save! diff --git a/app/models/sale.rb b/app/models/sale.rb index 969deb5c..6d17db0c 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -114,7 +114,10 @@ class Sale < ApplicationRecord order.save booking.sale_id = self.id - booking.checkout_at = Time.now.utc.getlocal + if booking.checkout_at < Time.now.utc.getlocal + booking.checkout_at = Time.now.utc.getlocal + end + booking.checkout_by = requested_by.name booking.save @@ -222,8 +225,6 @@ class Sale < ApplicationRecord sales_items.each do |item| #compute each item and added to total - puts "item.sales_item_id ddd" - puts item.sale_item_id subtotal_price = subtotal_price + item.price # only calc tax when true diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index bd9022d9..29903480 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -143,7 +143,11 @@ <% elsif @status_sale == 'sale' %>