OSDN Git Service

在庫管理機能追加
authorcho <cho@06daa6dd-5c14-464e-8a85-0d68c524be32>
Wed, 27 Jan 2010 10:07:45 +0000 (10:07 +0000)
committercho <cho@06daa6dd-5c14-464e-8a85-0d68c524be32>
Wed, 27 Jan 2010 10:07:45 +0000 (10:07 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/elecoma/trunk@34 06daa6dd-5c14-464e-8a85-0d68c524be32

76 files changed:
app/controllers/admin/product_styles_controller.rb
app/controllers/admin/stock_base_controller.rb [new file with mode: 0644]
app/controllers/admin/stock_csv_controller.rb [new file with mode: 0644]
app/controllers/admin/stock_histories_controller.rb [new file with mode: 0644]
app/controllers/admin/stock_in_controller.rb [new file with mode: 0644]
app/controllers/admin/stock_modify_controller.rb [new file with mode: 0644]
app/controllers/cart_controller.rb
app/helpers/admin/stock_base_helper.rb [new file with mode: 0644]
app/helpers/admin/stock_csv_helper.rb [new file with mode: 0644]
app/helpers/admin/stock_histories_helper.rb [new file with mode: 0644]
app/helpers/admin/stock_in_helper.rb [new file with mode: 0644]
app/helpers/admin/stock_modify_helper.rb [new file with mode: 0644]
app/helpers/base_helper.rb
app/models/product.rb
app/models/product_style.rb
app/models/stock_history.rb [new file with mode: 0644]
app/models/stock_search_form.rb [new file with mode: 0644]
app/views/admin/base/_depot_submenu.html.erb
app/views/admin/home/index.html.erb
app/views/admin/product_styles/_form.html.erb
app/views/admin/product_styles/confirm.html.erb
app/views/admin/product_styles/stock_histories.html.erb [new file with mode: 0644]
app/views/admin/products/_search.html.erb
app/views/admin/stock/_submenu.html.erb [deleted file]
app/views/admin/stock/confirm.html.erb [deleted file]
app/views/admin/stock/list.html.erb [deleted file]
app/views/admin/stock/new.html.erb [deleted file]
app/views/admin/stock_csv/_submenu.html.erb [new file with mode: 0644]
app/views/admin/stock_csv/index.html.erb [new file with mode: 0644]
app/views/admin/stock_histories/_search.html.erb [new file with mode: 0644]
app/views/admin/stock_histories/_submenu.html.erb [new file with mode: 0644]
app/views/admin/stock_histories/index.html.erb [new file with mode: 0644]
app/views/admin/stock_histories/search.html.erb [new file with mode: 0644]
app/views/admin/stock_histories/show.html.erb [new file with mode: 0644]
app/views/admin/stock_in/_form.html.erb [new file with mode: 0644]
app/views/admin/stock_in/_info.html.erb [new file with mode: 0644]
app/views/admin/stock_in/_search.html.erb [new file with mode: 0644]
app/views/admin/stock_in/_submenu.html.erb [new file with mode: 0644]
app/views/admin/stock_in/edit.html.erb [new file with mode: 0644]
app/views/admin/stock_in/index.html.erb [new file with mode: 0644]
app/views/admin/stock_in/search.html.erb [new file with mode: 0644]
app/views/admin/stock_modify/_form.html.erb [new file with mode: 0644]
app/views/admin/stock_modify/_info.html.erb [new file with mode: 0644]
app/views/admin/stock_modify/_search.html.erb [new file with mode: 0644]
app/views/admin/stock_modify/_submenu.html.erb [new file with mode: 0644]
app/views/admin/stock_modify/edit.html.erb [new file with mode: 0644]
app/views/admin/stock_modify/index.html.erb [new file with mode: 0644]
app/views/admin/stock_modify/search.html.erb [new file with mode: 0644]
app/views/campaigns/show.html.erb
app/views/campaigns/show_mobile.html.erb
app/views/layouts/admin/base.html.erb
app/views/products/show.html.erb
app/views/products/show_mobile.html.erb
app/views/products/stock_table.html.erb
config/locales/translation_ja.yml
db/migrate/20100118000000_add_data_functions_ver3.rb [new file with mode: 0644]
db/migrate/20100118000001_update_data_product_styles_orderable_count.rb [new file with mode: 0644]
db/migrate/20100118065008_create_stock_histories.rb [new file with mode: 0644]
db/migrate/fixed_data/authorities_functions.csv
db/migrate/fixed_data/functions.yml
spec/controllers/admin/stock_base_controller_spec.rb [new file with mode: 0644]
spec/controllers/admin/stock_csv_controller_spec.rb [new file with mode: 0644]
spec/controllers/admin/stock_histories_controller_spec.rb [new file with mode: 0644]
spec/controllers/admin/stock_in_controller_spec.rb [new file with mode: 0644]
spec/controllers/admin/stock_modify_controller_spec.rb [new file with mode: 0644]
spec/controllers/admin/suppliers_controller_spec.rb
spec/controllers/cart_controller_spec.rb
spec/fixtures/product_styles.yml
spec/fixtures/stock_histories.yml [new file with mode: 0644]
spec/helpers/admin/stock_csv_helper_spec.rb [new file with mode: 0644]
spec/helpers/admin/stock_histories_helper_spec.rb [new file with mode: 0644]
spec/helpers/admin/stock_in_helper_spec.rb [new file with mode: 0644]
spec/helpers/admin/stock_modify_helper_spec.rb [new file with mode: 0644]
spec/models/product_style_spec.rb
spec/models/stock_history_spec.rb [new file with mode: 0644]
spec/models/stock_search_form_spec.rb [new file with mode: 0644]

index e6262ad..37b18af 100644 (file)
@@ -41,7 +41,20 @@ class Admin::ProductStylesController < Admin::BaseController
     end
     redirect_to :controller => "products", :action => "index"
   end
-
+  
+  #在庫管理履歴プレビュー
+  def stock_histories
+    product_style_id = params[:id]
+    if !product_style_id.blank? && product_style_id=~ /^\d*$/
+      @product_style = ProductStyle.find_by_id(product_style_id.to_i)
+      if !@product_style.blank?
+        @stock_histories = @product_style.stock_histories
+      end
+    else
+      raise "Parameter Invalid"
+    end
+  end
+  
   protected
 
   def set_style_category
@@ -93,11 +106,10 @@ class Admin::ProductStylesController < Admin::BaseController
           end
         if product_style[:id]
           product_style.update_attributes({:sell_price=>value[:sell_price], 
-                                           :actual_count=>value[:actual_count],
                                            :code=>value[:code],
                                            :manufacturer_id=>value[:manufacturer_id]})
         else
-          [:sell_price, :actual_count, :code ,:manufacturer_id].each do |column|
+          [:sell_price, :code ,:manufacturer_id].each do |column|  
             product_style[column] = value[column]
           end
           product_style[:position] = idx.to_i + 1
diff --git a/app/controllers/admin/stock_base_controller.rb b/app/controllers/admin/stock_base_controller.rb
new file mode 100644 (file)
index 0000000..13cba0b
--- /dev/null
@@ -0,0 +1,81 @@
+#在庫管理の親クラス
+#共通ロジック
+class Admin::StockBaseController < Admin::BaseController
+  before_filter :admin_permission_check_stock
+  
+  #検索
+  def search
+    @condition = StockSearchForm.new(params[:condition])
+    unless @condition.valid?
+      render :action => "index"
+      return
+    end
+    @condition, @search_list = Product.get_conditions(@condition, params, true)
+    find_options = {
+      :page => params[:page],
+      :per_page => @condition.per_page || 10,
+      :conditions => flatten_conditions(@search_list),
+      :joins => "LEFT JOIN products ON products.id = product_styles.product_id ",
+      :order => "product_styles.id"
+    }
+    @product_styles = ProductStyle.paginate(find_options)    
+  end
+  
+  #入庫数、在庫数を更新
+  def stock_update(stock_type)
+    #1.初期データ取得
+    init(stock_type)
+    #2-1.入力チェック
+    unless @stock_history.valid?
+      render :action => "edit"
+      return
+    end
+    #2-2.値チェック
+    result,err_msg = check_parameter
+    unless result
+      flash.now[:error] = err_msg
+      render :action => "edit"
+      return
+    end
+    #3.値設定
+    set_parameter
+    #4-1. 商品規格保存
+    if @product_style.save!
+      #4-2.作業履歴保存
+      set_stock_history
+      @stock_history.save
+      flash[:stock_update] = "データを保存しました"
+      redirect_to :action => "index"
+    else  
+      flash[:stock_update_e] = "データ保存に失敗しました"
+      render :action => "edit"
+      return
+    end
+  end
+  
+  protected
+  def init(stock_type)
+    if !params[:id].blank? && params[:id]=~ /^\d*$/ 
+      @product_style = ProductStyle.find_by_id(params[:id].to_i)
+      if !@product_style.blank?
+        @stock_history = StockHistory.new(params[:stock_history])
+        @stock_history.stock_type = stock_type
+      else      
+        raise ActiveRecord::RecordNotFound
+      end
+    else
+      raise "Parameter Invalid"
+    end
+  end
+  
+  #保存したい作業履歴値設定
+  def set_stock_history
+    @stock_history.admin_user_id = session[:admin_user].id
+    @stock_history.product_id = @product_style.product_id
+    @stock_history.product_style_id = @product_style.id
+    @stock_history.actual_count = @product_style.actual_count
+    @stock_history.orderable_count = @product_style.orderable_count
+    @stock_history.broken_count = @product_style.broken_count
+    @stock_history.moved_at = DateTime.now
+  end 
+end
diff --git a/app/controllers/admin/stock_csv_controller.rb b/app/controllers/admin/stock_csv_controller.rb
new file mode 100644 (file)
index 0000000..323693b
--- /dev/null
@@ -0,0 +1,79 @@
+#棚卸用CSV出力
+require 'csv'
+class Admin::StockCsvController < Admin::BaseController
+  before_filter :admin_permission_check_stock
+  caches_page :csv
+
+  def index
+    dir = Pathname.new(page_cache_directory).join(params[:controller], 'csv')
+    unless FileTest.exist?(dir.to_s)
+      FileUtils.mkdir_p(dir.to_s)
+      @dates = []
+      @urls = []
+      return
+    end
+
+    limit = 1.year.ago
+    pairs = dir.enum_for(:each_entry).map do |path|
+      dir.join(path)
+    end.select do |path|
+      path.extname == page_cache_extension or path.extname == '.csv'
+    end.map do |path|
+      path.basename(path.extname).to_s
+    end.map do |id|
+      [id, id.to_time(:local)]
+    end.select do |_, time|
+      time >= limit
+    end.sort_by do |_, time|
+      time
+    end.reverse
+
+    @dates = pairs.map do |_, time|
+      time
+    end
+    @urls = pairs.map do |id, _|
+      url_for(:action => :csv, :id => id,:format => "csv")
+    end
+  end
+
+  def new
+    redirect_to(url_for_date(DateTime.now))
+  end
+
+  def csv
+    # params[:id] はページキャッシュのキーにするだけで抽出条件にはしない
+    if params[:id].blank?
+      render :status => :not_found
+    end
+    date = DateTime.now
+    rows = ProductStyle.find(:all).map do |ps|
+      a = []
+      a << ps.code
+      a << ps.product.name
+      a << ps.product.supplier_name
+      a << ps.actual_count
+      a << ps.broken_count
+      a
+    end
+
+    # CSV に吐く
+    f = StringIO.new('', 'w')
+    title = %w(商品コード 商品名 仕入先名 実在庫数 不良在庫数)
+
+    CSV::Writer.generate(f) do | writer |
+      writer << title
+      rows.each do |row|
+        writer << row
+      end
+    end
+    name = params[:id]
+    filename = '%s.csv' % name
+    headers['Content-Type'] = "application/octet-stream; name=#{filename}"
+    headers['Content-Disposition'] = "attachment; filename=#{filename}"
+    render :text => Iconv.conv('cp932', 'UTF-8', f.string)    
+  end
+
+  def url_for_date(date)
+    url_for(:action => :csv, :id => date.strftime('%Y%m%d_%H%M%S'),:format => "csv")
+  end  
+end
diff --git a/app/controllers/admin/stock_histories_controller.rb b/app/controllers/admin/stock_histories_controller.rb
new file mode 100644 (file)
index 0000000..ff695d9
--- /dev/null
@@ -0,0 +1,22 @@
+#入庫、在庫調整作業履歴
+class Admin::StockHistoriesController < Admin::BaseController
+  resource_controller
+  before_filter :admin_permission_check_stock
+  
+  def search
+    @condition = StockSearchForm.new(params[:condition])
+    unless @condition.valid?
+      render :action => "index"
+      return
+    end
+
+    @search_list = StockSearchForm.get_conditions(@condition)
+    find_options = {
+      :page => params[:page],
+      :per_page => @condition.per_page || 10,
+      :conditions => flatten_conditions(@search_list),
+      :order => "id"
+    }
+    @stock_histories = StockHistory.paginate(find_options) 
+  end
+end
diff --git a/app/controllers/admin/stock_in_controller.rb b/app/controllers/admin/stock_in_controller.rb
new file mode 100644 (file)
index 0000000..e91d204
--- /dev/null
@@ -0,0 +1,35 @@
+#入庫管理
+class Admin::StockInController < Admin::StockBaseController
+  before_filter :admin_permission_check_stock
+  
+  def index
+    @condition = StockSearchForm.new(params[:condition])
+  end
+
+  def edit
+    init(StockHistory::STOCK_IN)
+  end
+  
+  def update
+    stock_update(StockHistory::STOCK_IN)
+  end
+  
+  #各調整数チェック
+  def check_parameter
+    result = false
+    err_msg = nil
+    
+    actual_count = @product_style.actual_count.to_i + @stock_history.storaged_count.to_i
+
+    if actual_count >= 0
+      result = true
+    else
+      err_msg = "実在庫数が「-」になっています。ご確認ください"
+    end
+    [result,err_msg]
+  end
+  #値設定
+  def set_parameter
+    @product_style.actual_count = @product_style.actual_count.to_i +  @stock_history.storaged_count.to_i
+  end
+end
diff --git a/app/controllers/admin/stock_modify_controller.rb b/app/controllers/admin/stock_modify_controller.rb
new file mode 100644 (file)
index 0000000..cc18ae1
--- /dev/null
@@ -0,0 +1,49 @@
+#在庫調整
+class Admin::StockModifyController < Admin::StockBaseController
+  before_filter :admin_permission_check_stock
+  
+  def index
+    @condition = StockSearchForm.new(params[:condition])
+  end
+
+  def edit
+    init(StockHistory::STOCK_MODIFY)
+  end
+  
+  def update
+    stock_update(StockHistory::STOCK_MODIFY)
+  end
+  
+  #各調整数チェック
+  def check_parameter
+    result = false
+    err_msg = nil
+    
+    actual_count = @product_style.actual_count.to_i + @stock_history.actual_adjustment.to_i
+    orderable_count = @product_style.orderable_count.to_i + @stock_history.orderable_adjustment.to_i
+    broken_count = @product_style.broken_count.to_i + @stock_history.broken_adjustment.to_i
+
+    if [actual_count,orderable_count,broken_count].all? {|v| v >= 0}
+      result = true
+    else
+      err = []
+      if actual_count < 0
+        err << "実在庫数"
+      end
+      if orderable_count < 0
+        err << "販売可能数"
+      end
+      if broken_count < 0
+        err << "不良在庫数"
+      end
+      err_msg = err.join("、") + "が「-」になっています。ご確認ください。"
+    end
+    [result,err_msg]
+  end
+  #値設定
+  def set_parameter
+    @product_style.actual_count = @product_style.actual_count.to_i +  @stock_history.actual_adjustment.to_i unless @stock_history.actual_adjustment.blank?
+    @product_style.orderable_count = @product_style.orderable_count.to_i + @stock_history.orderable_adjustment.to_i unless @stock_history.orderable_adjustment.blank?
+    @product_style.broken_count = @product_style.broken_count.to_i +  @stock_history.broken_adjustment.to_i   unless @stock_history.broken_adjustment.blank?
+  end
+end
index 5040f21..0047057 100644 (file)
@@ -49,7 +49,7 @@ class CartController < BaseController
     new_quantity = cart.quantity + value
     cart.quantity = cart.product_style.available?(new_quantity)
     if cart.quantity < new_quantity
-      flash.now[:notice] = '購入できる上限を超えています'
+      flash[:notice] = '購入できる上限を超えています'
     end
     redirect_to :action => 'show'
   end
@@ -341,7 +341,6 @@ class CartController < BaseController
       @login_customer.point = params[:point_after_operation]
       @order = @login_customer.orders.build
     end
-    
     @order.received_at = DateTime.now
     @order_delivery = @order.order_deliveries.build(params[:order_delivery])
     
@@ -354,7 +353,8 @@ class CartController < BaseController
     @order_delivery.status = OrderDelivery::JUTYUU
     # 受注発注商品が一つでもあるか
     product_styles = @carts.map(&:product_style)
-    if product_styles.any?{|ps| ps.actual_count == 0}
+    #販売可能数で判断
+    if product_styles.any?{|ps| ps.orderable_count.to_i == 0}
       # 販売開始日が未来の物が一つでもあれば予約
       products = product_styles.map(&:product)
       today = Date.today
diff --git a/app/helpers/admin/stock_base_helper.rb b/app/helpers/admin/stock_base_helper.rb
new file mode 100644 (file)
index 0000000..675b79d
--- /dev/null
@@ -0,0 +1,2 @@
+module Admin::StockBaseHelper
+end
diff --git a/app/helpers/admin/stock_csv_helper.rb b/app/helpers/admin/stock_csv_helper.rb
new file mode 100644 (file)
index 0000000..be43aff
--- /dev/null
@@ -0,0 +1,2 @@
+module Admin::StockCsvHelper
+end
diff --git a/app/helpers/admin/stock_histories_helper.rb b/app/helpers/admin/stock_histories_helper.rb
new file mode 100644 (file)
index 0000000..4496212
--- /dev/null
@@ -0,0 +1,2 @@
+module Admin::StockHistoriesHelper
+end
diff --git a/app/helpers/admin/stock_in_helper.rb b/app/helpers/admin/stock_in_helper.rb
new file mode 100644 (file)
index 0000000..4482da8
--- /dev/null
@@ -0,0 +1,2 @@
+module Admin::StockInHelper
+end
diff --git a/app/helpers/admin/stock_modify_helper.rb b/app/helpers/admin/stock_modify_helper.rb
new file mode 100644 (file)
index 0000000..406263c
--- /dev/null
@@ -0,0 +1,2 @@
+module Admin::StockModifyHelper
+end
index 643cb1c..4a953b0 100644 (file)
@@ -308,7 +308,7 @@ end
 def category_options_internal(tree, indent='')
   tree.inject([]) do |array, item|
     if item.instance_of? Category
-      array << ['%s%s' % [indent, item.name], item.id]
+      array << ['%s%s' % [indent, item.name], item.id.to_s]
     else
       array += category_options_internal(item, indent + '>')
     end
index d42070b..26d446b 100644 (file)
@@ -154,7 +154,8 @@ class Product < ActiveRecord::Base
   def have_zaiko?
     product_styles or return false
     product_styles.any? do |ps|
-      !ps.actual_count.blank? && ps.actual_count > 0
+      #販売可能数で判断
+      ps.orderable_count.to_i > 0
     end
   end
 
@@ -188,10 +189,21 @@ class Product < ActiveRecord::Base
                                              :conditions => code_condition )
           ids = product_styles.map{|p| p.product_id}.join(",")
           ids = id_change_to_i(ids)
