badar_madeena/app/models/income.rb

14 lines
471 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class Income < ApplicationRecord
# Todays 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