# -*- coding: utf-8 -*-

# -*- coding: utf-8 -*-
class NewFieldsToCategories < ActiveRecord::Migration
  def self.up
#    add_column :category, :login, :boolean, :default => true
#    add_column :category, :loginroot, :boolean, :default => true
#    add_column :category, :mat_inst, :boolean, :default => true
#    add_column :category, :mat_sale, :boolean, :default => true
#    add_column :category, :mat_rent, :boolean, :default => true
#    add_column :category, :mat_rent_rate, :boolean, :default => true
    
    drop_table :companies
    remove_column :reports, :customer_id
    remove_column :reports, :contractor_id

    # Категории для "установка из воздуха" и "передача с логина на логин"
#    Category.create(:name => "Передача материалов между логинами", :department => "between_logins")
#    Category.create(:name => "Регистрация ранее установленных материалов", :department => "to_login")
    new_cat = Category.new #(:name => "ОКК-халява", :department => "soft")
    old_cat = Category.find 27
    new_cat.attributes = old_cat.attributes
    new_cat.name = "ОКК-халява"
    new_cat.save
    rs = Report.find(:all, :conditions => "category = 78")
    for r in rs do
      r.category = new_cat.id
      r.dhcp_login = "new2"
      r.save
    end

    pers = (Date.new(2008, 01)..Date.new(2015, 12)).select {|d| d.day == 1}  
    for month in pers do
      if month >= '01.01.2015'.to_date
        cl = false
      else
        cl = true
      end
      for dep in ['between_logins', 'to_login'] do
        Period.create(:month => month, :department => dep, :closed => cl)
      end
    end
  end

  def self.down
    remove_column :category, :login
    remove_column :category, :loginroot
    remove_column :category, :mat_inst
    remove_column :category, :mat_sale
    remove_column :category, :mat_rent
    remove_column :category, :mat_rent_rate
  end
end