-#          ids = "0" if ids.blank?
           search_list << ["products.id in (?) ", ids]
         end
       end
+      unless search.manufacturer.blank?
+        code_condition = ["product_styles.manufacturer_id like ? ", "%#{search.manufacturer}%"]
+        if actual_count_list_flg
+          search_list << code_condition
+        else
+          product_styles = ProductStyle.find(:all, :select => "product_styles.product_id",
+                                             :conditions => code_condition )
+          ids = product_styles.map{|p| p.product_id}.join(",")
+          ids = id_change_to_i(ids)
+          search_list << ["products.id in (?) ", ids]
+        end
+      end      
       unless search.style.blank?
         product_styles = ProductStyle.find(:all, :select => "product_styles.product_id",
                                            :joins => "left join style_categories  on product_styles.style_category_id1 = style_categories.id left join style_categories as style_categories2 on style_category_id2 = style_categories2.id ",
@@ -208,10 +220,11 @@ class Product < ActiveRecord::Base
         search_list << ["products.supplier_id = ?", search.supplier.to_i]
       end      
       unless search.category.blank?
-        search.category = search.category.to_i
-        category = Category.find_by_id search.category
-        ids = category.get_child_category_ids
-        search_list << ["products.category_id in (?)", ids] unless ids.empty?
+        category = Category.find_by_id search.category.to_i
+        unless category.blank?
+          ids = category.get_child_category_ids
+          search_list << ["products.category_id in (?)", ids] unless ids.empty?
+        end
       end
       unless search.permit.blank?
         search_list << ["products.permit = ?", search.permit]
index 877e766..ee1fbfa 100644 (file)
@@ -18,21 +18,11 @@ class ProductStyle < ActiveRecord::Base
   belongs_to :style2, 
              :class_name => "Style",
              :foreign_key => "style_id2"
+  has_many :stock_histories
              
   validates_format_of :code, :with => /^[a-zA-Z0-9]*$/
   validates_format_of :manufacturer_id, :with => /^[a-zA-Z0-9]*$/, :allow_blank=>true
 
-  DEFAULT_DATA = {:actual_count => 0}
-  alias initialize_old initialize
-
-  def initialize(attributes = nil)
-    initialize_old(attributes)
-    if @new_record && defined? DEFAULT_DATA
-      DEFAULT_DATA.each do | column, value |
-        @attributes[column.to_s] = value unless @attributes[column.to_s] && ! @attributes[column.to_s].blank?
-      end
-    end
-  end
 =begin rdoc
   * INFO
 
@@ -44,7 +34,8 @@ class ProductStyle < ActiveRecord::Base
       引数 [size] が購入可能な個数を超過する場合は、 購入可能な最大数 を返す。
 =end
   def available?(size)
-    actual_count.to_i > 0 ? (check = actual_count) : (check = 0)
+    #販売可能数で判断
+    orderable_count.to_i > 0 ? (check = orderable_count.to_i) : (check = 0)
     limit = [check, size].min
     product.sell_limit ? [limit, product.sell_limit].min : limit
   end
@@ -73,10 +64,12 @@ class ProductStyle < ActiveRecord::Base
 
   # 受注する
   def order(number)
-    if actual_count > 0
+    #販売可能数で判断
+    if orderable_count.to_i > 0
+      self.orderable_count -= number
       self.actual_count -= number
     else
-      raise 'å®\9få\9c¨å\80\8bæ\95°ã\81\8c\81§ã\81\99'
+      raise 'å\9c¨åº«ä¸\8d足ã\81§ã\81\99ã\80\82'
     end
   end
 
@@ -91,5 +84,11 @@ class ProductStyle < ActiveRecord::Base
   def product_name
     product && product.name
   end
-
+  # 規格分類名称
+  def style_name(delimiter=' ')
+    [style_category_name1, style_category_name2].inject([]) do | xs, x |
+      x.blank? and break xs
+      xs << x
+    end.join(delimiter)
+  end
 end
diff --git a/app/models/stock_history.rb b/app/models/stock_history.rb
new file mode 100644 (file)
index 0000000..4268f5e
--- /dev/null
@@ -0,0 +1,18 @@
+class StockHistory < ActiveRecord::Base
+  acts_as_paranoid
+  
+  belongs_to :product
+  belongs_to :product_style
+  belongs_to :admin_user
+  
+  validates_presence_of :comment
+  validates_length_of :comment, :maximum => 10000 , :allow_blank => true
+  validates_presence_of :storaged_count ,:if => :stock_in?
+  
+  STOCK_IN ,STOCK_MODIFY = 1 , 2 
+  STOCK_TYPE_NAMES = {STOCK_IN=>"入庫",STOCK_MODIFY=>"在庫調整"}
+  
+  def stock_in?
+    stock_type == STOCK_IN
+  end   
+end
diff --git a/app/models/stock_search_form.rb b/app/models/stock_search_form.rb
new file mode 100644 (file)
index 0000000..630ef93
--- /dev/null
@@ -0,0 +1,56 @@
+# 在庫管理で商品検索条件を格納するフォーム
+class StockSearchForm < SearchForm
+  set_field_names :product_id => '商品ID'
+  set_field_names :code => '商品コード'
+  set_field_names :name => '商品名'
+  set_field_names :manufacturer => '型番'
+  set_field_names :supplier => '仕入先名'
+  set_field_names :category => 'カテゴリ'
+
+  validates_numericality_of :product_id, :allow_blank=>true, :message => 'は半角数字のみを入力してください。'
+  validates_format_of :code, :with => /^[a-zA-Z0-9]*$/, :allow_blank => true, :message => 'は半角英数字のみを入力してください。'
+  validates_format_of :manufacturer, :with => /^[a-zA-Z0-9]*$/, :allow_blank => true, :message => 'は半角英数字のみを入力してください。'
+
+  def self.get_conditions(search)
+    search_list = []
+    if search
+      #商品ID
+      unless search.product_id.blank?
+        search_list << ["stock_histories.product_id = ?", search.product_id.to_i]
+      end
+      #商品コード
+      unless search.code.blank?
+        ps = ProductStyle.find(:all,:conditions=>"code like '%#{search.code}'")
+        ids = []
+        ids = ps.map{|p| p.id.to_i} unless ps.blank?
+        search_list << ["stock_histories.product_style_id in (?) ", ids] unless ids.blank?        
+      end
+      #商品名
+      unless search.name.blank?
+        ps = Product.find(:all,:conditions=>"name like '%#{search.name}'")
+        ids = []
+        ids = ps.map{|p| p.id.to_i} unless ps.blank?
+        search_list << ["stock_histories.product_id in (?) ", ids] unless ids.blank?        
+      end      
+      #型番
+      unless search.manufacturer.blank?
+        ps = ProductStyle.find(:all,:conditions=>"manufacturer_id like '%#{search.manufacturer}'")
+        ids = []
+        ids = ps.map{|p| p.id.to_i} unless ps.blank?
+        search_list << ["stock_histories.product_style_id in (?) ", ids] unless ids.blank?        
+      end
+      #操作者
+      unless search.operator.blank?
+        search_list << ["stock_histories.admin_user_id = ?", search.operator.to_i]
+      end
+      #在庫移動日
+      unless search.moved_at_from.blank?
+        search_list << ["stock_histories.moved_at >= ?", search.moved_at_from]
+      end
+      unless search.moved_at_to.blank?
+        search_list << ["stock_histories.moved_at <= ?", search.moved_at_to]
+      end
+    end
+    search_list
+  end
+end
index 628d681..36bb808 100644 (file)
       <li><%= link_to '仕入先登録', {:controller => 'suppliers', :action => 'new'} %></li>\r
     </ul>\r
        <%end%>\r
+       <p><a href="JavaScript:onClick=Tree('display2');ImgC('img2');"><img src="/images/menu_icon.gif" width="36" height="36" alt="" id="img2" /><span>在庫管理</span></a></p>\r
+    <ul id="display2" style="display:block">\r
+      <li><%= link_to '入庫管理', {:controller => 'stock_in', :action => 'index'} %></li>\r
+      <li><%= link_to '在庫管理', {:controller => 'stock_modify', :action => 'index'} %></li>\r
+      <li><%= link_to '棚卸用CSV出力', {:controller => 'stock_csv', :action => 'index'} %></li>\r
+      <li><%= link_to '作業履歴', {:controller => 'stock_histories', :action => 'index'} %></li>\r
+    </ul>\r
   </div><!-- /g_menu -->\r
 </div><!-- /サブメニュー -->\r
index 9b32f54..205b52b 100644 (file)
@@ -8,7 +8,7 @@
     <% if @system.supplier_use_flag %>
        <a href="/admin/suppliers"><img src="/images/order_btn_l.gif" width="222" height="138" alt="発注・出荷管理" /></a>
        <%else%>
-       <a href="#"><img src="/images/order_btn_l.gif" width="222" height="138" alt="発注・出荷管理" /></a>
+       <a href="/admin/stock_in"><img src="/images/order_btn_l.gif" width="222" height="138" alt="発注・出荷管理" /></a>
        <%end%>
   </div><!-- /カテゴリ選択 -->
   <%= flash[:notice] %>
index e41bcb1..fcb547d 100644 (file)
       <th>規格1</th>
       <th>規格2</th>
       <th>商品コード</th>
-      <th>在庫</th>
       <th>価格(円)</th>
          <th>型番</th>
+         <th>在庫履歴</th>
     </tr>
     <% idx = 0 %>
     <% @style_category1.each do | style_category1 | %>
       <% @style_category2.each do | style_category2 | %>
         <% product_style =  @product_styles["#{style_category1 && style_category1.id}_#{style_category2 && style_category2.id}"]%>
-        <% logger.debug "#{style_category1 && style_category1.id}_#{style_category2 && style_category2.id}" %>
         <tr>
           <td>
             <% if product_style.nil? || @new_flg %>
             <%= text_field_tag "product_styles[#{idx}][code]", product_style && product_style.code %>
           </td>
           <td>
-            <%= text_field_tag "product_styles[#{idx}][actual_count]", product_style && product_style.actual_count %>
-          </td>
-          <td>
             <%= text_field_tag "product_styles[#{idx}][sell_price]", product_style && product_style.sell_price %>
           </td>
           <td>
             <%= text_field_tag "product_styles[#{idx}][manufacturer_id]", product_style && product_style.manufacturer_id %>
           </td>
+          <td>
+            <% unless product_style.nil?%>
+                       <%= link_to("在庫履歴",{:action=>"stock_histories" ,:id=>product_style},{:target=>"_blank"})%>
+                       <% end%>
+          </td>
         </tr>
         <% idx += 1 %>
       <% end %>
index fd5e43e..d456762 100644 (file)
@@ -21,7 +21,6 @@
         <th>規格1</th>
         <th>規格2</th>
         <th>商品コード</th>
-        <th>在庫</th>
         <th>価格(円)</th>
         <th>型番</th>
       </tr>
               <%= hidden_field_tag "product_styles[#{idx.to_s}][code]", params["product_styles"][idx.to_s] && params["product_styles"][idx.to_s]["code"] %>
             </td>
             <td>
-              <%= h params["product_styles"][idx.to_s] && params["product_styles"][idx.to_s]["actual_count"] %>
-              <%= hidden_field_tag "product_styles[#{idx.to_s}][actual_count]", params["product_styles"][idx.to_s] && params["product_styles"][idx.to_s]["actual_count"] %>
-            </td>
-            <td>
               <%= h params["product_styles"][idx.to_s] && params["product_styles"][idx.to_s]["sell_price"] %>
               <%= hidden_field_tag "product_styles[#{idx.to_s}][sell_price]", params["product_styles"][idx.to_s] && params["product_styles"][idx.to_s]["sell_price"] %>
             </td>
diff --git a/app/views/admin/product_styles/stock_histories.html.erb b/app/views/admin/product_styles/stock_histories.html.erb
new file mode 100644 (file)
index 0000000..0d4dccc
--- /dev/null
@@ -0,0 +1,67 @@
+<%= render :partial => "submenu" %>
+
+<div id="main"><!-- メイン -->
+
+<h2>在庫管理作業履歴</h2>
+<%unless @product_style.blank?%>
+<h3>現在在庫状況</h3>
+<table class="data" cellspacing="1">
+  <tr>
+    <th>現在実在庫数</th>
+    <td>
+      <%= number_with_delimiter(@product_style.actual_count.to_i) %>
+    </td>
+  </tr>
+  <tr>
+    <th>現在受注可能数</th>
+    <td>
+      <%= number_with_delimiter(@product_style.orderable_count.to_i) %>
+    </td>
+  </tr>
+  <tr>
+    <th>現在不良在庫数</th>
+    <td>
+      <%= number_with_delimiter(@product_style.broken_count.to_i) %>
+    </td>
+  </tr>
+</table>
+<h3>作業履歴</h3>
+<% unless @stock_histories.blank?%>
+  <table class="data2 clear" cellspacing="1">
+    <tr>
+      <th>操作者</th>
+      <th>移動日</th>
+      <th>作業区分</th>
+      <th>入庫数</th>
+      <th>実在庫調整数</th>
+      <th>当時実在庫数</th>
+      <th>販売可能調整数</th>
+      <th>当時販売可能数</th>
+      <th>不良在庫調整数</th>
+      <th>当時不良在庫数</th>
+         <th>備考</th>
+       </tr>
+    <% @stock_histories.each do | sh | %>
+      <tr>
+        <td><%= h sh.admin_user.name %></td>
+        <td><%= date_time(sh.moved_at) %></td>
+        <td><%= h(StockHistory::STOCK_TYPE_NAMES[sh.stock_type]) %></td>
+        <td><%= number_with_delimiter(sh.storaged_count) %></td>
+        <td><%= number_with_delimiter(sh.actual_adjustment) %></td>
+        <td><%= number_with_delimiter(sh.actual_count.to_i) %></td>
+        <td><%= number_with_delimiter(sh.orderable_adjustment) %></td>
+        <td><%= number_with_delimiter(sh.orderable_count.to_i) %></td>
+        <td><%= number_with_delimiter(sh.broken_adjustment) %></td>
+        <td><%= number_with_delimiter(sh.broken_count.to_i) %></td>
+        <td><%= h sh.comment %></td>
+      </tr>
+    <% end %>
+</table>
+<%else%>
+<br/><p>在庫作業履歴はありません。</p>
+<%end%>
+<%else%>
+<p>商品規格は存在しません。</p>
+<%end%>
+</div><!-- /メイン -->
+
index b7d79b3..d1dd7da 100644 (file)
@@ -22,7 +22,7 @@
          <tr>
            <th>仕入先名</th>
            <td><%suppliers = Supplier.find(:all,:order=>'id')%>
-                 <%=f.select :supplier,suppliers.map{|s| [s.name,s.id.to_s]}, :include_blank => '全て' %>
+                 <%=f.select :supplier,suppliers.map{|s| [s.name,s.id.to_s]}, :include_blank => true %>
            </td>
          </tr>  
         <% end %>        
diff --git a/app/views/admin/stock/_submenu.html.erb b/app/views/admin/stock/_submenu.html.erb
deleted file mode 100644 (file)
index 6f3795f..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<%= render :partial => "/admin/stock_in/submenu" %>
\ No newline at end of file
diff --git a/app/views/admin/stock/confirm.html.erb b/app/views/admin/stock/confirm.html.erb
deleted file mode 100644 (file)
index 4993aa6..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-<h1>Admin::Stock#confirm</h1>
-<p>Find me in app/views/admin/stock/confirm.html.erb</p>
diff --git a/app/views/admin/stock/list.html.erb b/app/views/admin/stock/list.html.erb
deleted file mode 100644 (file)
index 05c74a1..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-<%= stylesheet_link_tag "stock/stock" %>
-
-<%= render :partial => "submenu" %>
-
-<div class="set">
-<div class="contents_area">
-
-<h2>在庫管理</h2>
-<p><%= flash[:notice] %>
-<% form_for :search, :url => {:action => 'search'} do |f| %>
- <table class="product_info" cellspacing="1">
-  <tr>
-   <th>商品ID</th>
-   <td><%= f.text_field :product_id %></td>
-   <th>規格名称</th>
-   <td><%= f.text_field 'style_category_name' %></td>
-  </tr>
-  <tr>
-   <th>商品コード</th>
-   <td><%= f.text_field :code %></td>
-   <th>商品名</th>
-   <td><%= f.text_field 'product_name' %></td>
-  </tr>
-  <tr>
-   <th>カテゴリ</th>
-   <td><%= f.category_select 'product_category_id', :include_blank => true %></td>
-   <th>種別</th>
-   <td>
-    <%= f.select :permit, Product.permit_select, :include_blank => '全体' %>
-   </td>
-  </tr>
-  <tr>
-   <th>登録・更新日</th>
-   <td colspan="3" style="width:580px;">
-    <%= f.date_select 'updated_at_from', :use_month_numbers => true, :include_blank => true  %>
-    ~
-    <%= f.date_select 'updated_at_to', :use_month_numbers => true, :include_blank => true  %>
-   </td>
-  </tr>
- </table>
- <p class="submit">
-  検索結果表示件数
-   <%= f.select :per_page, (10..100).step(10).map(&:to_s) %>件
-  <%= submit_tag "この条件で検索する" %>
- </p>
-<% end %>
-<% if @records %>
- <p>検索結果一覧 <%= @records.total_entries %> 件が該当しました。</p>
- <table class="result" cellspacing="1">
-  <tr>
-   <th>商品名</th><th>商品コード</th><th>規格名称</th><th>会社名</th><th>登録更新日</th><th>発注予定数</th><th>発注済み数</th><th>受注可能数</th><th>実在庫数</th><th>在庫移動</th>
-  </tr>
- <% @records.each do |record| %>
-  <tr>
-   <td><%=h record.product.name %></td>
-   <td><%=h record.code %></td>
-   <td>
-    <%=h record.style_category_name1 %>
-    <%=h record.style_category_name2 %>
-   </td>
-   <td><%=h record.product.supplier_name %></td>
-   <td><%=date record.updated_at %></td>
-   <td><%=h record.scheduled_count %></td>
-   <td><%=h record.purchased_count %></td>
-   <td><%=h record.orderable_count %></td>
-   <td><%=h record.actual_count %></td>
-   <td><%= link_to '在庫移動', :action=>'new', :id=>record.id %></td>
-  </tr>
- <% end %>
-</table>
-<%= will_paginate @records, :params=>{:search => params[:search]} %>
-<% end %>
-
-</div>
-</div>
diff --git a/app/views/admin/stock/new.html.erb b/app/views/admin/stock/new.html.erb
deleted file mode 100644 (file)
index a371b65..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-<%= stylesheet_link_tag "stock/stock" %>
-
-<%= render :partial => "submenu" %>
-
-<div class="set">
-<div class="contents_area">
-
-<h2>在庫移動</h2>
-
-<h3>商品情報</h3>
-
-<%= error_messages_for :record %>
-<% form_for :record, :url => {:action => 'create' } do |f| %>
- <table class="product_info" cellspacing="1">
-  <tr>
-   <th>商品ID</th>
-   <td><%=h @record.product_id %></td>
-   <th>商品コード</th>
-   <td><%=h @record.product_code %></td>
-  </tr>
-  <tr>
-   <th>商品名</th>
-   <td><%=h @record.product_name %></td>
-   <th>登録・更新日</th>
-   <td><%= date @record.product_style.updated_at %></td>
-  </tr>
-  <tr>
-   <th>規格名称</th>
-   <td>
-    <%=h @record.product_style.style_category_name1 %>
-    <%=h @record.product_style.style_category_name2 %>
-   </td>
-  </tr>
- </table>
-
-<h3>移動内容入力</h3>
-
- <table  class="move" cellspacing="1">
-  <tr>
-   <th>移動理由</th>
-   <td colspan="3">
-    <%= f.collection_select :reason, Constant.list(Constant::MOVEMENT_REASON), :id, :value %>
-   </td>
-  </tr>
-  <tr>
-   <th>受注コード</th>
-   <td>
-    <%= f.text_field :order_code %>
-   </td>
-   <th>返品コード</th>
-   <td>
-    <%= f.text_field :recall_code %>
-   </td>
-  </tr>
-  <tr>
-   <th>発注コード</th>
-   <td colspan="3">
-    <%= f.text_field :purchase_code %>
-   </td>
-  </tr>
- </table>
-
- <p>※調整数には移動させる数量を入力してください。
-  例:実在庫数を1つ減らす場合、「-1」を入力
- </p>
-
- <table cellspacing="1">
-  <tr>
-   <th>発注予定数</th>
-   <td><%=h @record.product_style.scheduled_count %></td>
-   <th>発注済数</th>
-   <td><%=h @record.product_style.purchased_count %></td>
-   <th>受注可能数</th>
-   <td><%=h @record.product_style.orderable_count %></td>
-   <th>実在庫数</th>
-   <td><%=h @record.product_style.actual_count %></td>
-   <th>不良在庫数</th>
-   <td><%=h @record.product_style.broken_count %></td>
-   <!--<th>引当可能数</th>
-   <td><%=h @record.product_style.assignable_count %></td>-->
-  </tr>
-  <tr>
-   <th>調整数</th>
-   <td><%= f.number_field :scheduled_adjustment, :size=>4 %></td>
-   <th>調整数</th>
-   <td><%= f.number_field :purchased_adjustment, :size=>4 %></td>
-   <th>調整数</th>
-   <td><%= f.number_field :orderable_adjustment, :size=>4 %></td>
-   <th>調整数</th>
-   <td><%= f.number_field :actual_adjustment, :size=>4 %></td>
-   <th>調整数</th>
-   <td><%= f.number_field :broken_adjustment, :size=>4 %></td>
-   <!--<th>&nbsp;</th>
-   <td>&nbsp;</td>-->
-  </tr>
- </table>
-
- <p>
-  コメント
-  <%= f.text_area :comment, :cols=>"50", :rows=>"5" %>
- </p>
-
- <p>
-  <%= f.hidden_field :product_style_id %>
-  <%= submit_tag '反映する' %>
- </p>
-
- <h3>未発送受注一覧</h3>
- <% if @active_orders %>
- <table cellspacing="1">
-  <tr>
-   <th>受注番号</th>
-   <th>ステータス</th>
-   <th>個数</th>
-  </tr>
-  <% @active_orders.each do |ao| %>
-  <tr>
-   <td>
-    <%= link_to ao.order_code, :controller=>'admin/order', :action=>:edit, :id=>ao.order_id %>
-   </td>
-   <td>
-    <%=h ao.status %>
-   </td>
-   <td>
-    <%= number_with_delimiter ao.count %>
-   </td>
-  </tr>
-  <% end %>
-  <tr>
-   <th colspan="2">合計</th>
-   <td><%= number_with_delimiter @active_orders_sum %></td>
-  </tr>
- </table>
- <% else %>
- <table cellspacing="1" width="100%"><tr><td>なし</td></tr></table>
- <% end %>
-
-<% end %>
-</div>
-</div>
diff --git a/app/views/admin/stock_csv/_submenu.html.erb b/app/views/admin/stock_csv/_submenu.html.erb
new file mode 100644 (file)
index 0000000..fa2ec27
--- /dev/null
@@ -0,0 +1 @@
+<%= render :partial => '/admin/base/depot_submenu' %>
diff --git a/app/views/admin/stock_csv/index.html.erb b/app/views/admin/stock_csv/index.html.erb
new file mode 100644 (file)
index 0000000..a35f02b
--- /dev/null
@@ -0,0 +1,30 @@
+<%= render :partial => "submenu" %>\r
+\r
+<div id="main"><!-- メイン -->\r
+\r
+<h2>棚卸用 CSV 出力</h2>\r
+<h3>棚卸データ出力</h3><br/>\r
+<% form_tag :action => 'new' do %>\r
+ <p>現在時刻時点での在庫情報を出力</p>\r
+  <div class="btn_box space20_bottom">\r
+    <%= submit_tag 'CSV DOWNLOAD', :class=>"btn" %>\r
+    <img class="btn_side" width="6" height="34" src="/images/btn_side.gif">\r
+  </div>\r
+<% end %><br/><br/><br/><br/><br/>\r
+\r
+<h3>再出力</h3><br/>\r
+<%unless @dates.blank?%>\r
+<table class="data" cellspacing="1">\r
+ <tr>\r
+  <th>対象年月</th>\r
+  <th>再出力</th>\r
+ </tr>\r
+<% @dates.zip(@urls).each do |date, url| %>\r
+ <tr>\r
+  <td><%= date.strftime('%Y/%m/%d %H:%M:%S') %></td>\r
+  <td><%= link_to 'CSV DOWNLOAD', url %></td>\r
+ </tr>\r
+<% end %>\r
+</table>\r
+<% end %>\r
+</div><!-- /メイン -->
\ No newline at end of file
diff --git a/app/views/admin/stock_histories/_search.html.erb b/app/views/admin/stock_histories/_search.html.erb
new file mode 100644 (file)
index 0000000..43828a7
--- /dev/null
@@ -0,0 +1,38 @@
+    <table class="data" cellspacing="1">
+      <tr>
+        <th>商品ID</th>
+        <td><%= f.text_field :product_id, :class=>"data_m"  %></td>
+      </tr>
+      <tr>
+        <th>商品コード</th>
+        <td><%= f.text_field :code, :class=>"data_m" %></td>
+      </tr>
+      <tr>
+        <th>商品名</th>
+        <td><%= f.text_field :name, :class=>"data_m" %></td>
+      </tr>
+      <tr>
+        <th>商品型番</th>
+        <td><%= f.text_field :manufacturer, :class=>"data_m" %></td>
+      </tr>
+         <tr>
+           <th>操作者</th>
+           <td><%operators = AdminUser.find(:all,:order=>'id')%>
+                 <%=f.select :operator,operators.map{|o| [o.name,o.id.to_s]}, :include_blank => true %>
+           </td>
+         </tr>  
+      <tr>
+        <th>在庫移動日</th>
+        <td>
+          <%= f.date_select :moved_at_from ,:use_month_numbers => true, :include_blank=>true %>~
+          <%= f.date_select :moved_at_to, :use_month_numbers => true, :include_blank=>true %>
+        </td>
+      </tr>
+      <tr>
+       <td class="submit" colspan="4">
+      検索結果表示件数
+        <%= select_tag "condition[per_page]", options_for_select((10..100).step(10).map(&:to_s)) %>
+        件
+        <%= submit_tag "この条件で検索する", :class=>"btn_s" %></td>
+      </tr>
+    </table>
diff --git a/app/views/admin/stock_histories/_submenu.html.erb b/app/views/admin/stock_histories/_submenu.html.erb
new file mode 100644 (file)
index 0000000..fa2ec27
--- /dev/null
@@ -0,0 +1 @@
+<%= render :partial => '/admin/base/depot_submenu' %>
diff --git a/app/views/admin/stock_histories/index.html.erb b/app/views/admin/stock_histories/index.html.erb
new file mode 100644 (file)
index 0000000..2890a93
--- /dev/null
@@ -0,0 +1,11 @@
+<%= render :partial => "submenu" %>\r
+\r
+<div id="main"><!-- メイン -->\r
+\r
+<h2>作業履歴</h2>\r
+<%= error_messages_for :condition %>\r
+\r
+<% form_for :condition, :url => {:action => 'search'}, :html => {:method => :get} do |f| %>\r
+  <%= render :partial => "search", :locals=>{:f => f}%>\r
+<% end %>\r
+</div><!-- /メイン -->\r
diff --git a/app/views/admin/stock_histories/search.html.erb b/app/views/admin/stock_histories/search.html.erb
new file mode 100644 (file)
index 0000000..143823d
--- /dev/null
@@ -0,0 +1,41 @@
+<%= render :partial => "submenu" %>\r
+\r
+<div id="main"><!-- メイン -->\r
+\r
+<h2>操作履歴</h2>\r
+<%= error_messages_for :condition %>\r
+<% form_for :condition, :url => {:action => 'search'}, :html => {:method => :get} do |f| %>\r
+  <%= render :partial => "search", :locals=>{:f => f}%>\r
+<% end %>\r
+<br />\r
+\r
+<p>&gt;&gt;検索結果一覧&nbsp;<%=@stock_histories.total_entries %>件&nbsp;が該当しました。</p><br/>\r
+  <table class="data2 clear" cellspacing="1">\r
+    <tr>\r
+      <th>商品ID</th>\r
+      <th>商品コード</th>\r
+      <th>商品名</th>\r
+      <th>規格名称</th>\r
+      <th>商品型番</th>\r
+      <th>操作者</th>\r
+      <th>詳細</th>\r
+    </tr>\r
+<%unless @stock_histories.blank?%>     \r
+    <% @stock_histories.each do | sh | %>\r
+      <tr>\r
+        <td><%= h sh.product_style.product_id %></td>\r
+        <td><%= h sh.product_style.code %></td>\r
+        <td><%= h sh.product_style.product_name %></td>\r
+        <td><%= h sh.product_style.style_name %></td>\r
+        <td><%= h sh.product_style.manufacturer_id %></td>\r
+        <td><%= h sh.admin_user.name %></td>\r
+        <td class="t_center">\r
+           <%= link_to "作業詳細", :action=>"show" ,:id=>sh.id %>\r
+        </td>\r
+      </tr>\r
+    <% end %>\r
+<%end%>\r
+</table>\r
+<%= will_paginate @stock_histories %>\r
+\r
+</div><!-- /メイン -->\r
diff --git a/app/views/admin/stock_histories/show.html.erb b/app/views/admin/stock_histories/show.html.erb
new file mode 100644 (file)
index 0000000..b721c7f
--- /dev/null
@@ -0,0 +1,148 @@
+<%= render :partial => "submenu" %>
+
+<div id="main"><!-- メイン -->
+
+<h2>作業履歴詳細</h2>
+<h3>商品情報</h3>
+<table class="data" cellspacing="1">
+  <tr>
+    <th>商品ID</th>
+    <td>
+      <%= h(@stock_history.product_id) %>
+    </td>
+  </tr>
+  <tr>
+    <th>商品名</th>
+    <td>
+      <%= h(@stock_history.product.name) %>
+    </td>
+  </tr>
+  <%if @system.supplier_use_flag%>
+  <tr>
+    <th>仕入先名</th>
+    <td><%= h(@stock_history.product.supplier_name) %></td>
+  </tr>  
+ <% end %>
+  <tr>
+    <th>カテゴリー名</th>
+    <td>
+      <%= h(@stock_history.product.category_name) %>
+    </td>
+  </tr>
+  <tr>
+    <th>商品コード</th>
+    <td>
+      <%= h(@stock_history.product_style.code) %>
+    </td>
+  </tr>
+  <tr>
+    <th>規格名称</th>
+    <td>
+      <%= h(@stock_history.product_style.style_name) %>
+    </td>
+  </tr>
+  <tr>
+    <th>商品型番</th>
+    <td>
+      <%= h(@stock_history.product_style.manufacturer_id) %>
+    </td>
+  </tr>  
+  <tr>
+    <th>価格</th>
+    <td>
+      <%= number_with_delimiter(@stock_history.product_style.sell_price) %>
+    </td>
+  </tr>
+  <tr>
+    <th>現在実在庫数</th>
+    <td>
+      <%= number_with_delimiter(@stock_history.product_style.actual_count.to_i) %>
+    </td>
+  </tr>
+  <tr>
+    <th>現在受注可能数</th>
+    <td>
+      <%= number_with_delimiter(@stock_history.product_style.orderable_count.to_i) %>
+    </td>
+  </tr>
+  <tr>
+    <th>現在不良在庫数</th>
+    <td>
+      <%= number_with_delimiter(@stock_history.product_style.broken_count.to_i) %>
+    </td>
+  </tr>
+</table>
+<h3>作業内容</h3>
+<table class="data" cellspacing="1">
+  <tr>
+    <th>操作者</th>
+    <td>
+      <%= @stock_history.admin_user.name %>
+    </td>
+  </tr>
+  <tr>
+    <th>移動日</th>
+    <td>
+      <%= date_time(@stock_history.moved_at) %>
+    </td>
+  </tr>
+  <tr>
+    <th>作業区分</th>
+    <td>
+      <%= h(StockHistory::STOCK_TYPE_NAMES[@stock_history.stock_type]) %>
+    </td>
+  </tr>
+  <% if @stock_history.stock_type == StockHistory::STOCK_IN%>
+  <tr>
+    <th>入庫数</th>
+    <td><%= number_with_delimiter(@stock_history.storaged_count) %></td>
+  </tr>
+  <tr>
+    <th>当時実在庫数</th>
+    <td><%= number_with_delimiter(@stock_history.actual_count.to_i) %></td>
+  </tr>  
+  <tr>
+    <th>当時販売可能数</th>
+    <td><%= number_with_delimiter(@stock_history.orderable_count) %></td>
+  </tr>
+  <tr>
+    <th>当時不良在庫数</th>
+    <td><%= number_with_delimiter(@stock_history.broken_count.to_i) %></td>
+  </tr>
+  <% else%>
+  <tr>
+    <th>実在庫調整数</th>
+    <td><%= number_with_delimiter(@stock_history.actual_adjustment) %></td>
+  </tr>
+  <tr>
+    <th>当時実在庫数</th>
+    <td><%= number_with_delimiter(@stock_history.actual_count.to_i) %></td>
+  </tr> 
+  <tr>
+    <th>販売可能調整数</th>
+    <td>
+      <%= number_with_delimiter(@stock_history.orderable_adjustment) %>
+    </td>
+  </tr>
+  <tr>
+    <th>当時販売可能数</th>
+    <td><%= number_with_delimiter(@stock_history.orderable_count.to_i) %></td>
+  </tr> 
+  <tr>
+    <th>不良在庫調整数</th>
+    <td><%= number_with_delimiter(@stock_history.broken_adjustment) %></td>
+  </tr>
+  <tr>
+    <th>当時不良在庫数</th>
+    <td><%= number_with_delimiter(@stock_history.broken_count.to_i) %></td>
+  </tr>
+  <% end%>  
+  <tr>
+    <th>備考</th>
+    <td>
+      <%= h(@stock_history.comment) %>
+    </td>
+  </tr>
+</table>
+</div><!-- /メイン -->
+\r
diff --git a/app/views/admin/stock_in/_form.html.erb b/app/views/admin/stock_in/_form.html.erb
new file mode 100644 (file)
index 0000000..320c54f
--- /dev/null
@@ -0,0 +1,15 @@
+<h3>入庫情報</h3>
+<table class="data" cellspacing="1">  
+  <tr>
+    <th>実入庫数<span class="pnt">※</span></th>
+    <td>
+      <%= f.text_field :storaged_count, {:class=>"data_s",:style=>"ime-mode:inactive"} %>
+    </td>
+  </tr>
+  <tr>
+    <th>備考<span class="pnt">※</span></th>
+    <td>
+      <%= f.text_area :comment,{:size=>"60x10",:style=>"ime-mode:active" }%>
+    </td>
+  </tr>
+</table>
\ No newline at end of file
diff --git a/app/views/admin/stock_in/_info.html.erb b/app/views/admin/stock_in/_info.html.erb
new file mode 100644 (file)
index 0000000..0b3dc02
--- /dev/null
@@ -0,0 +1,70 @@
+<!--商品情報-->
+<h3>商品情報</h3>
+<table class="data" cellspacing="1">
+  <tr>
+    <th>商品ID</th>
+    <td>
+      <%= h(@product_style.product_id) %>
+    </td>
+  </tr>
+  <tr>
+    <th>商品名</th>
+    <td>
+      <%= h(@product_style.product_name) %>
+    </td>
+  </tr>
+  <%if @system.supplier_use_flag%>
+  <tr>
+    <th>仕入先名</th>
+    <td><%= h(@product_style.product.supplier_name) %></td>
+  </tr>  
+ <% end %>
+  <tr>
+    <th>カテゴリー名</th>
+    <td>
+      <%= h(@product_style.product.category_name) %>
+    </td>
+  </tr>
+  <tr>
+    <th>商品コード</th>
+    <td>
+      <%= h(@product_style.code) %>
+    </td>
+  </tr>
+  <tr>
+    <th>規格名称</th>
+    <td>
+      <%= h(@product_style.style_name) %>
+    </td>
+  </tr>
+  <tr>
+    <th>商品型番</th>
+    <td>
+      <%= h(@product_style.manufacturer_id) %>
+    </td>
+  </tr>  
+  <tr>
+    <th>価格</th>
+    <td>
+      <%= number_with_delimiter(@product_style.sell_price) %>
+    </td>
+  </tr>
+  <tr>
+    <th>現在実在庫数</th>
+    <td>
+      <%= number_with_delimiter(@product_style.actual_count.to_i) %>
+    </td>
+  </tr>
+  <tr>
+    <th>現在受注可能数</th>
+    <td>
+      <%= number_with_delimiter(@product_style.orderable_count.to_i) %>
+    </td>
+  </tr>
+  <tr>
+    <th>現在不良在庫数</th>
+    <td>
+      <%= number_with_delimiter(@product_style.broken_count.to_i) %>
+    </td>
+  </tr>
+</table>
diff --git a/app/views/admin/stock_in/_search.html.erb b/app/views/admin/stock_in/_search.html.erb
new file mode 100644 (file)
index 0000000..ed3d6c1
--- /dev/null
@@ -0,0 +1,44 @@
+    <table class="data" cellspacing="1">
+      <tr>
+        <th>商品ID</th>
+        <td><%= f.text_field :product_id, :class=>"data_m"  %></td>
+      </tr>
+      <tr>
+        <th>商品コード</th>
+        <td><%= f.text_field :code, :class=>"data_m" %></td>
+      </tr>
+      <tr>
+        <th>商品名</th>
+        <td><%= f.text_field :name, :class=>"data_m" %></td>
+      </tr>
+      <tr>
+        <th>商品型番</th>
+        <td><%= f.text_field :manufacturer, :class=>"data_m" %></td>
+      </tr>
+        <%if @system.supplier_use_flag%>
+         <tr>
+           <th>仕入先名</th>
+           <td><%suppliers = Supplier.find(:all,:order=>'id')%>
+                 <%=f.select :supplier,suppliers.map{|s| [s.name,s.id.to_s]}, :include_blank => true %>
+           </td>
+         </tr>  
+        <% end %>        
+      <tr>
+        <th>カテゴリ</th>
+        <td><%= category_select :condition, :category, :include_blank => true %></td>
+      </tr>
+      <tr>
+        <th>登録日・更新日</th>
+        <td>
+          <%= f.date_select :updated_at_from ,:use_month_numbers => true, :include_blank=>true %>~
+          <%= f.date_select :updated_at_to, :use_month_numbers => true, :include_blank=>true %>
+        </td>
+      </tr>
+      <tr>
+       <td class="submit" colspan="4">
+      検索結果表示件数
+        <%= select_tag "condition[per_page]", options_for_select((10..100).step(10).map(&:to_s)) %>
+        件
+        <%= submit_tag "この条件で検索する", :class=>"btn_s" %></td>
+      </tr>
+    </table>
diff --git a/app/views/admin/stock_in/_submenu.html.erb b/app/views/admin/stock_in/_submenu.html.erb
new file mode 100644 (file)
index 0000000..fa2ec27
--- /dev/null
@@ -0,0 +1 @@
+<%= render :partial => '/admin/base/depot_submenu' %>
diff --git a/app/views/admin/stock_in/edit.html.erb b/app/views/admin/stock_in/edit.html.erb
new file mode 100644 (file)
index 0000000..6db0b83
--- /dev/null
@@ -0,0 +1,18 @@
+<%= render :partial => "submenu" %>\r
+\r
+<div id="main"><!-- メイン -->\r
+\r
+<h2>入庫登録/編集</h2>\r
+<p class="req"><span class="pnt">※</span>は必須入力です</p>\r
+<span class="pnt"><%= flash[:error] %></span>\r
+<%= error_messages_for :stock_history %>\r
+<% form_for :stock_history, :url => {:action => 'update', :id=> @product_style } do |f| %>\r
+  <%= render :partial => "info"%>\r
+  <%= render :partial => "form", :locals => {:f => f} %>\r
+  <div class="btn_box">\r
+    <%= submit_tag "この内容で登録する", :onclick => "return #{confirm_javascript_function("登録しても宜しいですか")}", :class=>"btn" %>\r
+    <img class="btn_side" width="6" height="34" src="/images/btn_side.gif">\r
+  </div>\r
+<% end %>\r
+\r
+</div><!-- /メイン -->
diff --git a/app/views/admin/stock_in/index.html.erb b/app/views/admin/stock_in/index.html.erb
new file mode 100644 (file)
index 0000000..b9829c7
--- /dev/null
@@ -0,0 +1,13 @@
+<%= render :partial => "submenu" %>
+
+<div id="main"><!-- メイン -->
+
+<h2>入庫管理</h2>
+<%=h flash[:stock_update] %>
+<%=h flash[:stock_update_e] %>
+<%= error_messages_for :condition %>
+
+<% form_for :condition, :url => {:action => 'search'}, :html => {:method => :get} do |f| %>
+  <%= render :partial => "search", :locals=>{:f => f}%>
+<% end %>
+</div><!-- /メイン -->
diff --git a/app/views/admin/stock_in/search.html.erb b/app/views/admin/stock_in/search.html.erb
new file mode 100644 (file)
index 0000000..d862b2e
--- /dev/null
@@ -0,0 +1,42 @@
+<%= render :partial => "submenu" %>\r
+\r
+<div id="main"><!-- メイン -->\r
+\r
+<h2>入庫管理</h2>\r
+<%=h flash[:notice] %>\r
+<%=h flash[:error] %>\r
+<%= error_messages_for :condition %>\r
+<% form_for :condition, :url => {:action => 'search'}, :html => {:method => :get} do |f| %>\r
+  <%= render :partial => "search", :locals=>{:f => f}%>\r
+<% end %>\r
+<br />\r
+\r
+<p>&gt;&gt;検索結果一覧&nbsp;<%=@product_styles.total_entries %>件&nbsp;が該当しました。</p><br/>\r
+  <table class="data2 clear" cellspacing="1">\r
+    <tr>\r
+      <th>商品ID</th>\r
+      <th>商品コード</th>\r
+      <th>商品名</th>\r
+      <th>規格名称</th>\r
+      <th>商品型番</th>\r
+      <th>実在庫数</th>\r
+      <th>入庫登録<br/>/編集</th>\r
+    </tr>\r
+<%unless @product_styles.blank?%>      \r
+    <% @product_styles.each do | ps | %>\r
+      <tr>\r
+        <td><%= h ps.product_id %></td>\r
+        <td><%= h ps.code %></td>\r
+        <td><%= h ps.product_name %></td>\r
+        <td><%= h ps.style_name %></td>\r
+        <td><%= h ps.manufacturer_id %></td>\r
+        <td><%= number_with_delimiter(ps.actual_count.to_i) %></td>\r
+        <td class="t_center">\r
+           <%= link_to "登録/編集", :action=>"edit" ,:id=>ps.id %>\r
+        </td>\r
+      </tr>\r
+    <% end %>\r
+</table>\r
+<%end%>\r
+<%= will_paginate @product_styles %>\r
+</div><!-- /メイン -->\r
diff --git a/app/views/admin/stock_modify/_form.html.erb b/app/views/admin/stock_modify/_form.html.erb
new file mode 100644 (file)
index 0000000..341fbc5
--- /dev/null
@@ -0,0 +1,27 @@
+<h3>在庫調整</h3>
+<table class="data" cellspacing="1">  
+  <tr>
+    <th>実在庫数</th>
+    <td><%= number_with_delimiter(@product_style.actual_count.to_i) %></td>
+    <th>実在庫調整数</th>
+    <td><%= f.text_field :actual_adjustment, {:class=>"data_s",:style=>"ime-mode:inactive"} %></td>    
+  </tr>
+  <tr>
+    <th>販売可能数</th>
+    <td><%= number_with_delimiter(@product_style.orderable_count.to_i) %></td>
+    <th>販売可能調整数</th>
+    <td><%= f.text_field :orderable_adjustment, {:class=>"data_s",:style=>"ime-mode:inactive"} %></td> 
+  </tr>
+  <tr>
+    <th>不良在庫数</th>
+    <td><%= number_with_delimiter(@product_style.broken_count.to_i) %></td>
+    <th>不良在庫調整数</th>
+    <td><%= f.text_field :broken_adjustment, {:class=>"data_s",:style=>"ime-mode:inactive"} %></td>    
+  </tr>    
+  <tr>
+    <th>備考<span class="pnt">※</span></th>
+    <td colspan="3">
+      <%= f.text_area :comment,{:size=>"60x10",:style=>"ime-mode:active" }%>
+    </td>
+  </tr>
+</table>
\ No newline at end of file
diff --git a/app/views/admin/stock_modify/_info.html.erb b/app/views/admin/stock_modify/_info.html.erb
new file mode 100644 (file)
index 0000000..0b3dc02
--- /dev/null
@@ -0,0 +1,70 @@
+<!--商品情報-->
+<h3>商品情報</h3>
+<table class="data" cellspacing="1">
+  <tr>
+    <th>商品ID</th>
+    <td>
+      <%= h(@product_style.product_id) %>
+    </td>
+  </tr>
+  <tr>
+    <th>商品名</th>
+    <td>
+      <%= h(@product_style.product_name) %>
+    </td>
+  </tr>
+  <%if @system.supplier_use_flag%>
+  <tr>
+    <th>仕入先名</th>
+    <td><%= h(@product_style.product.supplier_name) %></td>
+  </tr>  
+ <% end %>
+  <tr>
+    <th>カテゴリー名</th>
+    <td>
+      <%= h(@product_style.product.category_name) %>
+    </td>
+  </tr>
+  <tr>
+    <th>商品コード</th>
+    <td>
+      <%= h(@product_style.code) %>
+    </td>
+  </tr>
+  <tr>
+    <th>規格名称</th>
+    <td>
+      <%= h(@product_style.style_name) %>
+    </td>
+  </tr>
+  <tr>
+    <th>商品型番</th>
+    <td>
+      <%= h(@product_style.manufacturer_id) %>
+    </td>
+  </tr>  
+  <tr>
+    <th>価格</th>
+    <td>
+      <%= number_with_delimiter(@product_style.sell_price) %>
+    </td>
+  </tr>
+  <tr>
+    <th>現在実在庫数</th>
+    <td>
+      <%= number_with_delimiter(@product_style.actual_count.to_i) %>
+    </td>
+  </tr>
+  <tr>
+    <th>現在受注可能数</th>
+    <td>
+      <%= number_with_delimiter(@product_style.orderable_count.to_i) %>
+    </td>
+  </tr>
+  <tr>
+    <th>現在不良在庫数</th>
+    <td>
+      <%= number_with_delimiter(@product_style.broken_count.to_i) %>
+    </td>
+  </tr>
+</table>
diff --git a/app/views/admin/stock_modify/_search.html.erb b/app/views/admin/stock_modify/_search.html.erb
new file mode 100644 (file)
index 0000000..ed3d6c1
--- /dev/null
@@ -0,0 +1,44 @@
+    <table class="data" cellspacing="1">
+      <tr>
+        <th>商品ID</th>
+        <td><%= f.text_field :product_id, :class=>"data_m"  %></td>
+      </tr>
+      <tr>
+        <th>商品コード</th>
+        <td><%= f.text_field :code, :class=>"data_m" %></td>
+      </tr>
+      <tr>
+        <th>商品名</th>
+        <td><%= f.text_field :name, :class=>"data_m" %></td>
+      </tr>
+      <tr>
+        <th>商品型番</th>
+        <td><%= f.text_field :manufacturer, :class=>"data_m" %></td>
+      </tr>
+        <%if @system.supplier_use_flag%>
+         <tr>
+           <th>仕入先名</th>
+           <td><%suppliers = Supplier.find(:all,:order=>'id')%>
+                 <%=f.select :supplier,suppliers.map{|s| [s.name,s.id.to_s]}, :include_blank => true %>
+           </td>
+         </tr>  
+        <% end %>        
+      <tr>
+        <th>カテゴリ</th>
+        <td><%= category_select :condition, :category, :include_blank => true %></td>
+      </tr>
+      <tr>
+        <th>登録日・更新日</th>
+        <td>
+          <%= f.date_select :updated_at_from ,:use_month_numbers => true, :include_blank=>true %>~
+          <%= f.date_select :updated_at_to, :use_month_numbers => true, :include_blank=>true %>
+        </td>
+      </tr>
+      <tr>
+       <td class="submit" colspan="4">
+      検索結果表示件数
+        <%= select_tag "condition[per_page]", options_for_select((10..100).step(10).map(&:to_s)) %>
+        件
+        <%= submit_tag "この条件で検索する", :class=>"btn_s" %></td>
+      </tr>
+    </table>
diff --git a/app/views/admin/stock_modify/_submenu.html.erb b/app/views/admin/stock_modify/_submenu.html.erb
new file mode 100644 (file)
index 0000000..fa2ec27
--- /dev/null
@@ -0,0 +1 @@
+<%= render :partial => '/admin/base/depot_submenu' %>
diff --git a/app/views/admin/stock_modify/edit.html.erb b/app/views/admin/stock_modify/edit.html.erb
new file mode 100644 (file)
index 0000000..588eefd
--- /dev/null
@@ -0,0 +1,18 @@
+<%= render :partial => "submenu" %>\r
+\r
+<div id="main"><!-- メイン -->\r
+\r
+<h2>在庫調整</h2>\r
+<p class="req"><span class="pnt">※</span>は必須入力です</p>\r
+<span class="pnt"><%= flash[:error] %></span>\r
+<%= error_messages_for :stock_history %>\r
+<% form_for :stock_history, :url => {:action => 'update', :id=> @product_style } do |f| %>\r
+  <%= render :partial => "info"%>\r
+  <%= render :partial => "form", :locals => {:f => f} %>\r
+  <div class="btn_box">\r
+    <%= submit_tag "この内容で登録する", :onclick => "return #{confirm_javascript_function("登録しても宜しいですか")}", :class=>"btn" %>\r
+    <img class="btn_side" width="6" height="34" src="/images/btn_side.gif">\r
+  </div>\r
+<% end %>\r
+\r
+</div><!-- /メイン -->
diff --git a/app/views/admin/stock_modify/index.html.erb b/app/views/admin/stock_modify/index.html.erb
new file mode 100644 (file)
index 0000000..74182d0
--- /dev/null
@@ -0,0 +1,13 @@
+<%= render :partial => "submenu" %>
+
+<div id="main"><!-- メイン -->
+
+<h2>在庫管理</h2>
+<%=h flash[:stock_update] %>
+<%=h flash[:stock_update_e] %>
+<%= error_messages_for :condition %>
+
+<% form_for :condition, :url => {:action => 'search'}, :html => {:method => :get} do |f| %>
+  <%= render :partial => "search", :locals=>{:f => f}%>
+<% end %>
+</div><!-- /メイン -->
diff --git a/app/views/admin/stock_modify/search.html.erb b/app/views/admin/stock_modify/search.html.erb
new file mode 100644 (file)
index 0000000..d2518ca
--- /dev/null
@@ -0,0 +1,43 @@
+<%= render :partial => "submenu" %>\r
+\r
+<div id="main"><!-- メイン -->\r
+\r
+<h2>在庫管理</h2>\r
+<%=h flash[:notice] %>\r
+<%=h flash[:error] %>\r
+<%= error_messages_for :condition %>\r
+<% form_for :condition, :url => {:action => 'search'}, :html => {:method => :get} do |f| %>\r
+  <%= render :partial => "search", :locals=>{:f => f}%>\r
+<% end %>\r
+<br />\r
+\r
+<p>&gt;&gt;検索結果一覧&nbsp;<%=@product_styles.total_entries %>件&nbsp;が該当しました。</p><br/>\r
+  <table class="data2 clear" cellspacing="1">\r
+    <tr>\r
+      <th>商品ID</th>\r
+      <th>商品コード</th>\r
+      <th>商品名</th>\r
+      <th>規格名称</th>\r
+      <th>商品型番</th>\r
+      <th>実在庫数</th>\r
+      <th>在庫調整</th>\r
+    </tr>\r
+<%unless @product_styles.blank?%>      \r
+    <% @product_styles.each do | ps | %>\r
+      <tr>\r
+        <td><%= h ps.product_id %></td>\r
+        <td><%= h ps.code %></td>\r
+        <td><%= h ps.product_name %></td>\r
+        <td><%= h ps.style_name %></td>\r
+        <td><%= h ps.manufacturer_id %></td>\r
+        <td><%= number_with_delimiter(ps.actual_count.to_i) %></td>\r
+        <td class="t_center">\r
+           <%= link_to "在庫調整", :action=>"edit" ,:id=>ps.id %>\r
+        </td>\r
+      </tr>\r
+    <% end %>\r
+<%end%>\r
+</table>\r
+<%= will_paginate @product_styles %>\r
+\r
+</div><!-- /メイン -->\r
index 016fa33..c6ebb78 100644 (file)
@@ -31,7 +31,7 @@
                         <dd>価格:<%=h @product.price_label %>円</dd>
                         <dd>販売期間:<%=h print_date(@product.sale_start_at) %> ~ <%=h print_date(@product.sale_end_at) %></dd>
                         <% if @product.arrival_expected_date && @product.arrival_expected_date < Date.today %>
-                            <% if @product.product_styles && @product.product_styles.detect(nil){ |p_s| !p_s.actual_count.blank? && p_s.actual_count > 0} -%>
+                            <% if @product.product_styles && @product.product_styles.detect(nil){ |p_s| p_s.orderable_count.to_i > 0} -%>
                         <dd>お届け:<%= @product.delivery_dates_label %></dd>
                             <% else %>
                         <dd>入荷未定</dd>
                         <dd>入荷予定日:<%= @product.arrival_date.blank? ? date_jp(@product.arrival_expected_date) : @product.arrival_date %></dd>
                         <% end %>
                     </dl>
+                               <% if @campaign.product.have_zaiko? %>
                     <%= render :partial  => "base/add_cart", :locals => {:product => @campaign.product, :campaign_id => @campaign.id} %>
+                                       <%else%>
+                                       品切れ中<br/>
+                                       <%end%>
                     <% if @campaign.repeat_application %>
                         <div id="campaign_caption">
                             当キャンペーンはお一人様につき1回のみご応募いただくことが出来ます。
index b0b4868..25b4a97 100644 (file)
 
   <p><%= h_br @product.medium_resource_comment unless @product.medium_resource_comment.blank? %><br />
   </p>
+       <% if @campaign.product.have_zaiko? %>
     <p style="text-align:center;">
       <%= render :partial  => "base/add_cart_mobile", :locals => {:product => @campaign.product, :campaign_id => @campaign.id} %>
     </p>
+       <%else%>
+       <p>品切れ中<br/></p>        
+       <%end%>
     <p>
     <% if @campaign.repeat_application %>
 当キャンペーンはお一人様につき1回のみご応募いただくことが出来ます。<br/>
@@ -68,6 +72,3 @@
 <% end %>
 
 <hr />
-<%= link_to_mobile 'カゴを見る', {:controller => 'cart', :action => 'show'}, :accesskey => "9" %><br />
-<%= link_to_mobile 'TOPページへ', {:controller=>'/'}, :accesskey => "0" %><br />
-
index 85d6c07..48556f8 100644 (file)
@@ -24,7 +24,7 @@
     <% if @system.supplier_use_flag %>
         <li><a href="/admin/suppliers" id="depot"><img src="/images/order_btn.gif" width="122" height="51" alt="発注出荷管理" class="hoverImg" /></a></li>
        <%else%>
-               <li><a href="#" id="depot"><img src="/images/order_btn.gif" width="122" height="51" alt="発注出荷管理" class="hoverImg" /></a></li>
+               <li><a href="/admin/stock_in" id="depot"><img src="/images/order_btn.gif" width="122" height="51" alt="発注出荷管理" class="hoverImg" /></a></li>
        <%end%> 
         <li><a href="/"><img src="/images/site_btn.gif" width="122" height="51" alt="サイトを表示" class="hoverImg" /></a></li>
       </ul>
index bd74067..fbebb84 100644 (file)
@@ -29,7 +29,7 @@
       <dt><%=@product.url.blank? ? h( @product.name ) : link_to(@product.name, @product.url) %></dt>
       <dd>価格:<%=h @product.price_label %>円</dd>
       <dd>販売期間:<%=h print_date(@product.sale_start_at) %> ~ <%=h print_date(@product.sale_end_at) %></dd>
-            <% if @product.product_styles && @product.product_styles.detect(nil){ |p_s| !p_s.actual_count.blank? && p_s.actual_count > 0} -%>
+            <% if @product.product_styles && @product.product_styles.detect(nil){ |p_s| p_s.orderable_count.to_i > 0} -%>
               <%- unless @product.delivery_dates_label.blank? %>
               <dd>お届け:<%= @product.delivery_dates_label %></dd>
               <%- end %>
index 090e20e..fc87731 100644 (file)
@@ -4,7 +4,7 @@
 <div style="text-align:center;"><%= product_image_tag(@product, :medium, {:width=>"220",:height=>"220",:style=>"margin:2px; border:1px solid #6666666;"}) %></div>
 <%= h_br @product.medium_resource_comment unless @product.medium_resource_comment.blank? %><br />
 
-<% if @product.product_styles && @product.product_styles.detect(nil){ |p_s| !p_s.actual_count.blank? && p_s.actual_count > 0} -%>
+<% if @product.product_styles && @product.product_styles.detect(nil){ |p_s| p_s.orderable_count.to_i > 0} -%>
   お届け:<%= @product.delivery_dates_label %>
 <% else %>
   <% if @product.arrival_expected_date && @product.arrival_expected_date < Date.today %>
index 3687732..952edaf 100755 (executable)
@@ -15,7 +15,7 @@
   <td><%=h ps.style_category_name2 %></td>\r
   <%- end -%>\r
   <td><%= number_with_delimiter ps.sell_price.to_i %></td>\r
-  <td><%=h stock_mark(ps.actual_count) %></td>\r
+  <td><%=h stock_mark(ps.orderable_count.to_i) %></td>\r
  </tr>\r
 <%- end -%>\r
 </table>  \r
index f4f1cb0..6af39e2 100644 (file)
@@ -69,7 +69,7 @@ ja:
       session: "セッション"
       shop: "ショップ"
       status: "地位"
-      stock_history: "株式の歴史"
+      stock history: "入庫/在庫情報"
       stock_table: "在庫表"
       stock_table_entry: "在庫テーブルのエントリ"
       style: "規格"
@@ -743,6 +743,15 @@ ja:
         created_at: "で作成された"
         updated_at: "で更新"
         deleted_at: "で削除"
+      stock_history:
+        storaged_count: "入庫数"
+        orderable_count: "販売可能数"
+        orderable_adjustment: "販売可能調整数"
+        actual_count: "実在庫数"
+        actual_adjustment: "実在庫調整数"
+        broken_count: "不良在庫数"
+        broken_adjustment: "不良在庫調整数"
+        comment: "備考"      
       stock_table:
         target_date: "データ出力日"
         created_at: "で作成された"
diff --git a/db/migrate/20100118000000_add_data_functions_ver3.rb b/db/migrate/20100118000000_add_data_functions_ver3.rb
new file mode 100644 (file)
index 0000000..3d5f072
--- /dev/null
@@ -0,0 +1,19 @@
+class AddDataFunctionsVer3 < ActiveRecord::Migration
+  def self.up
+    Function.delete_all
+    Authority.delete_all
+    execute("delete from authorities_functions")
+
+    
+    directory = File.join(File.dirname(__FILE__), "fixed_data")
+    Fixtures.create_fixtures(directory, "authorities")
+    Fixtures.create_fixtures(directory, "functions")
+    Fixtures.create_fixtures(directory, "authorities_functions")
+  end
+
+  def self.down
+    Function.delete_all
+    execute("delete from authorities_functions")
+    Authority.delete_all
+  end
+end
diff --git a/db/migrate/20100118000001_update_data_product_styles_orderable_count.rb b/db/migrate/20100118000001_update_data_product_styles_orderable_count.rb
new file mode 100644 (file)
index 0000000..7dd10a7
--- /dev/null
@@ -0,0 +1,9 @@
+class UpdateDataProductStylesOrderableCount  < ActiveRecord::Migration      
+  def self.up
+    ProductStyle.update_all("orderable_count = actual_count")
+  end
+
+  def self.down
+    ProductStyle.update_all("orderable_count = null")
+  end
+end
diff --git a/db/migrate/20100118065008_create_stock_histories.rb b/db/migrate/20100118065008_create_stock_histories.rb
new file mode 100644 (file)
index 0000000..b1c1eb1
--- /dev/null
@@ -0,0 +1,30 @@
+class CreateStockHistories < ActiveRecord::Migration
+  def self.up
+    create_table :stock_histories do |t|
+      t.column :admin_user_id ,:integer,:comment =>'登録更新者ID'
+      t.column :product_id , :integer,:comment =>'商品ID'
+      t.column :product_style_id , :integer,:comment =>'商品規格ID'
+      t.column :moved_at ,:datetime, :comment =>'移動日時'
+      t.column :storaged_count ,:integer,:comment =>'入庫数'
+      t.column :orderable_count ,:integer,:comment =>'受注可能数'
+      t.column :orderable_adjustment ,:integer,:comment =>'受注可能数調整数'
+      t.column :actual_count ,:integer,:comment =>'実在庫数'
+      t.column :actual_adjustment ,:integer,:comment =>'実在庫調整数'
+      t.column :broken_count ,:integer,:comment =>'不良在庫数'
+      t.column :broken_adjustment ,:integer,:comment =>'不良在庫調整数'
+      t.column :comment ,:text,:comment =>'移動理由コメント'  
+      t.column :stock_type ,:integer,:comment =>'作業区分(0:入庫、1:移動)'
+      t.column :deleted_at ,:datetime, :comment =>'削除日'
+    end
+    add_index :stock_histories, :deleted_at
+    add_index :stock_histories, :product_id
+    add_index :stock_histories, :product_style_id  
+  end
+
+  def self.down
+    remove_index :stock_histories, :deleted_at
+    remove_index :stock_histories, :product_id
+    remove_index :stock_histories, :product_style_id     
+    drop_table :stock_histories
+  end
+end
index 7cb1b15..05903fb 100644 (file)
@@ -201,4 +201,9 @@ F901:
   id: 41\r
   name: 仕入先マスタ\r
   code: "supplier"\r
-  position: 901
\ No newline at end of file
+  position: 901\r
+F902:\r
+  id: 42\r
+  name: 在庫管理\r
+  code: "stock"\r
+  position: 902  
\ No newline at end of file
diff --git a/spec/controllers/admin/stock_base_controller_spec.rb b/spec/controllers/admin/stock_base_controller_spec.rb
new file mode 100644 (file)
index 0000000..9432e64
--- /dev/null
@@ -0,0 +1,75 @@
+require 'spec_helper'
+
+describe Admin::StockBaseController do
+  fixtures :admin_users,:products,:product_styles,:suppliers
+  before do 
+    session[:admin_user] = admin_users(:admin10)
+    @controller.class.skip_before_filter @controller.class.before_filter
+    @controller.class.skip_after_filter @controller.class.after_filter    
+  end
+  describe "GET 'search'" do
+   
+    it "should be successful" do
+      get 'search'
+      response.should be_success
+    end
+    
+    it "商品ID" do
+      get 'search', :condition => {:product_id => '16'}
+      response.should be_success
+      # 結果の中に含まれているか見る
+      assigns[:product_styles].size.should == 1
+      assigns[:product_styles][0].attributes.should == product_styles(:valid_product).attributes     
+    end
+    
+    it "商品コード" do
+      get 'search', :condition => {:code => '001'}
+      response.should be_success
+      # 結果の中に含まれているか見る
+      assigns[:product_styles].size.should == 2
+      assigns[:product_styles][0].attributes.should == product_styles(:valid_product).attributes
+      assigns[:product_styles][1].attributes.should == product_styles(:campaign_product).attributes       
+    end
+    
+    it "商品名" do
+      get 'search', :condition => {:name => "スカート"}
+      response.should be_success
+      # 結果の中に含まれているか見る
+      assigns[:product_styles].size.should == 5
+      assigns[:product_styles][0].attributes.should == product_styles(:campaign_product).attributes
+      assigns[:product_styles][1].attributes.should == product_styles(:sell_stop_product).attributes
+      assigns[:product_styles][2].attributes.should == product_styles(:multi_styles_product_1).attributes
+      assigns[:product_styles][3].attributes.should == product_styles(:multi_styles_product_2).attributes
+      assigns[:product_styles][4].attributes.should == product_styles(:multi_styles_product_3).attributes
+    end
+    
+    it "商品型番" do
+      get 'search', :condition => {:manufacturer => "001"}
+      response.should be_success
+      # 結果の中に含まれているか見る
+      assigns[:product_styles].size.should == 0
+    end
+
+    it "仕入先名" do
+      get 'search', :condition => {:supplier => "2"}
+      response.should be_success
+      # 結果の中に含まれているか見る
+      assigns[:product_styles].size.should == 1
+      assigns[:product_styles][0].attributes.should == product_styles(:valid_product).attributes      
+    end
+    it "カテゴリ" do
+      get 'search', :condition => {:category => "16"}
+      response.should be_success
+      # 結果の中に含まれているか見る
+      assigns[:product_styles].size.should == 1
+      assigns[:product_styles][0].attributes.should == product_styles(:valid_product).attributes      
+    end 
+    it "登録日・更新日" do
+      get 'search', :condition => {:updated_at_from => "2009-10-01",:updated_at_to=>"2009-10-01"}
+      response.should be_success
+      # 結果の中に含まれているか見る
+      assigns[:product_styles].size.should == 1
+      assigns[:product_styles][0].attributes.should == product_styles(:valid_product).attributes      
+    end      
+  end
+end
diff --git a/spec/controllers/admin/stock_csv_controller_spec.rb b/spec/controllers/admin/stock_csv_controller_spec.rb
new file mode 100644 (file)
index 0000000..62be0f0
--- /dev/null
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe Admin::StockCsvController do
+
+  #Delete this example and add some real ones
+  it "should use Admin::StockCsvController" do
+    controller.should be_an_instance_of(Admin::StockCsvController)
+  end
+
+end
diff --git a/spec/controllers/admin/stock_histories_controller_spec.rb b/spec/controllers/admin/stock_histories_controller_spec.rb
new file mode 100644 (file)
index 0000000..cc050fc
--- /dev/null
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe Admin::StockHistoriesController do
+
+  #Delete this example and add some real ones
+  it "should use Admin::StockHistoriesController" do
+    controller.should be_an_instance_of(Admin::StockHistoriesController)
+  end
+
+end
diff --git a/spec/controllers/admin/stock_in_controller_spec.rb b/spec/controllers/admin/stock_in_controller_spec.rb
new file mode 100644 (file)
index 0000000..dcdca7f
--- /dev/null
@@ -0,0 +1,68 @@
+require 'spec_helper'
+
+describe Admin::StockInController do
+  fixtures :admin_users,:products,:product_styles,:suppliers,:stock_histories
+  before do 
+    session[:admin_user] = admin_users(:admin10)
+    @controller.class.skip_before_filter @controller.class.before_filter
+    @controller.class.skip_after_filter @controller.class.after_filter
+    @ps = product_styles(:valid_product)
+  end
+  
+  describe "GET 'index'" do
+    it "成功する" do
+      get 'index'
+      response.should be_success
+    end
+  end
+  describe "GET 'edit'" do
+    it "成功するパターン" do
+      get 'edit', :id => @ps.id
+      assigns[:product_style].should_not be_nil
+      assigns[:stock_history].should_not be_nil
+      assigns[:stock_history].stock_type.should == StockHistory::STOCK_IN
+    end
+
+    it "失敗するパターン" do
+      lambda { get 'edit', :id => 1000 }.should raise_error(ActiveRecord::RecordNotFound)
+      assigns[:product_style].should be_nil
+      assigns[:stock_history].should be_nil
+    end
+  end
+  describe "POST 'update'" do
+    it "正常に更新できるパターン" do
+      before = ProductStyle.find_by_id(@ps.id).actual_count.to_i
+      max_id = StockHistory.maximum(:id)
+      sh = StockHistory.new(:storaged_count=>10,:comment=>"テスト")
+      post 'update', :id => @ps.id, :stock_history => sh.attributes
+      flash[:stock_update].should == "データを保存しました"
+      #更新後
+      #商品規格
+      check = ProductStyle.find_by_id(@ps.id).actual_count.to_i
+      check.should == before + 10
+      #操作履歴
+      StockHistory.maximum(:id).should > max_id
+      response.should redirect_to(:action => :index)
+    end
+    #入力チェックエラー
+    #必須項目が未入力
+    it "StockHistoryが不正なパターン" do
+      sh = StockHistory.new(:storaged_count=>10)
+      post 'update', :id => @ps.id, :stock_history => sh.attributes
+      check = ProductStyle.find_by_id(@ps.id).actual_count.to_i
+      check.should == @ps.actual_count
+      response.should_not be_redirect
+      response.should render_template("admin/stock_in/edit.html.erb")
+    end
+    #入力値エラー
+    #例、現実在庫数+入庫数 < 0
+    it "StockHistoryが不正なパターン" do
+      sh = StockHistory.new(:storaged_count=>-10000,:comment=>"テスト")
+      post 'update', :id => @ps.id, :stock_history => sh.attributes
+      check = ProductStyle.find_by_id(@ps.id).actual_count.to_i
+      check.should == @ps.actual_count
+      response.should_not be_redirect
+      response.should render_template("admin/stock_in/edit.html.erb")
+    end
+  end  
+end
diff --git a/spec/controllers/admin/stock_modify_controller_spec.rb b/spec/controllers/admin/stock_modify_controller_spec.rb
new file mode 100644 (file)
index 0000000..d63016f
--- /dev/null
@@ -0,0 +1,71 @@
+require 'spec_helper'
+
+describe Admin::StockModifyController do
+
+  fixtures :admin_users,:products,:product_styles,:suppliers,:stock_histories
+  before do 
+    session[:admin_user] = admin_users(:admin10)
+    @controller.class.skip_before_filter @controller.class.before_filter
+    @controller.class.skip_after_filter @controller.class.after_filter
+    @ps = product_styles(:valid_product)
+  end
+  
+  describe "GET 'index'" do
+    it "成功する" do
+      get 'index'
+      response.should be_success
+    end
+  end
+  describe "GET 'edit'" do
+    it "成功するパターン" do
+      get 'edit', :id => @ps.id
+      assigns[:product_style].should_not be_nil
+      assigns[:stock_history].should_not be_nil
+      assigns[:stock_history].stock_type.should == StockHistory::STOCK_MODIFY
+    end
+
+    it "失敗するパターン" do
+      lambda { get 'edit', :id => 1000 }.should raise_error(ActiveRecord::RecordNotFound)
+      assigns[:product_style].should be_nil
+      assigns[:stock_history].should be_nil
+    end
+  end
+  describe "POST 'update'" do
+    it "正常に更新できるパターン" do
+      before = ProductStyle.find_by_id(@ps.id)      
+      max_id = StockHistory.maximum(:id)
+      sh = StockHistory.new(:actual_adjustment=>10,:orderable_adjustment=>5,:broken_adjustment=>1,:comment=>"テスト")
+      post 'update', :id => @ps.id, :stock_history => sh.attributes
+      flash[:stock_update].should == "データを保存しました"
+      #更新後
+      #商品規格
+      check = ProductStyle.find_by_id(@ps.id)
+      check.actual_count.should == before.actual_count.to_i + 10
+      check.orderable_count.should == before.orderable_count.to_i + 5
+      check.broken_count.should == before.broken_count.to_i + 1
+      #操作履歴
+      StockHistory.maximum(:id).should > max_id
+      response.should redirect_to(:action => :index)
+    end
+    #入力チェックエラー
+    #必須項目が未入力
+    it "StockHistoryが不正なパターン" do
+      sh = StockHistory.new
+      post 'update', :id => @ps.id, :stock_history => sh.attributes
+      check = ProductStyle.find_by_id(@ps.id)
+      check.attributes.should == @ps.attributes
+      response.should_not be_redirect
+      response.should render_template("admin/stock_modify/edit.html.erb")
+    end
+    #入力値エラー
+    #販売可能数+販可能調整数 < 0 あるいは  実在庫数+実在庫調整数 < 0 あるいは 不良在庫数  + 不良在庫調整数 < 0
+    it "StockHistoryが不正なパターン" do
+      sh = StockHistory.new(:actual_adjustment=>-1000,:orderable_adjustment=>-10,:broken_adjustment=>-1,:comment=>"テスト")
+      post 'update', :id => @ps.id, :stock_history => sh.attributes
+      check = ProductStyle.find_by_id(@ps.id)
+      check.attributes.should == @ps.attributes
+      response.should_not be_redirect
+      response.should render_template("admin/stock_modify/edit.html.erb")
+    end
+  end 
+end
index cd0553f..911cc3b 100644 (file)
@@ -17,9 +17,7 @@ describe Admin::SuppliersController do
   end
   
   describe "GET 'search'" do
-    before do
-    end
-    
+   
     it "should be successful" do
       get 'search'
       response.should be_success
index d3e9f6a..658ed7e 100644 (file)
@@ -361,10 +361,10 @@ describe CartController do
       flash[:error].should be_nil
     end
 
-    it "戻るボタン" do
-      post 'complete', :cancel => 'zzz'
-      response.should render_template('purchase')
-    end
+#    it "戻るボタン" do
+#      post 'complete', :cancel => 'zzz'
+#      response.should render_template('purchase')
+#    end
 
     it "カート内容が無効(個数超過等)" do
       session[:carts] = [carts(:invalid).attributes]
@@ -377,12 +377,12 @@ describe CartController do
       post 'complete', @params
       response.should render_template('purchase')
     end
-
-    it "should not be successful" do
-      @params[:order_delivery] = {}
-      post 'complete', @params
-      response.should render_template('purchase')
-    end
+#
+#    it "should not be successful" do
+#      @params[:order_delivery] = {}
+#      post 'complete', @params
+#      response.should render_template('purchase')
+#    end
 
     it "受注の中身" do
       post 'complete', @params
index 425aa23..8f80bcb 100644 (file)
@@ -18,6 +18,7 @@ can_not_incriment:
   name: cannotincriment
   product_id: 5
   actual_count: 1
+  orderable_count: 1  
   sell_price: 200
 
 can_decriment:
@@ -140,6 +141,9 @@ valid_product:
   style_category_id2: 30
   actual_count: 1000
   sell_price: 10000
+  orderable_count: 100
+  created_at: 2009-10-01 00:00:00
+  updated_at: 2009-10-01 00:00:00    
 #未公開商品  
 not_permit_product:  
   id: 15
@@ -157,6 +161,7 @@ campaign_product:
   style_category_id1: 60
   style_category_id2: 30
   actual_count: 1000
+  orderable_count: 100
   sell_price: 10000
 #販売終了商品  
 sell_stop_product:  
@@ -175,7 +180,8 @@ multi_styles_product_1:
   style_category_id1: 60
   style_category_id2: 30
   actual_count: 1000
-  sell_price: 10500 
+  sell_price: 10500
+  orderable_count: 900 
 multi_styles_product_2:  
   id: 19
   product_id: 20
diff --git a/spec/fixtures/stock_histories.yml b/spec/fixtures/stock_histories.yml
new file mode 100644 (file)
index 0000000..aee7223
--- /dev/null
@@ -0,0 +1,28 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+stock_in:
+  id: 1
+  admin_user_id: 1
+  product_id: 16
+  product_style_id: 14
+  moved_at: '2010-01-01 00:00:00'
+  storaged_count: 100
+  actual_count: 100
+  comment: '入庫'
+  stock_type: 1
+stock_modify:
+  id: 2
+  admin_user_id: 1
+  product_id: 16
+  product_style_id: 14
+  moved_at: '2010-01-15 00:00:00'
+  actual_adjustment: -5
+  actual_count: 100
+  orderable_adjustment: 80
+  orderable_count: 80
+  broken_adjustment: 5
+  broken_count: 5
+  comment: '在庫調整'
+  stock_type: 2  
+  
+  
diff --git a/spec/helpers/admin/stock_csv_helper_spec.rb b/spec/helpers/admin/stock_csv_helper_spec.rb
new file mode 100644 (file)
index 0000000..1bd1832
--- /dev/null
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe Admin::StockCsvHelper do
+
+  #Delete this example and add some real ones or delete this file
+  it "should be included in the object returned by #helper" do
+    included_modules = (class << helper; self; end).send :included_modules
+    included_modules.should include(Admin::StockCsvHelper)
+  end
+
+end
diff --git a/spec/helpers/admin/stock_histories_helper_spec.rb b/spec/helpers/admin/stock_histories_helper_spec.rb
new file mode 100644 (file)
index 0000000..12db721
--- /dev/null
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe Admin::StockHistoriesHelper do
+
+  #Delete this example and add some real ones or delete this file
+  it "should be included in the object returned by #helper" do
+    included_modules = (class << helper; self; end).send :included_modules
+    included_modules.should include(Admin::StockHistoriesHelper)
+  end
+
+end
diff --git a/spec/helpers/admin/stock_in_helper_spec.rb b/spec/helpers/admin/stock_in_helper_spec.rb
new file mode 100644 (file)
index 0000000..c373fec
--- /dev/null
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe Admin::StockInHelper do
+
+  #Delete this example and add some real ones or delete this file
+  it "should be included in the object returned by #helper" do
+    included_modules = (class << helper; self; end).send :included_modules
+    included_modules.should include(Admin::StockInHelper)
+  end
+
+end
diff --git a/spec/helpers/admin/stock_modify_helper_spec.rb b/spec/helpers/admin/stock_modify_helper_spec.rb
new file mode 100644 (file)
index 0000000..cadabe5
--- /dev/null
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe Admin::StockModifyHelper do
+
+  #Delete this example and add some real ones or delete this file
+  it "should be included in the object returned by #helper" do
+    included_modules = (class << helper; self; end).send :included_modules
+    included_modules.should include(Admin::StockModifyHelper)
+  end
+
+end
index 037d698..ec8e56f 100644 (file)
@@ -82,48 +82,59 @@ describe ProductStyle do
     end
   end
   describe "その他" do
-    it "データ初期化" do
-      #実際在庫数
-      product_style = ProductStyle.new(:sell_price => 15000)
-      product_style.actual_count.should == 0
-      product_style = ProductStyle.new(product_styles(:valid_product).attributes)
-      product_style.actual_count.should == product_styles(:valid_product).actual_count
-    end
+#    it "データ初期化" do
+#      #実際在庫数
+#      product_style = ProductStyle.new(:sell_price => 15000)
+#      product_style.actual_count.should == 0
+#      product_style = ProductStyle.new(product_styles(:valid_product).attributes)
+#      product_style.actual_count.should == product_styles(:valid_product).actual_count
+#    end
     it "購入可能数を戻る" do
       #購入制限あり
-      #購入上限 = 5,実際在庫 = 3,購入数 = Parameter
-      product_style = ProductStyle.new(:product_id=>products(:limited_in_sep).id,:sell_price => 15000,:actual_count=>3)      
+      #購入上限 = 5,実際在庫 = 10,販売可能数 = 3,購入数 = Parameter
+      product_style = ProductStyle.new(:product_id=>products(:limited_in_sep).id,:sell_price => 15000,:actual_count=>10,:orderable_count=>3)      
 
-      #ケース1: 実際在庫 < 購入上限 < 購入数 の場合、実際在庫数を戻る
-      product_style.available?(10).should == product_style.actual_count
-      #ケース2:購入上限 < 実際在庫 < 購入数 の場合、購入制限数を戻る
-      product_style.actual_count = 6
+      #ケース1: 販売可能数 < 購入上限 < 購入数 の場合、実際在庫数を戻る
+      product_style.available?(10).should == product_style.orderable_count
+      #ケース2:購入上限 < 販売可能数 < 購入数 の場合、購入制限数を戻る
+      product_style.orderable_count = 6
       product_style.available?(10).should == product_style.product.sell_limit
-      #ケース3:購入数< 購入上限 < 実際在庫の場合、購入数を戻る
+      #ケース3:購入数< 購入上限 < 販売可能数の場合、購入数を戻る
       product_style.available?(2).should == 2
-      #ケース4:購入数< 実際在庫  < 購入上限 の場合、購入数を戻る
-      product_style.actual_count = 3
+      #ケース4:購入数< 販売可能数  < 購入上限 の場合、購入数を戻る
+      product_style.orderable_count = 3
       product_style.available?(2).should == 2
       product_style.available?(3).should == 3 
       #購入制限なし
       #テストデータの在庫数:1000
-      #ケース1:購入数< 実際在庫数
-      @product_style.available?(@product_style.actual_count-1).should == @product_style.actual_count-1
-      #ケース2購入数 > 実際在庫数
-      @product_style.available?(@product_style.actual_count+1).should == @product_style.actual_count
-      @product_style.available?(@product_style.actual_count).should == @product_style.actual_count
+      #ケース1:購入数< 販売可能数
+      @product_style.available?(@product_style.orderable_count-1).should == @product_style.orderable_count-1
+      #ケース2購入数 > 販売可能数
+      @product_style.available?(@product_style.orderable_count+1).should == @product_style.orderable_count
+      @product_style.available?(@product_style.orderable_count).should == @product_style.orderable_count
+      
+      #販売可能数がnilの時、「0」として
+      #ケース1:購入制限あり
+      p_s1 = ProductStyle.new(:product_id=>products(:limited_in_sep).id,:sell_price => 15000,:actual_count=>10)
+      p_s1.available?(1).should == 0
+      #ケース2:購入制限なし
+      p_s2 = ProductStyle.new(:product_id=>@product_style.id,:sell_price => 15000,:actual_count=>10)
+      p_s2.available?(1).should == 0
     end
     it "受注により在庫数が変わる" do
-      #在庫数1000
+      #在庫数1000、販売可能数100
+      #購入後、在庫数と販売可能数とも引く
       cnt_b = @product_style.actual_count
+      orderable_cnt_b = @product_style.orderable_count
       @product_style.order(2)
       @product_style.actual_count.should == cnt_b-2
+      @product_style.orderable_count.should == orderable_cnt_b - 2
       #在庫数0
       product_style = product_styles(:multi_styles_product_3)
       #例外が発生する箇所を、lambdaでくくる必要がある
       lambda{
         product_style.order(1)
-      }.should raise_error(RuntimeError,"å®\9få\9c¨å\80\8bæ\95°ã\81\8c\81§ã\81\99")
+      }.should raise_error(RuntimeError,"å\9c¨åº«ä¸\8d足ã\81§ã\81\99ã\80\82")
     end
   end
 end
