update for addorder and printer
This commit is contained in:
@@ -4,6 +4,8 @@ class DiningFacility < ApplicationRecord
|
||||
has_one :dining_charge
|
||||
has_one :cashier_terminal_by_zone, foreign_key: "zone_id", primary_key: "zone_id"
|
||||
has_one :cashier_terminal, through: :cashier_terminal_by_zone
|
||||
has_many :order_queue_process_by_zones, foreign_key: "zone_id", primary_key: "zone_id"
|
||||
has_many :order_queue_stations, -> { where(is_active: true) }, through: :order_queue_process_by_zones
|
||||
|
||||
has_many :bookings
|
||||
|
||||
|
||||
@@ -132,7 +132,6 @@ class Order < ApplicationRecord
|
||||
menu_items = MenuItem.search_by_item_code(item_instance_codes)
|
||||
menu_items += Product.search_by_product_code(item_instance_codes) if menu_items.length < item_instance_codes.length
|
||||
|
||||
new_order_items = []
|
||||
items.each do |order_item|
|
||||
menu_item = menu_items.find { |i| i[:item_instance_code].downcase == order_item[:item_instance_code].downcase }
|
||||
sub_order_items = []
|
||||
@@ -144,7 +143,7 @@ class Order < ApplicationRecord
|
||||
end
|
||||
end
|
||||
sub_order_items = sub_order_items.to_json
|
||||
new_order_items << OrderItem.new({
|
||||
self.order_items.build({
|
||||
item_code: menu_item[:item_code],
|
||||
item_instance_code: order_item[:item_instance_code],
|
||||
item_name: menu_item[:name],
|
||||
@@ -159,7 +158,6 @@ class Order < ApplicationRecord
|
||||
})
|
||||
end
|
||||
|
||||
self.order_items << new_order_items
|
||||
self.item_count = self.order_items.count
|
||||
self.save!
|
||||
|
||||
@@ -408,62 +406,28 @@ class Order < ApplicationRecord
|
||||
print_status = nil
|
||||
cup_status = nil
|
||||
|
||||
#Send to background job for processing
|
||||
order = Order.find(order_id)
|
||||
sidekiq = Lookup.find_by_lookup_type("sidekiq")
|
||||
#Send to background job for processing
|
||||
order = Order.find(order_id)
|
||||
sidekiq = Lookup.find_by_lookup_type("sidekiq")
|
||||
|
||||
if ENV["SERVER_MODE"] != 'cloud'
|
||||
cup_status = `#{"sudo service cups status"}`
|
||||
print_status = check_cup_status(cup_status)
|
||||
if ENV["SERVER_MODE"] != 'cloud'
|
||||
if Printer::PrinterWorker.printers.blank?
|
||||
msg = 'Print Error ! Please contact to service'
|
||||
ActionCable.server.broadcast "call_waiter_channel", table: msg, time:'print_error', from: ''
|
||||
end
|
||||
end
|
||||
|
||||
if print_status
|
||||
if !sidekiq.nil?
|
||||
OrderQueueProcessorJob.perform_later(order_id, table_id)
|
||||
else
|
||||
if order
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.process_order(order, table_id, source)
|
||||
end
|
||||
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
||||
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
|
||||
end
|
||||
else
|
||||
if ENV["SERVER_MODE"] != 'cloud'
|
||||
cup_start = `#{"sudo service cups start"}`
|
||||
cup_status = `#{"sudo service cups status"}`
|
||||
print_status = check_cup_status(cup_status)
|
||||
end
|
||||
|
||||
if print_status
|
||||
if !sidekiq.nil?
|
||||
OrderQueueProcessorJob.perform_later(order_id, table_id)
|
||||
else
|
||||
if order
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.process_order(order, table_id, source)
|
||||
end
|
||||
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
||||
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
|
||||
end
|
||||
else
|
||||
if ENV["SERVER_MODE"] != 'cloud'
|
||||
|
||||
msg = ' Print Error ! Please contact to service'
|
||||
ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error'
|
||||
end
|
||||
if !sidekiq.nil?
|
||||
OrderQueueProcessorJob.perform_later(order_id, table_id)
|
||||
else
|
||||
if order
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.process_order(order, table_id, source)
|
||||
end
|
||||
assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
||||
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
|
||||
end
|
||||
end
|
||||
if !sidekiq.nil?
|
||||
OrderQueueProcessorJob.perform_later(order_id, table_id)
|
||||
else
|
||||
if order
|
||||
oqs = OrderQueueStation.new
|
||||
oqs.process_order(order, table_id, order_source)
|
||||
end
|
||||
from = getCloudDomain #get sub domain in cloud mode
|
||||
assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
|
||||
ActionCable.server.broadcast "order_queue_station_channel", order: assign_order, from: from
|
||||
end
|
||||
end
|
||||
|
||||
def self.check_cup_status(status)
|
||||
|
||||
@@ -15,14 +15,14 @@ class OrderQueueStation < ApplicationRecord
|
||||
validates_presence_of :station_name, :printer_name
|
||||
|
||||
def process_order(order, table_id, order_source = nil, pdf_status = nil ,change_to=nil, current_user=nil)
|
||||
oqs_stations = OrderQueueStation.active
|
||||
order_items = order.order_items
|
||||
|
||||
if table_id.to_i > 0
|
||||
# get dining
|
||||
dining = DiningFacility.find(table_id)
|
||||
oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}").pluck(:order_queue_station_id)
|
||||
oqs_stations = oqs_stations.select { |s| oqs_by_zones.include? s.id }
|
||||
oqs_stations = dining.order_queue_stations
|
||||
else
|
||||
oqs_stations = OrderQueueStation.active
|
||||
end
|
||||
|
||||
assigned_order_items = []
|
||||
@@ -30,12 +30,12 @@ class OrderQueueStation < ApplicationRecord
|
||||
|
||||
# ToDo per item per printer
|
||||
oqs_stations.each do |oqs|
|
||||
oqs_order_items = nil
|
||||
oqs_order_items = order_items.select { |i| JSON.parse(oqs.processing_items).include? i.item_code }
|
||||
assigned_order_items += oqs_order_items.map { |i| AssignedOrderItem.new({ order: order, item_code: i.item_code, instance_code: i.item_instance_code, order_queue_station: oqs, print_status: false, delivery_status: false }) }
|
||||
oqs_order_items_by_zones << { oqs: oqs, oqs_order_items: oqs_order_items }
|
||||
|
||||
print_status = false
|
||||
if oqs.auto_print && order_source != "quick_service"
|
||||
print_status = true
|
||||
if oqs_order_items.length > 0
|
||||
if oqs.cut_per_item
|
||||
print_slip_item(oqs, order, oqs_order_items, pdf_status, change_to, current_user, table_id)
|
||||
@@ -44,9 +44,9 @@ class OrderQueueStation < ApplicationRecord
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
assigned_order_items.each(&:save)
|
||||
oqs_order_items.each { |i| AssignedOrderItem.create({ order: order, item_code: i.item_code, instance_code: i.item_instance_code, order_queue_station: oqs, print_status: print_status, delivery_status: false }) }
|
||||
end
|
||||
end
|
||||
|
||||
def pay_process_order_queue (order_id, table_id)
|
||||
@@ -155,13 +155,10 @@ class OrderQueueStation < ApplicationRecord
|
||||
else
|
||||
move_print_pdf(change_to,current_user,table_id,order_items,oqs)
|
||||
end
|
||||
|
||||
AssignedOrderItem.where("order_id = ?", order.order_id).update_all(print_status: true)
|
||||
end
|
||||
|
||||
#Print order_item in 1 slip per item
|
||||
def print_slip_item(oqs, order, assigned_items,pdf_status=nil,change_to=nil,current_user=nil,table_id=nil)
|
||||
|
||||
if pdf_status.nil?
|
||||
# order_item = OrderItem.where("order_id='#{assigned_item.order_id}' AND item_instance_code='#{assigned_item.instance_code}'").first()
|
||||
# print when complete click
|
||||
@@ -176,8 +173,6 @@ class OrderQueueStation < ApplicationRecord
|
||||
else
|
||||
move_print_pdf(change_to,current_user,table_id,assigned_items,oqs)
|
||||
end
|
||||
|
||||
AssignedOrderItem.where("order_id = ?", order.order_id).update_all(print_status: true)
|
||||
end
|
||||
|
||||
def move_print_pdf(change_to,current_user,change_from,order_items,oqs)
|
||||
|
||||
@@ -23,28 +23,18 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
|
||||
pdf.render_file filename
|
||||
|
||||
if oqs.print_copy
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#For print copy
|
||||
# pdf.render_file filename.gsub(".","-copy.")
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
else
|
||||
print_settings.print_copies = 1
|
||||
print_settings.save!
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#For print copy
|
||||
# pdf.render_file filename.gsub(".","-copy.")
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
|
||||
return filename, order_id, oqs.printer_name
|
||||
end
|
||||
|
||||
# Query for per order
|
||||
def print_order_summary(print_settings,oqs, order_id, order_items, print_status, before_updated_qty="", options="")
|
||||
def print_order_summary(print_settings, oqs, order_id, order_items, print_status, before_updated_qty="", options="")
|
||||
#Use CUPS service
|
||||
#Generate PDF
|
||||
#Print
|
||||
@@ -55,7 +45,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
end
|
||||
|
||||
shop = Shop.current_shop
|
||||
directory_name = 'public/orders_'+shop.shop_code
|
||||
directory_name = "public/orders_#{shop.shop_code}"
|
||||
Dir.mkdir(directory_name) unless File.exists?(directory_name)
|
||||
|
||||
# For Print Per Item
|
||||
@@ -64,10 +54,10 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
order_items.each do |odi|
|
||||
odi_item = print_query('order_item', odi.order_items_id)
|
||||
|
||||
filename = directory_name + "/order_item_#{order_id}" + ".pdf"
|
||||
filename = directory_name + "/order_item_#{order_id}.pdf"
|
||||
# filename = "tmp/order_item_#{order_id}" + ".pdf"
|
||||
# For Item Options
|
||||
options = odi.options == "[]"? "" : odi.options
|
||||
options = odi.options == "[]" ? "" : odi.options
|
||||
|
||||
# check for item not to show
|
||||
#if odi.price != 0
|
||||
@@ -75,19 +65,10 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
|
||||
# pdf.render_file "tmp/order_item.pdf"
|
||||
pdf.render_file filename
|
||||
if oqs.print_copy
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
end
|
||||
else
|
||||
print_settings.print_copies = 1
|
||||
print_settings.save!
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
end
|
||||
#end
|
||||
end
|
||||
@@ -95,33 +76,24 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
else
|
||||
order = print_query('order_summary', order_id)
|
||||
|
||||
filename = directory_name + "/order_summary_#{order_id}" + ".pdf"
|
||||
filename = directory_name + "/order_summary_#{order_id}.pdf"
|
||||
# filename = "tmp/order_summary_#{order_id}" + ".pdf"
|
||||
pdf = print_settings.unique_code.constantize.new(print_settings, order, print_status, order_items, oqs.use_alternate_name, before_updated_qty)
|
||||
|
||||
pdf.render_file filename
|
||||
if oqs.print_copy
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#For print copy
|
||||
# pdf.render_file filename.gsub(".","-copy.")
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
else
|
||||
print_settings.print_copies = 1
|
||||
print_settings.save!
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#For print copy
|
||||
# pdf.render_file filename.gsub(".","-copy.")
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
end
|
||||
return filename, order_id, oqs.printer_name
|
||||
end
|
||||
|
||||
# Print for orders in booking
|
||||
def print_booking_summary(print_settings,oqs, booking_id, print_status,before_updated_qty="")
|
||||
def print_booking_summary(print_settings, oqs, booking_id, print_status,before_updated_qty="")
|
||||
# Must be one print
|
||||
if print_settings.print_copies == 0
|
||||
print_settings.print_copies = 1
|
||||
@@ -146,36 +118,10 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
|
||||
# check for item not to show
|
||||
#if odi.price != 0
|
||||
pdf = print_settings.unique_code.constantize.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
|
||||
pdf = print_settings.unique_code.constantize.new(print_settings, odi, print_status, options, oqs.use_alternate_name, before_updated_qty)
|
||||
|
||||
pdf.render_file filename
|
||||
|
||||
if oqs.print_copy
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#For print copy
|
||||
# pdf.render_file filename.gsub(".","-copy.")
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
else
|
||||
print_settings.print_copies = 1
|
||||
print_settings.save!
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
end
|
||||
#end
|
||||
end
|
||||
# For Print Order Summary
|
||||
else
|
||||
# filename = "tmp/booking_summary_#{booking_id}" + ".pdf"
|
||||
filename = directory_name + "/booking_summary_#{booking_id}" + ".pdf"
|
||||
pdf = print_settings.unique_code.constantize.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
|
||||
|
||||
pdf.render_file filename
|
||||
if oqs.print_copy
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
@@ -183,14 +129,22 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
#For print copy
|
||||
# pdf.render_file filename.gsub(".","-copy.")
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
else
|
||||
print_settings.print_copies = 1
|
||||
print_settings.save!
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#end
|
||||
end
|
||||
# For Print Order Summary
|
||||
else
|
||||
# filename = "tmp/booking_summary_#{booking_id}" + ".pdf"
|
||||
filename = directory_name + "/booking_summary_#{booking_id}" + ".pdf"
|
||||
pdf = print_settings.unique_code.constantize.new(print_settings, order, print_status, oqs.use_alternate_name, before_updated_qty)
|
||||
|
||||
pdf.render_file filename
|
||||
#no print in cloud server
|
||||
if ENV["SERVER_MODE"] != "cloud"
|
||||
self.print(filename, oqs.printer_name)
|
||||
end
|
||||
#For print copy
|
||||
# pdf.render_file filename.gsub(".","-copy.")
|
||||
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
|
||||
end
|
||||
return filename, booking_id, oqs.printer_name
|
||||
end
|
||||
@@ -206,14 +160,14 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
.joins("left join menu_items as item ON item.item_code = order_items.item_code")
|
||||
|
||||
if type == "order_item"
|
||||
query.where("order_items.order_items_id = '#{ id }'")
|
||||
query.where("order_items.order_items_id = ?", id)
|
||||
.group("order_items.item_code")
|
||||
elsif type == "order_summary"
|
||||
query.where("orders.order_id = '#{ id }'")
|
||||
query.where("orders.order_id = ?", id)
|
||||
.group("order_items.order_items_id")
|
||||
else
|
||||
# order summary for booking
|
||||
query.where("b.booking_id = '#{ id }'")
|
||||
query.where("b.booking_id = ?", id)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -37,14 +37,15 @@ class Printer::PrinterWorker
|
||||
Cups.default_printer
|
||||
end
|
||||
|
||||
def print(file_path,printer_destination = nil )
|
||||
def self.printer_exists?(printer)
|
||||
Cups.show_destinations.include? printer
|
||||
end
|
||||
|
||||
def print(file_path, printer_destination = nil )
|
||||
if printer_destination.nil?
|
||||
printer_destination = self.printer_destination
|
||||
end
|
||||
|
||||
puts printer_destination
|
||||
puts '........Printer Destination..........'
|
||||
|
||||
copy = self.print_copies
|
||||
#Print only when printer information is not null
|
||||
if !self.printer_destination.nil?
|
||||
|
||||
Reference in New Issue
Block a user