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

@@ -94,27 +94,24 @@ class HomeController < ApplicationController
@shop = Shop.first
today = DateTime.now.strftime('%Y-%m-%d')
@orders = Sale.where("payment_status = 'new' and sale_status = 'bill'")
@sales = Sale.completed
if !@from.nil? && !@to.nil?
@orders = @orders.date_between(@from, @to)
@sales = @sales.date_between(@from, @to)
if !@from_time.nil? && @to_time.nil?
@orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count()
else
@orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
@orders = @orders.time_between(@from_time, @to_time)
@sales = @sales.time_between(@from_time, @to_time)
end
else
@orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
@orders = @orders.date_on(today)
@sales = @sales.date_on(today)
end
if !@from.nil? && !@to.nil?
if !@from_time.nil? && @to_time.nil?
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count()
else
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
end
else
@sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
end
@top_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"top").sum('i.qty')
@bottom_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"bottom").sum('i.qty')
@hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time).sum(:grand_total)
@top_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"top")
@bottom_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"bottom")
@hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time)
# .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p')
# .sum(:grand_total)
logger.debug 'hourly_sales<>><><><<<<<<>><<<><><><><><><><><><<>><'