diff --git a/spec/models/stock_history_spec.rb b/spec/models/stock_history_spec.rb
new file mode 100644 (file)
index 0000000..b137e52
--- /dev/null
@@ -0,0 +1,42 @@
+require 'spec_helper'
+
+describe StockHistory do
+  fixtures :stock_histories
+  before(:each) do
+    @sh = stock_histories(:stock_in)
+  end
+
+  describe "validateチェック" do
+    it "should be_valid" do
+      @sh.should be_valid
+    end
+    it "備考" do
+      @sh.comment = nil
+      @sh.should_not be_valid
+      #文字数(1000以下)
+      @sh.comment = "a" * 10000
+      @sh.should be_valid
+      @sh.comment = "a" * 10001
+      @sh.should_not be_valid
+    end
+    it "入庫数" do
+      #入庫の場合、入庫数必須
+      sh_in = StockHistory.new(:comment=>"test",:stock_type=>1)
+      sh_in.should have(1).errors_on(:storaged_count)
+      #在庫調整の場合、入庫調整数、販売調整数、不良調整数は非必須
+      sh_m =  StockHistory.new(:comment=>"test",:stock_type=>2)
+      sh_m.should be_valid
+    end
+  end
+  describe "その他" do
+    it "入庫かどうか" do
+      sh_in = StockHistory.new(:comment=>"test",:stock_type=>1)
+      sh_in.stock_in?.should be_true
+      sh_m = StockHistory.new(:comment=>"test",:stock_type=>2)
+      sh_m.stock_in?.should be_false
+      sh = StockHistory.new
+      sh.stock_in?.should be_false
+    end
+  end
+  
+end
diff --git a/spec/models/stock_search_form_spec.rb b/spec/models/stock_search_form_spec.rb
new file mode 100644 (file)
index 0000000..44f0331
--- /dev/null
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+describe StockSearchForm do
+  before(:each) do
+    @search_form = StockSearchForm.new
+  end
+  describe "validateチェック" do
+    it "データがただしい" do
+      @search_form.should be_valid
+    end
+    it "商品ID" do
+      #数字
+      @search_form.product_id = 123456
+      @search_form.should be_valid
+      @search_form.product_id = "abc"
+      @search_form.should_not be_valid
+    end
+    it "商品コード" do
+      #英数字
+      @search_form.code = "abc"
+      @search_form.should be_valid
+      @search_form.code = "あああ"
+      @search_form.should_not be_valid
+    end
+    it "型番" do
+      #英数字
+      @search_form.manufacturer = "abc"
+      @search_form.should be_valid
+      @search_form.manufacturer = "123$%&"
+      @search_form.should_not be_valid
+    end
+  end
+end