124 lines
4.5 KiB
Ruby
Executable File
124 lines
4.5 KiB
Ruby
Executable File
|
|
# Order Queue station is where order are submitted to
|
|
# Order can send from tablet | table
|
|
# Source of order will determin where it will appear
|
|
class OrderQueueStation < ApplicationRecord
|
|
has_many :assigned_order_items
|
|
has_many :order_items
|
|
has_many :order_queue_process_by_zones
|
|
has_many :zones, through: :order_queue_process_by_zones
|
|
|
|
scope :active, -> {where(is_active: true)}
|
|
|
|
# validations
|
|
validates_presence_of :station_name, :printer_name
|
|
|
|
def process_order (order, table_id)
|
|
oqs_stations = OrderQueueStation.active
|
|
dining=DiningFacility.find(table_id)
|
|
# oqpbz = OrderQueueProcessByZone.find_by_zone_id(dining.zone_id)
|
|
|
|
order_items = order.order_items
|
|
|
|
# get dining
|
|
booking = Booking.find_by_dining_facility_id(dining.id)
|
|
|
|
#Assign OQS id to order Items
|
|
# oqs_stations.each do |oqs|
|
|
# is_auto_printed = false
|
|
# oqs_order_items = []
|
|
# #Get List of items -
|
|
# pq_items = JSON.parse(oqs.processing_items)
|
|
|
|
# #Loop through the processing items
|
|
# pq_items.each do |pq_item|
|
|
# #Processing through the looping items
|
|
# order_items.each do |order_item|
|
|
# if (pq_item == order_item.item_code)
|
|
# # if oqs.id == oqpbz.order_queue_station_id
|
|
# # #Same Order_items can appear in two location.
|
|
# # AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
|
|
# # else
|
|
|
|
# if (order_item.price != 0)
|
|
# AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
|
|
# oqs_order_items.push(order_item)
|
|
# end
|
|
# # end
|
|
# end
|
|
# end
|
|
# end
|
|
|
|
# ToDo per item per printer
|
|
|
|
OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}").find_each do |oqpbz|
|
|
oqs = OrderQueueStation.find(oqpbz.order_queue_station_id)
|
|
is_auto_printed = false
|
|
oqs_order_items = []
|
|
|
|
if oqs.is_active
|
|
#Get List of items -
|
|
pq_items = JSON.parse(oqs.processing_items)
|
|
#Loop through the processing items
|
|
pq_items.each do |pq_item|
|
|
#Processing through the looping items
|
|
order_items.each do |order_item|
|
|
if (pq_item == order_item.item_code)
|
|
# if oqs.id == oqpbz.order_queue_station_id
|
|
# #Same Order_items can appear in two location.
|
|
# AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
|
|
# else
|
|
|
|
# if (order_item.price != 0)
|
|
AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs)
|
|
oqs_order_items.push(order_item)
|
|
# end
|
|
# end
|
|
end
|
|
end
|
|
end
|
|
|
|
# if oqs.auto_print
|
|
# if oqs_order_items.length > 0
|
|
# print_slip(oqs, order, oqs_order_items)
|
|
# is_auto_printed = true
|
|
# end
|
|
# end
|
|
end
|
|
end
|
|
# end
|
|
end
|
|
|
|
private
|
|
#Print order_items in 1 slip
|
|
def print_slip(oqs, order, order_items)
|
|
# unique_code="OrderSummaryPdf"
|
|
|
|
# print_settings=PrintSetting.find_by_unique_code(unique_code)
|
|
# 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
|
|
end
|
|
|
|
#Print order_item in 1 slip per item
|
|
def print_slip_item(oqs, assigned_item)
|
|
# unique_code="OrderItemPdf"
|
|
# order_item = OrderItem.where("order_id='#{assigned_item.order_id}' AND item_instance_code='#{assigned_item.instance_code}'").first()
|
|
# # print when complete click
|
|
# print_settings=PrintSetting.find_by_unique_code(unique_code)
|
|
# order_queue_printer= Printer::OrderQueuePrinter.new(print_settings)
|
|
# order_queue_printer.print_order_item(print_settings, oqs,item.order_id, order_item.order_items_id, print_status="" )
|
|
|
|
# # update print status for completed same order items
|
|
# assigned_order_item.each do |ai|
|
|
# ai.print_status=true
|
|
# ai.save
|
|
# end
|
|
end
|
|
end
|