class Login < ActiveRecord::Base
   has_many :active_data
   belongs_to :office
    def self.login_name(output_name)
	    result=self.select(
            "(CASE WHEN full_name IS NULL  OR full_name = '' THEN \"logins\".\"name\" ELSE full_name END) as #{output_name}"
        )
	    return result
    end
    def self.global_filter(id)
        @filter=GlobalFilter.where(:user_id => id).first
        @filter_id=@filter.custom_filter_id
        @result=self
        if @filter_id == 0
            @result=@result.all
        else
            @result=@result\
            .where(:id => LoginFilter.where(:custom_filter_id => @filter_id).select(:login_id))
        end 
        return @result
    end
end
