Sha256: 4dd492c7afbb51fe59bac1fefe0ab55f47ff7b1353a2b4659c09ac98508f950a

Contents?: true

Size: 1.89 KB

Versions: 9

Compression:

Stored size: 1.89 KB

Contents

module Logistics
  module Core
    class ContractTwentyFeetEquivalenceUnitRate < ContractRate
      belongs_to :chargeable_service_unit_of_charge
      belongs_to :transaction_type
      belongs_to :contract

      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

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

      def self.generate_rate_for_twenty_feet_equivalence_service(client_contract_id)
        service_delivery_units = get_service_delivery_units
        transaction_types = TransactionType.all
        service_delivery_units.each{ |sdu|
          transaction_types.each { |transaction_type|
            chargeable_services = get_chargeable_services(sdu.id)
            chargeable_services.each { |cs|
              service_rate = ContractTwentyFeetEquivalenceUnitRate.where('chargeable_service_unit_of_charge_id' => cs.id, 'transaction_type_id' => transaction_type.id,
                                                                         'contract_id' => client_contract_id)
              if service_rate.count == 0
                ContractTwentyFeetEquivalenceUnitRate.create('chargeable_service_unit_of_charge_id' => cs.id, 'transaction_type_id' => transaction_type.id,
                                                             'rate' => 0, 'contract_id' => client_contract_id,
                                                             'margin' => 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/contract_twenty_feet_equivalence_unit_rate.rb
logistics_core-21.11.1 app/models/logistics/core/contract_twenty_feet_equivalence_unit_rate.rb
logistics_core-21.08.1 app/models/logistics/core/contract_twenty_feet_equivalence_unit_rate.rb
logistics_core-21.03.1 app/models/logistics/core/contract_twenty_feet_equivalence_unit_rate.rb
logistics_core-20.10.3 app/models/logistics/core/contract_twenty_feet_equivalence_unit_rate.rb
logistics_core-20.10.2 app/models/logistics/core/contract_twenty_feet_equivalence_unit_rate.rb
logistics_core-20.10.1 app/models/logistics/core/contract_twenty_feet_equivalence_unit_rate.rb
logistics_core-20.9.1 app/models/logistics/core/contract_twenty_feet_equivalence_unit_rate.rb
logistics_core-20.8.1 app/models/logistics/core/contract_twenty_feet_equivalence_unit_rate.rb