From 08b378f95858863ef92fe5692651ca33a08d6c80 Mon Sep 17 00:00:00 2001 From: ymatsumoto Date: Mon, 18 Mar 2013 19:14:43 +0900 Subject: [PATCH] =?utf8?q?=E5=95=86=E5=93=81=E5=88=A5=E9=9B=86=E8=A8=88?= =?utf8?q?=E3=81=8C=E6=AD=A3=E3=81=97=E3=81=8F=E9=9B=86=E8=A8=88=E3=81=95?= =?utf8?q?=E3=82=8C=E3=81=AA=E3=81=84=E4=B8=8D=E5=85=B7=E5=90=88=E4=BF=AE?= =?utf8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- app/controllers/admin/totals_controller.rb | 25 +++++++++++++++++++------ app/views/admin/totals/index.html.erb | 4 ++-- lib/totalizer.rb | 18 +++++++++--------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/app/controllers/admin/totals_controller.rb b/app/controllers/admin/totals_controller.rb index 6f09631..450b8b6 100644 --- a/app/controllers/admin/totals_controller.rb +++ b/app/controllers/admin/totals_controller.rb @@ -6,43 +6,55 @@ class Admin::TotalsController < Admin::BaseController def index - #searchの日付をparse + #searchに商品集計用の要素を追加 params[:search] ||= {} [:month, :date_from, :date_to, :sale_start_from, :sale_start_to].each do | key | params[:search][key] = parse_date_select(params[:search], key) end - + + #販売元id=ログインしているユーザーの販売元id params[:search][:retailer_id] ||= session[:admin_user].retailer_id - + + #ログインユーザーのショップが無くて販売元idが違ったらエラー if !session[:admin_user].master_shop? && params[:search][:retailer_id] != session[:admin_user].retailer_id raise ActiveRecord::RecordNotFound end + #OpenStructのsearch生成 @search = OpenStruct.new(params[:search]) + + #:pageがnilだったら代入 params[:page] ||= 'term' + + #:pageのクラス取得 @agent = Totalizer.get_instance(params[:page]) + #取得できなかったら取得 if not @agent params[:page] = 'term' @agent = Totalizer.get_instance(params[:page]) end + #productのページだったらtrue @sale_start_enabled = (params[:page] == 'product') params[:type] ||= @agent.default_type + + # @title = @agent.title @list_view = @agent.columns @links = @agent.links @labels = @agent.labels + @total = @agent.total + #当てはまったものをレコードに入れる begin @records = @agent.get_records(params) rescue => e logger.error e.message e.backtrace.each{|bt|logger.error(bt)} end - - @total = @agent.total - + + # begin flash[:graph] = @agent.graph rescue =>e @@ -50,6 +62,7 @@ class Admin::TotalsController < Admin::BaseController e.backtrace.each{|bt|logger.error(bt)} end + # @selected_retailer = params[:search][:retailer_id].to_i end diff --git a/app/views/admin/totals/index.html.erb b/app/views/admin/totals/index.html.erb index 0e13e63..9c0d174 100644 --- a/app/views/admin/totals/index.html.erb +++ b/app/views/admin/totals/index.html.erb @@ -107,7 +107,7 @@ <% end %> <% end %> - + <% if @total %> <% @list_view.each do | column | %> @@ -118,7 +118,7 @@ <% end %> <% end %> - + <% @labels.each do | label | %> <%= label and label.sub("\n", '
') %> diff --git a/lib/totalizer.rb b/lib/totalizer.rb index 167732f..2287393 100644 --- a/lib/totalizer.rb +++ b/lib/totalizer.rb @@ -345,7 +345,6 @@ class ProductTotalizer < Totalizer def search conditions records = OrderDetail.find_by_sql([<<-EOS, conditions]) select - order_details.id, 1 as position, product_code, product_name, @@ -361,16 +360,17 @@ class ProductTotalizer < Totalizer join product_styles on product_styles.id = order_details.product_style_id join products on products.id = product_styles.product_id where #{WHERE_CLAUSE} - #{if @member == 'member' - " and (customers.activate in (:activate)) " - elsif @member == 'nomember' - " and (customers.activate is null) " - else - " and (customers.activate in (:activate) or customers.activate is null) " - end} + #{if @member == 'member' + " and (customers.activate in (:activate)) " + elsif @member == 'nomember' + " and (customers.activate is null) " + else + " and (customers.activate in (:activate) or customers.activate is null) " + end} and ((:sale_start_from is null or :sale_start_to is null) or products.sale_start_at between :sale_start_from and :sale_start_to) - group by order_details.id, product_code, product_name, unit_price, products.sale_start_at + and product_styles.deleted_at is null + group by product_code, product_name, unit_price, products.sale_start_at order by price desc EOS # position の振り直し & 販売開始日を Date に -- 2.11.0