class AddInvTables < ActiveRecord::Migration[6.0]
  def change
    drop_table :billing_companies, if_exists: true
    drop_table :billing_lines, if_exists: true
    drop_table :billing_settings, if_exists: true
    drop_table :billing_types, if_exists: true
    drop_table :billings, if_exists: true
    drop_table :discount_types, if_exists: true
    drop_table :payment_lines, if_exists: true
    drop_table :payments, if_exists: true
    drop_table :right_owners, if_exists: true
    drop_table :simulations, if_exists: true
    drop_table :statement_lines, if_exists: true
    drop_table :statements, if_exists: true

    create_table "inv_billing_companies" do |t|
      t.string "billing_company"
      t.string "billing_address"
      t.string "billing_zip_code"
      t.string "billing_city"
      t.integer "billing_country_id"
      t.string "billing_email"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
      t.string "billing_phone"
      t.string "billing_complement"
      t.integer "discount"
      t.integer "vat_id"
      t.string "vat_number"
      t.boolean "distributor", default: false, null: false
      t.string "bank_account"
      t.integer "payment_type_id"
      t.integer "time_limit"
      t.boolean "end_of_month", default: false, null: false
      t.string "siret"
      t.integer "title_id"
    end

    create_table "inv_billing_lines", id: :integer, unsigned: true do |t|
      t.integer "billing_id", null: false
      t.integer "product_type_id", null: false
      t.integer "image_id"
      t.text "description"
      t.integer "right_owner_id"
      t.integer "photographer_rate"
      t.integer "quantity", default: 1, null: false
      t.decimal "price_ht", precision: 10, scale: 3, default: "0.0", null: false
      t.decimal "vat", precision: 10, scale: 3, default: "0.0", null: false
      t.decimal "discount", precision: 10, scale: 3, default: "0.0", null: false
      t.decimal "total_ht", precision: 10, scale: 3, default: "0.0", null: false
      t.decimal "total_ttc", precision: 10, scale: 3, default: "0.0", null: false
      t.boolean "retribution", default: false, null: false, unsigned: true
    end

    create_table "inv_billing_settings", id: :integer, unsigned: true do |t|
      t.string "type", default: "", null: false
      t.string "code"
      t.string "name", default: "", null: false
      t.integer "ordering", default: 0, null: false
      t.decimal "amount", precision: 10, scale: 3
      t.boolean "retribution"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
      t.integer "ttv_id"
      t.integer "ctv_id"
      t.date "application_date"
      t.boolean "photo"
      t.index ["type"], name: "type"
    end

    create_table "inv_billing_types" do |t|
      t.string "name", null: false
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
    end

    create_table "inv_billings", id: :integer, unsigned: true do |t|
      t.integer "billing_type_id", null: false
      t.string "number"
      t.string "sub_number"
      t.integer "billing_company_id"
      t.date "date"
      t.date "deadline"
      t.decimal "paid", precision: 10, scale: 3, default: "0.0", null: false
      t.integer "discount_type_id", null: false
      t.text "conditions"
      t.decimal "total", precision: 10, scale: 3, default: "0.0", null: false
      t.decimal "discount", precision: 10, scale: 3, default: "0.0", null: false
      t.decimal "total_ht", precision: 10, scale: 3, default: "0.0", null: false
      t.decimal "general_discount", precision: 10, scale: 3, default: "0.0", null: false
      t.decimal "total_ht_final", precision: 10, scale: 3, default: "0.0", null: false
      t.decimal "vat", precision: 10, scale: 3, default: "0.0", null: false
      t.decimal "total_ttc", precision: 10, scale: 3, default: "0.0", null: false
      t.string "state", default: "", null: false
      t.text "heading"
    end

    create_table "inv_discount_types" do |t|
      t.string "name", null: false
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
    end

    create_table "inv_payment_lines", id: :integer, unsigned: true do |t|
      t.integer "payment_id", null: false
      t.integer "billing_id", null: false
      t.decimal "amount", precision: 10, scale: 3, default: "0.0", null: false
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
    end

    create_table "inv_payments", id: :integer, unsigned: true do |t|
      t.integer "billing_company_id"
      t.integer "payment_type_id", null: false
      t.date "payment_date", null: false
      t.decimal "total", precision: 10, scale: 3, default: "0.0", null: false
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
    end

    create_table "inv_right_owners" do |t|
      t.string "first_name"
      t.string "last_name"
      t.string "complement"
      t.string "address"
      t.string "zip_code"
      t.string "city"
      t.integer "country_id"
      t.string "phone"
      t.string "mobile"
      t.string "email"
      t.integer "language_id"
      t.integer "right_owner_type_id"
      t.integer "provider_id"
      t.integer "currency_id"
      t.integer "france_rate", default: 0, null: false
      t.integer "foreign_rate", default: 0, null: false
      t.boolean "avp", default: false, null: false
      t.boolean "csg", default: false, null: false
      t.integer "vat_id"
      t.integer "withholding_tax_id"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
      t.string "creator_label"
      t.string "author_code"
      t.string "social_security_number"
      t.string "account_number"
    end

    create_table "inv_simulations" do |t|
      t.text "params"
      t.string "status", default: "unprocessed"
      t.text "error"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
    end

    create_table "inv_statement_lines" do |t|
      t.integer "statement_id", null: false
      t.integer "resource_line_id"
      t.integer "billing_line_id", null: false
      t.decimal "base", precision: 10, scale: 3, null: false
      t.decimal "rate", precision: 10, scale: 3, null: false
      t.decimal "amount", precision: 10, scale: 3, null: false
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
    end

    create_table "inv_statements" do |t|
      t.date "date"
      t.integer "right_owner_id"
      t.string "number"
      t.string "status", default: "pending"
      t.decimal "total_fees", precision: 10, scale: 3
      t.decimal "total_rights", precision: 10, scale: 3
      t.decimal "total_sales", precision: 10, scale: 3
      t.decimal "total_paid", precision: 10, scale: 3
      t.decimal "total", precision: 10, scale: 3
      t.decimal "avp_rate", precision: 10, scale: 3
      t.decimal "avp_amount", precision: 10, scale: 3
      t.decimal "base_fee_rate", precision: 10, scale: 3
      t.decimal "base_fee_amount", precision: 10, scale: 3
      t.decimal "csg_rate", precision: 10, scale: 3
      t.decimal "csg_amount", precision: 10, scale: 3
      t.decimal "rds_rate", precision: 10, scale: 3
      t.decimal "rds_amount", precision: 10, scale: 3
      t.decimal "ret_rate", precision: 10, scale: 3
      t.decimal "ret_amount", precision: 10, scale: 3
      t.decimal "vat_rate", precision: 10, scale: 3
      t.decimal "vat_amount", precision: 10, scale: 3
      t.integer "payment_type_id"
      t.date "payment_date"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
    end
  end
end
