86 lines
3.4 KiB
Ruby
86 lines
3.4 KiB
Ruby
class CheckInOutPdf < 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,:order_no_font_size, :item_height,:qty_width,:total_width,:item_description_width
|
|
def initialize(print_settings,booking, table)
|
|
self.page_width = print_settings.page_width
|
|
self.page_height = print_settings.page_height
|
|
self.header_font_size = print_settings.header_font_size.to_i
|
|
self.item_font_size = print_settings.item_font_size.to_i
|
|
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
|
|
self.order_no_font_size = 8
|
|
|
|
super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height])
|
|
# super(:margin => [10, 5, 30, 5], :page_size => [200,400])
|
|
|
|
# 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"]
|
|
end
|
|
# font "public/fonts/Zawgyi-One.ttf"
|
|
# font "public/fonts/padauk.ttf"
|
|
#font "public/fonts/Chinese.ttf"
|
|
|
|
if table.type == "Table"
|
|
text "Table - #{table.name}", :size => self.header_font_size,:align => :center, :left_margin => -20
|
|
elsif table.type == "Room"
|
|
text "Room - #{table.name}", :size => self.header_font_size,:align => :center, :left_margin => -20
|
|
end
|
|
|
|
|
|
stroke_horizontal_rule
|
|
move_down 3
|
|
|
|
#check_in_out_info
|
|
check_in_out_info(booking.checkin_by)
|
|
|
|
# check_time
|
|
check_time(booking.checkin_at,booking.checkout_at)
|
|
end
|
|
|
|
# Write Check in-out Information to PDF
|
|
def check_in_out_info(checkin_by)
|
|
|
|
move_down 2
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
|
|
text "CheckBy : #{checkin_by} ", :size => self.order_no_font_size,:align => :left
|
|
end
|
|
|
|
stroke_horizontal_rule
|
|
|
|
move_down 5
|
|
|
|
end
|
|
|
|
# Write Check time to PDF
|
|
def check_time(checkin_at, checkout_at)
|
|
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width => self.item_width) do
|
|
text "Check In : #{checkin_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left
|
|
end
|
|
|
|
move_down 2
|
|
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width => self.item_width) do
|
|
text "Check Out : #{checkout_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left
|
|
end
|
|
end
|
|
end
|