177 lines
6.1 KiB
Ruby
Executable File
177 lines
6.1 KiB
Ruby
Executable File
class OrderSummarySetPdf < Prawn::Document
|
|
include ActionView::Helpers::NumberHelper
|
|
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(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty)
|
|
self.page_width = print_settings.page_width
|
|
self.page_height = print_settings.page_height
|
|
self.margin = 0
|
|
self.price_width = 40 # No Need for item
|
|
self.qty_width = 40
|
|
self.total_width = 40 # No Need for item
|
|
self.item_width = self.page_width - (self.qty_width - self.margin)
|
|
self.item_height = 15
|
|
self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width)
|
|
self.label_width=90
|
|
|
|
super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height])
|
|
|
|
# db font setup
|
|
if print_settings.font != ""
|
|
font_families.update("#{print_settings.font}" => {
|
|
:normal => "public/fonts/#{print_settings.font}.ttf",
|
|
:italic => "public/fonts/#{print_settings.font}.ttf",
|
|
:bold => "public/fonts/#{print_settings.font}.ttf",
|
|
:bold_italic => "public/fonts/#{print_settings.font}.ttf"
|
|
})
|
|
|
|
font "#{print_settings.font}"
|
|
fallback_fonts ["Courier", "Helvetica", "Times-Roman"]
|
|
|
|
self.header_font_size = 11
|
|
self.item_font_size = 9
|
|
else
|
|
self.header_font_size = 12
|
|
self.item_font_size = 10
|
|
end
|
|
|
|
# font "public/fonts/Zawgyi-One.ttf"
|
|
# font "public/fonts/padauk.ttf"
|
|
if !order[0].dining.nil?
|
|
text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20
|
|
else
|
|
text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20
|
|
end
|
|
|
|
stroke_horizontal_rule
|
|
move_down 5
|
|
|
|
#order_info
|
|
order_info(order[0].order_id, order[0].order_by,order[0].order_at)
|
|
|
|
# order items
|
|
if order_items == nil
|
|
order_items(order, alt_name, print_settings.precision)
|
|
else
|
|
order_items(order_items, alt_name, print_settings.precision)
|
|
end
|
|
end
|
|
|
|
# Write Order Information to PDF
|
|
def order_info(order_no, order_by, order_at)
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
|
|
text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left
|
|
end
|
|
|
|
move_down 5
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
|
|
text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left
|
|
end
|
|
|
|
move_down 5
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
|
|
text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left
|
|
end
|
|
|
|
stroke_horizontal_rule
|
|
|
|
move_down 10
|
|
end
|
|
|
|
# Write Order items to PDF
|
|
def order_items(order_item, alt_name, precision)
|
|
y_position = cursor
|
|
|
|
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
|
|
text "Item", :size => self.item_font_size,:align => :left
|
|
end
|
|
|
|
bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do
|
|
text "Qty", :size => self.item_font_size,:align => :left
|
|
end
|
|
|
|
stroke_horizontal_rule
|
|
move_down 5
|
|
|
|
#Add Order Item
|
|
add_order_items(order_item, alt_name, precision)
|
|
|
|
end
|
|
|
|
# Add order items under order info
|
|
def add_order_items(order_item, alt_name, precision)
|
|
y_position = cursor
|
|
|
|
move_down 5
|
|
|
|
order_item.each do|odi|
|
|
# check for item not to show
|
|
# if odi.price != 0
|
|
y_position = cursor
|
|
|
|
bounding_box([0,y_position], :width => self.item_width) do
|
|
text "#{odi.item_code} - #{odi.item_name}", :size => self.item_font_size,:align => :left
|
|
|
|
end
|
|
|
|
bounding_box([self.item_width,y_position], :width => self.qty_width) do
|
|
text "#{number_with_precision(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left
|
|
end
|
|
|
|
bounding_box([0,y_position], :width => self.item_width) do
|
|
text "#{odi.item_code} - #{odi.item_name}", :size => self.item_font_size,:align => :left
|
|
|
|
end
|
|
|
|
if alt_name
|
|
if !(odi.alt_name).empty?
|
|
move_down 4
|
|
font("public/fonts/NotoSansCJKtc-Regular.ttf") do
|
|
text "(#{odi.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
#add set menu items
|
|
if !odi.set_menu_items.nil?
|
|
set_menu_items = JSON.parse(odi.set_menu_items)
|
|
if !set_menu_items.empty?
|
|
# json_item_instance_code = nil
|
|
set_menu_items.each do |set_item|
|
|
# if set_item["item_instance_code"] != json_item_instance_code
|
|
item_instance_name = MenuItemInstance.find_by_item_instance_code(set_item["item_instance_code"]).item_instance_name
|
|
move_down 2
|
|
text "#{item_instance_name}", :size => self.item_font_size,:align => :left, :inline_format => true
|
|
# end
|
|
# json_item_instance_code = set_item["item_instance_code"]
|
|
end
|
|
end
|
|
end
|
|
|
|
# add option
|
|
options = odi.options == "[]"? "" : odi.options
|
|
|
|
if options != ""
|
|
move_down 5
|
|
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width => self.item_width) do
|
|
text "#{options}", :size => self.item_font_size,:align => :left
|
|
end
|
|
|
|
move_down 5
|
|
end
|
|
|
|
move_down 5
|
|
|
|
dash(1, :space => 1, :phase => 1)
|
|
stroke_horizontal_line 0, (self.page_width - self.margin)
|
|
move_down 5
|
|
# end
|
|
end
|
|
end
|
|
end
|