Sha256: 4e43035caec1621af7c6501d1a2645c6a462e2b046252fe65b8a6cd68d4527f1

Contents?: true

Size: 1.44 KB

Versions: 9

Compression:

Stored size: 1.44 KB

Contents

module Logistics
  module Core
    class ItemRate < ApplicationRecord
      belongs_to :chargeable_service_unit_of_charge
      belongs_to :transaction_type

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

      def self.generate_rate_for_item_services(effective_date)
        transaction_types = TransactionType.all
        service_delivery_units = ServiceDeliveryUnit.all
        service_delivery_units.each { |sdu|
          transaction_types.each { |transaction_type|
            chargeable_services = get_chargeable_services(sdu.id)
            chargeable_services.each { |chargeable_service|
              item_rate = ItemRate.where('transaction_type_id' => transaction_type.id,
                                         'chargeable_service_unit_of_charge_id' => chargeable_service.id)
              if item_rate.count == 0
                ItemRate.create('transaction_type_id' => transaction_type.id, 'chargeable_service_unit_of_charge_id' =>
                    chargeable_service.id, 'minimum_quantity' => 0, 'rate' => 0,
                                'margin' => 0, 'effective_date' => effective_date)
              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/item_rate.rb
logistics_core-21.11.1 app/models/logistics/core/item_rate.rb
logistics_core-21.08.1 app/models/logistics/core/item_rate.rb
logistics_core-21.03.1 app/models/logistics/core/item_rate.rb
logistics_core-20.10.3 app/models/logistics/core/item_rate.rb
logistics_core-20.10.2 app/models/logistics/core/item_rate.rb
logistics_core-20.10.1 app/models/logistics/core/item_rate.rb
logistics_core-20.9.1 app/models/logistics/core/item_rate.rb
logistics_core-20.8.1 app/models/logistics/core/item_rate.rb