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