From d58f7d1605793efd3df74d298d8fee5d17b23a5a Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 28 Dec 2017 16:21:49 +0630 Subject: [PATCH 1/3] update addord for extra time --- .../origami/addorders_controller.rb | 67 ++++++++++++------- app/models/order.rb | 2 +- db/seeds.rb | 21 ++++-- 3 files changed, 60 insertions(+), 30 deletions(-) diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index d283b06e..ece423c7 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -62,9 +62,25 @@ 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 - puts params[:order_items] + extra_time = false + time = '' + items_arr = [] JSON.parse(params[:order_items]).each { |i| + if i["item_instance_code"] == 'Exti60' || i["item_instance_code"] == 'Exti30' + extra_time = true + if i["item_instance_code"] == 'Exti30' + t = Time.now + time = 30*i["quantity"] + puts time + puts "timmmmmmmmmmmmmmmmmmm" + else + t = Time.now + time = 1*i["quantity"] + puts time + puts "timmmmmmmmmmmmmmmmmmm" + end + end items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": i["options"]} items_arr.push(items) } @@ -78,35 +94,38 @@ 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 #Create Table Booking or Room Booking if !params["booking_id"].nil? - # check booking id is already completed. - booking = Booking.find(params[:booking_id]) - 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") + # 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 + else + @order.new_booking = false + @order.booking_id = params[:booking_id] + 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 - else - @order.new_booking = false - @order.booking_id = params[:booking_id] - 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 + end #booking exists else + puts "seeeeeeeeeeeeeeeeee" sale_status = check_order_with_table(params[:table_id]) # puts "MMMMMMMM" # puts sale_status diff --git a/app/models/order.rb b/app/models/order.rb index ba8adc8f..676c129f 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 + attr_accessor :items, :guest, :table_id, :new_booking, :booking_type, :employee_name, :booking_id, :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 : { diff --git a/db/seeds.rb b/db/seeds.rb index 79aab88f..78321b72 100755 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -140,10 +140,11 @@ menu_options = MenuItemOption.create([{option_type: "Oil", name: "Less Oil", val menu_pkg_options = MenuItemOption.create([{option_type: "Package", name: "Bottle", value: "Bottle"},{option_type: "Package", name: "Can", value: "can"}]) # #Default Menu Category - # menu_category1 = MenuCategory.create({menu: menu, code:"C001", name: "Person", alt_name: "Person", order_by: 1, is_available: 1, created_by: "SYSTEM DEFAULT"}) +# menu_category1 = MenuCategory.create({menu: menu, code:"C001", name: "Person", alt_name: "Person", order_by: 1, is_available: 1, created_by: "SYSTEM DEFAULT"}) # menu_category2 = MenuCategory.create({menu: menu, code:"C005", name: "Beef & Mutton", alt_name: "Beef_and_mutton", order_by: 2,created_by: "SYSTEM DEFAULT"}) # menu_category3 = MenuCategory.create({menu: menu, code:"C006", name: "Pork", alt_name: "Pork", order_by: 3,created_by: "SYSTEM DEFAULT"}) # menu_category4 = MenuCategory.create({menu: menu, code:"C006", name: "Chicken", alt_name: "Chicken", order_by: 1, menu_category_id: menu_category3.id, created_by: "SYSTEM DEFAULT"}) +# menu_category5 = MenuCategory.create({menu: menu, code:"C001", name: "Extra Time", alt_name: "Extra Time", order_by: 1, is_available: 1, created_by: "SYSTEM DEFAULT"}) # # #Default Menu items # menu_category1_menu_item0 = SimpleMenuItem.create({item_code:"01001", name: "Single Pot", alt_name: "Single Pot",menu_category: menu_category1 , min_selectable_item: 1, max_selectable_item:1, account: food }) @@ -162,11 +163,21 @@ menu_pkg_options = MenuItemOption.create([{option_type: "Package", name: "Bottle # menu_item_attribute_adult = MenuItemAttribute.create({attribute_type:"person", name: "Adult", value: "adult"}) # menu_item_attribute_child = MenuItemAttribute.create({attribute_type:"person", name: "Child", value: "child"}) - # menu_category1_menu_item0 = SimpleMenuItem.create({item_code:"P00001", name: "Adult", alt_name: "",menu_category: menu_category1 , min_qty: 1, account: person, :item_attributes => "['1']", created_by: "System" }) - # menu_item0_instance = MenuItemInstance.create({item_instance_name:"",item_instance_code:"PI0001", menu_item: menu_category1_menu_item0, price:15000.00, is_on_promotion:false, is_default:true, :item_attributes => "['1']" }) +# menu_category1_menu_item0 = SimpleMenuItem.create({item_code:"P00001", name: "Adult", alt_name: "",menu_category: menu_category1 , min_qty: 1, account: person, :item_attributes => "['1']", created_by: "System" }) +# menu_item0_instance = MenuItemInstance.create({item_instance_name:"",item_instance_code:"PI0001", menu_item: menu_category1_menu_item0, price:15000.00, is_on_promotion:false, is_default:true, :item_attributes => "['1']" }) + +# menu_category1_menu_item1 = SimpleMenuItem.create({item_code:"P00002", name: "Child", alt_name: "",menu_category: menu_category1 , min_qty: 1, account: person, :item_attributes => "['2']", created_by: "System" }) +# menu_item1_instance = MenuItemInstance.create({item_instance_name:"",item_instance_code:"PI0002", menu_item: menu_category1_menu_item1, price:10000.00, is_on_promotion:false, is_default:true, :item_attributes => "['2']" }) + +# menu_item_attribute_30_min = MenuItemAttribute.create({attribute_type:"Extra Time", name: "30 min", value: "30_min"}) +# menu_item_attribute_60_min = MenuItemAttribute.create({attribute_type:"Extra Time", name: "1 hrs", value: "60_min"}) + +# menu_category1_menu_item2 = SimpleMenuItem.create({item_code:"Ext30", name: "30 minutes", alt_name: "",menu_category: menu_category5 , min_qty: 1, account: extra_time, :item_attributes => "['1']", created_by: "System" }) +# menu_item0_instance = MenuItemInstance.create({item_instance_name:"",item_instance_code:"Exti30", menu_item: menu_category1_menu_item2, price:15000.00, is_on_promotion:false, is_default:true, :item_attributes => "['1']" }) + +# menu_category1_menu_item3 = SimpleMenuItem.create({item_code:"Ext60", name: "1 hour", alt_name: "",menu_category: menu_category5 , min_qty: 1, account: extra_time, :item_attributes => "['2']", created_by: "System" }) +# menu_item1_instance = MenuItemInstance.create({item_instance_name:"",item_instance_code:"Exti60", menu_item: menu_category1_menu_item3, price:10000.00, is_on_promotion:false, is_default:true, :item_attributes => "['2']" }) - # menu_category1_menu_item1 = SimpleMenuItem.create({item_code:"P00002", name: "Child", alt_name: "",menu_category: menu_category1 , min_qty: 1, account: person, :item_attributes => "['2']", created_by: "System" }) - # menu_item1_instance = MenuItemInstance.create({item_instance_name:"",item_instance_code:"PI0002", menu_item: menu_category1_menu_item1, price:10000.00, is_on_promotion:false, is_default:true, :item_attributes => "['2']" }) # END menu_item_attribute_size_small = MenuItemAttribute.create({attribute_type:"size", name: "Small", value: "small"}) From 26a11ebecd04de0558ce655e2836eb50585435cd Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 29 Dec 2017 14:39:47 +0630 Subject: [PATCH 2/3] add extra charge in oroder --- .../origami/addorders_controller.rb | 25 ++++++++----------- app/models/order.rb | 19 +++++++++++++- 2 files changed, 29 insertions(+), 15 deletions(-) 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! From b1fa5f15181e504709683d62ba9cdfc6e4ccf961 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 2 Jan 2018 12:30:57 +0630 Subject: [PATCH 3/3] update add extra time --- app/controllers/api/orders_controller.rb | 21 +++++++++++++ .../origami/addorders_controller.rb | 10 ++----- app/controllers/origami/sales_controller.rb | 7 ++++- app/models/order.rb | 30 ++++++++++--------- app/models/sale.rb | 7 +++-- app/views/origami/home/show.html.erb | 6 +++- 6 files changed, 54 insertions(+), 27 deletions(-) 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' %>
INVOICE DETAILS | Table <%= @dining.name rescue "" %> - Checkin Time : <%= @booking.checkin_at.utc.getlocal.strftime("%I:%M %p") %> + <% if !@booking.reserved_by.nil? && %> + <%= @booking.checkin_at.utc.getlocal.strftime("%I:%M %p") %> - <%= @booking.checkout_at.utc.getlocal.strftime("%I:%M %p") %> + <% else %> + Checkin Time : <%= @booking.checkin_at.utc.getlocal.strftime("%I:%M %p") %> + <% end %>
<% else %> ORDER DETAILS | Table <%= @dining.name rescue "" %>