2015-05-28 13:20:14 +00:00
|
|
|
module JamRuby
|
|
|
|
|
class AffiliatePayment < ActiveRecord::Base
|
|
|
|
|
|
|
|
|
|
belongs_to :affiliate_monthly_payment
|
|
|
|
|
belongs_to :affiliate_quarterly_payment
|
|
|
|
|
|
|
|
|
|
def self.index(user, options)
|
|
|
|
|
|
|
|
|
|
unless user.affiliate_partner
|
|
|
|
|
return [[], nil]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
affiliate_partner_id = user.affiliate_partner.id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2021-02-15 04:32:27 +00:00
|
|
|
# query = AffiliatePayment
|
|
|
|
|
# .includes(affiliate_quarterly_payment: [], affiliate_monthly_payment:[])
|
|
|
|
|
# .where(affiliate_partner_id: affiliate_partner_id)
|
|
|
|
|
# .where("(payment_type='quarterly' AND closed = true) OR payment_type='monthly'")
|
|
|
|
|
# .where('(paid = TRUE or due_amount_in_cents < 10000 or paid is NULL)')
|
|
|
|
|
# .paginate(:page => page, :per_page => limit)
|
|
|
|
|
# .order('year ASC, time_sort ASC, payment_type ASC')
|
|
|
|
|
|
2015-05-28 13:20:14 +00:00
|
|
|
query = AffiliatePayment
|
2021-02-15 04:32:27 +00:00
|
|
|
.includes(:affiliate_monthly_payment => { :affiliate_partner => :affiliate_distributions })
|
2015-05-28 13:20:14 +00:00
|
|
|
.where(affiliate_partner_id: affiliate_partner_id)
|
2021-02-15 04:32:27 +00:00
|
|
|
.where("payment_type='monthly'")
|
2015-05-28 13:20:14 +00:00
|
|
|
.where('(paid = TRUE or due_amount_in_cents < 10000 or paid is NULL)')
|
|
|
|
|
.paginate(:page => page, :per_page => limit)
|
2021-02-15 04:32:27 +00:00
|
|
|
.order('year DESC, month DESC')
|
|
|
|
|
|
2015-05-28 13:20:14 +00:00
|
|
|
if query.length == 0
|
|
|
|
|
[query, nil]
|
|
|
|
|
elsif query.length < limit
|
|
|
|
|
[query, nil]
|
|
|
|
|
else
|
|
|
|
|
[query, start + limit]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|