14 lines
471 B
Ruby
14 lines
471 B
Ruby
class Income < ApplicationRecord
|
||
# Today’s income
|
||
scope :today, -> { where("created_at >= ?", Time.zone.now.beginning_of_day) }
|
||
|
||
# This week income
|
||
scope :this_week, -> { where(created_at: Time.zone.now.beginning_of_week..Time.zone.now.end_of_week) }
|
||
|
||
# This month income
|
||
scope :this_month, -> { where(created_at: Time.zone.now.beginning_of_month..Time.zone.now.end_of_month) }
|
||
|
||
# Optional: total amount
|
||
scope :total_amount, -> { sum(:amount) }
|
||
end
|