94 lines
2.9 KiB
Ruby
94 lines
2.9 KiB
Ruby
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
|
|
def initialize(order)
|
|
self.page_width = 254
|
|
self.page_height = 1450
|
|
self.margin = 10
|
|
self.price_width = 40 # No Need for item
|
|
self.qty_width = 34
|
|
self.total_width = 40 # No Need for item
|
|
self.item_width = self.page_width - (self.qty_width + (self.margin*4))
|
|
self.item_height = 15
|
|
self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width)
|
|
self.label_width=100
|
|
|
|
super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height])
|
|
|
|
# font "public/fonts/#{font_name}".to_s + ".ttf".to_s
|
|
# font "public/fonts/Zawgyi-One.ttf"
|
|
# font "public/fonts/padauk.ttf"
|
|
self.header_font_size = 12
|
|
self.item_font_size = 10
|
|
|
|
text "#{order[0].dining}", :size => self.header_font_size,:align => :center, :left_margin => -20
|
|
stroke_horizontal_rule
|
|
move_down 5
|
|
|
|
#order_info
|
|
order_info(order[0].order_by,order[0].order_at)
|
|
|
|
# order items
|
|
order_items(order)
|
|
|
|
end
|
|
|
|
# Write Order Information to PDF
|
|
def order_info(order_by, order_at)
|
|
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.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)
|
|
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)
|
|
end
|
|
|
|
# Add order items under order info
|
|
def add_order_items(order_item)
|
|
y_position = cursor
|
|
|
|
move_down 5
|
|
|
|
order_item.each do|odi|
|
|
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
|
|
end
|
|
|
|
bounding_box([self.item_width,y_position], :width => self.qty_width, :height => self.item_height) do
|
|
text "#{odi.qty}", :size => self.item_font_size,:align => :left
|
|
end
|
|
|
|
move_down 5
|
|
end
|
|
|
|
end
|
|
end
|