Files
sx-fc/app/models/order_queue_station.rb
2017-06-19 15:55:21 +06:30

83 lines
2.6 KiB
Ruby

# 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)}
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
#Assign OQS id to order Items
oqs_stations.each do |oqs|
#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
AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
end
puts oqs.station_name
puts oqs.auto_print
puts oqs.cut_per_item
puts oqs.print_copy
if oqs.auto_print
print_slip(oqs, order, order_items)
end
end
end
end
end
#Print OQS where printing is require
end
private
#Print order_items in 1 slip
def print_slip(oqs, order, items)
unique_code="OrderSummaryPdf"
# 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_summary(oqs,order.order_id)
# update print status for completed same order items
items.each do |ai|
ai.print_status=true
ai.save
end
end
#Print order_item in 1 slip per item
def print_slip_item(oqs, item)
unique_code="OrderItemPdf"
# 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(oqs,item.order_id, item.item_code )
# update print status for completed same order items
item.each do |ai|
ai.print_status=true
ai.save
end
end
end