oqs updated

This commit is contained in:
Yan
2017-06-20 13:33:41 +06:30
parent 7fe36e8ef4
commit e43818fdf5
7 changed files with 53 additions and 36 deletions

View File

@@ -122,11 +122,13 @@ $(document).ready(function(){
// Print Order Summary // Print Order Summary
$('#print_order_summary').on('click',function(){ $('#print_order_summary').on('click',function(){
var table_name=$('.selected-item').children().children().children('.order-zone').text().trim();
var assigned_item_id=$('.selected-item').children('.card-block').children('.assigned-order-item').text(); var assigned_item_id=$('.selected-item').children('.card-block').children('.assigned-order-item').text();
var params = { 'id':assigned_item_id }; var params = { 'table_name':table_name };
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: '/oqs/print/print_order_summary/'+assigned_item_id, url: '/oqs/print/print_order_summary/'+assigned_item_id,
data: params,
success: function(data){ } success: function(data){ }
}); });
}); });

View File

@@ -8,11 +8,12 @@ class Oqs::PrintController < ApplicationController
# order queue stations # order queue stations
oqs = assigned_item.order_queue_station oqs = assigned_item.order_queue_station
print_status = assigned_item.print_status == true ? " (Re-Print)" : ""
# print when complete click # print when complete click
print_settings=PrintSetting.find_by_unique_code(unique_code) print_settings=PrintSetting.find_by_unique_code(unique_code)
order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings)
order_queue_printer.print_order_item(oqs,assigned_item.order_id, assigned_item.item_code ) order_queue_printer.print_order_item(oqs, assigned_item.order_id, assigned_item.item_code, print_status )
# update print status for completed same order items # update print status for completed same order items
assigned_items.each do |ai| assigned_items.each do |ai|
@@ -25,16 +26,22 @@ class Oqs::PrintController < ApplicationController
def print_order_summary def print_order_summary
unique_code="OrderSummaryPdf" unique_code="OrderSummaryPdf"
assigned_item_id=params[:id] assigned_item_id=params[:id]
table_name=params[:table_name]
assigned_item=AssignedOrderItem.find(assigned_item_id) assigned_item=AssignedOrderItem.find(assigned_item_id)
assigned_items=AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_id + "'"); assigned_items=AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_id + "'");
# order queue stations # order queue stations
oqs = assigned_item.order_queue_station oqs = assigned_item.order_queue_station
print_status = assigned_item.print_status == true ? " (Re-Print)" : ""
# get dining
dining = DiningFacility.find_by_name(table_name);
booking = Booking.find_by_dining_facility_id(dining.id)
# print when complete click # print when complete click
print_settings=PrintSetting.find_by_unique_code(unique_code) print_settings=PrintSetting.find_by_unique_code(unique_code)
order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings)
order_queue_printer.print_order_summary(oqs,assigned_item.order_id) order_queue_printer.print_order_summary(oqs, booking, print_status)
# update print status for completed same order items # update print status for completed same order items
assigned_items.each do |ai| assigned_items.each do |ai|

View File

@@ -31,6 +31,9 @@ class OrderQueueStation < ApplicationRecord
# #Same Order_items can appear in two location. # #Same Order_items can appear in two location.
# AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) # AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
# else # else
puts pq_item
puts order_item.item_code
puts oqs.station_name
AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
# end # end

View File

@@ -1,11 +1,11 @@
class Printer::OrderQueuePrinter < Printer::PrinterWorker class Printer::OrderQueuePrinter < Printer::PrinterWorker
def print_order_item(oqs,order_id, item_code) def print_order_item(oqs,order_id, item_code, print_status)
#Use CUPS service #Use CUPS service
#Generate PDF #Generate PDF
#Print #Print
order_item= print_query('order_item', item_code) #OrderItem.find_by_item_code(item_code) order_item = print_query('order_item', item_code) #OrderItem.find_by_item_code(item_code)
pdf = OrderItemPdf.new(order_item[0]) pdf = OrderItemPdf.new(order_item[0], print_status)
pdf.render_file "tmp/order_item.pdf" pdf.render_file "tmp/order_item.pdf"
if oqs.print_copy if oqs.print_copy
self.print("tmp/order_item.pdf", oqs.printer_name) self.print("tmp/order_item.pdf", oqs.printer_name)
@@ -15,16 +15,16 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
end end
end end
def print_order_summary(oqs,order_id) def print_order_summary(oqs,booking, print_status)
#Use CUPS service #Use CUPS service
#Generate PDF #Generate PDF
#Print #Print
order=print_query('order_summary',order_id) order=print_query('order_summary',booking.booking_id)
# For Print Per Item # For Print Per Item
if oqs.cut_per_item if oqs.cut_per_item
order.each do|odi| order.each do|odi|
filename = "tmp/order_item_#{odi.item_name}" + ".pdf" filename = "tmp/order_item_#{odi.item_name}" + ".pdf"
pdf = OrderItemPdf.new(odi) pdf = OrderItemPdf.new(odi, print_status)
# pdf.render_file "tmp/order_item.pdf" # pdf.render_file "tmp/order_item.pdf"
pdf.render_file filename pdf.render_file filename
if oqs.print_copy if oqs.print_copy
@@ -36,8 +36,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
end end
# For Print Order Summary # For Print Order Summary
else else
filename = "tmp/order_summary_#{order_id}" + ".pdf" filename = "tmp/order_summary_#{booking.booking_id}" + ".pdf"
pdf = OrderSummaryPdf.new(order) pdf = OrderSummaryPdf.new(order, print_status)
pdf.render_file filename pdf.render_file filename
if oqs.print_copy if oqs.print_copy
self.print(filename, oqs.printer_name) self.print(filename, oqs.printer_name)
@@ -66,8 +66,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
left join bookings AS b ON b.booking_id = bo.booking_id left join bookings AS b ON b.booking_id = bo.booking_id
left join dining_facilities AS df ON df.id = b.dining_facility_id left join dining_facilities AS df ON df.id = b.dining_facility_id
left join customers as cus ON cus.customer_id = orders.customer_id") left join customers as cus ON cus.customer_id = orders.customer_id")
.where("orders.order_id='" + code + "'") .where("b.booking_id='" + code + "'")
.group("order_items.item_code") # .group("order_items.item_code")
end end
end end

