class CreatePurchases < ActiveRecord::Migration

  def self.up
    create_table "purchases", :force => true do |t|
      t.integer  "accept_order_id",         :comment => '受注番号'
      t.integer  "order_id",                :comment => '発注番号'
      t.integer  "purchase_id",             :comment => '赤黒元伝票番号'
      t.integer  "arriving_id",             :comment => '入荷番号'
      t.integer  "rev_number",              :comment => 'リビジョン番号'
      t.date     "input_date",              :comment => '入力日'
      t.date     "target_date",             :comment => '処理日'
      t.integer  "user_id",                 :comment => '入力者'
      t.integer  "section_id",              :comment => '入力者部署'
      t.column   "purchase_trigger_code",   :"SMALLINT(6)", :comment => '仕入要因'
      t.column   "purchase_type_code",      :"SMALLINT(6)", :comment => '仕入区分'
      t.integer  "supplier_id",             :comment => '仕入先'
      t.integer  "payto_supplier_id",       :comment => '支払先'
      t.integer  "payto_supplier_group_id", :comment => '支払先グループ'
      t.string   "invoice_number",          :limit => 20, :comment => '仕入先番号'
      t.integer  "warehouse_id",            :comment => '納品先'
      t.integer  "own_warehouse_id",        :comment => '入庫先'
      t.integer  "user_position_id",        :comment => '営業担当者'
      t.integer  "sales_user_id",           :comment => '担当者'
      t.integer  "sales_area_id",           :comment => '営業エリア'
      t.integer  "sales_section_id",        :comment => '営業部署'
      t.integer  "customer_id",             :comment => '得意先'
      t.column   "currency_type_code",      :"SMALLINT(6)", :comment => '通貨'
      t.decimal  "exchange_rate",           :precision => 16, :scale => 2, :comment => '為替レート'
      t.integer  "total_price",             :comment => '合計金額'
      t.integer  "total_duty",              :comment => '消費税'
      t.column   "duty_type_code",          :"SMALLINT(6)", :comment => '課税'
      t.integer  "duty_rate",               :comment => '税率'
      t.column   "price_duty_type_code",    :"SMALLINT(6)", :comment => '価格課税方式'
      t.column   "duty_calc_type_code",     :"SMALLINT(6)", :comment => '税計算方式'
      t.column   "frac_digit_code",         :"SMALLINT(6)", :comment => '端数処理桁'
      t.column   "fraction_method_code",    :"SMALLINT(6)", :comment => '端数処理方式'
      t.column   "unit_price_fraction_method_code",    :"SMALLINT(6)", :comment => '単価端数処理方式'
      t.column   "price_fraction_method_code",         :"SMALLINT(6)", :comment => '金額端数処理方式'
      t.column   "sign_type_code",          :"SMALLINT(6)", :comment => '赤黒'
      t.column   "cutoff_date_code",        :"SMALLINT(6)", :comment => '締日'
      t.column   "charge_timing_code",      :"SMALLINT(6)", :comment => '仕入時期'
      t.integer  "total_quantity",          :comment => '総数'
      t.column   "state_code",              :"SMALLINT(6)", :comment => '状態'
      t.string   "note",                    :limit => 200, :comment => '備考'
      t.column   "invalid_flag_code",       :"SMALLINT(6)", :comment => '削除フラグ'
      t.datetime "print_check_date",        :comment => '記録票印刷日時'
      t.datetime "print_lot_date",          :comment => '識別票印刷日時'
      t.datetime "deleted_at",              :comment => '削除日時'
      t.datetime "created_at",              :comment => '作成日時'
      t.datetime "updated_at",              :comment => '更新日時'
    end
    execute "ALTER TABLE purchases COMMENT = '仕入'"
    add_index 'purchases', ['accept_order_id'], :name => 'accept_order_id'
    add_index 'purchases', ['order_id'], :name => 'order_id'
    add_index 'purchases', ['target_date'], :name => 'target_date'
    add_index 'purchases', ['supplier_id'], :name => 'supplier_id'
    add_index 'purchases', ['payto_supplier_id'], :name => 'payto_supplier_id'
    add_index 'purchases', ['warehouse_id'], :name => 'warehouse_id'
    add_index 'purchases', ['user_position_id'], :name => 'user_position_id'
    add_index 'purchases', ['sales_user_id'], :name => 'sales_user_id'
    add_index 'purchases', ['sales_area_id'], :name => 'sales_area_id'
    add_index 'purchases', ['sales_section_id'], :name => 'sales_section_id'
    add_index 'purchases', ['customer_id'], :name => 'customer_id'
    add_index 'purchases', ['invalid_flag_code'], :name => 'invalid_flag_code'
    add_index "purchases", ["purchase_type_code"], :name => "purchase_type_code"
  end

  def self.down
    drop_table :purchases
  end

end
