print settings ActionCable

This commit is contained in:
Thein Lin Kyaw
2020-08-18 16:11:17 +06:30
parent 583d7ee473
commit 5dfdc7353e
25 changed files with 1050 additions and 802 deletions

View File

@@ -1,94 +1,66 @@
class Printer::OrderQueuePrinter < Printer::PrinterWorker
def print_order_item(print_settings, oqs, order_id, order_item_id, print_status, before_updated_qty="", options="")
# Must be one print
if print_settings.print_copies == 0
print_settings.print_copies = 1
print_settings.save!
end
order_item = print_query('order_item', order_item_id) #OrderItem.find_by_item_code(item_code)
options = order_item[0].options
# check for item not to show
# if order_item[0].price != 0
pdf = print_settings.unique_code.constantize.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
booking_id = Booking.get_booking_id(order_id)
# end
order_item = print_query('order_item', order_item_id).first #OrderItem.find_by_item_code(item_code)
shop = Shop.current_shop
directory_name = 'public/orders_'+shop.shop_code
Dir.mkdir(directory_name) unless File.exists?(directory_name)
if Lookup.collection_of('print_settings').none? { |x| x == ["ActionCable", "1"] }
# Must be one print
if print_settings.print_copies == 0
print_settings.print_copies = 1
print_settings.save!
end
filename = directory_name + "/order_item_#{order_id}_#{order_item_id}" + ".pdf"
options = order_item.options
# check for item not to show
pdf = print_settings.unique_code.constantize.new(print_settings, order_item, print_status, options, oqs.use_alternate_name, before_updated_qty)
pdf.render_file filename
shop = Shop.current_shop
directory_name = "public/orders_#{shop.shop_code}"
Dir.mkdir(directory_name) unless File.exists?(directory_name)
if ENV["SERVER_MODE"] != "cloud"
self.print(filename, oqs.printer_name)
filename = directory_name + "/order_item_#{order_id}_#{order_item_id}" + ".pdf"
pdf.render_file filename
if ENV["SERVER_MODE"] != "cloud"
self.print(filename, oqs.printer_name)
end
return filename, order_id, oqs.printer_name
else
ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}",
queue: oqs.station_name,
unique_code: print_settings.unique_code,
print_copies: print_settings.print_copies,
data: {
order_item: order_item[0].as_json(methods: :type),
order_item: order_item.as_json(methods: :type),
print_status: print_status.gsub(/[()]/, ""),
booking_id: booking_id,
precision: print_settings.precision
}
)
)
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="")
#Use CUPS service
#Generate PDF
#Print
# Must be one print
if print_settings.print_copies == 0
print_settings.print_copies = 1
print_settings.save!
end
booking_id = Booking.get_booking_id(order_id) #order[0].order_id
order = print_query('order_summary', order_id)
shop = Shop.current_shop
directory_name = "public/orders_#{shop.shop_code}"
Dir.mkdir(directory_name) unless File.exists?(directory_name)
# For Print Per Item
if oqs.cut_per_item
order_items.each do |odi|
odi_item = print_query('order_item', odi.order_items_id)
filename = directory_name + "/order_item_#{order_id}.pdf"
# filename = "tmp/order_item_#{order_id}" + ".pdf"
# For Item Options
options = odi.options == "[]" ? "" : odi.options
# check for item not to show
#if odi.price != 0
pdf = print_settings.unique_code.constantize.new(print_settings, odi_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
# pdf.render_file "tmp/order_item.pdf"
pdf.render_file filename
#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
if Lookup.collection_of('print_settings').none? { |x| x == ["ActionCable", "1"] }
#Use CUPS service
#Generate PDF
#Print
# Must be one print
if print_settings.print_copies == 0
print_settings.print_copies = 1
print_settings.save!
end
# For Print Order Summary
else
booking_id = Booking.get_booking_id(order_id) #order[0].order_id
order = print_query('order_summary', order_id)
shop = Shop.current_shop
directory_name = "public/orders_#{shop.shop_code}"
Dir.mkdir(directory_name) unless File.exists?(directory_name)
filename = directory_name + "/order_summary_#{order_id}.pdf"
# filename = "tmp/order_summary_#{order_id}" + ".pdf"
@@ -98,29 +70,27 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
#no print in cloud server
if ENV["SERVER_MODE"] != "cloud"
self.print(filename, oqs.printer_name)
else
ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}",
queue: oqs.station_name,
unique_code: print_settings.unique_code,
print_copies: print_settings.print_copies,
data: {
order_item: order_items,
order: order.as_json(methods: :type),
print_status: "",
booking_id: booking_id,
precision: print_settings.precision}
)
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
else
ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}",
queue: oqs.station_name,
unique_code: print_settings.unique_code,
print_copies: print_settings.print_copies,
data: {
order_item: order_items,
order: order.as_json(methods: :type),
print_status: "",
booking_id: booking_id,
precision: print_settings.precision
}
)
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