module Logistics module Core class BreakBulkDemurrageRate < ApplicationRecord belongs_to :break_bulk_unit belongs_to :transaction_type belongs_to :demurrage_rate_period def self.generate_demurage_rate(rate_period_id, effective_date) transaction_types = get_transaction_types break_bulk_units = get_break_bulk_units transaction_types.each { |tt| break_bulk_units.each{ |bb| bdr = BreakBulkDemurrageRate.where('transaction_type_id' => tt.id, 'demurage_rate_period_id' => rate_period_id, 'break_bulk_unit_id' => bb.id) if bdr.count == 0 BreakBulkDemurrageRate.create('transaction_type_id' => tt.id, 'demurage_rate_period_id' => rate_period_id, 'break_bulk_unit_id' => bb.id, 'rate' => 0, 'effective_date' => effective_date) end } } end end end end