if product_style[:id]
product_style.update_attributes({:sell_price=>value[:sell_price],
:actual_count=>value[:actual_count],
- :code=>value[:code]})
+ :code=>value[:code],
+ :manufacturer_id=>value[:manufacturer_id]})
else
- [:sell_price, :actual_count, :code].each do |column|
+ [:sell_price, :actual_count, :code ,:manufacturer_id].each do |column|
product_style[column] = value[column]
end
product_style[:position] = idx.to_i + 1
redirect_to :action => params[:return_act]
end
+ #使用機能一覧
+ def settings
+
+ end
+ #使用機能設定
+ def settings_update
+ type = params[:set_id]
+ case type.to_i
+ #set_id_id = 1の場合、仕入先使用か使用しないかの設定
+ when 1
+ supplier_update
+ else
+ #将来何か追加したい場合、ここで追加してください
+ render :action => "settings"
+ return
+ end
+ end
private
@kiyakus = Kiyaku.find(:all, :order=>"position")
end
+ #仕入先を使用するかどうか設定
+ def supplier_update
+ @system.attributes = params[:system]
+ if @system.save
+ if @system.supplier_use_flag
+ #使用する->使用しない変更する時、既存の仕入先をそのまま
+ #supplier_use_flagの変更のみ
+ redirect_to :controller => "suppliers",:action => ""
+ else
+ flash.now[:notice] = "仕入先を使用しないように設定しました"
+ render :action => "settings"
+ end
+ else
+ flash.now[:error] = "設定に失敗しました"
+ render :action => "settings"
+ end
+ end
end
--- /dev/null
+class Admin::SuppliersController < Admin::BaseController
+ #共通
+ resource_controller
+ before_filter :admin_permission_check_supplier
+ before_filter :check_supplier_use
+ before_filter :check_default,:only => [:edit,:confirm]
+
+ def search
+ @condition = SupplierSearchForm.new(params[:condition])
+ unless @condition.valid?
+ render :action => "index"
+ return
+ end
+
+ sql_condition, conditions = SupplierSearchForm.get_sql_condition(@condition)
+ sql = SupplierSearchForm.get_sql_select + sql_condition
+ sqls = [sql]
+ conditions.each do |c|
+ sqls << c
+ end
+ @suppliers = Supplier.paginate_by_sql(sqls,
+ :page => params[:page],
+ :per_page => @condition.per_page ||10,
+ :order => "id")
+ end
+
+ edit.before do
+ get_supplier
+ end
+
+ #確認画面
+ def confirm
+ if !params[:id].blank?
+ get_supplier
+ else
+ @supplier = Supplier.new(params[:supplier])
+ end
+ #入力チェック
+ unless @supplier.valid?
+ if !params[:id].blank?
+ render :action => :edit
+ else
+ render :action => :new
+ end
+ return
+ end
+ end
+ #遷移先指定
+ [create, update,destroy].each do |action|
+ action.wants.html do
+ redirect_to :action => "index"
+ end
+ end
+ #仕入先を使用しているかしないと判断のフィルタ
+ def check_supplier_use
+ unless @system.supplier_use_flag
+ redirect_to :controller=>"/admin/home"
+ return
+ end
+ end
+ #編集・削除の時、ID=1かどうかチェック
+ #ID=1のデータは編集不可、削除不可にさせる
+ def check_default
+ if params[:id].to_i == Supplier::DEFAULT_SUPPLIER_ID
+ redirect_to :controller=>"/admin/suppliers"
+ return
+ end
+ end
+ private
+ def get_supplier
+ @supplier = Supplier.find_by_id(params[:id])
+ @supplier.attributes = params[:supplier]
+ end
+end
def load_system
@system = System.find(:first)
+ @system.supplier_use_flag ||= false
end
#郵便番号から住所を取得
--- /dev/null
+module Admin::SuppliersHelper
+end
has_many :product_styles, :dependent => :destroy, :order => 'position'
has_many :order_details
has_one :campaign
+ belongs_to :supplier
validates_length_of :name , :maximum => 50
validates_length_of :name , :minimum => 1
validates_presence_of :medium_resource
validates_presence_of :description
validates_presence_of :introduction
+ validates_presence_of :supplier
validates_associated :sub_products
attr_accessor :small_resource_path
def category_name
self.category && self.category.name
end
-
+ def supplier_name
+ self.supplier && self.supplier.name
+ end
# 送料無料?
def free_delivery?
statuses.exists?(['name=?', '送料無料'])
unless search.name.blank?
search_list << ["products.name like ?", "%#{search.name}%"]
end
+ unless search.supplier.blank?
+ 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
end
elsif column.to_s == "delivery_dates_label"
product.delivery_dates_label
- elsif ![:small_resource_path,:medium_resource_path,:large_resource_path,:category_name,:delivery_dates_label].include?(column)&& Product.columns_hash[column.to_s].type == :datetime
+ elsif ![:small_resource_path,:medium_resource_path,:large_resource_path,:category_name,:delivery_dates_label,:supplier_name].include?(column)&& Product.columns_hash[column.to_s].type == :datetime
(product[column] + (60*60*9)).strftime("%Y-%m-%d %H:%M") if product[column]
else
product[column] || product.send(column)
product.other = arr[28]
product.free_comment = arr[29]
setDelivery_dates(product,arr[30])
+ setSupplierId(product,arr[31])
end
def setPermit(product, permit)
def setDelivery_dates(product, delivery_dates_label)
product.delivery_dates = DELIVERY_DATE[delivery_dates_label] unless delivery_dates_label.blank?
end
-
+ def setSupplierId(product, s_name)
+ if s_name.blank?
+ product.supplier_id = Supplier::DEFAULT_SUPPLIER_ID
+ else
+ s = Supplier.find_by_name(s_name)
+ if !s.blank?
+ product.supplier_id = s.id
+ else
+ raise ActiveRecord::RecordNotFound
+ end
+ end
+ end
#画像データセット
def setImageId(product,arr)
#画像IDと画像パスの項目を別々に設定して画像パスがあった場合は、その先にある画像を登録し、なかった場合は画像IDを登録する
:other,
:free_comment,
:delivery_dates_label,
+ :supplier_name,
:created_at,
:updated_at
]
:other => "その他仕様",
:free_comment => "フリー入力",
:delivery_dates_label => "配送日",
+ :supplier_name => "仕入先名",
:created_at => "登録日",
:updated_at => "更新日"
}
:foreign_key => "style_id2"
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
--- /dev/null
+class Supplier < ActiveRecord::Base
+ acts_as_paranoid
+ belongs_to :prefecture
+ has_many :products
+ #DEFAULT_IDは仕入先不使用時のIDとして定義
+ #id=1のデータは編集不可、削除不可
+ DEFAULT_SUPPLIER_ID = 1
+ SHISYAGONYU, KIRISUTE, KIRIAGE = 0, 1, 2
+ TAX_RULE_NAMES = { SHISYAGONYU => "四捨五入", KIRISUTE => "切り捨て", KIRIAGE => "切り上げ"}
+
+ validates_presence_of :name
+ validates_uniqueness_of :name
+ validates_length_of :name, :maximum => 50
+
+ validates_presence_of :zipcode01, :zipcode02
+ validates_numericality_of :zipcode01, :zipcode02, :allow_blank=>true
+ validates_length_of :zipcode01, :is => 3, :allow_blank=>true
+ validates_length_of :zipcode02, :is => 4, :allow_blank=>true
+ validates_associated :prefecture
+ validates_presence_of :prefecture_id,:address_city, :address_detail
+ validates_length_of :address_city, :address_detail, :maximum => 100
+
+ validates_presence_of :contact_name
+ validates_length_of :contact_name, :maximum => 50
+
+ validates_presence_of :tel01, :tel02, :tel03
+ validates_numericality_of :tel01, :tel02, :tel03, :allow_blank => true
+ validates_length_of :tel01, :tel02, :tel03, :maximum => 6, :allow_blank => true
+
+ validates_numericality_of :fax01, :fax02, :fax03, :allow_blank => true
+ validates_length_of :fax01, :fax02, :fax03, :maximum => 6, :allow_blank => true
+
+ validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :allow_blank => true
+
+ validates_inclusion_of :percentage, :in => (0..100), :allow_blank => true
+
+ validates_length_of :free_comment, :maximum => 10000 , :allow_blank => true
+ validates_inclusion_of :tax_rule, :in => [SHISYAGONYU, KIRISUTE, KIRIAGE] , :allow_blank => true
+
+ before_update :check_default
+ before_destroy :check_default_and_products
+
+ def validate
+ super
+ # FAX どれかが入力されている時だけ検証
+ if not [fax01, fax02, fax03].all?(&:blank?)
+ fax_items = %w(fax01 fax02 fax03)
+ errors.add_on_blank fax_items, "が入力されていません"
+ end
+ end
+
+ def tel
+ "#{tel01}-#{tel02}-#{tel03}" unless tel01.blank? or tel02.blank? or tel03.blank?
+ end
+
+ def fax
+ "#{fax01}-#{fax02}-#{fax03}" unless fax01.blank? or fax02.blank? or fax03.blank?
+ end
+
+ def prefecture_name
+ prefecture && prefecture.name
+ end
+
+ def tax_rule_label
+ TAX_RULE_NAMES[tax_rule] unless tax_rule.blank?
+ end
+ def check_default_and_products
+ check_default
+ #直接URL入力で商品を持っている仕入先を削除防止するため
+ unless self.products.blank?
+ raise ActiveRecord::ReadOnlyRecord
+ end
+ end
+ def check_default
+ #id=1のデータはデフォルトの状態のみで、編集不可、削除不可
+ if self.id == DEFAULT_SUPPLIER_ID
+ raise ActiveRecord::ReadOnlyRecord
+ end
+ end
+end
--- /dev/null
+# -*- coding: utf-8 -*-\r
+# 仕入先マスタ管理で検索条件を格納するフォーム\r
+class SupplierSearchForm < SearchForm\r
+ set_field_names :supplier_id => '仕入先ID'\r
+ set_field_names :email => 'メールアドレス'\r
+ set_field_names :tel_no => '電話番号'\r
+ set_field_names :fax_no => 'ファックス'\r
+ set_field_names :name => '仕入先名'\r
+ set_field_names :contact_name => '担当者名'\r
+\r
+ validates_numericality_of :supplier_id, :allow_blank=>true, :message => 'は半角数字のみを入力してください。'\r
+ validates_format_of :email, :with => /[\x1-\x7f]/, :allow_blank => true, :message => 'は半角英数字のみを入力してください。'\r
+ validates_numericality_of :tel_no, :only_integer => true, :allow_blank => true, :message => 'は半角数字のみを入力してください。'\r
+ validates_numericality_of :fax_no, :only_integer => true, :allow_blank => true, :message => 'は半角数字のみを入力してください。'\r
+\r
+ def self.get_sql_select\r
+ <<-EOS\r
+ select s.*\r
+ EOS\r
+ end\r
+\r
+ def self.get_sql_condition(condition)\r
+ conditions = []\r
+ sql_condition = <<-EOS\r
+from\r
+suppliers s\r
+where\r
+(s.deleted_at IS NULL OR s.deleted_at > '#{Time.now.gmtime.strftime("%Y-%m-%d %H:%M:%S")}')\r
+#{unless condition.supplier_id.blank?\r
+ conditions << condition.supplier_id.to_i\r
+ "and s.id = ?"\r
+ end}\r
+#{unless condition.name.blank?\r
+ conditions << "%#{condition.name}%"\r
+ "and s.name like ?"\r
+ end}\r
+#{unless condition.contact_name.blank?\r
+ conditions << "%#{condition.contact_name}%"\r
+ "and s.contact_name like ?"\r
+ end}\r
+#{unless condition.tel_no.blank?\r
+ conditions << "%#{condition.tel_no}%"\r
+ "and (s.tel01 || s.tel02 || s.tel03) like ? "\r
+ end}\r
+#{unless condition.fax_no.blank?\r
+ conditions << "%#{condition.fax_no}%"\r
+ "and (s.fax01 || s.fax02 || s.fax03) like ? "\r
+ end} \r
+#{unless condition.email.blank?\r
+ conditions << "%#{condition.email}%"\r
+ "and s.email like ? "\r
+ end}\r
+order by s.id\r
+EOS\r
+ return [sql_condition, conditions] \r
+ end\r
+\r
+end\r
--- /dev/null
+<script>\r
+ window.onload = function init() {\r
+ document.getElementById("depot").style.display = 'none';\r
+ }\r
+</script>\r
+<div id="sub"><!-- サブメニュー -->\r
+ <div id="menu" class="clearfix"><!-- g_menu -->\r
+ <% if @system.supplier_use_flag %>\r
+ <p><a href="JavaScript:onClick=Tree('display1');ImgC('img1');"><img src="/images/menu_icon.gif" width="36" height="36" alt="" id="img1" /><span>仕入先管理</span></a></p>\r
+ <ul id="display1" style="display:block">\r
+ <li><%= link_to '仕入先マスタ管理', {:controller => 'suppliers', :action => 'index'} %></li>\r
+ <li><%= link_to '仕入先登録', {:controller => 'suppliers', :action => 'new'} %></li>\r
+ </ul>\r
+ <%end%>\r
+ </div><!-- /g_menu -->\r
+</div><!-- /サブメニュー -->\r
<ul id="display4" style="display:block">
<li><%= link_to 'メンバー管理', {:controller => 'admin_users', :action => 'index'} %></li>
<li><%= link_to '管理者権限管理', {:controller => 'authorities', :action => 'index'} %></li>
+ <li><%= link_to '環境設定', {:controller => 'shops', :action => 'settings'} %></li>
</ul>
</div><!-- /g_menu -->
</div><!-- /sサブメニュー -->
<p id="category_info">編集したいカテゴリをクリックして下さい。</p>
<a href="/admin/shops"><img src="/images/store_btn_l.gif" width="222" height="138" alt="店舗管理" /></a>
<a href="/admin/products"><img src="/images/goods_btn_l.gif" width="222" height="138" alt="商品管理" id="category_img" /></a>
- <a href="#"><img src="/images/order_btn_l.gif" width="222" height="138" alt="発注・出荷管理" /></a>
+ <% 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>
+ <%end%>
</div><!-- /カテゴリ選択 -->
<%= flash[:notice] %>
<h2>ショップの状況</h2>
<th>商品コード</th>
<th>在庫</th>
<th>価格(円)</th>
+ <th>型番</th>
</tr>
<% idx = 0 %>
<% @style_category1.each do | style_category1 | %>
<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>
</tr>
<% idx += 1 %>
<% end %>
<th>商品コード</th>
<th>在庫</th>
<th>価格(円)</th>
+ <th>型番</th>
</tr>
<% idx = 0 %>
<% @style_category1.each do | style_category1 | %>
<%= 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>
+ <td>
+ <%= h params["product_styles"][idx.to_s] && params["product_styles"][idx.to_s]["manufacturer_id"] %>
+ <%= hidden_field_tag "product_styles[#{idx.to_s}][manufacturer_id]", params["product_styles"][idx.to_s] && params["product_styles"][idx.to_s]["manufacturer_id"] %>
+ </td>
</tr>
<% idx += 1 %>
<% end %>
<div id="main"><!-- メイン -->
+<%= @error_messages %>
+
<% if @product.valid? %>
<h2>規格登録</h2>
<% if @new_flg = ( @product.product_styles.empty? || @product.product_styles.first.code.blank? ) %>
<%= confirm_tag :text_field, :product, :name, :class=>"data_m" %> (上限50文字)
</td>
</tr>
+ <%if @system.supplier_use_flag%>
+ <tr>
+ <th>仕入先名<span class="pnt">※</span></th>
+ <td><%suppliers = Supplier.find(:all,:order=>'id')%>
+ <%= confirm_select(confirm_tag(:select, :product, :supplier_id, suppliers.map{|s| [s.name,s.id]}), @product.supplier.name, "product") %>
+ </td>
+ </tr>
+ <% end %>
<tr>
<th>カテゴリー名<span class="pnt">※</span></th>
<td>
<th>商品名</th>
<td><%= f.text_field :name, :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 => '全て' %>
+ </td>
+ </tr>
+ <% end %>
<tr>
<th>カテゴリ</th>
<td><%= category_select :search, :category, :include_blank => true %></td>
--- /dev/null
+<%=h flash[:notice] %>
+<%=h flash[:error] %>
+<%= error_messages_for :shop %>
+<!--仕入先-->
+<% form_for :system, :url =>{:action => "settings_update"} do |f|%>
+<table cellspacing="1" cellpadding="0" class="data" >
+ <tr>
+ <th>仕入先を使用しますか</th>
+ <td><%= f.radio_button :supplier_use_flag , false%>使用しない <%= f.radio_button :supplier_use_flag , true%>使用する</td>
+ </tr>
+</table>
+<div class="btn_box">
+ <%= hidden_field_tag "set_id","1"%>
+ <%= submit_tag "この内容で登録する", :onclick => "return #{confirm_javascript_function("登録しても宜しいですか")}", :class=>"btn" %>
+ <img class="btn_side" width="6" height="34" src="/images/btn_side.gif">
+</div>
+<% end %>
\ No newline at end of file
--- /dev/null
+<%= render :partial => "submenu" %>
+
+<div id="main"><!-- メイン -->
+
+<h2>環境設定</h2>
+<p class="req"><span class="pnt">※</span>は必須入力です</p>
+<h3>仕入先</h3>
+<%= render :partial => "settings_form" %>
+</div><!-- /メイン -->
+
--- /dev/null
+<table class="data" cellspacing="1">
+ <tr>
+ <th>仕入先ID</th>
+ <td>
+ <%= h @supplier.id %>
+ </td>
+ </tr>
+ <tr>
+ <th>仕入先名 <span class="pnt">※</span></th>
+ <td>
+ <%= confirm_tag :text_field, :supplier, :name, {:class=>"data_m",:style=>"ime-mode:active"} %> (上限50文字)
+ </td>
+ </tr>
+ <tr>
+ <th>郵便番号 <span class="pnt">※</span></th>
+ <td>
+ 〒 <%= confirm_tag :text_field, :supplier, :zipcode01, {:size => 10,:style=>"ime-mode:inactive"} %>-
+ <%= confirm_tag :text_field, :supplier, :zipcode02, {:size => 10,:style=>"ime-mode:inactive"} %>
+ <% unless params[:action] =~ /confirm/ && @supplier.errors.empty? %>
+ <input name="zipcode_input" value="住所入力" onclick="address_by_zip('supplier_zipcode01','supplier_zipcode02', 'supplier_prefecture_name', 'supplier_address_city', 'supplier_address_detail', 'supplier_prefecture_id', 'admin/suppliers');" type="button" class="btn_s">
+ <% end %>
+ </td>
+ </tr>
+ <tr>
+ <th>ご住所 <span class="pnt">※</span></th>
+ <td>
+ <% prefectures = Prefecture.find(:all, :order => "position").map {|p| [p.name, p.id]} %>
+ <%= confirm_select(confirm_tag(:select, :supplier, :prefecture_id, prefectures), @supplier.prefecture_name, "supplier") %>
+ <br/><br/>
+ <%= confirm_tag :text_field, :supplier, :address_city, {:class=>"data_m",:style=>"ime-mode:active"} %><span> (上限100文字)</span><br/>
+ ※市区町村を入力(例:東京都渋谷区恵比寿西)<br />
+ <br/>
+ <%= confirm_tag :text_field, :supplier, :address_detail, {:class=>"data_m",:style=>"ime-mode:active"} %><span> (上限100文字)</span><br/>
+ ※番地、建物、マンション名などを入力(例:0-0-0)<br/>
+ </td>
+ </tr>
+ <tr>
+ <th>担当者名 <span class="pnt">※</span></th>
+ <td>
+ <%= confirm_tag :text_field, :supplier, :contact_name, {:class=>"data_m",:style=>"ime-mode:active"} %> (上限50文字)
+ </td>
+ </tr>
+ <tr>
+ <th>TEL <span class="pnt">※</span></th>
+ <td>
+ <%= confirm_tag :text_field, :supplier, :tel01, {:class=>"data_s",:style=>"ime-mode:inactive"} %>-
+ <%= confirm_tag :text_field, :supplier, :tel02, {:class=>"data_s",:style=>"ime-mode:inactive"} %>-
+ <%= confirm_tag :text_field, :supplier, :tel03, {:class=>"data_s",:style=>"ime-mode:inactive"} %>
+ </td>
+ </tr>
+ <tr>
+ <th>FAX</th>
+ <td>
+ <%= confirm_tag :text_field, :supplier, :fax01, {:class => "data_s",:style=>"ime-mode:inactive"} %>-
+ <%= confirm_tag :text_field, :supplier, :fax02, {:class => "data_s",:style=>"ime-mode:inactive"} %>-
+ <%= confirm_tag :text_field, :supplier, :fax03, {:class => "data_s",:style=>"ime-mode:inactive"} %>
+ </td>
+ </tr>
+ <tr>
+ <th>メールアドレス</th>
+ <td><%= confirm_tag :text_field, :supplier, :email, {:class=>"data_m",:style=>"ime-mode:inactive"} %></td>
+ </tr>
+ <tr>
+ <th>商品掛け率</th>
+ <td>
+ <%= confirm_tag :text_field, :supplier, :percentage, {:class=>"data_s",:style=>"ime-mode:inactive"} %> %(100分率)
+ </td>
+ </tr>
+ <tr>
+ <th>税額端数処理</th>
+ <td><%= confirm_select(confirm_tag(:select, :supplier, :tax_rule, Supplier::TAX_RULE_NAMES.map{|a,b|[b,a]}), @supplier.tax_rule_label, "supplier") %></td>
+ </tr>
+ <tr>
+ <th>備考</th>
+ <td>
+ <%= confirm_tag :text_area, :supplier ,:free_comment, {:size=>"60x10",:style=>"ime-mode:active"} %>
+ </td>
+ </tr>
+</table>
+<%= hidden_field_tag "id", params[:id] %>
--- /dev/null
+
+ <table class="data" cellspacing="1">
+ <tr>
+ <th>仕入先ID</th>
+ <td><%= f.text_field :supplier_id,{:class=>"data_m",:style=>"ime-mode:inactive"}%></td>
+ </tr>
+ <tr>
+ <th>仕入先名</th>
+ <td><%= f.text_field :name,{:class=>"data_m",:style=>"ime-mode:active"}%></td>
+ </tr>
+ <tr>
+ <th>担当者名</th>
+ <td><%= f.text_field :contact_name, {:class=>"data_m",:style=>"ime-mode:active"}%></td>
+ </tr>
+ <tr>
+ <th>電話番号</th>
+ <td><%= f.text_field :tel_no, {:class=>"data_m",:style=>"ime-mode:inactive"} %></td>
+ </tr>
+ <tr>
+ <th>ファックス</th>
+ <td><%= f.text_field :fax_no, {:class=>"data_m",:style=>"ime-mode:inactive"} %></td>
+ </tr>
+ <tr>
+ <th>メールアドレス</th>
+ <td><%= f.text_field :email, {:class=>"data_m",:style=>"ime-mode:inactive"} %></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>
--- /dev/null
+<%= render :partial => '/admin/base/depot_submenu' %>
--- /dev/null
+<%= render :partial => "submenu" %>
+
+<div id="main"><!-- メイン -->
+
+<h2>仕入先入力確認</h2>
+<%= flash[:notice] %>
+<%= flash[:errors] %>
+<%= error_messages_for :supplier %>
+
+<p class="req"><span class="pnt">※</span>は必須入力です</p>
+
+<% form_for :supplier do |f| %>
+ <%= render :partial => "form", :locals => {:f => f} %>
+<% end %>
+<div class="btn_box">
+<% form_for([:admin, @supplier],:url=>{:action => ( !params[:id].blank? ? "update" : "create" ), :id => @supplier}, :html=>{:method => ( !params[:id].blank? ? "put" : "post" )}) do%>
+ <% @supplier.attribute_names.each do | column | %>
+ <%= hidden_field "supplier", column.to_s %>
+ <% end %>
+ <%= submit_tag 'この内容で登録する', :class => "btn"%><img width="6" height="34" class="btn_side" alt="" src="/images/btn_side.gif"/>
+<% end %>
+
+<% form_for([:admin, @supplier],:url=>{:action => ( !params[:id].blank? ? "edit" : "new" ), :id => @supplier}, :html=>{:method => "get"}) do%>
+ <% @supplier.attribute_names.each do | column | %>
+ <%= hidden_field "supplier", column.to_s %>
+ <% end %>
+ <%= submit_tag '戻る', :class => "btn"%><img width="6" height="34" class="btn_side" alt="" src="/images/btn_side.gif"/>
+<% end %>
+</div>
+
+</div><!-- /メイン -->
--- /dev/null
+<%= stylesheet_link_tag "admin" %>
+
+<%= render :partial => "submenu" %>
+
+<div id="main"><!-- メイン -->
+
+<h2>仕入先編集</h2>
+
+<%= flash[:notice] %>
+<%= flash[:error] %>
+<%= error_messages_for :supplier %>
+
+<p class="req"><span class="pnt">※</span>は必須入力です</p>
+<% form_for [:admin, @supplier], :url => {:action => 'confirm',:id =>@supplier} do |f| %>
+<%= render :partial => "form", :locals => {:f => f} %>
+<div class="btn_box">
+ <%= submit_tag '確認する', :class => "btn"%><img width="6" height="34" class="btn_side" alt="" src="/images/btn_side.gif"/>
+</div>
+<% end %>
+</div><!-- /メイン -->
+
--- /dev/null
+<%= render :partial => "submenu" %>
+
+<div id="main"><!-- メイン -->
+
+<h2>仕入先マスタ管理</h2>
+<%=h flash[:notice] %>
+<%=h flash[:error] %>
+<%= error_messages_for :condition %>
+
+<% form_for :condition, :url => {:action => 'search'}, :html => {:method => :get} do |f| %>
+ <%= render :partial => "search", :locals=>{:f => f}%>
+<% end %>
+</div><!-- /メイン -->
--- /dev/null
+<%= render :partial => "submenu" %>\r
+\r
+<div id="main"><!-- メイン -->\r
+\r
+<h2>仕入先登録</h2>\r
+<%=h flash[:notice] %>\r
+<%=h flash[:error] %>\r
+<%= error_messages_for :supplier %>\r
+\r
+<p class="req"><span class="pnt">※</span>は必須入力です</p>\r
+<% form_for :product, :url => {:action => "confirm"} do |f| %>\r
+ <%= render :partial => "form", :locals => {:f => f} %>\r
+ <div class="btn_box">\r
+ <%= submit_tag "確認する", :class=>"btn" %>\r
+ <img class="btn_side" width="6" height="34" src="/images/btn_side.gif">\r
+ </div>\r
+<% end %>\r
+\r
+</div><!-- /メイン -->\r
--- /dev/null
+<%= render :partial => "submenu" %>\r
+\r
+<div id="main"><!-- メイン -->\r
+\r
+<h2>仕入先マスタ管理</h2>\r
+<%=h flash[:notice] %>\r
+<%=h flash[:error] %>\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>>>検索結果一覧 <%=@suppliers.total_entries %>件 が該当しました。</p><br/>\r
+<span class="pnt">※ID=1のデータはデフォルトデータとして編集、削除不可です。</span><br/>\r
+<span class="pnt">※商品を持っている仕入先は削除できません。</span><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>e-mail</th>\r
+ <th>編集</th>\r
+ <th>削除</th>\r
+ </tr>\r
+<%unless @suppliers.blank?%> \r
+ <% @suppliers.each do | supplier | %>\r
+ <tr>\r
+ <td><%= h supplier.id %></td>\r
+ <td><%= h supplier.name %></td>\r
+ <td><%= h supplier.contact_name %></td>\r
+ <td><%= h supplier.tel %></td>\r
+ <td><%= h supplier.fax %></td>\r
+ <td><%= h supplier.email %></td>\r
+ <td class="t_center">\r
+ <% if supplier.id != Supplier::DEFAULT_SUPPLIER_ID%>\r
+ <%= link_to "編集", :action=>"edit" ,:id=>supplier.id %>\r
+ <% end%>\r
+ </td>\r
+ <td class="t_center">\r
+ <% if supplier.id != Supplier::DEFAULT_SUPPLIER_ID && supplier.products.blank?%> \r
+ <%= link_to "削除", :action=>"destroy" ,:id=>supplier.id %>\r
+ <% end%> \r
+ </td>\r
+ </tr>\r
+ <% end %>\r
+<%end%>\r
+</table>\r
+<%= will_paginate @suppliers %>\r
+<br/>\r
+<div class="t_center btn_t">\r
+<input type="button" class="btn_s" value="新規登録" onclick="location.href = '/admin/suppliers/new'">\r
+</div>\r
+</div><!-- /メイン -->\r
<ul id="con_menu" class="clearfix">
<li><a href="/admin/shops" id="shop"><img src="/images/store_btn.gif" width="122" height="51" alt="店舗管理" class="hoverImg" /></a></li>
<li><a href="/admin/products" id="product"><img src="/images/goods_btn.gif" width="122" height="51" alt="商品管理" class="hoverImg" /></a></li>
+ <% 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>
+ <%end%>
<li><a href="/"><img src="/images/site_btn.gif" width="122" height="51" alt="サイトを表示" class="hoverImg" /></a></li>
</ul>
<div id="head_r" class="clearfix">
stock_table_entry: "在庫テーブルのエントリ"
style: "規格"
style_category: "規格分類"
+ supplier: "仕入先"
sub_product: "商品情報(サブ)"
system: "システム"
target_column: "ターゲット列"
updated_at: "で更新"
deleted_at: "で削除"
no: "番号"
+ supplier:
+ name: "仕入先名"
+ zipcode01: "郵便番号(前半)"
+ zipcode02: "郵便番号(後半)"
+ tel01: "電話番号1"
+ tel02: "電話番号2"
+ tel03: "電話番号3"
+ fax01: "FAX番号1"
+ fax02: "FAX番号2"
+ fax03: "FAX番号3"
+ address_city: "住所(市町村)"
+ address_detail: "住所(番地・ビル名)"
+ email: "メールアドレス"
+ contact_name: "担当者"
+ percentage: "商品かけ率"
+ free_comment: "備考"
system:
tax: "消費税率"
tax_rule: "消費税規則"
--- /dev/null
+class CreateSuppliers < ActiveRecord::Migration
+ def self.up
+ create_table :suppliers do |t|
+ t.column :name, :string, :comment => '仕入先名'
+ t.column :zipcode01, :string, :comment => "郵便番号(前半)"
+ t.column :zipcode02, :string, :comment => "郵便番号(後半)"
+ t.column :prefecture_id, :integer, :comment => "都道府県ID"
+ t.column :address_city, :string, :comment => "住所(市町村)"
+ t.column :address_detail, :string, :comment => "住所(詳細)"
+ t.column :tel01, :string, :comment => "電話番号1"
+ t.column :tel02, :string, :comment => "電話番号2"
+ t.column :tel03, :string, :comment => "電話番号3"
+ t.column :fax01, :string, :comment => "FAX番号1"
+ t.column :fax02, :string, :comment => "FAX番号2"
+ t.column :fax03, :string, :comment => "FAX番号3"
+ t.column :contact_name, :string, :comment => '仕入先担当者名'
+ t.column :email, :string, :comment => "メールアドレス"
+ t.column :percentage, :integer, :comment => "商品掛け率"
+ t.column :tax_rule, :integer, :comment => "税額端数処理"
+ t.column :free_comment, :text, :comment => "備考"
+ t.column :deleted_at, :datetime, :comment => "削除日"
+ end
+ add_index :suppliers, :deleted_at
+ add_index :suppliers, :name
+ end
+
+ def self.down
+ remove_index :suppliers, :deleted_at
+ remove_index :suppliers, :name
+ drop_table :suppliers
+ end
+end
--- /dev/null
+class AddDataSuppliers < ActiveRecord::Migration
+ def self.up
+ Supplier.delete_all
+ directory = File.join(File.dirname(__FILE__), "fixed_data")
+ Fixtures.create_fixtures(directory, "suppliers")
+ end
+
+ def self.down
+ Supplier.delete_all
+ end
+end
--- /dev/null
+class AddColumnSupplierUseFlagToSystems < ActiveRecord::Migration
+ def self.up
+ add_column :systems, :supplier_use_flag, :boolean,:default => false, :comment => "仕入先使用可否"
+ end
+
+ def self.down
+ remove_columns :systems, :supplier_use_flag
+ end
+end
--- /dev/null
+class AddDataFunctionsVer2 < 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
--- /dev/null
+class AddColumnSupplierIdToProducts < ActiveRecord::Migration
+ def self.up
+ add_column :products, :supplier_id, :integer,:default => 1, :comment => "仕入先ID"
+ Product.update_all("supplier_id = 1")
+ end
+
+ def self.down
+ remove_columns :products, :supplier_id
+ end
+end
--- /dev/null
+class AddManufacturerIdToProductStyles < ActiveRecord::Migration
+ def self.up
+ add_column :product_styles, :manufacturer_id, :string, :comment => "型番"
+ end
+
+ def self.down
+ remove_columns :product_styles, :manufacturer_id
+ end
+end
name: メンバー管理\r
code: "member"\r
position: 900\r
+F901:\r
+ id: 41\r
+ name: 仕入先マスタ\r
+ code: "supplier"\r
+ position: 901
\ No newline at end of file
--- /dev/null
+default_supplier:
+ id: 1
+ name: 'DEFAULT'
+ zipcode01: '000'
+ zipcode02: '0000'
+ prefecture_id: '13'
+ address_city: '-'
+ address_detail: '-'
+ tel01: '000'
+ tel02: '0000'
+ tel03: '0000'
+ contact_name: 'DEFAULT'
\ No newline at end of file
describe Admin::ProductsController do
fixtures :products, :admin_users, :authorities, :functions, :authorities_functions, :admin_users, :categories, :resource_datas, :image_resources
- fixtures :styles, :product_styles, :style_categories
+ fixtures :styles, :product_styles, :style_categories,:suppliers
before do
session[:admin_user] = admin_users(:admin10)
it "code" do
get "search", :search => {:code => "AC001"}
end
-
+ it "code" do
+ get "search", :search => {:supplier => 2}
+ end
it "category" do
get "search", :search => {:category => @valid_product.category_id}
end
--- /dev/null
+require 'spec_helper'
+
+describe Admin::SuppliersController do
+ fixtures :admin_users,:suppliers,:prefectures
+ 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
+ @supplier = suppliers(:one)
+ end
+
+ describe "GET 'index'" do
+ it "成功する" do
+ get 'index'
+ assigns[:suppliers].should_not be_nil
+ end
+ end
+
+ describe "GET 'search'" do
+ before do
+ end
+
+ it "should be successful" do
+ get 'search'
+ response.should be_success
+ end
+
+ it "仕入先ID" do
+ get 'search', :condition => {:supplier_id => '2'}
+ response.should be_success
+ # 結果の中に含まれているか見る
+ assigns[:suppliers].size.should == 1
+ assigns[:suppliers][0].attributes.should == @supplier.attributes
+ end
+
+ it "仕入先名" do
+ get 'search', :condition => {:name => 'てすと'}
+ response.should be_success
+ # 結果の中に含まれているか見る
+ assigns[:suppliers].size.should == 2
+ assigns[:suppliers][0].attributes.should == @supplier.attributes
+ assigns[:suppliers][1].attributes.should == suppliers(:two).attributes
+ end
+
+ it "担当者名" do
+ get 'search', :condition => {:contact_name => "test"}
+ response.should be_success
+ # 結果の中に含まれているか見る
+ assigns[:suppliers].size.should == 1
+ assigns[:suppliers][0].attributes.should == suppliers(:three).attributes
+ end
+
+ it "メールアドレス" do
+ get 'search', :condition => {:email => "test@kbmj.com"}
+ response.should be_success
+ # 結果の中に含まれているか見る
+ assigns[:suppliers].size.should == 0
+ end
+
+ it "電話番号" do
+ get 'search', :condition => {:tel_no => "0311111111"}
+ response.should be_success
+ # 結果の中に含まれているか見る
+ assigns[:suppliers].size.should == 2
+ assigns[:suppliers][0].attributes.should == @supplier.attributes
+ assigns[:suppliers][1].attributes.should == suppliers(:three).attributes
+ end
+ it "電話番号" do
+ get 'search', :condition => {:fax_no => "0399999999"}
+ response.should be_success
+ # 結果の中に含まれているか見る
+ assigns[:suppliers].size.should == 1
+ assigns[:suppliers][0].attributes.should == suppliers(:three).attributes
+ end
+ end
+ describe "GET 'new'" do
+ it "成功" do
+ get 'new'
+ assigns[:supplier].should_not be_nil
+ assigns[:supplier].id.should be_nil
+ end
+ end
+ describe "POST 'confirm'" do
+ it "confirm" do
+ post 'confirm', :supplier =>@supplier.attributes.merge({:name=>"テスト(株)"})
+ assigns[:supplier].name.should == "テスト(株)"
+ assigns[:supplier].contact_name.should == @supplier.contact_name
+ assigns[:supplier].tel01.should == @supplier.tel01
+ assigns[:supplier].tel02.should == @supplier.tel02
+ assigns[:supplier].tel03.should == @supplier.tel03
+ assigns[:supplier].fax01.should == @supplier.fax01
+ assigns[:supplier].fax02.should == @supplier.fax02
+ assigns[:supplier].fax03.should == @supplier.fax03
+ assigns[:supplier].zipcode01.should == @supplier.zipcode01
+ assigns[:supplier].zipcode02.should == @supplier.zipcode02
+ assigns[:supplier].prefecture_id.should == @supplier.prefecture_id
+ assigns[:supplier].address_city.should == @supplier.address_city
+ assigns[:supplier].address_detail.should == @supplier.address_detail
+ assigns[:supplier].email.should == @supplier.email
+ assigns[:supplier].percentage.should == @supplier.percentage
+ assigns[:supplier].free_comment.should == @supplier.free_comment
+
+ response.should render_template("admin/suppliers/confirm.html.erb")
+ #validateエラーがある場合
+ post 'confirm', :supplier => {:name => ""}
+ response.should render_template("admin/suppliers/new.html.erb")
+ end
+ end
+ describe "GET 'edit'" do
+ it "成功するパターン" do
+ get 'edit', :id => @supplier.id
+ assigns[:supplier].should_not be_nil
+ assigns[:supplier].attributes.should == @supplier.attributes
+ end
+
+ it "失敗するパターン" do
+ lambda { get 'edit', :id => 1000 }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ describe "POST 'create'" do
+ it "正常に追加できるパターン" do
+ max_id = Supplier.maximum(:id)
+ post 'create', :supplier => @supplier.attributes.merge({:name=>"テスト(株)"})
+ assigns[:supplier].should_not be_nil
+ assigns[:supplier].id.should > max_id
+ flash[:notice].should == "データを保存しました"
+ response.should redirect_to(:action => :index)
+ end
+
+ it "supplierが不正なパターン" do
+ max_id = Supplier.maximum(:id)
+ post 'create', :supplier => {:name => ""}
+ assigns[:supplier].should_not be_nil
+ assigns[:supplier].id.should be_nil
+ response.should_not be_redirect
+ response.should render_template("admin/suppliers/new.html.erb")
+ end
+ end
+
+ describe "POST 'update'" do
+ it "正常に更新できるパターン" do
+ post 'update', :id => @supplier.id, :supplier => @supplier.attributes.merge(:name=>"(株)テスト")
+ flash[:notice].should == "データを保存しました"
+ #更新後
+ check = Supplier.find_by_id(@supplier.id)
+ check.name.should == "(株)テスト"
+ response.should redirect_to(:action => :index)
+ end
+
+ it "supplierが不正なパターン" do
+ post 'update', :id => @supplier.id, :supplier => {:name => ""}
+ check = Supplier.find_by_id(@supplier.id)
+ check.attributes.should == @supplier.attributes
+ response.should_not be_redirect
+ response.should render_template("admin/suppliers/edit.html.erb")
+ end
+ end
+ describe "POST 'destroy'" do
+ it "成功に削除" do
+ Supplier.find_by_id(3).should_not be_nil
+ post 'destroy', :id => 3
+ Supplier.find_by_id(3).should be_nil
+ end
+ it "ID=2のデータは商品を持っているので削除不可" do
+ lambda { post 'destroy', :id => @supplier.id }.should raise_error(ActiveRecord::ReadOnlyRecord)
+ end
+ it "ID=1のデータが削除不可" do
+ lambda { post 'destroy', :id => 1 }.should raise_error(ActiveRecord::ReadOnlyRecord)
+ end
+ end
+end
style_id: 7
created_at: 2009-10-01 00:00:00
updated_at: 2009-10-01 00:00:00
+ supplier_id: 2
#未公開商品 +CSVアップロード元データとして使用
not_permit_product:
id: 17
--- /dev/null
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+default:
+ id: 1
+one:
+ id: 2
+ name: 'てすと(株)'
+ contact_name: 'てすと太郎'
+ zipcode01: '103'
+ zipcode02: '0003'
+ prefecture_id: 13
+ address_city: '東京都テスト区テスト町'
+ address_detail: '2-2-2'
+ tel01: '03'
+ tel02: '1111'
+ tel03: '1111'
+two:
+ id: 3
+ name: 'てすと'
+ contact_name: 'てすとてすと'
+ zipcode01: '103'
+ zipcode02: '0003'
+ prefecture_id: 13
+ address_city: '東京都テスト区テスト町'
+ address_detail: '2-2-2'
+ tel01: '03'
+ tel02: '1111'
+ tel03: '2222'
+three:
+ id: 4
+ name: 'test'
+ contact_name: 'testtest'
+ zipcode01: '103'
+ zipcode02: '0003'
+ prefecture_id: 13
+ address_city: '東京都テスト区テスト町'
+ address_detail: '2-2-2'
+ tel01: '03'
+ tel02: '1111'
+ tel03: '1111'
+ fax01: '03'
+ fax02: '9999'
+ fax03: '9999'
\ No newline at end of file
--- /dev/null
+require 'spec_helper'
+
+describe Admin::SuppliersHelper 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::SuppliersHelper)
+ end
+
+end
require File.dirname(__FILE__) + '/../spec_helper'
describe Category do
- fixtures :categories, :products, :image_resources
+ fixtures :categories, :products, :image_resources,:suppliers
before(:each) do
@category = categories(:dai_category)
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Product do
- fixtures :products, :image_resources, :product_statuses,:categories,:product_styles,:statuses
+ fixtures :products, :image_resources, :product_statuses,:categories,:product_styles,:statuses,:suppliers
include ActionView::Helpers::NumberHelper
product = Product.new(:category_id =>categories(:dai_category).id)
product.category_name.should == categories(:dai_category).name
end
+ it "仕入先名" do
+ product = Product.new(:supplier_id =>suppliers(:one).id)
+ product.supplier_name.should == suppliers(:one).name
+ end
end
describe "その他" do
it "送料無料判断" do
#画像IDがすべて18
#元データ
- #products.ymlの最後ID:23
- #image_resoures.ymlの最後ID:70
cnt_image_b = ImageResource.count
cnt_image_data_b = ResourceData.count
cnt_product_b = Product.count
Product.add_by_csv(File.read("#{RAILS_ROOT}/spec/product_csv_upload_image_for_spec.csv"))
#期待結果
- #商品データが2件増加
- #1件:小画像ID=18、中画像IDが新規作成(72)、大画像ID=18
- #1件:小画像IDが新規作成(71)、中画像ID=18、大画像ID=nil
+ #商品データが1件更新、1件増加、
+ #1件:小画像ID=18、中画像IDが新規作成、大画像ID=18
+ #1件:小画像IDが新規作成、中画像ID=18、大画像ID=nil
#image_resourceのデータ数が2件増やす
#resource_dataのデータ数が2件増やす
cnt_image_a = ImageResource.count
cnt_image_data_a = ResourceData.count
cnt_product_a = Product.count
- (cnt_product_a - cnt_product_b).should == 2
- #1件目
- max_id += 1
- product = Product.find_by_id(max_id)
- product.should_not be_nil
-
+ (cnt_product_a - cnt_product_b).should == 1
+ #1件目更新
+ product = Product.find_by_id(17)
+ product.small_resource_id.should == 18
+ product.large_resource_id.should == 18
+ #2件目追加
+ product2 = Product.find(:last)
product.medium_resource_id.should == 18
- product.large_resource_id.should be_nil
-
- #2件目
- max_id += 1
- product2 = Product.find_by_id(max_id)
- product2.should_not be_nil
- product2.small_resource_id.should_not be_nil
- product2.small_resource_id.should == 18
- product2.large_resource_id.should == 18
+ product2.large_resource_id.should be_nil
#CSV画像アップテストは環境により結果が異なるので、ここでテストコードをコメントアウトする
pending("CSV画像アップテストは環境により結果が異なるので、ここで関連テストコードをコメントアウトする") do
# (cnt_image_a - cnt_image_b).should == 2
@product_style.style_category1 = nil
@product_style.should_not be_valid
end
-
+ it "型番" do
+ #非必須
+ @product_style.manufacturer_id = nil ;
+ @product_style.should be_valid
+ #フォーマット
+ @product_style.manufacturer_id = "aあ" ;
+ @product_style.should_not be_valid
+ @product_style.manufacturer_id = "abc123" ;
+ @product_style.should be_valid
+ end
end
describe "金額計算系" do
it "税込販売額" do
--- /dev/null
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe SupplierSearchForm do
+ fixtures :suppliers
+ before(:each) do
+ @search_form = SupplierSearchForm.new
+ end
+ describe "validateチェック" do
+ it "データがただしい" do
+ @search_form.should be_valid
+ end
+ it "仕入先ID(数字)" do
+ @search_form.supplier_id = 123456
+ @search_form.should be_valid
+ @search_form.supplier_id = "abc"
+ @search_form.should_not be_valid
+ end
+ it "メールアドレス(英数字)" do
+ @search_form.email = "abc"
+ @search_form.should be_valid
+ @search_form.email = "a_bc@email.com"
+ @search_form.should be_valid
+ @search_form.email = "あ"
+ @search_form.should_not be_valid
+ end
+ it "電話番号(数字)" do
+ @search_form.tel_no = "abc"
+ @search_form.should_not be_valid
+ @search_form.tel_no = 123
+ @search_form.should be_valid
+ end
+ it "ファックス番号(数字)" do
+ @search_form.fax_no = "abc"
+ @search_form.should_not be_valid
+ @search_form.fax_no = "0311110001"
+ @search_form.should be_valid
+ end
+ end
+end
--- /dev/null
+require 'spec_helper'
+
+describe Supplier do
+ fixtures :suppliers
+ before(:each) do
+ @supplier = suppliers(:one)
+ end
+
+ describe "validateチェック" do
+ it "データが正しい" do
+ @supplier.should be_valid
+ end
+ it "仕入先名" do
+ #必須
+ @supplier.name = ""
+ @supplier.should_not be_valid
+ #文字数
+ @supplier.name = "あ" * 50
+ @supplier.should be_valid
+ @supplier.name = "あ" * 51
+ @supplier.should_not be_valid
+ end
+ it "担当者名" do
+ #必須
+ @supplier.contact_name = ""
+ @supplier.should_not be_valid
+ #文字数
+ @supplier.contact_name = "あ" * 50
+ @supplier.should be_valid
+ @supplier.contact_name = "あ" * 51
+ @supplier.should_not be_valid
+ end
+ it "住所" do
+ @supplier.address_city = ""
+ @supplier.should_not be_valid
+
+ @supplier.address_city = "あ" * 101
+ @supplier.should_not be_valid
+
+ @supplier.address_city = "あ" * 100
+ @supplier.should be_valid
+
+ @supplier.address_detail = ""
+ @supplier.should_not be_valid
+
+ @supplier.address_detail = "a" * 101
+ @supplier.should_not be_valid
+
+ @supplier.address_detail = "a" * 100
+ @supplier.should be_valid
+ end
+ it "電話番号1" do
+ #必須
+ @supplier.tel01 = nil
+ @supplier.should_not be_valid
+ #数字
+ @supplier.tel01 = "aaa"
+ @supplier.should_not be_valid
+ #桁数
+ @supplier.tel01 = "1" * 7
+ @supplier.should_not be_valid
+ @supplier.tel01 = "1" * 6
+ @supplier.should be_valid
+ end
+ it "電話番号2" do
+ #必須
+ @supplier.tel02 = nil
+ @supplier.should_not be_valid
+ #数字
+ @supplier.tel02 = "aaa"
+ @supplier.should_not be_valid
+ #桁数
+ @supplier.tel02 = "1" * 7
+ @supplier.should_not be_valid
+ @supplier.tel02 = "1" * 6
+ @supplier.should be_valid
+ end
+ it "電話番号3" do
+ #必須
+ @supplier.tel03 = nil
+ @supplier.should_not be_valid
+ #数字
+ @supplier.tel03 = "aaa"
+ @supplier.should_not be_valid
+ #桁数
+ @supplier.tel03 = "1" * 7
+ @supplier.should_not be_valid
+ @supplier.tel03 = "1" * 6
+ @supplier.should be_valid
+ end
+ it "郵便番号(前半)" do
+ #必須
+ @supplier.zipcode01 = nil
+ @supplier.should_not be_valid
+ #数字
+ @supplier.zipcode01 = "aaa"
+ @supplier.should_not be_valid
+ #桁数
+ @supplier.zipcode01 = "1034"
+ @supplier.should_not be_valid
+ @supplier.zipcode01 = "103"
+ @supplier.should be_valid
+ end
+ it "郵便番号(後半)" do
+ #必須
+ @supplier.zipcode02 = nil
+ @supplier.should_not be_valid
+ #数字
+ @supplier.zipcode02 = "aaa"
+ @supplier.should_not be_valid
+ #桁数
+ @supplier.zipcode02 = "001"
+ @supplier.should_not be_valid
+ @supplier.zipcode02 = "0001"
+ @supplier.should be_valid
+ end
+ it "FAX番号" do
+ #数字
+ @supplier.fax01 = 'abc'
+ @supplier.fax02 = 'defg'
+ @supplier.fax03 = 'hijk'
+ @supplier.should have(1).errors_on(:fax01)
+ @supplier.should have(1).errors_on(:fax02)
+ @supplier.should have(1).errors_on(:fax03)
+ #入力の場合、3か所とも
+ @supplier.fax01 = nil
+ @supplier.fax02 = '1111'
+ @supplier.fax03 = '2222'
+ @supplier.should_not be_valid
+ end
+ it "メールアドレス" do
+ #フォーマット
+ @supplier.email = "aaa"
+ @supplier.should_not be_valid
+ end
+ it "備考" do
+ #桁数
+ @supplier.free_comment = "a" * 10000
+ @supplier.should be_valid
+ @supplier.free_comment = "a" * 10001
+ @supplier.should_not be_valid
+ end
+ it "商品かけ率" do
+ @supplier.percentage = 101
+ @supplier.should_not be_valid
+ @supplier.percentage = "aaa"
+ @supplier.should_not be_valid
+ @supplier.percentage = -1
+ @supplier.should_not be_valid
+ @supplier.percentage = 0
+ @supplier.should be_valid
+ @supplier.percentage = 100
+ @supplier.should be_valid
+ end
+ it "税額端数処理" do
+ @supplier.tax_rule = 3
+ @supplier.should_not be_valid
+ @supplier.tax_rule = "aaa"
+ @supplier.should_not be_valid
+ @supplier.tax_rule = -1
+ @supplier.should_not be_valid
+ @supplier.tax_rule = 0
+ @supplier.should be_valid
+ @supplier.tax_rule = 2
+ @supplier.should be_valid
+ end
+ end
+ describe "その他" do
+ fixtures :prefectures
+ it "都道県府名" do
+ supplier = Supplier.new(:prefecture_id =>11)
+ supplier.prefecture_name.should == prefectures(:prefecture_00011).name
+ end
+ end
+
+end
-\8f¤\95iID,\8cö\8aJ\90Ý\92è,\96¼\91O,\8eQ\8fÆURL,\88ê\97\97\83R\83\81\83\93\83g,\8fÚ\8d×\83R\83\81\83\93\83g,\83L\81[\83\8f\81[\83h,\8es\8fê\8eQ\8dl\89¿\8ai,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9cID,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9c\83R\83\81\83\93\83g,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9c\83p\83X,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9cID,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9c\83R\83\81\83\93\83g,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9c\83p\83X,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9cID,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9c\83R\83\81\83\93\83g,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9c\83p\83X,\8dw\93ü\90§\8cÀ,\83|\83C\83\93\83g\95t\97^\97¦,\94Ì\94\84\8aJ\8en\93ú,\94Ì\94\84\8fI\97¹\93ú,\8f¤\95i\83J\83e\83S\83\8a,\93ü\89×\97\\92è\93ú,\83T\83C\83Y,\91f\8dÞ,\8c´\8eY\92n,\8fd\82³,\93ü\89×\93ú,\82»\82Ì\91¼\8ed\97l,\83t\83\8a\81[\93ü\97Í,\94z\91\97\93ú,\93o\98^\93ú,\8dX\90V\93ú\r
-17,\94ñ\8cö\8aJ,\89º\92\85,,\83e\83X\83g01,\83e\83X\83g01,\83t\83@\83b\83V\83\87\83\93,5000,18,,,18,,,,,,,,,,\91å\83J\83e\83S\83\8a,2009/10/1,,,japan,,,,,3\93ú\8cã,,\r
-,\8cö\8aJ,\83\8d\83\93\83O\83R\81[\83g,,\83e\83X\83g02,\83e\83X\83g02,\83t\83@\83b\83V\83\87\83\93,15000,18,,,18,,,,,,,,,,\91å\83J\83e\83S\83\8a,2009/10/1,,,english,,,,,,,\r
+\8f¤\95iID,\8cö\8aJ\90Ý\92è,\96¼\91O,\8eQ\8fÆURL,\88ê\97\97\83R\83\81\83\93\83g,\8fÚ\8d×\83R\83\81\83\93\83g,\83L\81[\83\8f\81[\83h,\8es\8fê\8eQ\8dl\89¿\8ai,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9cID,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9c\83R\83\81\83\93\83g,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9c\83p\83X,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9cID,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9c\83R\83\81\83\93\83g,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9c\83p\83X,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9cID,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9c\83R\83\81\83\93\83g,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9c\83p\83X,\8dw\93ü\90§\8cÀ,\83|\83C\83\93\83g\95t\97^\97¦,\94Ì\94\84\8aJ\8en\93ú,\94Ì\94\84\8fI\97¹\93ú,\8f¤\95i\83J\83e\83S\83\8a,\93ü\89×\97\\92è\93ú,\83T\83C\83Y,\91f\8dÞ,\8c´\8eY\92n,\8fd\82³,\93ü\89×\93ú,\82»\82Ì\91¼\8ed\97l,\83t\83\8a\81[\93ü\97Í,\94z\91\97\93ú,\8ed\93ü\90æ\96¼,\93o\98^\93ú,\8dX\90V\93ú\r
+17,\94ñ\8cö\8aJ,\89º\92\85,,\83e\83X\83g01,\83e\83X\83g01,\83t\83@\83b\83V\83\87\83\93,5000,18,,,18,,,,,,,,,,\91å\83J\83e\83S\83\8a,2009/10/1,,,japan,,,,,3\93ú\8cã,,,\r
+,\8cö\8aJ,\83\8d\83\93\83O\83R\81[\83g,,\83e\83X\83g02,\83e\83X\83g02,\83t\83@\83b\83V\83\87\83\93,15000,18,,,18,,,,,,,,,,\91å\83J\83e\83S\83\8a,2009/10/1,,,english,,,,,,\82Ä\82·\82Æ\81i\8a\94\81j,,\r
-\8f¤\95iID,\8cö\8aJ\90Ý\92è,\96¼\91O,\8eQ\8fÆURL,\88ê\97\97\83R\83\81\83\93\83g,\8fÚ\8d×\83R\83\81\83\93\83g,\83L\81[\83\8f\81[\83h,\8es\8fê\8eQ\8dl\89¿\8ai,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9cID,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9c\83R\83\81\83\93\83g,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9c\83p\83X,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9cID,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9c\83R\83\81\83\93\83g,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9c\83p\83X,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9cID,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9c\83R\83\81\83\93\83g,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9c\83p\83X,\8dw\93ü\90§\8cÀ,\83|\83C\83\93\83g\95t\97^\97¦,\94Ì\94\84\8aJ\8en\93ú,\94Ì\94\84\8fI\97¹\93ú,\8f¤\95i\83J\83e\83S\83\8a,\93ü\89×\97\\92è\93ú,\83T\83C\83Y,\91f\8dÞ,\8c´\8eY\92n,\8fd\82³,\93ü\89×\93ú,\82»\82Ì\91¼\8ed\97l,\83t\83\8a\81[\93ü\97Í,\94z\91\97\93ú,\93o\98^\93ú,\8dX\90V\93ú\r
-,\94ñ\8cö\8aJ,\89º\92\85,,\83e\83X\83g01,\83e\83X\83g01,\83t\83@\83b\83V\83\87\83\93,5000,18,,,18,,sea1.PNG,18,,,,,,,\91å\83J\83e\83S\83\8a,2009/10/1,,,japan,,,,,,,,,,2012/10/30 0:00,2009/10/1 0:00,2012/10/30 0:00,2009/10/1 0:00\r
-,\8cö\8aJ,\83\8d\83\93\83O\83R\81[\83g,,\83e\83X\83g02,\83e\83X\83g02,\83t\83@\83b\83V\83\87\83\93,15000,18,,sea1.PNG,18,,,,,,,,,,\91å\83J\83e\83S\83\8a,2009/10/1,,,english,,,,,,,,,2012/10/30 0:00,2009/10/1 0:00,2012/10/30 0:00,2009/10/1 0:00
+\8f¤\95iID,\8cö\8aJ\90Ý\92è,\96¼\91O,\8eQ\8fÆURL,\88ê\97\97\83R\83\81\83\93\83g,\8fÚ\8d×\83R\83\81\83\93\83g,\83L\81[\83\8f\81[\83h,\8es\8fê\8eQ\8dl\89¿\8ai,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9cID,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9c\83R\83\81\83\93\83g,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9c\83p\83X,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9cID,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9c\83R\83\81\83\93\83g,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9c\83p\83X,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9cID,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9c\83R\83\81\83\93\83g,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9c\83p\83X,\8dw\93ü\90§\8cÀ,\83|\83C\83\93\83g\95t\97^\97¦,\94Ì\94\84\8aJ\8en\93ú,\94Ì\94\84\8fI\97¹\93ú,\8f¤\95i\83J\83e\83S\83\8a,\93ü\89×\97\\92è\93ú,\83T\83C\83Y,\91f\8dÞ,\8c´\8eY\92n,\8fd\82³,\93ü\89×\93ú,\82»\82Ì\91¼\8ed\97l,\83t\83\8a\81[\93ü\97Í,\94z\91\97\93ú,\8ed\93ü\90æ\96¼,\93o\98^\93ú,\8dX\90V\93ú\r
+17,\94ñ\8cö\8aJ,\89º\92\85,,\83e\83X\83g01,\83e\83X\83g01,\83t\83@\83b\83V\83\87\83\93,5000,18,,,18,,sea1.PNG,18,,,,,,,\91å\83J\83e\83S\83\8a,2009/10/1,,,japan,,,,,,,,\r
+,\8cö\8aJ,\83\8d\83\93\83O\83R\81[\83g,,\83e\83X\83g02,\83e\83X\83g02,\83t\83@\83b\83V\83\87\83\93,15000,18,,sea1.PNG,18,,,,,,,,,,\91å\83J\83e\83S\83\8a,2009/10/1,,,english,,,,,,,,\r
-\8f¤\95iID,\8cö\8aJ\90Ý\92è,\96¼\91O,\8eQ\8fÆURL,\88ê\97\97\83R\83\81\83\93\83g,\8fÚ\8d×\83R\83\81\83\93\83g,\83L\81[\83\8f\81[\83h,\8eQ\8dl\8es\8fê\89¿\8ai,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9cID,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9c\83R\83\81\83\93\83g,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9c\83p\83X,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9cID,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9c\83R\83\81\83\93\83g,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9c\83p\83X,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9cID,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9c\83R\83\81\83\93\83g,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9c\83p\83X,\8dw\93ü\90§\8cÀ,\83|\83C\83\93\83g\95t\97^\97¦,\94Ì\94\84\8aJ\8en\93ú,\94Ì\94\84\8fI\97¹\93ú,\8f¤\95i\83J\83e\83S\83\8a,\93ü\89×\97\\92è\93ú,\83T\83C\83Y,\91f\8dÞ,\8c´\8eY\8d\91,\8fd\82³,\93ü\89×\93ú,\82»\82Ì\91¼\8ed\97l,\83t\83\8a\81[\93ü\97Í,\94z\91\97\93ú,\93o\98^\93ú,\8dX\90V\93ú\r
-18,\8cö\8aJ,\83X\83J\81[\83g,,\83e\83X\83g,\83e\83X\83g,,1000,70,,,69,,,,,,,,2009/10/1 9:00,2012/10/1 9:00,\91å\83J\83e\83S\83\8a,2009/10/1 9:00,,,,,,,,,2009/12/8 19:01,2009/12/8 19:01\r
-,\8cö\8aJ,\83X\83J\81[\83g,,\83e\83X\83g,\83e\83X\83g,,1000,70,,,69,,,,,,,,2009/10/1 9:00,2012/10/1 9:00,\91å\83J\83e\83S\83\8a,2009/10/1 9:00,,,,,,,,,2009/12/8 19:01,2009/12/8 19:01\r
+\8f¤\95iID,\8cö\8aJ\90Ý\92è,\96¼\91O,\8eQ\8fÆURL,\88ê\97\97\83R\83\81\83\93\83g,\8fÚ\8d×\83R\83\81\83\93\83g,\83L\81[\83\8f\81[\83h,\8eQ\8dl\8es\8fê\89¿\8ai,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9cID,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9c\83R\83\81\83\93\83g,\88ê\97\97\81E\83\81\83C\83\93\89æ\91\9c\83p\83X,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9cID,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9c\83R\83\81\83\93\83g,\8fÚ\8d×\81E\83\81\83C\83\93\89æ\91\9c\83p\83X,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9cID,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9c\83R\83\81\83\93\83g,\8fÚ\8d×\81E\83\81\83C\83\93\8ag\91å\89æ\91\9c\83p\83X,\8dw\93ü\90§\8cÀ,\83|\83C\83\93\83g\95t\97^\97¦,\94Ì\94\84\8aJ\8en\93ú,\94Ì\94\84\8fI\97¹\93ú,\8f¤\95i\83J\83e\83S\83\8a,\93ü\89×\97\\92è\93ú,\83T\83C\83Y,\91f\8dÞ,\8c´\8eY\8d\91,\8fd\82³,\93ü\89×\93ú,\82»\82Ì\91¼\8ed\97l,\83t\83\8a\81[\93ü\97Í,\94z\91\97\93ú,\8ed\93ü\90æ\96¼,\93o\98^\93ú,\8dX\90V\93ú\r
+18,\8cö\8aJ,\83X\83J\81[\83g,,\83e\83X\83g,\83e\83X\83g,,1000,70,,,69,,,,,,,,2009/10/1 9:00,2012/10/1 9:00,\91å\83J\83e\83S\83\8a,2009/10/1 9:00,,,,,,,,,,2009/12/8 19:01,2009/12/8 19:01\r
+,\8cö\8aJ,\83X\83J\81[\83g,,\83e\83X\83g,\83e\83X\83g,,1000,70,,,69,,,,,,,,2009/10/1 9:00,2012/10/1 9:00,\91å\83J\83e\83S\83\8a,2009/10/1 9:00,,,,,,,,,,2009/12/8 19:01,2009/12/8 19:01\r