Sha256: 152ed34aca7c9489de7daff54961f68069bc88474f447c6c99e4d7683541bb35

Contents?: true

Size: 568 Bytes

Versions: 8

Compression:

Stored size: 568 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

      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

8 entries across 8 versions & 1 rubygems

Version Path
ecom_core-1.2.20 app/models/ecom/core/payment.rb
ecom_core-1.2.19 app/models/ecom/core/payment.rb
ecom_core-1.2.18 app/models/ecom/core/payment.rb
ecom_core-1.2.17 app/models/ecom/core/payment.rb
ecom_core-1.2.16 app/models/ecom/core/payment.rb
ecom_core-1.2.15 app/models/ecom/core/payment.rb
ecom_core-1.2.14 app/models/ecom/core/payment.rb
ecom_core-1.2.13 app/models/ecom/core/payment.rb