# -*- coding: utf-8 -*-
class Mobile::StocksDetailsController < Mobile::StocksController
  def index    
    require 'config/site_config'
    @show_own_stock = $SHOW_OWN_STOCK

    @results_header = Array.new
    params[:where].each do |key, value|
      @results_header << col_descriptions(key)
    end
    
    set_next
    @group_by = params[:next]
    @target_id = params[:next]
    @target_dn = params[:next].gsub(/(_id)$/,'_dn')
    @results = hashfy_and_add_disp_names(find_stock(@group_by + (params[:next]=='lot_number'? ',ubd' : ''), params[:own_warehouse])) #自社在庫

    @total_quantity = total_quantity(@results)
    if params[:own_warehouse] == STR_FALSE
      @own_total_quantity = total_quantity(@results, 'own_quantity')
    end
    
    respond_to do |format|
      format.html
    end
    
  end
  
  def set_next
    case params[:next]
      when 'sales_area_id'
        @next = 'user_position_id'
      when 'user_position_id'
        @next = 'warehouse_id'
      when 'product_id'
        @next = 'lot_number'
      when 'product_set_id'
        @next = 'product_id'
      when 'warehouse_id'
        if params[:where].include?('product_set_id')
          @next = 'product_id'
        else
          @next = 'product_set_id'
        end
      else 
        @next = ''
    end
  end
end
