From c40a2c78e7ef58974f74e6361d41bf31e680b658 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 16 Jun 2017 13:44:39 +0630 Subject: [PATCH 1/4] oqs autoprint developing --- app/controllers/oqs/print_controller.rb | 12 +++---- .../order_queue_stations_controller.rb | 2 +- app/models/printer/order_queue_printer.rb | 33 ++++++++++++++----- .../order_queue_stations/_form.html.erb | 1 + .../order_queue_stations/index.html.erb | 2 ++ .../order_queue_stations/show.html.erb | 5 +++ 6 files changed, 40 insertions(+), 15 deletions(-) diff --git a/app/controllers/oqs/print_controller.rb b/app/controllers/oqs/print_controller.rb index ecbc94e7..9fc2a2d7 100644 --- a/app/controllers/oqs/print_controller.rb +++ b/app/controllers/oqs/print_controller.rb @@ -6,13 +6,13 @@ class Oqs::PrintController < ApplicationController assigned_item=AssignedOrderItem.find(assigned_item_id) assigned_items=AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_id + "'"); - # printer for each stations - printer_name = assigned_item.order_queue_station.printer_name + # order queue stations + oqs = assigned_item.order_queue_station # 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(printer_name,assigned_item.order_id, assigned_item.item_code ) + order_queue_printer.print_order_item(oqs,assigned_item.order_id, assigned_item.item_code ) # update print status for completed same order items assigned_items.each do |ai| @@ -28,13 +28,13 @@ class Oqs::PrintController < ApplicationController assigned_item=AssignedOrderItem.find(assigned_item_id) assigned_items=AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_id + "'"); - # printer for each stations - printer_name = assigned_item.order_queue_station.printer_name + # order queue stations + oqs = assigned_item.order_queue_station # 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(printer_name,assigned_item.order_id) + order_queue_printer.print_order_summary(oqs,assigned_item.order_id) # update print status for completed same order items assigned_items.each do |ai| diff --git a/app/controllers/settings/order_queue_stations_controller.rb b/app/controllers/settings/order_queue_stations_controller.rb index e8b9bbe0..408519d2 100644 --- a/app/controllers/settings/order_queue_stations_controller.rb +++ b/app/controllers/settings/order_queue_stations_controller.rb @@ -71,6 +71,6 @@ class Settings::OrderQueueStationsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def settings_order_queue_station_params - params.require(:order_queue_station).permit(:station_name, :is_active, :processing_items, :print_copy, :printer_name, :font_size, :cut_per_item, :use_alternate_name, :created_by) + params.require(:order_queue_station).permit(:station_name, :is_active, :auto_print, :processing_items, :print_copy, :printer_name, :font_size, :cut_per_item, :use_alternate_name, :created_by) end end diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 9b3f5205..57a819c9 100644 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -1,25 +1,42 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker - def print_order_item(printer_name,order_id, item_code) + def print_order_item(oqs,order_id, item_code) #Use CUPS service #Generate PDF #Print order_item= print_query('order_item', item_code) #OrderItem.find_by_item_code(item_code) pdf = OrderItemPdf.new(order_item[0]) pdf.render_file "tmp/receipt.pdf" - self.print("tmp/receipt.pdf", printer_name) + if oqs.print_copy + self.print("tmp/receipt.pdf", oqs.printer_name)*2 + else + self.print("tmp/receipt.pdf", oqs.printer_name) + end end - def print_order_summary(printer_name,order_id) + def print_order_summary(oqs,order_id) #Use CUPS service #Generate PDF #Print order=print_query('order_summary',order_id) - filename = "tmp/order_summary_#{order_id}" + ".pdf" - pdf = OrderSummaryPdf.new(order) - pdf.render_file filename - - self.print(filename, printer_name) + # For Print Per Item + if oqs.cut_per_item + order.each do|odi| + pdf = OrderItemPdf.new(odi) + pdf.render_file "tmp/receipt.pdf" + if oqs.print_copy + self.print("tmp/receipt.pdf", oqs.printer_name)*2 + else + self.print("tmp/receipt.pdf", oqs.printer_name) + end + end + # For Print Order Summary + else + filename = "tmp/order_summary_#{order_id}" + ".pdf" + pdf = OrderSummaryPdf.new(order) + pdf.render_file filename + self.print(filename, printer_name) + end end # Query for OQS with status diff --git a/app/views/settings/order_queue_stations/_form.html.erb b/app/views/settings/order_queue_stations/_form.html.erb index db7ed5fd..bc76f044 100644 --- a/app/views/settings/order_queue_stations/_form.html.erb +++ b/app/views/settings/order_queue_stations/_form.html.erb @@ -4,6 +4,7 @@
<%= f.input :station_name %> <%= f.input :is_active %> + <%= f.input :auto_print %> <%= f.input :printer_name %> <%= f.input :font_size %> <%= f.input :print_copy %> diff --git a/app/views/settings/order_queue_stations/index.html.erb b/app/views/settings/order_queue_stations/index.html.erb index 03da3c23..287fb10b 100644 --- a/app/views/settings/order_queue_stations/index.html.erb +++ b/app/views/settings/order_queue_stations/index.html.erb @@ -17,6 +17,7 @@ Station name Is active + Auto Print Print copy Printer name Cut per item @@ -31,6 +32,7 @@ <%= link_to settings_order_queue_station.station_name, settings_order_queue_station_path(settings_order_queue_station) %> <%= settings_order_queue_station.is_active %> + <%= settings_order_queue_station.auto_print %> <%= settings_order_queue_station.print_copy %> <%= settings_order_queue_station.printer_name %> <%= settings_order_queue_station.cut_per_item %> diff --git a/app/views/settings/order_queue_stations/show.html.erb b/app/views/settings/order_queue_stations/show.html.erb index 1a80c2c0..e92ed0bb 100644 --- a/app/views/settings/order_queue_stations/show.html.erb +++ b/app/views/settings/order_queue_stations/show.html.erb @@ -18,6 +18,11 @@ <%= @settings_order_queue_station.is_active %>

