class AlpReport < ActiveRecord::Base
  has_many :rep_employees, :foreign_key => "report_id"
  accepts_nested_attributes_for :rep_employees
#  has_many :employees, :through => :rep_employees
#  accepts_nested_attributes_for :employees
  has_many :rep_logins, :foreign_key => 'report_id'
#  accepts_nested_attributes_for :rep_logins
  has_many :logins_from, :through => :rep_logins, :source => 'login_from'
#  accepts_nested_attributes_for :logins_from
  has_many :logins_to, :through => :rep_logins, :source => 'login_to'
  has_many :rep_works, :foreign_key => "report_id"
  has_many :works, :through => :rep_works
  has_many :rep_materials
  has_many :materials, :through => :rep_materials
  serialize :all_desc, Hash


  def employees
    employees = []
    rep_employes.each do |ou|
      employees << ou.employee
    end
    user
  end

  def all_desc
    attributes[:all_desc] || {:j_other_materials => false, :j_error_desc => false, :j_conflicts => false, :j_downtime_desc => false}
  end


  def self.categories
    [['Без статуса', 1], ['Корпоративный', 2],['Линейный',3],['Административный',4],['Дежурство',5],['Демонтаж',6],['Авария',7]]
  end

end