View File

@@ -1,16 +1,16 @@
class OrderItemPdf < Prawn::Document class OrderItemPdf < Prawn::Document
attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width
def initialize(order_item) def initialize(order_item, print_status)
self.page_width = 254 self.page_width = 210
self.page_height = 1450 self.page_height = 2500
self.margin = 10 self.margin = 5
self.price_width = 40 # No Need for item self.price_width = 40 # No Need for item
self.qty_width = 34 self.qty_width = 30
self.total_width = 40 # No Need for item self.total_width = 40 # No Need for item
self.item_width = self.page_width - (self.qty_width + (self.margin*4)) self.item_width = self.page_width - self.qty_width
self.item_height = 15 self.item_height = 15
self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width)
self.label_width=80 self.label_width=100
super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height])
# super(:margin => [10, 5, 30, 5], :page_size => [200,400]) # super(:margin => [10, 5, 30, 5], :page_size => [200,400])
@@ -21,7 +21,7 @@ class OrderItemPdf < Prawn::Document
self.header_font_size = 14 self.header_font_size = 14
self.item_font_size = 12 self.item_font_size = 12
text "#{order_item.dining}", :size => self.header_font_size,:align => :center, :left_margin => -20 text "#{ order_item.dining+print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20
stroke_horizontal_rule stroke_horizontal_rule
move_down 5 move_down 5

View File

@@ -1,13 +1,13 @@
class OrderSummaryPdf < Prawn::Document class OrderSummaryPdf < Prawn::Document
attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width
def initialize(order) def initialize(order, print_status)
self.page_width = 254 self.page_width = 210
self.page_height = 1450 self.page_height = 2500
self.margin = 10 self.margin = 5
self.price_width = 40 # No Need for item self.price_width = 40 # No Need for item
self.qty_width = 34 self.qty_width = 30
self.total_width = 40 # No Need for item self.total_width = 40 # No Need for item
self.item_width = self.page_width - (self.qty_width + (self.margin*4)) self.item_width = self.page_width - (self.qty_width - self.margin)
self.item_height = 15 self.item_height = 15
self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width)
self.label_width=100 self.label_width=100
@@ -20,7 +20,7 @@ class OrderSummaryPdf < Prawn::Document
self.header_font_size = 12 self.header_font_size = 12
self.item_font_size = 10 self.item_font_size = 10
text "#{order[0].dining}", :size => self.header_font_size,:align => :center, :left_margin => -20 text "#{ order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20
stroke_horizontal_rule stroke_horizontal_rule
move_down 5 move_down 5
@@ -59,7 +59,7 @@ class OrderSummaryPdf < Prawn::Document
text "Item", :size => self.item_font_size,:align => :left text "Item", :size => self.item_font_size,:align => :left
end end
bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do bounding_box([self.item_width-2,y_position], :width => self.qty_width, :height => self.item_height) do
text "Qty", :size => self.item_font_size,:align => :left text "Qty", :size => self.item_font_size,:align => :left
end end
@@ -78,12 +78,17 @@ class OrderSummaryPdf < Prawn::Document
order_item.each do|odi| order_item.each do|odi|
y_position = cursor y_position = cursor
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
text "#{odi.item_name}", :size => self.item_font_size,:align => :left # pad_top(15) {
# text_box "#{odi.item_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
# text_box "#{odi.qty}", :at =>[self.item_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
# }
bounding_box([0,y_position], :width => self.item_width) do
text "#{odi.item_name}", :size => self.item_font_size,:align => :left, :height => self.item_height
end end
bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do bounding_box([self.item_width,y_position], :width => self.qty_width) do
text "#{odi.qty}", :size => self.item_font_size,:align => :left text "#{odi.qty}", :size => self.item_font_size,:align => :left, :height => self.item_height
end end
move_down 5 move_down 5

View File

@@ -3,7 +3,7 @@ class CreateOrderQueueStations < ActiveRecord::Migration[5.1]
create_table :order_queue_stations do |t| create_table :order_queue_stations do |t|
t.string :station_name, :null => false t.string :station_name, :null => false
t.boolean :is_active, :null => false, :default => false t.boolean :is_active, :null => false, :default => false
t.json :processing_items, :default => "[]" t.json :processing_items
t.boolean :print_copy, :null => false, :default => false t.boolean :print_copy, :null => false, :default => false
t.string :printer_name t.string :printer_name
t.integer :font_size, :null => false, :default => 10 t.integer :font_size, :null => false, :default => 10