1) eager load reports for receipt/details 2) introduce number_format lookups to replace print_settings for number formatting 3) implement NumberFormattable concern, reference number_format lookups or print_settings if not exist, to get number format settings and number formatting 4) replace rails NumberHelper.number_with_precision with NumberFormattable.number_format hopefully to reduce overhead, formatting numbers for huge lists of data
240 lines
10 KiB
Ruby
240 lines
10 KiB
Ruby
class SaleItemsStarPdf < Prawn::Document
|
|
include NumberFormattable
|
|
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,:text_width
|
|
|
|
def initialize(printer_settings, shop_details, period, type, account, from_date, to_date, shift, sale_items, total_other_charges)
|
|
self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width
|
|
self.page_height = printer_settings.page_height
|
|
self.header_font_size = printer_settings.header_font_size.to_i
|
|
self.item_font_size = printer_settings.item_font_size.to_i
|
|
self.margin = 5
|
|
self.price_width = 60
|
|
self.qty_width = 20
|
|
self.total_width = 40
|
|
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-20) / 2
|
|
@label_name_width = 50
|
|
@label_item_width = self.page_width-@label_name_width
|
|
self.label_width = 100
|
|
|
|
self.text_width = (self.page_width - 80) - self.price_width / 3
|
|
# @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 => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height])
|
|
|
|
# db font setup
|
|
if printer_settings.font != ""
|
|
font_families.update("#{printer_settings.font}" => {
|
|
:normal => "public/fonts/#{printer_settings.font}.ttf",
|
|
:italic => "public/fonts/#{printer_settings.font}.ttf",
|
|
:bold => "public/fonts/#{printer_settings.font}.ttf",
|
|
:bold_italic => "public/fonts/#{printer_settings.font}.ttf"
|
|
})
|
|
|
|
font "#{printer_settings.font}"
|
|
fallback_fonts ["Courier", "Helvetica", "Times-Roman"]
|
|
end
|
|
# font "public/fonts/Zawgyi-One.ttf"
|
|
# font "public/fonts/padauk.ttf"
|
|
|
|
header( shop_details)
|
|
|
|
stroke_horizontal_rule
|
|
|
|
sale_details(period, type, account, from_date, to_date, shift)
|
|
|
|
sale_items_detail(sale_items, total_other_charges)
|
|
end
|
|
|
|
def header (shop_details)
|
|
move_down 7
|
|
text "#{shop_details.name}", :left_margin => -10, :size => self.header_font_size,:align => :center
|
|
move_down 5
|
|
text "#{shop_details.address}", :size => self.item_font_size,:align => :center
|
|
# move_down self.item_height
|
|
move_down 5
|
|
text "#{shop_details.phone_no}", :size => self.item_font_size,:align => :center
|
|
move_down 5
|
|
|
|
stroke_horizontal_rule
|
|
end
|
|
|
|
def sale_details(period, type, account, from_date, to_date, shift)
|
|
move_down 7
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width =>@label_name_width, :height => self.item_height) do
|
|
text "Period : ", :size => self.item_font_size,:align => :left
|
|
end
|
|
bounding_box([@label_name_width,y_position], :width => @label_item_width, :height => self.item_height) do
|
|
text "#{period}" , :size => self.item_font_size,:align => :left
|
|
end
|
|
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width =>@label_name_width, :height => self.item_height) do
|
|
text "Type : ", :size => self.item_font_size,:align => :left
|
|
end
|
|
bounding_box([@label_name_width,y_position], :width => @label_item_width, :height => self.item_height) do
|
|
text "#{type}" , :size => self.item_font_size,:align => :left
|
|
end
|
|
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width =>@label_name_width, :height => self.item_height) do
|
|
text "Account : ", :size => self.item_font_size,:align => :left
|
|
end
|
|
bounding_box([@label_name_width,y_position], :width => @label_item_width, :height => self.item_height) do
|
|
text "#{account}" , :size => self.item_font_size,:align => :left
|
|
end
|
|
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width =>@label_name_width, :height => self.item_height) do
|
|
text "From Date : ", :size => self.item_font_size,:align => :left
|
|
end
|
|
bounding_box([@label_name_width,y_position], :width => @label_item_width, :height => self.item_height) do
|
|
text "#{ from_date.utc.getlocal.strftime("%d-%m-%Y")}" , :size => self.item_font_size,:align => :left
|
|
end
|
|
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width =>@label_name_width, :height => self.item_height) do
|
|
text "To Date : ", :size => self.item_font_size,:align => :left
|
|
end
|
|
bounding_box([@label_name_width,y_position], :width => @label_item_width, :height => self.item_height) do
|
|
text "#{ to_date.utc.getlocal.strftime("%d-%m-%Y")}" , :size => self.item_font_size,:align => :left
|
|
end
|
|
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width =>@label_name_width, :height => self.item_height) do
|
|
text "Shift : ", :size => self.item_font_size,:align => :left
|
|
end
|
|
bounding_box([@label_name_width,y_position], :width => @label_item_width) do
|
|
text "#{shift}" , :size => self.item_font_size,:align => :left
|
|
end
|
|
|
|
move_down 10
|
|
end
|
|
|
|
def sale_items_detail(sale_items, total_other_charges)
|
|
self.item_width = 73
|
|
self.price_width = 35
|
|
item_label_qty_front_width = (self.item_width+self.price_width) + 2
|
|
item_label_qty_end_width = 32
|
|
item_label_total_front_width = (self.item_width+self.price_width) + 2
|
|
item_label_total_end_width = 64
|
|
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width =>self.page_width - 10, :height => 20) do
|
|
text "Sale Items Summary", :size => self.header_font_size, :align => :center
|
|
end
|
|
|
|
total_items = 0
|
|
total_amount = 0
|
|
total_qty = 0
|
|
sub_total = 0
|
|
|
|
arr = Array.new
|
|
|
|
unless sale_items.nil?
|
|
sale_items.each do |item|
|
|
|
|
if !arr.include?(item['menu_category_id'])
|
|
|
|
if flag == true
|
|
move_down 5
|
|
stroke_horizontal_rule
|
|
total_details('Sub Total', total_qty, sub_total)
|
|
end
|
|
|
|
total_qty = 0
|
|
sub_total = 0
|
|
|
|
move_down 10
|
|
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width =>self.page_width - 10, :height => 20) do
|
|
text "#{item['menu_category_name']}", :size => self.header_font_size, :align => :left
|
|
end
|
|
|
|
# write_stroke_dash
|
|
# dash(1, :space => 1, :phase => 1)
|
|
# stroke_horizontal_rule
|
|
# move_down 2
|
|
y_position = cursor
|
|
pad_top(15) {
|
|
text_box "Items", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
|
|
text_box "Price", :at =>[(self.item_width),y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :left, :overflow => :shrink_to_fix
|
|
text_box "Qty", :at =>[item_label_qty_front_width,y_position], :width => item_label_qty_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
|
|
text_box "Total", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
|
|
}
|
|
move_down 2
|
|
stroke_horizontal_rule
|
|
end
|
|
|
|
|
|
move_down 3
|
|
|
|
y_position = cursor
|
|
pad_top(15) {
|
|
bounding_box([0,y_position], :width =>self.item_width) do
|
|
text "#{item['product_name']}", :size => self.item_font_size, :align => :left#, :overflow => :shrink_to_fix
|
|
end
|
|
text_box "#{item['unit_price'].to_i}", :at =>[(self.item_width),y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
|
|
text_box "#{item['total_item'].to_i}", :at =>[item_label_qty_front_width,y_position], :width => item_label_qty_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
|
|
text_box "#{item['grand_total'].to_i}", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
|
|
}
|
|
|
|
if item['total_item'].to_i > 0 or item['status_type'] == 'foc' or item['status_type'] == 'void'
|
|
total_qty += item['total_item'].to_i
|
|
total_items += item['total_item'].to_i
|
|
end
|
|
|
|
sub_total += item['grand_total'].to_i
|
|
total_amount += item['grand_total'].to_i
|
|
arr.push(item['menu_category_id'])
|
|
end
|
|
|
|
move_down 5
|
|
stroke_horizontal_rule
|
|
total_details('Sub Total', total_qty, sub_total)
|
|
move_down 5
|
|
move_down 5
|
|
stroke_horizontal_rule
|
|
total_details('Total Amount', total_items, total_amount)
|
|
|
|
other_charges = get_other_charges(total_other_charges)
|
|
total_details('Total Other Amount', nil, other_charges)
|
|
move_down 20
|
|
end
|
|
end
|
|
|
|
def total_details(col_name, total_qty, sub_total)
|
|
self.item_width = 73
|
|
self.price_width = 35
|
|
item_label_qty_front_width = (self.item_width+self.price_width) + 2
|
|
item_label_qty_end_width = 32
|
|
item_label_total_front_width = (self.item_width+self.price_width) + 2
|
|
item_label_total_end_width = 64
|
|
|
|
y_position = cursor
|
|
pad_top(15) {
|
|
text_box "#{col_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
|
|
text_box "#{total_qty.to_i}", :at =>[item_label_qty_front_width,y_position], :width => item_label_qty_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
|
|
text_box "#{sub_total.to_i}", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
|
|
}
|
|
end
|
|
|
|
def get_other_charges(total_other_charges)
|
|
other_sub_total = 0
|
|
unless total_other_charges.nil?
|
|
total_other_charges.each do |charges|
|
|
other_sub_total += charges.grand_total
|
|
end
|
|
end
|
|
|
|
return other_sub_total
|
|
end
|
|
|
|
end
|