Files
sx-fc/app/pdf/receipt_bill_pdf.rb

192 lines
8.3 KiB
Ruby

class ReceiptBillPdf < Prawn::Document
attr_accessor :receipt_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(printer_settings, sale_items, sale_data, customer_name, food_total, beverage_total)
self.page_width = 300
self.page_height = 1450
self.margin = 10
self.price_width = 50
self.qty_width = 30
self.total_width = 50
self.item_width = self.page_width - (self.price_width + self.qty_width + self.total_width)
self.item_height = 15
self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width)
self.receipt_width=100
# @item_width = self.page_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.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
header( printer_settings.printer_name, printer_settings.name)
stroke_horizontal_rule
cashier_info(sale_data, customer_name)
line_items(sale_items, food_total, beverage_total)
all_total(sale_data)
end
def header (printer_name, name)
text "#{printer_name}", :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 cashier_info(sale_data, customer_name)
move_down 7
# move_down 2
y_position = cursor
bounding_box([0,y_position], :width =>self.receipt_width, :height => self.item_height) do
text "Receipt No:", :size => self.item_font_size,:align => :left
end
bounding_box([self.receipt_width, y_position], :width =>self.receipt_width) do
text "#{sale_data.receipt_no}" , :size => self.item_font_size, :align => :left
end
move_down 5
y_position = cursor
bounding_box([0,y_position], :width =>self.receipt_width, :height => self.item_height) do
text "Customer:", :size => self.item_font_size,:align => :left
end
bounding_box([self.receipt_width,y_position], :width =>self.receipt_width) do
text "#{customer_name}" , :size => self.item_font_size,:align => :left
end
move_down 5
y_position = cursor
bounding_box([0,y_position], :width =>self.receipt_width, :height => self.item_height) do
text "Date:", :size => self.item_font_size,:align => :left
end
bounding_box([self.receipt_width,y_position], :width =>self.receipt_width) do
text "#{sale_data.receipt_date.strftime('%Y %m %d %h:%m')}" , :size => self.item_font_size,:align => :left
end
# stroke_horizontal_rule
move_down 5
end
def line_items(sale_items, food_total, beverage_total)
y_position = cursor
stroke_horizontal_rule
move_down 5
pad_top(15) {
# @item_width.to_i + @half_qty.to_i
text_box "Items", :at =>[0,y_position], :width => self.item_width - 20, :height =>self.item_height, :size => self.item_font_size
text_box "Price", :at =>[self.item_width-20,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right
text_box "Qty", :at =>[self.item_width+self.price_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :right
text_box "Total", :at =>[self.item_width+self.price_width+self.qty_width,y_position], :width => self.total_width, :height =>self.item_height, :size => self.item_font_size, :align => :right
}
move_down 5
stroke_horizontal_rule
add_line_item_row(sale_items, food_total, beverage_total)
end
def add_line_item_row(sale_items, food_total, beverage_total)
item_name_width = self.item_width-20
y_position = cursor
move_down 5
sub_total = 0.0
sale_items.each do |item|
sub_total += item.qty*item.unit_price
qty = item.qty
total_price = item.qty*item.unit_price
price = item.unit_price
product_name = item.product_name
y_position = cursor
pad_top(15) {
# @item_width.to_i + @half_qty.to_i
text_box "#{product_name}", :at =>[0,y_position], :width => item_name_width, :height =>self.item_height, :overflow => :shrink_to_fix, :size => self.item_font_size
text_box "#{price}", :at =>[item_name_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right
text_box "#{qty.to_i}", :at =>[item_name_width+self.price_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :right
text_box "#{total_price}", :at =>[item_name_width+self.price_width+self.qty_width,y_position], :width =>self.total_width, :height =>self.item_height, :size => self.item_font_size, :align => :right
}
move_down 3
end
stroke_horizontal_rule
move_down 5
y_position = cursor
bounding_box([0,y_position], :width =>(item_name_width+self.price_width+self.qty_width), :height => self.item_height) do
text "Sub Total", :size => self.item_font_size,:align => :left
end
bounding_box([(item_name_width+self.price_width+self.qty_width),y_position], :width =>self.total_width) do
text "#{sub_total}" , :size => self.item_font_size,:align => :right
end
# Food and Beverage
food_beverage_total = food_total.to_s + '/' + beverage_total.to_s
move_down 5
y_position = cursor
bounding_box([0,y_position], :width =>(item_name_width+self.price_width+self.qty_width), :height => self.item_height) do
text "Food/Beverage Total", :size => self.item_font_size,:align => :left
end
bounding_box([(item_name_width+self.price_width+self.qty_width),y_position], :width =>self.total_width) do
text "#{ food_beverage_total }" , :size => self.item_font_size,:align => :right
end
end
def all_total(sale_data)
item_name_width = self.item_width-20
move_down 5
y_position = cursor
bounding_box([0,y_position], :width =>(item_name_width+self.price_width+self.qty_width), :height => self.item_height) do
text "Discount", :size => self.item_font_size,:align => :left
end
bounding_box([(item_name_width+self.price_width+self.qty_width),y_position], :width =>self.total_width) do
text "( " +"#{sale_data.total_discount}" +" )" , :size => self.item_font_size,:align => :right
end
move_down 5
y_position = cursor
bounding_box([0,y_position], :width =>(item_name_width+self.price_width+self.qty_width), :height => self.item_height) do
text "Total Tax", :size => self.item_font_size,:align => :left
end
bounding_box([(item_name_width+self.price_width+self.qty_width),y_position], :width =>self.total_width) do
text "( " +"#{sale_data.total_tax}" +" )" , :size => self.item_font_size,:align => :right
end
move_down 5
y_position = cursor
move_down 5
bounding_box([0,y_position], :width =>(item_name_width+self.price_width+self.qty_width), :height => self.item_height) do
text "Grand Total", :size => self.item_font_size,:align => :left
end
bounding_box([(item_name_width+self.price_width+self.qty_width),y_position], :width =>self.total_width) do
text "#{sale_data.grand_total}" , :size => self.item_font_size,:align => :right
end
move_down 5
# stroke_horizontal_rule
end
end