module Ecom module Core class Payroll < ApplicationRecord validates :month, :year, presence: true has_many :payments, class_name: 'Ecom::Core::Payment' belongs_to :site scope :by_site, ->(id) { where(site_id: id) } scope :by_month, ->(month) { where(month: month) } scope :by_year, ->(year) { where(year: year) } def create_next m = month + 1 y = year if m > 12 m = 1 y += 1 end Payroll.create(month: m, year: y, site_id: site_id) end end end end