module Logistics module Core class BreakBulkUnitRate < ApplicationRecord belongs_to :chargeable_service_unit_of_charge belongs_to :transaction_type belongs_to :break_bulk_unit def self.get_chargeable_services(service_delivery_unit_id) unit_of_charge_id = UnitOfCharge.select(:id).where('code' => 'UNIT') csuocs = ChargeableServiceUnitOfCharge.where('service_delivery_unit_id' => service_delivery_unit_id, 'unit_of_charge_id' => unit_of_charge_id ) return csuocs end def self.get_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.generate_rate_for_break_bulk_units(effective_date) transaction_types = TransactionType.all breakBulkUnits = BreakBulkUnit.all service_delivery_units = ServiceDeliveryUnit.all service_delivery_units.each { |sdu| transaction_types.each { |transaction_type| breakBulkUnits.each { |bbu| chargeable_services = get_chargeable_services(sdu.id) chargeable_services.each { |chargeable_service| break_bulk_unit_rate = BreakBulkUnitRate.where('transaction_type_id' =>transaction_type.id, 'chargeable_service_unit_of_charge_id' => chargeable_service.id, 'break_bulk_unit_id' => bbu.id) if break_bulk_unit_rate.count == 0 BreakBulkUnitRate.create('transaction_type_id' => transaction_type.id,'chargeable_service_unit_of_charge_id' => chargeable_service.id, 'low' => 0, 'medium' => 0,'high' => 0,'margin' => 0, 'effective_date' => effective_date, 'break_bulk_unit_id' => bbu.id) end } } } } end end end end