From a3c24e8bf69dbd7baadf4166b4e0c60a3cf00a1c Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Wed, 4 Jul 2018 15:23:57 +0630 Subject: [PATCH] Pull from master --- .../origami/addorders_controller.rb | 4 +- app/controllers/origami/home_controller.rb | 2 +- app/controllers/origami/rooms_controller.rb | 4 +- app/models/order.rb | 7 ++-- app/models/order_queue_station.rb | 24 +++++++----- app/models/sale_order.rb | 8 ++-- app/models/shift_sale.rb | 4 +- .../api/restaurant/zones/index.json.jbuilder | 16 ++------ app/views/origami/home/index.html.erb | 37 +++++++++++++------ app/views/origami/home/show.html.erb | 4 +- app/views/origami/rooms/show.html.erb | 36 +++++++++--------- 11 files changed, 82 insertions(+), 64 deletions(-) diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 220cce6c..1d3bd755 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -96,8 +96,8 @@ class Origami::AddordersController < BaseOrigamiController end def create - Rails.logger.debug "Order Source - " + params[:order_source].to_s - Rails.logger.debug "Table ID - " + params[:table_id].to_s + # Rails.logger.debug "Order Source - " + params[:order_source].to_s + # Rails.logger.debug "Table ID - " + params[:table_id].to_s is_extra_time = false extra_time = '' diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 773892f3..2d03d298 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -7,7 +7,7 @@ class Origami::HomeController < BaseOrigamiController @tables = Table.unscoped.all.active.order('status desc') @rooms = Room.unscoped.all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) - @orders = Order.where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') + @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @shop = Shop.first # @shift = ShiftSale.current_open_shift(current_user.id) diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index 6877f8aa..49b7ce14 100755 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -3,7 +3,7 @@ class Origami::RoomsController < BaseOrigamiController @tables = Table.unscoped.all.active.order('status desc') @rooms = Room.unscoped.all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) - @orders = Order.where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') + @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') # @shift = ShiftSale.current_open_shift(current_user.id) @webview = false if check_mobile @@ -20,7 +20,7 @@ class Origami::RoomsController < BaseOrigamiController @tables = Table.unscoped.all.active.order('status desc') @rooms = Room.unscoped.all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) - @orders = Order.where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') + @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @room = DiningFacility.find(params[:room_id]) diff --git a/app/models/order.rb b/app/models/order.rb index 571c549c..01136578 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -44,8 +44,9 @@ class Order < ApplicationRecord if self.table_id.to_i > 0 table = DiningFacility.find(self.table_id) - table.status = "occupied" - table.save + table.update_attributes(status:"occupied") + # table.status = "occupied" + # table.save end else @@ -144,7 +145,7 @@ class Order < ApplicationRecord end #if (!menu_item.nil?) - Rails.logger.debug menu_item + # Rails.logger.debug menu_item set_order_items = Array.new ##If menu Item set item - must add child items to order as well, where price is only take from menu_item if (menu_item[:type] == "SetMenuItem") diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index 9ecd54c0..19bf82be 100755 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -232,12 +232,15 @@ class OrderQueueStation < ApplicationRecord order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) order_queue_printer.print_order_summary(print_settings, oqs,order.order_id, order_items, print_status="") - AssignedOrderItem.where("order_id = '#{ order.order_id }'").find_each do |ai| - # update print status for order items - ai.print_status=true - ai.save - end + assigned =AssignedOrderItem.where("order_id = '#{ order.order_id }'").pluck(:assigned_order_item_id) + AssignedOrderItem.where({ order_id: '#{assigned}'}).update_all(print_status: true) + # assigned_items =AssignedOrderItem.where("order_id = '#{ order.order_id }'") + # assigned_items.each do |ai| + # # update print status for order items + # ai.print_status=true + # ai.save + # end end #Print order_item in 1 slip per item @@ -273,9 +276,12 @@ class OrderQueueStation < ApplicationRecord end end # update print status for completed same order items - AssignedOrderItem.where("order_id = '#{ order.order_id }'").find_each do |ai| - ai.print_status=true - ai.save - end + # AssignedOrderItem.where("order_id = '#{ order.order_id }'").update_all(print_status: true) + # AssignedOrderItem.where("order_id = '#{ order.order_id }'").find_each do |ai| + # ai.print_status=true + # ai.save + # end + assigned =AssignedOrderItem.where("order_id = '#{ order.order_id }'").pluck(:assigned_order_item_id) + AssignedOrderItem.where({ order_id: '#{assigned}'}).update_all(print_status: true) end end diff --git a/app/models/sale_order.rb b/app/models/sale_order.rb index 786054c9..56a64353 100755 --- a/app/models/sale_order.rb +++ b/app/models/sale_order.rb @@ -8,10 +8,10 @@ class SaleOrder < ApplicationRecord belongs_to :order def create_sale_order(sale, order) - self.sale_id = sale - self.order_id = order - self.save - + sale_order = SaleOrder.new + sale_order.sale_id = sale + sale_order.order_id = order + sale_order.save! end private diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index d217a75c..77adf0bd 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -17,8 +17,8 @@ class ShiftSale < ApplicationRecord belongs_to :employee, :foreign_key => 'employee_id' def self.current_shift - today_date = DateTime.now.strftime("%Y-%m-%d") - shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null").take + # today_date = DateTime.now.strftime("%Y-%m-%d") + shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null").first return shift end diff --git a/app/views/api/restaurant/zones/index.json.jbuilder b/app/views/api/restaurant/zones/index.json.jbuilder index e4d09977..4a8666b4 100755 --- a/app/views/api/restaurant/zones/index.json.jbuilder +++ b/app/views/api/restaurant/zones/index.json.jbuilder @@ -6,25 +6,21 @@ if @zones #List all tables json.tables zone.tables do |table| if table.is_active - booking = table.get_current_booking json.id table.id json.name table.name json.status table.status json.zone_id table.zone_id #Add this zone_id to keep data structure consistance - json.current_booking booking.booking_id rescue "" - json.sale_id booking.sale_id rescue "" + json.current_booking table.get_current_booking.booking_id rescue "" end end json.rooms zone.rooms do |room| if room.is_active - booking = room.get_current_booking json.id room.id json.name room.name json.status room.status json.zone_id room.zone_id #Add this zone_id to keep data structure consistance - json.current_booking booking.booking_id rescue "" - json.sale_id booking.sale_id rescue "" + json.current_booking room.get_current_booking.booking_id rescue "" end end end @@ -32,25 +28,21 @@ if @zones else #list all tables and rooms with out zones json.tables @all_tables do |table| if table.is_active - booking = table.get_current_booking json.id table.id json.name table.name json.status table.status json.zone_id table.zone_id #Add this zone_id to keep data structure consistance - json.current_booking booking.booking_id rescue "" - json.sale_id booking.sale_id rescue "" + json.current_booking table.get_current_booking.booking_id rescue "" end end json.rooms @all_rooms do |room| if room.is_active - booking = room.get_current_booking json.id room.id json.name room.name json.status room.status json.zone_id room.zone_id #Add this zone_id to keep data structure consistance - json.current_booking booking.booking_id rescue "" - json.sale_id booking.sale_id rescue "" + json.current_booking room.get_current_booking.booking_id rescue "" end end end diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 3f9daa9a..3e565ffa 100755 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -50,8 +50,8 @@
<% end %>
- Zone <%= table.zone_id %>
- Table <%= table.name %> ( <%= table.seater %> Seat ) + Table <%= table.name %> ( <%= table.seater %> Seat )
+ Zone <%= table.zone_id %>
<% else %> @@ -61,16 +61,16 @@
<% end %>
- Zone <%= table.zone_id %>
- Table <%= table.name %> ( <%= table.seater %> Seat ) + Table <%= table.name %> ( <%= table.seater %> Seat )
+ Zone <%= table.zone_id %>
<% end %> <% else %>
- Zone <%= table.zone_id %>
- Table <%= table.name %> ( <%= table.seater %> Seat ) + Table <%= table.name %> ( <%= table.seater %> Seat )
+ Zone <%= table.zone_id %>
<% end %> @@ -107,11 +107,26 @@
<% @orders.each do |order| %> -
-
- <%= order.order_id %> -
-
+
text-white" data-id="<%= order.order_id %>"> +
+ <% + order_status = "" + sale_order = order.sale_orders.first + if sale_order + unless sale_order.sale_id.nil? + sale = Sale.find(sale_order.sale_id) + order_status = sale.sale_status + if order_status == 'new' + order_status = order.status + end + end + else + order_status = order.status + end + %> + <%= order.order_id %> <% if !order_status.empty? %>| <%= order_status %> <% end %> +
+
<% end %>
diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 211cc23b..11057247 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -371,7 +371,9 @@ <% else %> No Tax <% end %>
- + <%if !@webview %> + + <% end %> <%= @obj_sale.total_tax rescue 0%> diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 52c5d108..0f3064f1 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -144,25 +144,25 @@
<% @orders.each do |order| %>
text-white" data-id="<%= order.order_id %>"> -
- <% - order_status = "" - sale_order = SaleOrder.find_by_order_id(order) - if sale_order - unless sale_order.sale_id.nil? - sale = Sale.find(sale_order.sale_id) - order_status = sale.sale_status - if order_status == 'new' - order_status = order.status +
+ <% + order_status = "" + sale_order = order.sale_orders.first + if sale_order + unless sale_order.sale_id.nil? + sale = Sale.find(sale_order.sale_id) + order_status = sale.sale_status + if order_status == 'new' + order_status = order.status + end end + else + order_status = order.status end - else - order_status = order.status - end - %> + %> <%= order.order_id %> <% if !order_status.empty? %>| <%= order_status %> <% end %> -
-
+
+
<% end %> @@ -360,7 +360,9 @@ <% else %> No Tax <% end %>
- + <%if !@webview %> + + <% end %> <%= @obj_sale.total_tax rescue 0%>