2014-09-16 20:50:58 -04:00
|
|
|
class Client < ActiveRecord::Base
|
2015-09-23 09:29:42 -05:00
|
|
|
# TODO: figure out why application_date validation is fubar
|
|
|
|
# validates :application_date, presence: true
|
2016-05-07 10:14:30 -05:00
|
|
|
belongs_to :bike
|
2014-09-22 19:44:03 -04:00
|
|
|
belongs_to :agency
|
2014-09-24 20:08:05 -04:00
|
|
|
|
|
|
|
def self.waiting_list
|
|
|
|
clients = Client.all
|
2016-01-05 14:16:24 -06:00
|
|
|
nonvoided_clients = clients.select{|client| !client.application_voided}
|
|
|
|
active_nonvoided_clients = nonvoided_clients.select{|client| !client.pickup_date}
|
|
|
|
waiting_list = active_nonvoided_clients.select{|client| !client.application_date.nil?}
|
2015-04-16 09:12:55 -05:00
|
|
|
waiting_list.sort_by!{|client| client.application_date}
|
2014-09-24 20:08:05 -04:00
|
|
|
end
|
|
|
|
|
2014-10-07 21:01:29 -04:00
|
|
|
def name
|
|
|
|
self.first_name + ' ' + self.last_name
|
|
|
|
end
|
|
|
|
|
2014-10-07 21:17:44 -04:00
|
|
|
def self.closed_applications
|
2015-12-05 17:01:57 -06:00
|
|
|
Client.all.select{|client| client.application_voided || client.pickup_date}
|
2014-10-07 21:17:44 -04:00
|
|
|
end
|
|
|
|
|
2014-09-16 20:50:58 -04:00
|
|
|
end
|