blend_spreadsheet_loan_generator 0.1.21 → 0.1.26

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: 2f28ea47a7ea85e82f8bb7e6235025a727c4ed68e48ca775b8504a55e0ae104c
4
- data.tar.gz: 933c6ad4f65149b569d0ac66e695b1896e6cd80d7e4b259cbd95920af99d811a
3
+ metadata.gz: 46ffd519aaf8bc1d7b8bb2bb84c376e107f04cf2c8af6ee23ad028a563e63d8b
4
+ data.tar.gz: da8b157b33839272a2647e201111a4349451a62c569195e95c293071c77800df
5
5
  SHA512:
6
- metadata.gz: acf4406ebca9f8ec7bee91d47d8ab9f187b7e5da5253d64ddf58d2e66f451c1f54522ae43eaee1a9002f490101c7b4323bf0591ad0765d49befffdd4134e1c6b
7
- data.tar.gz: 39c9ce533a34f54a95ee4147759fddfb5ebcc0c985c0b32b9ea0cdbe75865752aba7c4add64c0a60c51f7acae4585342c73a08a1c165c2eb8ed0b0852d116f37
6
+ metadata.gz: 3ba10779043886b9870cd78fbbda175362c231a9afd824fa4d0a2107284d16ce493dd76469f542f8508359efd57041306e1727f645c409100e16e50712cf74a9
7
+ data.tar.gz: 6c497e6e9d39c7b537a5f07fb14306850b53cfe77b12653cb0ce6dd2b1e4329ce199fb73c007beb50c945e193146cddb7ad20cd1526f1beb15a5b3ee828f86b3
data/exe/bslg CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require_relative '../lib/blend_spreadsheet_loan_generator'
4
+
4
5
  Dry::CLI.new(BlendSpreadsheetLoanGenerator).call
@@ -44,11 +44,11 @@ module BlendSpreadsheetLoanGenerator
44
44
  values = f.to_a
45
45
  values.map! { |r| set_types([columns, r].transpose.to_h.with_indifferent_access) }
46
46
 
47
- 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
48
48
  guaranteed_line = values.index { |term| term[:index] == options.fetch(:guaranteed_terms, -1).to_i } || nil
49
49
  total_guaranteed_interests = (
50
- if guaranteed_line.present? && guaranteed_line > last_paid_line
51
- values[(last_paid_line + 1)..guaranteed_line].sum { |value| value[:period_calculated_interests] }
50
+ if guaranteed_line.present? && guaranteed_line >= (last_paid_line + 2)
51
+ values[(last_paid_line + 2)..guaranteed_line].sum { |value| value[:period_calculated_interests] }
52
52
  else
53
53
  0
54
54
  end
@@ -65,7 +65,14 @@ module BlendSpreadsheetLoanGenerator
65
65
  if total_to_be_paid == amount_paid
66
66
  1
67
67
  else
68
- 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
+ )
69
76
  end
70
77
  )
71
78
 
@@ -73,16 +80,26 @@ module BlendSpreadsheetLoanGenerator
73
80
 
74
81
  capital_paid = amount_paid.to_f - (
75
82
  values[last_paid_line + 1][:capitalized_interests_start] +
76
- values[last_paid_line + 1][:capitalized_fees_start]
83
+ values[last_paid_line + 1][:capitalized_fees_start] +
84
+ values[last_paid_line + 1][:period_calculated_interests] +
85
+ values[last_paid_line + 1][:period_calculated_fees]
77
86
  )
87
+
78
88
  ratio = options.fetch(:ratio, (capital_paid.to_f / values[last_paid_line + 1][:remaining_capital_start])).to_f
79
89
  guaranteed_interests_paid = (
80
90
  ratio * total_guaranteed_interests
81
91
  )
82
- capital_paid -= guaranteed_interests_paid
92
+
93
+ amount = (
94
+ if last_paid_line == -1
95
+ values[0][:remaining_capital_start]
96
+ else
97
+ values[last_paid_line][:remaining_capital_end]
98
+ end
99
+ )
83
100
 
84
101
  @loan = Loan.new(
85
- amount: values[last_paid_line][:remaining_capital_end],
102
+ amount: amount,
86
103
  duration: duration,
87
104
  rate: rate,
88
105
  fees_rate: options.fetch(:fees_rate),
@@ -104,10 +121,10 @@ module BlendSpreadsheetLoanGenerator
104
121
  apply_formulas(worksheet: worksheet)
105
122
 
106
123
  worksheet[2, columns.index('remaining_capital_start') + 1] =
107
- excel_float(values[last_paid_line][:remaining_capital_end])
124
+ excel_float(values[last_paid_line + 1][:remaining_capital_start])
108
125
 
109
126
  worksheet[2, columns.index('remaining_capital_end') + 1] =
110
- "=#{excel_float(values[last_paid_line][:remaining_capital_end])} - #{period_capital(2)}"
127
+ "=#{excel_float(values[last_paid_line + 1][:remaining_capital_start])} - #{period_capital(2)}"
111
128
 
112
129
  worksheet[2, columns.index('period_interests') + 1] =
113
130
  "=ARRONDI(#{period_theoric_interests(2)}; 2)"
@@ -118,8 +135,7 @@ module BlendSpreadsheetLoanGenerator
118
135
  worksheet[2, columns.index('period_fees') + 1] =
119
136
  "=#{excel_float(values[last_paid_line + 1][:period_calculated_fees])}"
120
137
 
121
- worksheet[2, columns.index('period_capital') + 1] =
122
- "=#{excel_float(capital_paid)} - #{period_interests(2)} - #{period_fees(2)}"
138
+ worksheet[2, columns.index('period_capital') + 1] = "=#{excel_float(capital_paid)}"
123
139
 
124
140
  worksheet[2, columns.index('capitalized_interests_start') + 1] =
125
141
  excel_float(values[last_paid_line + 1][:capitalized_interests_start])
@@ -1,7 +1,7 @@
1
1
  require 'dry/cli'
2
2
 
3
3
  module BlendSpreadsheetLoanGenerator
4
- VERSION = '0.1.21'.freeze
4
+ VERSION = '0.1.26'.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.21
4
+ version: 0.1.26
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-13 00:00:00.000000000 Z
11
+ date: 2021-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport