Sha256: 023bf09204e5534b1a2c4c1aef9cb2c3f42d91520994a5b1c99d600cf4686db8

Contents?: true

Size: 1.14 KB

Versions: 9

Compression:

Stored size: 1.14 KB

Contents

module Logistics
  module Core
    class ContainerDemurrageRate < ApplicationRecord
      belongs_to :container_size
      belongs_to :transaction_type
      belongs_to :demurrage_rate_period
      belongs_to :container_type

      def self.generate_demurage_rate(rate_period_id)
        transaction_types = TransactionType.all
        container_sizes = ContainerSize.all
        container_types = ContainerType.all
        transaction_types.each { |t|
          container_sizes.each { |c|
            container_types.each { |ct|
              rate = ContainerDemurrageRate.where('transaction_type_id' => t.id, 'container_size_id' => c.id,
                                                 'container_type_id' => ct.id, 'demurrage_rate_period_id' => rate_period_id)
              if rate.count == 0
                ContainerDemurrageRate.create('transaction_type_id' => t.id, 'container_size_id' => c.id,
                                             'container_type_id' => ct.id, 'demurrage_rate_period_id' => rate_period_id,
                                             'rate' => 0)
              end
            }
          }
        }
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
logistics_core-21.11.2 app/models/logistics/core/container_demurrage_rate.rb
logistics_core-21.11.1 app/models/logistics/core/container_demurrage_rate.rb
logistics_core-21.08.1 app/models/logistics/core/container_demurrage_rate.rb
logistics_core-21.03.1 app/models/logistics/core/container_demurrage_rate.rb
logistics_core-20.10.3 app/models/logistics/core/container_demurrage_rate.rb
logistics_core-20.10.2 app/models/logistics/core/container_demurrage_rate.rb
logistics_core-20.10.1 app/models/logistics/core/container_demurrage_rate.rb
logistics_core-20.9.1 app/models/logistics/core/container_demurrage_rate.rb
logistics_core-20.8.1 app/models/logistics/core/container_demurrage_rate.rb