fixed conflict after merge with dev branch for report query updated
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
class BaseReportController < ActionController::Base
|
||||
include LoginVerification
|
||||
layout "application"
|
||||
layout "application"
|
||||
|
||||
before_action :check_user
|
||||
before_action :check_user
|
||||
|
||||
#before_action :check_installation
|
||||
protect_from_forgery with: :exception
|
||||
#before_action :check_installation
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
rescue_from CanCan::AccessDenied do |exception|
|
||||
flash[:warning] = exception.message
|
||||
@@ -29,7 +29,7 @@ class BaseReportController < ActionController::Base
|
||||
period_type = params[:period_type]
|
||||
period = params[:period]
|
||||
from = params[:from]
|
||||
to = params[:to]
|
||||
to = params[:to]
|
||||
day_ref = Time.now.utc.getlocal
|
||||
|
||||
if from.present? && to.present?
|
||||
@@ -39,10 +39,10 @@ class BaseReportController < ActionController::Base
|
||||
f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec)
|
||||
t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec)
|
||||
from = f_time.beginning_of_day.utc.getlocal
|
||||
to = t_time.end_of_day.utc.getlocal
|
||||
to = t_time.end_of_day.utc.getlocal
|
||||
|
||||
else
|
||||
|
||||
else
|
||||
|
||||
case period.to_i
|
||||
when PERIOD["today"]
|
||||
|
||||
@@ -77,10 +77,10 @@ class BaseReportController < ActionController::Base
|
||||
when PERIOD["last_year"]
|
||||
from = (day_ref - 1.year).beginning_of_year.utc
|
||||
to = (day_ref - 1.year).end_of_year.utc
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return from, to
|
||||
return from, to
|
||||
end
|
||||
|
||||
def check_user
|
||||
|
||||
57
app/controllers/concerns/number_formattable.rb
Normal file
57
app/controllers/concerns/number_formattable.rb
Normal file
@@ -0,0 +1,57 @@
|
||||
module NumberFormattable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def precision
|
||||
@precision ||= Lookup.number_formats.find { |f| f.name.parameterize.underscore == 'precision'}
|
||||
if @precision
|
||||
@precision.value.to_i
|
||||
else
|
||||
@print_settings ||= PrintSetting.get_precision_delimiter
|
||||
if @print_settings
|
||||
@print_settings.precision.to_i
|
||||
end
|
||||
end || 2
|
||||
end
|
||||
|
||||
def delimiter
|
||||
@delimiter ||= Lookup.number_formats.find { |f| f.name.parameterize.underscore == 'delimiter'}
|
||||
if @delimiter
|
||||
@delimiter_value ||= @delimiter.value.to_s.gsub(/\\u(\h{4})/) { |m| [$1].pack("H*").unpack("n*").pack("U*") }
|
||||
else
|
||||
@print_settings ||= PrintSetting.get_precision_delimiter
|
||||
if @print_settings
|
||||
"," if @print_settings.delimiter
|
||||
end
|
||||
end || ""
|
||||
end
|
||||
|
||||
def strip_insignificant_zeros
|
||||
@strip_insignificant_zeros ||= Lookup.number_formats.find { |f| f.name.parameterize.underscore == 'strip_insignificant_zeros'}
|
||||
if @strip_insignificant_zeros
|
||||
['1', 't', 'true', 'on', 'y', 'yes'].include? @strip_insignificant_zeros.value.to_s
|
||||
end || false
|
||||
end
|
||||
|
||||
def number_format(number, options = {})
|
||||
options[:precision] = options[:precision] || precision
|
||||
# options[:delimiter] = options[:delimiter] || delimiter
|
||||
options[:strip_insignificant_zeros] = options[:strip_insignificant_zeros] || strip_insignificant_zeros
|
||||
|
||||
if options[:precision] > 0
|
||||
if options[:strip_insignificant_zeros]
|
||||
formatted = "%.12g" % number.round(options[:precision])
|
||||
else
|
||||
formatted = "%.#{options[:precision]}f" % number.round(options[:precision])
|
||||
end
|
||||
else
|
||||
formatted = number.to_i.to_s
|
||||
end
|
||||
|
||||
if options[:delimiter] &&
|
||||
formatted = formatted.gsub(/(\d)(?=\d{3}+(\.\d*)?$)/, "\\1#{options[:delimiter]}")
|
||||
end
|
||||
|
||||
return formatted
|
||||
end
|
||||
|
||||
end
|
||||
@@ -93,29 +93,39 @@ class HomeController < ApplicationController
|
||||
def dashboard
|
||||
@from, @to, @from_time, @to_time = get_date_range_from_params
|
||||
today = DateTime.now.strftime('%Y-%m-%d')
|
||||
if !@from.nil? && !@to.nil?
|
||||
if !@from_time.nil? && @to_time.nil?
|
||||
@orders = Sale::where("shop_code='#{@shop.shop_code}' and 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("shop_code='#{@shop.shop_code}' and payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count()
|
||||
end
|
||||
else
|
||||
@orders = Sale::where("shop_code='#{@shop.shop_code}' and payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count()
|
||||
end
|
||||
if !@from.nil? && !@to.nil?
|
||||
if !@from_time.nil? && @to_time.nil?
|
||||
@sales = Sale::where("shop_code='#{@shop.shop_code}' and 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("shop_code='#{@shop.shop_code}' and 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("shop_code='#{@shop.shop_code}' and 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",@shop).sum('i.qty')
|
||||
@bottom_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"bottom",@shop).sum('i.qty')
|
||||
@hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time,@shop).sum(:grand_total)
|
||||
@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 = @orders.time_between(@from_time, @to_time)
|
||||
@sales = @sales.time_between(@from_time, @to_time)
|
||||
end
|
||||
else
|
||||
@orders = @orders.date_on(today)
|
||||
@sales = @sales.date_on(today)
|
||||
end
|
||||
|
||||
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
|
||||
if shift = ShiftSale.current_open_shift(current_user.id)
|
||||
@orders = @orders.where(shift_sale_id: shift.id)
|
||||
@sales = @sales.where(shift_sale_id: shift.id)
|
||||
end
|
||||
end
|
||||
|
||||
@top_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"top", @shop)
|
||||
@bottom_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"bottom", @shop)
|
||||
@hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time, @shop)
|
||||
# .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p')
|
||||
# .sum(:grand_total)
|
||||
logger.debug 'hourly_sales<>><><><<<<<<>><<<><><><><><><><><><<>><'
|
||||
logger.debug @hourly_sales.to_json
|
||||
employee_sales = Sale.employee_sales(today,current_user,@from,@to,@from_time,@to_time, @shop)
|
||||
# .sum("(CASE WHEN sp.payment_method='cash' THEN ((sp.payment_amount) - (sales.amount_changed)) ELSE (sp.payment_amount) END)")
|
||||
|
||||
employee_sales = Sale.employee_sales(today,current_user,@from,@to,@from_time,@to_time,@shop)
|
||||
@employee_sales = []
|
||||
if !employee_sales.nil?
|
||||
employee_sales.each do |emp|
|
||||
@@ -129,10 +139,12 @@ class HomeController < ApplicationController
|
||||
end
|
||||
@inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time,@shop).sum(:balance)
|
||||
|
||||
|
||||
@total_trans = Sale.total_trans(today,current_user,@from,@to,@from_time,@to_time,@shop)
|
||||
@total_card = Sale.total_card_sale(today,current_user,@from,@to,@from_time,@to_time,@shop)
|
||||
@total_credit = Sale.credit_payment(today,current_user,@from,@to,@from_time,@to_time,@shop)
|
||||
|
||||
|
||||
@sale_data = Array.new
|
||||
@total_payment_methods = Sale.total_payment_methods(@shop,today,current_user,@from,@to,@from_time,@to_time)
|
||||
|
||||
@@ -150,16 +162,18 @@ class HomeController < ApplicationController
|
||||
@summ_sale = Sale.summary_sale_receipt(@shop,today,current_user,@from,@to,@from_time,@to_time)
|
||||
@total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(@shop,today,current_user,@from,@to,@from_time,@to_time)
|
||||
|
||||
@total_order = Sale.total_order(@shop,today,current_user,@from,@to,@from_time,@to_time)
|
||||
@total_accounts = Sale.total_account(@shop,today,current_user,@from,@to,@from_time,@to_time)
|
||||
|
||||
@total_order = Sale.total_order(@shop, today,current_user,@from,@to,@from_time,@to_time)
|
||||
@total_accounts = Account.select("accounts.id as account_id, accounts.title as title")
|
||||
@account_data = Array.new
|
||||
if !@total_accounts.nil?
|
||||
@total_accounts.each do |account|
|
||||
acc = Sale.account_data(@shop,account.account_id, today,current_user,@from,@to,@from_time,@to_time)
|
||||
if !acc.nil?
|
||||
acc = Sale.account_data(@shop, account.account_id, today,current_user,@from,@to,@from_time,@to_time)
|
||||
if !acc.nil? && acc.cnt_acc > 0
|
||||
@account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc})
|
||||
end
|
||||
end
|
||||
@total_accounts = @total_accounts.reject.with_index { |x, i| @account_data[i].nil? }
|
||||
end
|
||||
|
||||
@top_items = Sale.top_items(@shop,today,current_user,@from,@to,@from_time,@to_time)
|
||||
|
||||
@@ -24,8 +24,9 @@ class Origami::DashboardController < BaseOrigamiController
|
||||
@total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(@shop,today,current_user,@from,@to,@from_time,@to_time)
|
||||
# @total_other_customer = Sale.total_other_customer(today,current_user)
|
||||
|
||||
@total_order = Sale.total_order(@shop,today,current_user)
|
||||
@total_accounts = Sale.total_account(@shop,today,current_user)
|
||||
|
||||
@total_order = Sale.total_order(@shop, today,current_user)
|
||||
@total_accounts = Account.select("accounts.id as account_id, accounts.title as title")
|
||||
@account_data = Array.new
|
||||
if !@total_accounts.nil?
|
||||
@total_accounts.each do |account|
|
||||
@@ -34,6 +35,7 @@ class Origami::DashboardController < BaseOrigamiController
|
||||
@account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc})
|
||||
end
|
||||
end
|
||||
@total_accounts = @total_accounts.reject.with_index { |x, i| @account_data[i].nil? }
|
||||
else
|
||||
@account_data = nil
|
||||
end
|
||||
|
||||
@@ -163,8 +163,6 @@ class Origami::SaleEditController < BaseOrigamiController
|
||||
# end
|
||||
# end
|
||||
|
||||
sale.compute_by_sale_items(sale.total_discount, nil, order_source)
|
||||
|
||||
ProductCommission.edit_product_commission(saleitemObj,sale.shop_code)
|
||||
end
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ authorize_resource :class => false
|
||||
@shift = ''
|
||||
if params[:shift_name].to_i != 0
|
||||
|
||||
@shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'")
|
||||
@shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED)
|
||||
|
||||
@shift_sale = ShiftSale.find(params[:shift_name])
|
||||
if to.blank?
|
||||
@shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",@shift_sale.shift_started_at)
|
||||
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',@shift_sale.shift_started_at)
|
||||
else
|
||||
if @shift_sale.shift_closed_at.blank?
|
||||
@shift = ShiftSale.where("shift_started_at = ? and shift_closed_at is NULL and shop_code='#{@shop.shop_code}'",@shift_sale.shift_started_at)
|
||||
@@ -25,8 +25,10 @@ authorize_resource :class => false
|
||||
end
|
||||
|
||||
payment_type = params[:payment_type]
|
||||
|
||||
@sale_data = Sale.get_shift_sales_by_receipt_no_detail(@shift_sale_range,@shift,from,to,payment_type).where("sales.shop_code='#{@shop.shop_code}'")
|
||||
|
||||
|
||||
@from = from
|
||||
@to = to
|
||||
# get printer info
|
||||
|
||||
Reference in New Issue
Block a user