class TimerWatcher < ActiveRecord::Base

  belongs_to :p_customer
  belongs_to :admin
	scope :after, lambda { |date|
	        where("(created_at >= ?)", date )
	    }
	scope :before, lambda { |date|
	        where("(created_at <= ?)", date )
	    }
  
  
  before_save do
    
    if self.id
    
      diff = self.end_at - self.created_at
    
      diff * 1.days
    
      self.time_ok = diff
  
    end
  
  
  end
  
  
  after_save do
    if !self.time_ok
    
      diff = self.end_at - self.created_at
    
      diff * 1.days
    
      self.time_ok = diff
      self.save
  
    end
  end

end
