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:
Thein Lin Kyaw
2019-11-25 23:17:53 +06:30
parent a36e170d94
commit 3c1cc737b5
71 changed files with 1338 additions and 1898 deletions

View File

@@ -1,5 +1,5 @@
class OrderItemCustomisePdf < 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,:order_no_font_size,:item_height,:qty_width,:total_width,:item_description_width
def initialize(print_settings,order_item, print_status, options, alt_name, before_updated_qty)
self.page_width = print_settings.page_width
@@ -47,7 +47,7 @@ class OrderItemCustomisePdf < Prawn::Document
order_info(order_item.order_id, order_item.order_by,order_item.order_at)
# order items
order_items(order_item, options, alt_name, print_settings.precision, before_updated_qty)
order_items(order_item, options, alt_name, precision, before_updated_qty)
end
# Write Order Information to PDF
@@ -107,7 +107,7 @@ class OrderItemCustomisePdf < Prawn::Document
end
bounding_box([self.item_width - 10,y_position], :width => self.qty_width) do
text "[#{number_with_precision(order_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right
text "[#{number_format(order_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right
end
bounding_box([0,y_position], :width => self.item_width) do
@@ -146,7 +146,7 @@ class OrderItemCustomisePdf < Prawn::Document
# add option
y_position = cursor
bounding_box([0,y_position], :width => self.page_width) do
text "* Change quantity [#{number_with_precision(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_with_precision(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left
text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left
end
end
end