# -*- coding: utf-8 -*-
class TopController < ApplicationController
  before_filter :redirect_if_mobile
  
  #== トップ画面用
  #-----------------------------------------------------------------#++
  def index
    require 'config/site_config'
    @ext_ver    = ENV['EXT_VERSION'] || '2.2'
    @user_id    = session[:user_id]
    @user       = User.find(@user_id)
    @user_name  = @user.disp_name
    role_ids = @user.vroles.map {|r| r.id }
    @roles      = role_ids.join(',')
    @admin_flag = role_ids.index(ROLE_ADMIN_ID) ? true : false
    @sections = UserPosition.asign('user_id', @user_id).possort.selekt('section_id').all.extract('section_id').join(',')
    @rev_number = MasterRevision.get_rev_number
    @print_label = $PRINT_LABEL
    @production = Rails.env.production? 
    @display_theme = $XTHEME
    @lite_flag = params[:lite]==STR_TRUE ? true : false
    @no_invalid = params[:no_invalid]==STR_TRUE ? true : false
    @custom_params = params[:custom_params]
    @cutoff_table = $CUTOFF_CHECK_TYPE==1 ? true : false
    @timeout = params[:timeout] || $TIMEOUT || 600000 #設定がなければ、10分
    @std_product_price = $PRODUCTS_PRICES_CALC_CODE == CommLogistics::Const::Code::PRODUCTS_PRICES_CALC_CODE_STANDARD_COST #標準原価かどうか。
    @glan_ver = File.basename(RAILS_ROOT).to_f
    #受託販売対応
    supplier_ids = SuppliersUser.vsuppliers(@user_id)
    customer_ids = CustomersUser.vcustomers(@user_id)
    @suppliers   = supplier_ids.join(',')
    @customers   = customer_ids.join(',')
    own_user_flag = ($ENABLE_SUPPLIER_FILTER == true || $ENABLE_CUSTOMER_FILTER == true) ? ( User.own_user_flag(@user_id) ? true : false ) : true
    @own_user_flag = own_user_flag
    @own_supplier_flag = own_user_flag || ($ENABLE_CUSTOMER_FILTER==true && customer_ids.length > 0)
    @own_customer_flag = own_user_flag || ($ENABLE_SUPPLIER_FILTER==true && supplier_ids.length > 0)
    @show_own_product_to_supplier = $SHOW_OWN_PRODUCT_TO_SUPPLIER
    @show_own_product_to_customer = $SHOW_OWN_PRODUCT_TO_CUSTOMER
    @enable_location = $ENABLE_LOCATION
    @only_shippable_flag = $AUTO_FLOW_NON_SHIPPABLE
    @merge_lot_flag = $AUTO_FLOW_MERGE_LOT
    @show_duty_rate = $SHOW_DUTY_RATE
    @show_non_inspect_stocks_list = $SHOW_NON_INSPECT_STOCKS_LIST
    @accept_order_auto_flag = $ACCEPT_ORDER_AUTO_FLAG
    @show_shipping_for_accept_order = $SHOW_SHIPPING_FOR_ACCEPT_ORDER
    @warehouse_price_definition = $WAREHOUSE_PRICE_DEFINITION
    @wholesale_price_num = $WHOLESALE_PRICE_NUM || 0
    @invoice_price_num = $INVOICE_PRICE_NUM  || 0
  end
  
  #== ホーム画面用
  #-----------------------------------------------------------------#++
  def show
    @user_info={}
    respond_to do |format|
      format.json { render :json => @user_info.to_json }
    end
  end

  private
  def redirect_if_mobile
    redirect_to :controller => '/mobile/top', :action => 'index' if request.mobile?
  end
end
