app/models/account.rb in has_accounts-0.2.1 vs app/models/account.rb in has_accounts-0.2.2
- old
+ new
@@ -81,20 +81,28 @@
:first_id => selector.first.id,
:last_id => selector.last.id
}]
end
elsif
- # TODO support inclusive param
- condition = {:value_date => selector}
+ if selector.first == selector.last
+ condition = ["date(value_date) = :value_date", {
+ :value_date => selector.first
+ }]
+ else
+ condition = ["date(value_date) BETWEEN :first_value_date AND :latest_value_date", {
+ :first_value_date => selector.first,
+ :latest_value_date => selector.last
+ }]
+ end
end
else
if selector.is_a? Booking
equality = "=" if inclusive
# date(value_date) is needed on sqlite!
condition = ["(value_date < :value_date) OR (date(value_date) = :value_date AND id <#{equality} :id)", {:value_date => selector.value_date, :id => selector.id}]
else
equality = "=" if inclusive
- condition = ["value_date <#{equality} ?", selector]
+ condition = ["date(value_date) <#{equality} ?", selector]
end
end
credit_amount = credit_bookings.where(condition).sum(:amount)
debit_amount = debit_bookings.where(condition).sum(:amount)