blend_spreadsheet_loan_generator 0.1.36 → 0.1.40

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: 5a7e3accb3a4c91a0e137d14ce6edd247ee88ebfe3d0274eecc6c00c8992bff3
4
- data.tar.gz: 07d4a5959dfff0b803ebd21d8bd8373169d5e59e112a8ed8d9004cdfa6afff0c
3
+ metadata.gz: 36f54b0c351b2b367ae9742d235e2aaa484df2e16388935da8ca576aa405b862
4
+ data.tar.gz: f87380832034597138217d523984e200e45c3826433ad4e25d9addc03b344da8
5
5
  SHA512:
6
- metadata.gz: f696017d9e91af295abfa3f6c35a2a8a166b4c2db458df06119e8572d19e36bdba78442f2529cced271394e5652fe8c29483c322daf513a75faeb28dcb5a8bd3
7
- data.tar.gz: d98ef75e469b8bda35fd9a6d1f46ebaecf7e57d2f3e20164f7b2839a147aba24a1b2d5d59e09da7d13a97e317a89e98bac144efd05177a02b2b1594b0be8fe57
6
+ metadata.gz: 2cfa0694a3f2ef0ca4fe5e85025e1f6912bc37c2667ff0fe872add54a85664f7868dc79d79c96fdf5a753485aa5685652f7f4af9499e06f417187e85448e5eed
7
+ data.tar.gz: 5dbd7beb01e12da8b58f6402769c0842b0929a61e04fefc93f427ba94b5ccc34d53b21517b2dad53b9f32eea6f620636d03638f000dafe76d787f927e72635ba
@@ -87,13 +87,17 @@ module BlendSpreadsheetLoanGenerator
87
87
  end
88
88
  end
89
89
 
90
- def apply_formulas(worksheet:)
90
+ def apply_formulas(worksheet:, early_repayment?: true)
91
91
  columns.each.with_index do |title, column|
92
92
  worksheet[1, column + 1] = title
93
93
  end
94
94
  loan.duration.times do |line|
95
95
  columns.each.with_index do |title, column|
96
- worksheet[line + 2, column + 1] = @formula.send("#{title}_formula", line: line + 2)
96
+ if early_repayment && title == 'period_calculated_fees'
97
+ worksheet[line + 2, column + 1] = @formula.send("#{title}_formula", line: line + 2, early_repayment?: true)
98
+ else
99
+ worksheet[line + 2, column + 1] = @formula.send("#{title}_formula", line: line + 2)
100
+ end
97
101
  end
98
102
  end
99
103
  end
@@ -127,7 +127,7 @@ module BlendSpreadsheetLoanGenerator
127
127
 
128
128
  @formula = Formula.new(loan: loan)
129
129
 
130
- apply_formulas(worksheet: worksheet)
130
+ apply_formulas(worksheet: worksheet, early_repayment?: true)
131
131
 
132
132
  worksheet[2, columns.index('remaining_capital_start') + 1] =
133
133
  excel_float(values[last_paid_line + 1][:remaining_capital_start])
@@ -163,19 +163,31 @@ module BlendSpreadsheetLoanGenerator
163
163
  term = line - 1
164
164
  if term <= loan.deferred_and_capitalized
165
165
  excel_float(0.0)
166
- elsif loan.deferred_and_capitalized > 0 && loan.deferred.present?
167
-
168
166
  else
169
167
  "=ARRONDI(#{period_calculated_fees(line)}; 2)"
170
168
  end
171
169
  end
172
170
 
173
- def period_calculated_fees_formula(line:)
171
+ def period_calculated_fees_formula(line:, early_repayment?: false)
174
172
  term = line - 1
175
173
  if loan.deferred_and_capitalized > 0 && term > loan.deferred_and_capitalized
176
174
  with_fees = "#{remaining_capital_start(line)} * (1 + #{period_rate(line)} + #{period_fees_rate(line)})^#{loan.deferred_and_capitalized} * (#{period_rate(line)} + #{period_fees_rate(line)})"
177
175
  without_fees = "#{remaining_capital_start(line)} * (1 + #{period_rate(line)})^#{loan.deferred_and_capitalized} * #{period_rate(line)}"
176
+
178
177
  "=#{with_fees} - #{without_fees}"
178
+ elsif loan.bullet_term?(term)
179
+ index = (
180
+ if early_repayment?
181
+ index(line - 1)
182
+ else
183
+ index(line)
184
+ end
185
+ )
186
+ with_fees = "#{remaining_capital_start(line)} * (1 + #{period_fees_rate(line)} + #{period_rate(line)})^#{index}"
187
+ without_fees = "#{remaining_capital_start(line)} * (1 + #{period_rate(line)})^#{index}"
188
+ current = "#{with_fees} - #{without_fees}"
189
+
190
+ "=#{current} - #{capitalized_fees_start(line)}"
179
191
  else
180
192
  amount_to_capitalize = [
181
193
  '(',
@@ -112,6 +112,10 @@ module BlendSpreadsheetLoanGenerator
112
112
  fully_deferred? && deferred_and_capitalized == total_deferred_duration
113
113
  end
114
114
 
115
+ def bullet_term?(term)
116
+ deferred_and_capitalized <= term || bullet? # for last term
117
+ end
118
+
115
119
  def in_fine?
116
120
  fully_deferred? && deferred == total_deferred_duration
117
121
  end
@@ -1,7 +1,7 @@
1
1
  require 'dry/cli'
2
2
 
3
3
  module BlendSpreadsheetLoanGenerator
4
- VERSION = '0.1.36'.freeze
4
+ VERSION = '0.1.40'.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.36
4
+ version: 0.1.40
5
5
  platform: ruby
6
6
  authors:
7
7
  - MZiserman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-24 00:00:00.000000000 Z
11
+ date: 2021-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport