class CreateSales < ActiveRecord::Migration

  def self.up
    create_table "sales", :force => true do |t|
      t.integer  "rev_number",               :comment => 'リビジョン番号'
      t.integer  "accept_order_id",          :comment => '受注番号'
      t.integer  "purchase_id",              :comment => '仕入番号'
      t.integer  "sale_id",                  :comment => '赤黒元伝票番号'
      t.integer  "rev_number",               :comment => 'リビジョン番号'
      t.date     "input_date",               :comment => '入力日'
      t.date     "target_date",              :comment => '処理日'
      t.date     "operate_date",             :comment => '使用日'
      t.integer  "user_id",                  :comment => '入力者'
      t.integer  "section_id",               :comment => '入力者部署'
      t.column   "sale_trigger_code",        :"SMALLINT(6)", :comment => '売上要因'
      t.column   "sale_type_code",           :"SMALLINT(6)", :comment => '売上区分'
      t.integer  "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.integer  "supplier_id",              :comment => '在庫主'
      t.string   "customer_order_number",    :limit => 40, :comment => '注文番号'
      t.integer  "charge_customer_id",       :comment => '請求先'
      t.integer  "charge_customer_group_id", :comment => '請求先グループ'
      t.column   "sale_sheet_type_code",     :"SMALLINT(6)", :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.string   "sale_note",                :limit => 200, :comment => '伝票備考'
      t.column   "invalid_flag_code",        :"SMALLINT(6)", :comment => '削除フラグ'
      t.datetime "print_sheet_date",         :comment => '伝票印刷日時'
      t.datetime "deleted_at",               :comment => '削除日時'
      t.datetime "created_at",               :comment => '作成日時'
      t.datetime "updated_at",               :comment => '更新日時'
    end
    execute "ALTER TABLE sales COMMENT = '売上'"
    add_index 'sales', ['accept_order_id'], :name => 'accept_order_id'
    add_index 'sales', ['purchase_id'], :name => 'purchase_id'
    add_index 'sales', ['target_date'], :name => 'target_date'
    add_index 'sales', ['warehouse_id'], :name => 'warehouse_id'
    add_index 'sales', ['user_position_id'], :name => 'user_position_id'
    add_index 'sales', ['sales_user_id'], :name => 'sales_user_id'
    add_index 'sales', ['sales_area_id'], :name => 'sales_area_id'
    add_index 'sales', ['sales_section_id'], :name => 'sales_section_id'
    add_index 'sales', ['customer_id'], :name => 'customer_id'
    add_index "sales", ['supplier_id'], :name => 'supplier_id'
    add_index 'sales', ['charge_customer_id'], :name => 'charge_customer_id'
    add_index "sales", ["sale_type_code"], :name => "sale_type_code"
  end

  def self.down
    drop_table :sales
  end

end
