Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 9919bda742
Fetching contributors…

Cannot retrieve contributors at this time

file 33 lines (26 sloc) 1.146 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
class Fee < ActiveRecord::Base
  acts_as_indexed :fields => [:from_account, :message]

  belongs_to :user
  
  validates :from_account, :presence => true
  validates :vs, :presence => true, :numericality => { :only_integer => true }
  validates :amount, :presence => true
  validates :month, :presence => true, :numericality => { :only_integer => true }
  validates :year, :presence => true, :numericality => { :only_integer => true }
  validates :stamp, :presence => true, :uniqueness => true
  
  validates_associated :user

  scope :unpaired, :conditions => {:user_id => nil}
  scope :paired, :conditions => 'user_id IS NOT NULL'
      
  def self.search(search, page, user)
    paginate :per_page => 20, :page => page,
             :conditions => ['user_id = ? AND (from_account like ? OR message like ?)', user.id, "%#{search}%", "%#{search}%"],
             :order => 'year DESC, month DESC'
  end

  def self.mine(page, user)
    paginate :per_page => 20, :page => page,
             :conditions => ['user_id = ?', user.id],
             :order => 'year DESC, month DESC'
  end
  
  def self.latest(number = 7)
    limit(number)
  end
end
Something went wrong with that request. Please try again.