Sha256: c77f009840d85e2a8b06d6ea0f5f385cc6162798020eef726c10d76a228b9c66

Contents?: true

Size: 1.69 KB

Versions: 3

Compression:

Stored size: 1.69 KB

Contents

# == Schema Information
#
# Table name: swaps
#
#  id            :integer          not null, primary key
#  shift_id      :integer
#  reason        :string(255)
#  status        :string(255)      default("pending")
#  in_trash      :boolean          default(FALSE)
#  viewed        :boolean          default(FALSE)
#  created_at    :datetime
#  updated_at    :datetime
#  alert         :boolean          default(FALSE)
#  approved_date :datetime
#  approved_by   :integer
#

class Swap < ActiveRecord::Base

  belongs_to :shift

  has_many :candidates, :dependent => :destroy
  has_many :shift_trades, :through => :candidates

  validates_presence_of :shift
  validates_uniqueness_of :shift_id

  def notify
    if alert 
      employees = shift.schedule.user.organization.get_employees
      employees.each do |candidate|
        candidate.notify_alert(self)
      end
    end
  end
  def shift_detail
    "AS #{shift.job_name} from #{shift.start_time.strftime('%H:%M')} to #{shift.end_time.strftime('%H:%M')} on #{shift.formatted_due_date}"
    
  end
  def pending?
    self.status == 'pending'
  end

  def approved?
    self.status == 'approved'
  end
  
  def user_name
    self.shift.schedule.user.name
  end
  

  def get_shift
       @swap = Swap.find_by_id(self.alert_type_id)
       if !@swap.nil? 
        @swap.shift
       end 
  end

  def shift_hours
    self.shift.hours.strftime('%H')
  end
  
  def due_date
    self.shift.due_date
  end

  def approve
    #self.approved_by = manager.id
    #self.approved_date = Time.zone.now
    self.status = 'approved'
    save
  end

  def cancel
    #self.approved_by = manager.id
    #self.approved_date = Time.zone.now
    self.status = 'cancelled'
    save
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pshq_engine-0.1.6 app/models/swap.rb
pshq_engine-0.1.5 app/models/swap.rb
pshq_engine-0.0.1 app/models/swap.rb