Sha256: b5b7a0c1be76b6426d42650e39be59d9a87630266d0e4361348fd2f4f2d8851f

Contents?: true

Size: 567 Bytes

Versions: 51

Compression:

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

51 entries across 51 versions & 1 rubygems

Version Path
ecom_core-1.1.20 app/models/ecom/core/payment.rb
ecom_core-1.1.19 app/models/ecom/core/payment.rb
ecom_core-1.1.18 app/models/ecom/core/payment.rb
ecom_core-1.1.17 app/models/ecom/core/payment.rb
ecom_core-1.1.16 app/models/ecom/core/payment.rb
ecom_core-1.1.15 app/models/ecom/core/payment.rb
ecom_core-1.1.14 app/models/ecom/core/payment.rb
ecom_core-1.1.13 app/models/ecom/core/payment.rb
ecom_core-1.1.12 app/models/ecom/core/payment.rb
ecom_core-1.1.11 app/models/ecom/core/payment.rb
ecom_core-1.1.10 app/models/ecom/core/payment.rb
ecom_core-1.1.9 app/models/ecom/core/payment.rb
ecom_core-1.1.8 app/models/ecom/core/payment.rb
ecom_core-1.1.7 app/models/ecom/core/payment.rb
ecom_core-1.1.6 app/models/ecom/core/payment.rb
ecom_core-1.1.5 app/models/ecom/core/payment.rb
ecom_core-1.1.4 app/models/ecom/core/payment.rb
ecom_core-1.1.3 app/models/ecom/core/payment.rb
ecom_core-1.1.2 app/models/ecom/core/payment.rb
ecom_core-1.1.1 app/models/ecom/core/payment.rb