Files
sx-fc/app/pdf/crm_order_pdf.rb
2017-06-08 16:52:50 +06:30

107 lines
4.3 KiB
Ruby

class CrmOrderPdf < Prawn::Document
attr_accessor :receipt_width,:price_column_width,:p_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_column_width,:item_description_width
def initialize(booking,order_items,print_settings)
self.p_width = 200
self.page_height = 1450
self.margin = 10
# self.price_width = self.p_width / 2
self.price_width=80
self.item_width = self.p_width - self.price_width
self.item_height = self.item_height
self.qty_column_width = self.p_width / 2
self.item_description_width=self.p_width - self.price_width
self.receipt_width=130
@item_width = self.p_width.to_i / 2
@qty_width = @item_width.to_i / 3
@double = @qty_width * 1.3
@half_qty = @qty_width / 2
#setting page margin and width
super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.p_width, self.page_height])
self.header_font_size = 7
self.item_font_size = 9
header( booking.type, booking.dining_facility.name)
stroke_horizontal_rule
order_detail(booking.checkin_by,booking.checkin_at,booking.dining_facility.name)
line_items(order_items)
#all_total(order_items)
end
def header (type, name)
text "#{type}", :size => self.header_font_size,:align => :center
move_down 5
text "#{name}", :size => self.header_font_size,:align => :center
# move_down self.item_height
move_down 5
stroke_horizontal_rule
end
def order_detail(order_by,order_at,customer)
move_down 5
move_down 2
y_position = cursor
qty_column_width = self.p_width * 0.2
item_description_width = self.p_width * 0.5
price_column_width = self.p_width * 0.3
stroke_horizontal_rule
move_down 5
y_position = cursor
pad_top(15) {
# @item_width.to_i + @half_qty.to_i
text_box "Order By", :at =>[0,y_position], :width => @item_width.to_i - @half_qty.to_i , :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size
text_box "Order At", :at =>[@item_width.to_i - @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
text_box "Customer", :at =>[@item_width.to_i-@qty_width,y_position], :width => @half_qty, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
}
move_down 5
stroke_horizontal_rule
y_position = cursor
pad_top(15) {
text_box "#{order_by}", :at =>[@item_width.to_i - @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
text_box "#{order_at.to_i}", :at =>[@item_width.to_i-@qty_width,y_position], :width => @half_qty, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
text_box "#{customer}", :at =>[@item_width.to_i + @half_qty.to_i,y_position], :width => @double, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
}
end
def line_items(order_items)
y_position = cursor
qty_column_width = self.p_width * 0.2
item_description_width = self.p_width * 0.5
price_column_width = self.p_width * 0.3
stroke_horizontal_rule
move_down 5
y_position = cursor
pad_top(15) {
# @item_width.to_i + @half_qty.to_i
text_box "Items", :at =>[0,y_position], :width => @item_width.to_i - @half_qty.to_i , :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size
text_box "Price", :at =>[@item_width.to_i - @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
text_box "Qty", :at =>[@item_width.to_i-@qty_width,y_position], :width => @half_qty, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
text_box "Total", :at =>[@item_width.to_i + @half_qty.to_i,y_position], :width => @double, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
}
move_down 5
stroke_horizontal_rule
end
end