42 lines
915 B
Ruby
42 lines
915 B
Ruby
class JamRuby::AffiliateQuarterlyPayment < ActiveRecord::Base
|
|
|
|
belongs_to :affiliate_partner, class_name: 'JamRuby::AffiliatePartner', inverse_of: :quarters
|
|
|
|
|
|
def self.index(user, options)
|
|
unless user.affiliate_partner
|
|
return [[], nil]
|
|
end
|
|
|
|
page = options[:page].to_i
|
|
per_page = options[:per_page].to_i
|
|
|
|
if page == 0
|
|
page = 1
|
|
end
|
|
|
|
if per_page == 0
|
|
per_page = 50
|
|
end
|
|
|
|
start = (page -1 ) * per_page
|
|
limit = per_page
|
|
|
|
query = AffiliateQuarterlyPayment
|
|
.paginate(page: page, per_page: per_page)
|
|
.where(affiliate_partner_id: user.affiliate_partner.id)
|
|
.where(closed:true)
|
|
.where(paid:true)
|
|
.order('year ASC, quarter ASC')
|
|
|
|
if query.length == 0
|
|
[query, nil]
|
|
elsif query.length < limit
|
|
[query, nil]
|
|
else
|
|
[query, start + limit]
|
|
end
|
|
end
|
|
|
|
end
|