Sha256: ce2ff8a8c49097d40aaaa9bb9776fd14c7d2d7856fe2237fc509b23107b36f7d

Contents?: true

Size: 632 Bytes

Versions: 31

Compression:

Stored size: 632 Bytes

Contents

module Ecom
  module Core
    class Payment < ApplicationRecord
      belongs_to :payroll
      has_many :payment_details, class_name: 'Ecom::Core::PaymentDetail', dependent: :destroy
      validates :from, :to, presence: true

      before_validation :set_payment_order

      scope :by_status, ->(status) { where(approved: status) }

      def set_payment_order
        unless payroll
          self.payment_order = 1
          return
        end
        previous_payment = payroll.payments.find_by(approved: true)
        self.payment_order = previous_payment ? previous_payment.payment_order + 1 : 1
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
ecom_core-1.3.14 app/models/ecom/core/payment.rb
ecom_core-1.3.13 app/models/ecom/core/payment.rb
ecom_core-1.3.12 app/models/ecom/core/payment.rb
ecom_core-1.3.11 app/models/ecom/core/payment.rb
ecom_core-1.3.10 app/models/ecom/core/payment.rb
ecom_core-1.3.9 app/models/ecom/core/payment.rb
ecom_core-1.3.8 app/models/ecom/core/payment.rb
ecom_core-1.3.7 app/models/ecom/core/payment.rb
ecom_core-1.3.6 app/models/ecom/core/payment.rb
ecom_core-1.3.5 app/models/ecom/core/payment.rb
ecom_core-1.3.4 app/models/ecom/core/payment.rb
ecom_core-1.3.3 app/models/ecom/core/payment.rb
ecom_core-1.3.2 app/models/ecom/core/payment.rb
ecom_core-1.3.1 app/models/ecom/core/payment.rb
ecom_core-1.3.0 app/models/ecom/core/payment.rb
ecom_core-1.2.36 app/models/ecom/core/payment.rb
ecom_core-1.2.35 app/models/ecom/core/payment.rb
ecom_core-1.2.34 app/models/ecom/core/payment.rb
ecom_core-1.2.33 app/models/ecom/core/payment.rb
ecom_core-1.2.32 app/models/ecom/core/payment.rb