improve receipt/details reports and implement number formatting
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
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
class OrderSummarySlimPdf < Prawn::Document
|
||||
include ActionView::Helpers::NumberHelper
|
||||
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
|
||||
def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty)
|
||||
self.page_width = print_settings.page_width
|
||||
@@ -11,9 +11,9 @@ class OrderSummarySlimPdf < Prawn::Document
|
||||
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_height = 15
|
||||
self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width)
|
||||
self.label_width=90
|
||||
self.label_width=90
|
||||
|
||||
super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height])
|
||||
|
||||
@@ -37,7 +37,7 @@ class OrderSummarySlimPdf < Prawn::Document
|
||||
else
|
||||
text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20
|
||||
end
|
||||
|
||||
|
||||
stroke_horizontal_rule
|
||||
move_down 1
|
||||
|
||||
@@ -46,38 +46,38 @@ class OrderSummarySlimPdf < Prawn::Document
|
||||
|
||||
# order items
|
||||
if order_items == nil
|
||||
order_items(order, alt_name, print_settings.precision)
|
||||
order_items(order, alt_name, precision)
|
||||
else
|
||||
order_items(order_items, alt_name, print_settings.precision)
|
||||
order_items(order_items, alt_name, precision)
|
||||
end
|
||||
end
|
||||
|
||||
# Write Order Information to PDF
|
||||
def order_info(order_no, order_by, order_at)
|
||||
def order_info(order_no, order_by, order_at)
|
||||
#booking ID
|
||||
booking_id = get_booking_id(order_no)
|
||||
|
||||
y_position = cursor
|
||||
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
|
||||
text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left
|
||||
end
|
||||
|
||||
move_down 1
|
||||
y_position = cursor
|
||||
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
|
||||
text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left
|
||||
text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left
|
||||
end
|
||||
|
||||
move_down 1
|
||||
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
|
||||
text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left
|
||||
end
|
||||
|
||||
move_down 1
|
||||
y_position = cursor
|
||||
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
|
||||
text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left
|
||||
text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left
|
||||
end
|
||||
|
||||
move_down 1
|
||||
y_position = cursor
|
||||
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
|
||||
text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left
|
||||
end
|
||||
|
||||
stroke_horizontal_rule
|
||||
@@ -102,7 +102,7 @@ class OrderSummarySlimPdf < Prawn::Document
|
||||
|
||||
#Add Order Item
|
||||
add_order_items(order_item, alt_name, precision)
|
||||
|
||||
|
||||
end
|
||||
|
||||
# Add order items under order info
|
||||
@@ -112,7 +112,7 @@ class OrderSummarySlimPdf < Prawn::Document
|
||||
move_down 1
|
||||
|
||||
order_item.each do|odi|
|
||||
# check for item not to show
|
||||
# check for item not to show
|
||||
# if odi.price != 0
|
||||
y_position = cursor
|
||||
|
||||
@@ -122,14 +122,14 @@ class OrderSummarySlimPdf < Prawn::Document
|
||||
end
|
||||
|
||||
bounding_box([self.item_width,y_position], :width => self.qty_width) do
|
||||
text "#{number_with_precision(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left
|
||||
text "#{number_format(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left
|
||||
end
|
||||
|
||||
bounding_box([0,y_position], :width => self.item_width) do
|
||||
text "#{odi.item_name}", :size => self.item_font_size,:align => :left
|
||||
|
||||
end
|
||||
|
||||
|
||||
if alt_name
|
||||
if !(odi.alt_name).empty?
|
||||
move_down 1
|
||||
@@ -141,7 +141,7 @@ class OrderSummarySlimPdf < Prawn::Document
|
||||
|
||||
# add option
|
||||
options = odi.options == "[]"? "" : odi.options
|
||||
|
||||
|
||||
if options != ""
|
||||
move_down 1
|
||||
|
||||
@@ -159,7 +159,7 @@ class OrderSummarySlimPdf < Prawn::Document
|
||||
stroke_horizontal_line 0, (self.page_width - self.margin)
|
||||
move_down 1
|
||||
# end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_booking_id(order_no)
|
||||
|
||||
Reference in New Issue
Block a user