Class: Dorsale::BillingMachine::SmallData::FilterStrategyByPaymentStatus

Inherits:
Agilibox::SmallData::FilterStrategy
  • Object
show all
Defined in:
app/filters/dorsale/billing_machine/small_data/filter_strategy_by_payment_status.rb

Instance Method Summary collapse

Instance Method Details

#apply(query, value) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/filters/dorsale/billing_machine/small_data/filter_strategy_by_payment_status.rb', line 2

def apply(query, value)
  table_name = query.model.table_name

  if value == "paid"
    query.where(paid: true)
  elsif value == "unpaid"
    query.where(paid: false)
  elsif value == "pending"
    query
      .where(paid: false)
      .where("#{table_name}.due_date >= ?", Date.current)
  elsif value == "late"
    query
      .where(paid: false)
      .where("#{table_name}.due_date < ? OR #{table_name}.due_date IS NULL", Date.current)
  else
    query
  end
end