summaryrefslogtreecommitdiff
path: root/app/models/license.rb
blob: d207feeb1523490b068a3044f7c5bc5f8d376eb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class License < ActiveRecord::Base
  belongs_to :company
  belongs_to :well_type
  belongs_to :location
  belongs_to :applicant, class_name: 'User', foreign_key: 'user_id'

  def status
    LicenseStatus.status_for(self)
  end

  def active_on?(date)
    issued_at < date && expired_at > date
  end

  def self.most_recent(page: 1, per_page: 10)
    offset = (page - 1) * per_page
    offset = offset >= 0 ? offset : 0
    order(created_at: :desc).offset(offset).limit(per_page)
  end

  def self.township(township)
    joins(:location).where(locations: { township: township })
  end

  def self.status(status)
    status.filter(self)
  end
end