45 lines
1.2 KiB
Ruby
45 lines
1.2 KiB
Ruby
class PHire
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
|
|
field :start_time, type: DateTime
|
|
field :end_time, type: DateTime
|
|
field :hiring_person_email
|
|
field :hiring_person_number
|
|
field :hiring_person_id
|
|
field :hiring_person_name
|
|
field :reason_for_hire
|
|
field :note_for_hire
|
|
field :passed, type: Boolean, default: false
|
|
|
|
belongs_to :property
|
|
|
|
def as_json(options = {})
|
|
{
|
|
:id => self.id.to_s,
|
|
:title => self.reason_for_hire,
|
|
:note => self.note_for_hire || "",
|
|
:start => self.start_time.rfc822,
|
|
:end => self.end_time.rfc822,
|
|
:allDay => false,
|
|
:color => "#FC4040"
|
|
}
|
|
end
|
|
|
|
def period
|
|
return self.start_time.strftime("%y-%m-%d %H:%M") + " ~ " + self.end_time.strftime("%y-%m-%d %H:%M")
|
|
end
|
|
|
|
def hirer_name
|
|
return self.hiring_person_name.nil? ? self.hiring_person_profile.name : self.hiring_person_name
|
|
end
|
|
|
|
def hiring_person_profile
|
|
return MemberProfile.find(self.hiring_person_id) rescue nil
|
|
end
|
|
|
|
def self.monthly_event(start_date,end_date,property_id)
|
|
self.where(:property_id => property_id, :passed => true).any_of(:start_time.gte => start_date, :end_time.gte => start_date).and(:start_time.lte => end_date).asc(:start_time)
|
|
end
|
|
|
|
end |