Method: Client.find_invoiceable_clients_at

Defined in:
app/models/client.rb

.find_invoiceable_clients_at(occurred_at) ⇒ Object

This is mostly used by the batch create feature. Here, we return an array of clients, which have approved, unassigned activity which occurred before the specified_date



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'app/models/client.rb', line 192

def self.find_invoiceable_clients_at(occurred_at)
  find(
    :all,
    :select     => 'DISTINCT `clients`.*',
    :joins      => 'LEFT JOIN `activities` ON `clients`.id = `activities`.client_id',
    :conditions => [
      [
        '`activities`.occurred_on <= ?',
        '`activities`.is_published = ?',
        '`activities`.invoice_id IS NULL'
      ].join(" AND "),
      occurred_at, 
      true
    ],
    :order => ["`clients`.company_name ASC","`clients`.id ASC"].join(",")
  )
end