+

+ Auto Print: + <%= @settings_order_queue_station.auto_print %> +

+

Processing items: <%= @settings_order_queue_station.processing_items %> From 841f74b4066ba9ec1e547a6d7afc4732143e09c6 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 16 Jun 2017 18:22:18 +0630 Subject: [PATCH 2/4] update footer in req bill --- app/pdf/receipt_bill_pdf.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 2d67989d..524ee7e5 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -229,7 +229,7 @@ class ReceiptBillPdf < Prawn::Document stroke_horizontal_rule move_down 5 - text "*** Thank You ***", :left_margin => -10, :size => self.header_font_size,:align => :center + text "Thank You! See you Again", :left_margin => -10, :size => self.header_font_size,:align => :center move_down 5 end From 0a496f227446325ffa7723438f3324279aed9a8c Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 16 Jun 2017 18:55:14 +0630 Subject: [PATCH 3/4] update order for oqs --- app/jobs/order_queue_processor_job.rb | 4 ++-- app/models/order.rb | 2 +- app/models/order_queue_station.rb | 24 ++++++++++++++---------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/jobs/order_queue_processor_job.rb b/app/jobs/order_queue_processor_job.rb index e92faa36..5b3423dc 100644 --- a/app/jobs/order_queue_processor_job.rb +++ b/app/jobs/order_queue_processor_job.rb @@ -1,7 +1,7 @@ class OrderQueueProcessorJob < ApplicationJob queue_as :default - def perform(order_id) + def perform(order_id, table_id) # Do something later #Order ID order = Order.find(order_id) @@ -10,7 +10,7 @@ class OrderQueueProcessorJob < ApplicationJob #Execute orders and send to order stations if order oqs = OrderQueueStation.new - oqs.process_order(order) + oqs.process_order(order, table_id) end end diff --git a/app/models/order.rb b/app/models/order.rb index f3ae798c..2ea76a98 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -199,7 +199,7 @@ class Order < ApplicationRecord #Process order items and send to order queue def process_order_queue #Send to background job for processing - OrderQueueProcessorJob.perform_later(self.id) + OrderQueueProcessorJob.perform_later(self.id, self.table_id) end diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index b0619af2..062c2c65 100644 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -8,26 +8,30 @@ class OrderQueueStation < ApplicationRecord scope :active, -> {where(is_active: true)} - def process_order (order) + def process_order (order, table_id) oqs_stations = OrderQueueStation.active + dining=DiningFacility.find_by_name(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) + 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) - #Same Order_items can appear in two location. - AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) + if oqs.id == oqpbz.order_queue_station_id + #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) + #Same Order_items can appear in two location. + AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) + end end end - end + end #Print OQS where printing is require From 9f3acad10d29c6d461c86a8b5b344331a0080a81 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 16 Jun 2017 19:26:21 +0630 Subject: [PATCH 4/4] update order for oqs --- app/controllers/api/orders_controller.rb | 2 +- app/models/order_queue_station.rb | 3 +-- db/seeds.rb | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index 08847f6f..c383fafb 100644 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -31,7 +31,7 @@ class Api::OrdersController < Api::ApiController @order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile @order.items = params[:order_items] @order.guest = params[:guest_info] - @order.table_id = params[:table_id] + @order.table_id = params[:table_id] # this is dining facilities's id @order.new_booking = true @order.employee_name = current_login_employee.name #Create Table Booking or Room Booking diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index 062c2c65..d6e21c64 100644 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -10,7 +10,7 @@ class OrderQueueStation < ApplicationRecord def process_order (order, table_id) oqs_stations = OrderQueueStation.active - dining=DiningFacility.find_by_name(table_id) + dining=DiningFacility.find(table_id) oqpbz = OrderQueueProcessByZone.find_by_zone_id(dining.zone_id) order_items = order.order_items @@ -31,7 +31,6 @@ class OrderQueueStation < ApplicationRecord end end end - end #Print OQS where printing is require diff --git a/db/seeds.rb b/db/seeds.rb index 56591e2c..07e5746c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -147,8 +147,8 @@ admin_employee = Employee.create({name: "Waiter", role: "waiter", password: "111 admin_employee = Employee.create({name: "Waiter 2", role: "waiter", password: "22222", emp_id:"222", created_by: "SYSTEM DEFAULT"}) admin_employee = Employee.create({name: "Cashier", role: "cashier", password: "33333", emp_id:"333", created_by: "SYSTEM DEFAULT"}) -order_station1=PrintSetting.create({name: "OrderItemPdf", unique_code: "OrderItemPdf", printer_name: "EPSON-TM-T82-S-A"}) -order_station2=PrintSetting.create({name: "Order Summary", unique_code: "OrderSummaryPdf", printer_name: "EPSON-TM-T82-S-A"}) +# order_station1=PrintSetting.create({name: "OrderItemPdf", unique_code: "OrderItemPdf", printer_name: "EPSON-TM-T82-S-A"}) +# order_station2=PrintSetting.create({name: "Order Summary", unique_code: "OrderSummaryPdf", printer_name: "EPSON-TM-T82-S-A"}) request_bill_printer=PrintSetting.create({name: "Receipt Bill", unique_code: "ReceiptBillPdf", printer_name: "EPSON-TM-T82-S-A"}) crm_order_printer=PrintSetting.create({name: "CRM Order", unique_code: "CrmOrderPdf", printer_name: "EPSON-TM-T82-S-A"}) queue_no_printer=PrintSetting.create({name: "Queue No", unique_code: "QueueNoPdf", printer_name: "EPSON-TM-T82-S-A"})