From 7c194f843841c95038c74615fcf50c4893c10d91 Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Wed, 9 Oct 2019 10:05:46 +0630 Subject: [PATCH] fixed hourly sale report --- app/controllers/reports/dailysale_controller.rb | 1 + app/controllers/reports/hourly_saleitem_controller.rb | 4 +--- app/models/sale.rb | 7 ++++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/reports/dailysale_controller.rb b/app/controllers/reports/dailysale_controller.rb index 6fb7fe3f..2603fce4 100755 --- a/app/controllers/reports/dailysale_controller.rb +++ b/app/controllers/reports/dailysale_controller.rb @@ -9,6 +9,7 @@ class Reports::DailysaleController < BaseReportController @to = to @payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method") + # get printer info @print_settings = PrintSetting.get_precision_delimiter() respond_to do |format| diff --git a/app/controllers/reports/hourly_saleitem_controller.rb b/app/controllers/reports/hourly_saleitem_controller.rb index 24547c0c..a08c24e4 100644 --- a/app/controllers/reports/hourly_saleitem_controller.rb +++ b/app/controllers/reports/hourly_saleitem_controller.rb @@ -27,8 +27,6 @@ class Reports::HourlySaleitemController < BaseReportController account_type = params[:account_type] @type = params[:sale_type] @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_hourly_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) - # logger.debug 'product>>>>>>>>>>>>>>>>>>>>>>>>>>' - # logger.debug @sale_data.group(:date_format) @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) @@ -59,7 +57,7 @@ class Reports::HourlySaleitemController < BaseReportController # @hourly_total_qty = @sale_data.group_by {|s| s.date_format }.collect{|key,qty| {"date" => key , "total_qty" => qty.sum{|d| d.qty.to_i}}} @hourly_total_qty = @sale_data.group_by(&:date_format).map { |k,v|{"date" => k , "total_qty" => v.count }} - puts @hourly_total_qty.to_json + respond_to do |format| format.html format.xls diff --git a/app/models/sale.rb b/app/models/sale.rb index a7208d50..dc8769ce 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -2862,15 +2862,16 @@ def self.get_hourly_item_query(type) "i.unit_price,i.price as price,i.product_name as product_name, " + "i.menu_category_name,i.menu_category_code as menu_category_id, " + "date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p') - as date_format") + as date_format," + + "hour(CONVERT_TZ(receipt_date,'+00:00', '+06:30')) as hour") query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" + " JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id") # "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ") query = query.joins(" JOIN accounts acc ON acc.id = i.account_id") query = query.where("#{sale_type}") - query = query.group("acc.title,i.account_id,i.menu_category_code,i.item_instance_code,i.product_name,i.unit_price") - .order("date_format asc") + query = query.group("acc.title,i.account_id,i.menu_category_code,i.item_instance_code,i.product_name,i.unit_price,hour") + .order("hour asc") # query = query.order("i.menu_category_name asc, SUM(i.qty) desc") end