Class: Logistics::Core::ServiceRate

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

Class Method Summary collapse

Methods inherited from ApplicationRecord

as_json

Class Method Details

.generate_rate_for_containerized_chargeable_service(effective_date) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/logistics/core/service_rate.rb', line 19

def self.generate_rate_for_containerized_chargeable_service(effective_date)
  service_delivery_units = ServiceDeliveryUnit.all
  transaction_types = TransactionType.all
  container_sizes = ContainerSize.all
  service_delivery_units.each{ |sdu|
    transaction_types.each { |transaction_type|
      container_sizes.each {|container_size|
        chargeable_services = get_chargeable_services(sdu.id)
        chargeable_services.each { |cs|
          service_rate = ServiceRate.where('chargeable_service_unit_of_charge_id' => cs.id, 'transaction_type_id' => transaction_type.id,
                                           'container_size_id' => container_size.id)
          if service_rate.count == 0
            ServiceRate.create('chargeable_service_unit_of_charge_id' => cs.id, 'transaction_type_id' => transaction_type.id,
                               'container_size_id' => container_size.id, 'effective_date' => effective_date, 'low' => 0,
                               'medium' => 0, 'high' => 0, 'margin' => 0)
          end
        }
      }
    }
  }
end

.get_chargeable_services(service_delivery_unit_id) ⇒ Object



13
14
15
16
17
# File 'app/models/logistics/core/service_rate.rb', line 13

def self.get_chargeable_services(service_delivery_unit_id)
  unit_of_charge_id = UnitOfCharge.select(:id).where('code' => 'CNT')
  acsuocs = ChargeableServiceUnitOfCharge.where('service_delivery_unit_id' => service_delivery_unit_id, 'unit_of_charge_id' => unit_of_charge_id )
  return acsuocs
end

.get_service_delivery_unitsObject



8
9
10
11
# File 'app/models/logistics/core/service_rate.rb', line 8

def self.get_service_delivery_units
  transport_id = ServiceDeliveryUnitType.select(:id).where('lower(name) = ?', 'Transport'.downcase)
  return ServiceDeliveryUnit.where.not('service_delivery_unit_type_id' => transport_id)
end