Class: Smerp::Quotation::DistributionCalculator

Inherits:
Object
  • Object
show all
Includes:
ExtendedCalculator, TR::CondUtils, TeLogger::TeLogHelper
Defined in:
lib/smerp/quotation/calculators/distribution_calculator.rb

Constant Summary collapse

DistributedAmount =
:distributed_amount
ValueWithDistribution =
:value_with_distribution

Instance Attribute Summary

Attributes included from ExtendedCalculator

#ecid, #input_field, #listener, #output_field, #owner, #owner_id, #params, #result

Instance Method Summary collapse

Methods included from ExtendedCalculator

#for_storage, from_storage, #initialize, instance, instance_from_hash

Instance Method Details

#calculate(mdl) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/smerp/quotation/calculators/distribution_calculator.rb', line 17

def calculate(mdl)
  
  srcVal = mdl.send(@input_field)
  if not_empty?(srcVal)

    srcVal = srcVal.to_f

    res = { input: @input_field, input_value: srcVal }
    case @params
    when Smerp::Common::FinUtils::Percent
      res[DistributedAmount] = srcVal * @params.rep_value
    when Smerp::Common::FinUtils::RawValue
      res[DistributedAmount] = @params.rep_value
    else
      res[DistributedAmount] = @params.to_f
    end

    res[ValueWithDistribution] = srcVal + res[DistributedAmount]

    #if not_empty?(@output_field) and not outMdl.nil?

    #  case @output_field
    #  when Array
    #    @output_field.each do |of|
    #      of.each do |f, v|
    #        outMdl.send("#{f}=", res[v])
    #      end
    #    end
    #  when Hash
    #    @output_field.each do |f,v|
    #      outMdl.send("#{f}=", res[v])
    #    end
    #  when Symbol
    #    outMdl.send("#{@output_field}=", res[DistributedAmount])
    #  end

    #  res[:output] = @output_field
    #  res[:output_model] = outMdl
    #  outMdl.recalculate

    #end # if @output_field not empty

    @result = res

    trigger_listener(:after_calculation, mdl)

    teLogger.debug "Distribution calculation log : #{res}"

    @result

  end

end