blend_spreadsheet_loan_generator 0.1.19 → 0.1.24

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a4482f5c0a0e93b8085f1bc9d064a15873d9da91d4a3c945febb087b9a233ff
4
- data.tar.gz: a00f98340c0aa4109b950d59c132bbbeab5878992b474875db21078010762162
3
+ metadata.gz: 0473a465aaf8c05516fd8ed8eeff3009996f4afe3c9dbc5578df88fb4985a03a
4
+ data.tar.gz: a73d70c1cbfd2d2241dd2bc875750358bf6893914739b0b5efaf65271e8800f1
5
5
  SHA512:
6
- metadata.gz: 3a7e731e49a56746d8a0b60e7a867efa6f10c65e59ad785fed1dd0529e3f1ca748582f1c6e54867b3c25cf54fb553d05f3b5d4a915194815960868c1c0fda226
7
- data.tar.gz: 3337ca2d8d85a4eabb170869097eded13b92404f5ea402bb70ef6b943946479784f8e46d0fa868a58498f9b0c52184958671050d3a4944ce3a7099a7e1a2f1c3
6
+ metadata.gz: 55e0989827c375bc5f13d58c7bef7d7bf0024126f838997b7a5c669e5a4bb378020c4dff1d616b78f6686f3b3050bbba7a5132fd18385cf0aaa668d1e8fd09a6
7
+ data.tar.gz: 76cbd06e23b5250740ad087e08f4f61f22c6ae828e2ea1dec23559a2d55ae4bfbd5e1f7d72f81f0efa823ca3de7dd7dd86c2ca3c864fb68e7a7d7e4ee41a6bf8
@@ -3,7 +3,6 @@ module BlendSpreadsheetLoanGenerator
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
-
7
6
  def columns
8
7
  %w[
9
8
  index
@@ -13,6 +13,7 @@ module BlendSpreadsheetLoanGenerator
13
13
  argument :rate, type: :float, required: true, desc: 'year rate post restructuration'
14
14
 
15
15
  option :guaranteed_terms, type: :integer, default: 0
16
+ option :ratio, type: :float
16
17
  option :duration, type: :integer, desc: 'duration'
17
18
  option :period_duration, type: :integer, default: 1, desc: 'duration of a period in months'
18
19
  option :due_on, type: :date, default: Date.today, desc: 'date of the pay day of the first period DD/MM/YYYY'
@@ -43,7 +44,7 @@ module BlendSpreadsheetLoanGenerator
43
44
  values = f.to_a
44
45
  values.map! { |r| set_types([columns, r].transpose.to_h.with_indifferent_access) }
45
46
 
46
- last_paid_line = values.index { |term| term[:index] == last_paid_term.to_i }
47
+ last_paid_line = values.index { |term| term[:index] == last_paid_term.to_i } || -1
47
48
  guaranteed_line = values.index { |term| term[:index] == options.fetch(:guaranteed_terms, -1).to_i } || nil
48
49
  total_guaranteed_interests = (
49
50
  if guaranteed_line.present? && guaranteed_line > last_paid_line
@@ -64,7 +65,14 @@ module BlendSpreadsheetLoanGenerator
64
65
  if total_to_be_paid == amount_paid
65
66
  1
66
67
  else
67
- options.fetch(:duration, values.last[:index] - values[last_paid_line][:index])
68
+ options.fetch(
69
+ :duration,
70
+ if last_paid_line == -1
71
+ values.last[:index]
72
+ else
73
+ values.last[:index] - values[last_paid_line][:index]
74
+ end
75
+ )
68
76
  end
69
77
  )
70
78
 
@@ -74,14 +82,27 @@ module BlendSpreadsheetLoanGenerator
74
82
  values[last_paid_line + 1][:capitalized_interests_start] +
75
83
  values[last_paid_line + 1][:capitalized_fees_start]
76
84
  )
85
+ actual_capital_paid = (
86
+ capital_paid -
87
+ values[last_paid_line + 1][:period_calculated_interests] -
88
+ values[last_paid_line + 1][:period_calculated_fees]
89
+ )
90
+
91
+ ratio = options.fetch(:ratio, (actual_capital_paid.to_f / values[last_paid_line + 1][:remaining_capital_start])).to_f
77
92
  guaranteed_interests_paid = (
78
- (capital_paid.to_f / values[last_paid_line + 1][:remaining_capital_start]) *
79
- total_guaranteed_interests
93
+ ratio * total_guaranteed_interests
80
94
  )
81
95
  capital_paid -= guaranteed_interests_paid
82
96
 
97
+ amount = (
98
+ if last_paid_line == -1
99
+ values[0][:remaining_capital_end]
100
+ else
101
+ values[last_paid_line][:remaining_capital_end]
102
+ end
103
+ )
83
104
  @loan = Loan.new(
84
- amount: values[last_paid_line][:remaining_capital_end],
105
+ amount: amount,
85
106
  duration: duration,
86
107
  rate: rate,
87
108
  fees_rate: options.fetch(:fees_rate),
@@ -1,7 +1,7 @@
1
1
  require 'dry/cli'
2
2
 
3
3
  module BlendSpreadsheetLoanGenerator
4
- VERSION = '0.1.19'.freeze
4
+ VERSION = '0.1.24'.freeze
5
5
 
6
6
  class Version < Dry::CLI::Command
7
7
  desc 'Print version'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blend_spreadsheet_loan_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.19
4
+ version: 0.1.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - MZiserman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-12 00:00:00.000000000 Z
11
+ date: 2021-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport