Sha256: 102547b08019d3493dbb633237b28c1bdfebd867b2cc0a53492d638d51444e66

Contents?: true

Size: 1.38 KB

Versions: 5

Compression:

Stored size: 1.38 KB

Contents

class WorkUnit < ActiveRecord::Base
  module Finders
    def hours_types
      ['Normal', 'Overtime', 'CTO', 'PTO']
    end

    def scheduled_between(start_time, end_time)
      where('scheduled_at BETWEEN ? AND ?', start_time, end_time)
    end

    def unpaid
      where(:paid => [nil, ''])
    end

    def not_invoiced
      where(:invoiced => [nil, ''])
    end

    def for_client(client)
      joins({:ticket => {:project => [:client]}}).where("clients.id = ?", client.id)
    end

    def except_client(client)
      joins({:ticket => {:project => [:client]}}).where("clients.id <> ?", client.id)
    end

    def for_project(project)
      joins({:ticket => [:project]}).where("projects.id = ?", project.id)
    end

    def for_ticket(ticket)
      where(:ticket_id => ticket.id)
    end

    def for_user(user)
      where(:user_id => user.id)
    end

    def for_users(users)
      where("user_id IN (?)", users.map{|user| user.id})
    end

    def sort_by_scheduled_at
      order('scheduled_at DESC')
    end

    def pto
      where(:hours_type => 'PTO')
    end

    def cto
      where(:hours_type => 'CTO')
    end

    def overtime
      where(:hours_type => 'Overtime')
    end

    def normal
      where(:hours_type => 'Normal')
    end

    def on_estimated_ticket
       joins(:ticket).where("tickets.estimated_hours IS NOT NULL AND tickets.estimated_hours > 0")
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
xrono-1.0.4 app/models/work_unit/finders.rb
xrono-1.0.3 app/models/work_unit/finders.rb
xrono-1.0.2 app/models/work_unit/finders.rb
xrono-1.0.1 app/models/work_unit/finders.rb
xrono-1.0.0 app/models/work_unit/finders.rb