Class: Logistics::Core::ContainerStorageRate

Inherits:
ApplicationRecord show all
Defined in:
app/models/logistics/core/container_storage_rate.rb

Class Method Summary collapse

Methods inherited from ApplicationRecord

as_json

Class Method Details

.generate_storage_rate(rate_period_id, effective_date) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/logistics/core/container_storage_rate.rb', line 10

def self.generate_storage_rate(rate_period_id, effective_date)
  transaction_types = TransactionType.all
  container_sizes = ContainerSize.all
  content_types = ContentType.all
  container_types = ContainerType.all
  transaction_types.each { |t|
    container_sizes.each { |c|
      content_types.each { |ct|
        container_types.each { |container_type|
          rate = ContainerStorageRate.where('transaction_type_id' => t.id, 'container_size_id' => c.id,
                                            'content_type_id' => ct.id, 'container_type_id' => container_type.id,
                                            'warehouse_rate_period_id' => rate_period_id)
          if rate.count == 0
            ContainerStorageRate.create('transaction_type_id' => t.id, 'container_size_id' => c.id, 'rate' => 0,
                                        'content_type_id' => ct.id, 'container_type_id' => container_type.id,
                                        'warehouse_rate_period_id' => rate_period_id, 'effective_date' => effective_date)
          end
        }
      }
    }
  }
end