From 74e29f7c3959aa667d114ba35f30a0bf15514378 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Mon, 18 Nov 2019 14:00:52 +0630 Subject: [PATCH] remove def total_account from sale --- Gemfile.lock | 4 ++-- app/controllers/home_controller.rb | 7 ++++--- .../origami/dashboard_controller.rb | 3 ++- app/models/sale.rb | 21 ------------------- 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 49926b1c..a1fd1f6d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -375,8 +375,8 @@ DEPENDENCIES web-console (>= 3.3.0) whenever - RUBY VERSION - ruby 2.6.3p62 + ruby 2.4.1p111 + BUNDLED WITH 2.0.2 diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index d9c67962..4d8c715a 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -134,7 +134,7 @@ class HomeController < ApplicationController end @inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time).sum(:balance) - @total_trans = Sale.total_trans(today,current_user,@from,@to,@from_time,@to_time) + @total_trans = Sale.total_trans(today,current_user,@from,@to,@from_time,@to_time) @total_card = Sale.total_card_sale(today,current_user,@from,@to,@from_time,@to_time) @total_credit = Sale.credit_payment(today,current_user,@from,@to,@from_time,@to_time) @@ -157,15 +157,16 @@ class HomeController < ApplicationController # @total_other_customer = Sale.total_other_customer(today,current_user) @total_order = Sale.total_order(today,current_user,@from,@to,@from_time,@to_time) - @total_accounts = Sale.total_account(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(account.account_id, today,current_user,@from,@to,@from_time,@to_time) - if !acc.nil? + 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(today,current_user,@from,@to,@from_time,@to_time) diff --git a/app/controllers/origami/dashboard_controller.rb b/app/controllers/origami/dashboard_controller.rb index 1daa652b..a1aa2064 100644 --- a/app/controllers/origami/dashboard_controller.rb +++ b/app/controllers/origami/dashboard_controller.rb @@ -27,7 +27,7 @@ class Origami::DashboardController < BaseOrigamiController # @total_other_customer = Sale.total_other_customer(today,current_user) @total_order = Sale.total_order(today,current_user) - @total_accounts = Sale.total_account(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| @@ -36,6 +36,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 diff --git a/app/models/sale.rb b/app/models/sale.rb index fe43ea69..999a18fd 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1878,27 +1878,6 @@ end query = query.first end - def self.total_account(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - query = Sale.select("distinct b.id as account_id, b.title as title") - .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .joins("JOIN accounts as b ON b.id = a.account_id") - .where('sales.sale_status = "completed"') - if (!from.nil? && !to.nil?) && (from != "" && to!="") - query = query.date_between(from, to) - if !from_time.nil? && !to_time.nil? - query = query.time_between(from_time, to_time) - end - else - query = query.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) - query = query.where("sales.shift_sale_id = ?", shift.id) - end - end - return query - end - def self.account_data(account_id, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")