blend_spreadsheet_loan_generator 0.1.41 → 0.1.45

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: 1357474c60cfb9e4c2856a80890d3d009fc78a66d38848e1b280ba3e1326dbd1
4
- data.tar.gz: 6c7c524d35b0877d3d8a446142fc7c3e7bb5291af9fa9c07fc8343334e7dba6f
3
+ metadata.gz: cca84a8a3514638dbbdf412c9c3847f2e5ec299c6a057fe31bf64bed84214d5b
4
+ data.tar.gz: bbcea0582d8d49b4deeb03fd18e7485d2c721c74c63625fc0b7b5319d5ff870f
5
5
  SHA512:
6
- metadata.gz: 774098b91a0e32d71bfa251adf70f888e5a2447172da89fe6f8310d2e6dc460910c3c9e60cf05589e41fd03a95ad466b3ee1fc3a1f2c2e98d3713ef49a96736e
7
- data.tar.gz: 269d14778cc7c31d65a900e6542cc2a0dfe101d07aa2670b11bf8ed22b9556cf13d97df81b2d64a3f615d7c03d5b50a52baf56927b7904c6b04d72c5e46bf009
6
+ metadata.gz: 1040a0c2b2c5e7a2fbfc4bbb2b277ffa136ce4b57b849a1e96a5f7710aa84125940c779be295ae1cee150427d9c5d4c56b301497d3afcd2cedf079f73177e537
7
+ data.tar.gz: 4736c7b12ec0202759f72a953f81da8001c317d6183dfb8846ed0b3695c56a6a55bb58566e7ebdfd1bc85ff1965ee0c9c2bd141bf6dc9e6e6e86e236a13b3aa5
@@ -87,13 +87,20 @@ module BlendSpreadsheetLoanGenerator
87
87
  end
88
88
  end
89
89
 
90
- def apply_formulas(worksheet:, early_repayment: true)
90
+ def custom_early_repayment
91
+ %w[
92
+ period_calculated_fees
93
+ capitalized_fees_end
94
+ ]
95
+ end
96
+
97
+ def apply_formulas(worksheet:, early_repayment: false)
91
98
  columns.each.with_index do |title, column|
92
99
  worksheet[1, column + 1] = title
93
100
  end
94
101
  loan.duration.times do |line|
95
102
  columns.each.with_index do |title, column|
96
- if early_repayment && title == 'period_calculated_fees'
103
+ if early_repayment && title.in?(custom_early_repayment)
97
104
  worksheet[line + 2, column + 1] = @formula.send("#{title}_formula", line: line + 2, early_repayment: true)
98
105
  else
99
106
  worksheet[line + 2, column + 1] = @formula.send("#{title}_formula", line: line + 2)
@@ -168,6 +168,10 @@ module BlendSpreadsheetLoanGenerator
168
168
  worksheet[2, columns.index('period_reimbursed_guaranteed_fees') + 1] =
169
169
  excel_float(guaranteed_fees_paid)
170
170
 
171
+ worksheet[2, columns.index('period_calculated_fees') + 1] =
172
+ excel_float(0.0)
173
+
174
+
171
175
  apply_formats(worksheet: worksheet)
172
176
 
173
177
  worksheet.save
@@ -170,12 +170,7 @@ module BlendSpreadsheetLoanGenerator
170
170
 
171
171
  def period_calculated_fees_formula(line:, early_repayment: false)
172
172
  term = line - 1
173
- if loan.deferred_and_capitalized > 0 && term > loan.deferred_and_capitalized
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)})"
175
- without_fees = "#{remaining_capital_start(line)} * (1 + #{period_rate(line)})^#{loan.deferred_and_capitalized} * #{period_rate(line)}"
176
-
177
- "=#{with_fees} - #{without_fees}"
178
- elsif loan.bullet_term?(term)
173
+ if loan.bullet_term?(term)
179
174
  index = (
180
175
  if early_repayment
181
176
  index(line - 1)
@@ -188,6 +183,11 @@ module BlendSpreadsheetLoanGenerator
188
183
  current = "#{with_fees} - #{without_fees}"
189
184
 
190
185
  "=#{current} - #{capitalized_fees_start(line)}"
186
+ elsif loan.deferred_and_capitalized > 0 && term > loan.deferred_and_capitalized
187
+ 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)})"
188
+ without_fees = "#{remaining_capital_start(line)} * (1 + #{period_rate(line)})^#{loan.deferred_and_capitalized} * #{period_rate(line)}"
189
+
190
+ "=#{with_fees} - #{without_fees}"
191
191
  else
192
192
  amount_to_capitalize = [
193
193
  '(',
@@ -207,11 +207,12 @@ module BlendSpreadsheetLoanGenerator
207
207
  "=ARRONDI(#{capitalized_fees_end(line - 1)}; 2)"
208
208
  end
209
209
 
210
- def capitalized_fees_end_formula(line:)
210
+ def capitalized_fees_end_formula(line:, early_repayment: false)
211
211
  term = line - 1
212
212
  if term <= loan.deferred_and_capitalized
213
- with_fees = "#{remaining_capital_start(line)} * (1 + #{period_fees_rate(line)} + #{period_rate(line)})^#{index(line)}"
214
- without_fees = "#{remaining_capital_start(line)} * (1 + #{period_rate(line)})^#{index(line)}"
213
+ index = early_repayment ? index(line - 1) : index(line)
214
+ with_fees = "#{remaining_capital_start(line)} * (1 + #{period_fees_rate(line)} + #{period_rate(line)})^#{index}"
215
+ without_fees = "#{remaining_capital_start(line)} * (1 + #{period_rate(line)})^#{index}"
215
216
  "=ARRONDI(#{with_fees} - #{without_fees}; 2)"
216
217
  else
217
218
  "=ARRONDI(#{capitalized_fees_start(line)} - #{period_reimbursed_capitalized_fees(line)}; 2)"
@@ -113,7 +113,7 @@ module BlendSpreadsheetLoanGenerator
113
113
  end
114
114
 
115
115
  def bullet_term?(term)
116
- deferred_and_capitalized <= term || bullet? # for last term
116
+ deferred_and_capitalized >= term || bullet? # for last term
117
117
  end
118
118
 
119
119
  def in_fine?
@@ -1,7 +1,7 @@
1
1
  require 'dry/cli'
2
2
 
3
3
  module BlendSpreadsheetLoanGenerator
4
- VERSION = '0.1.41'.freeze
4
+ VERSION = '0.1.45'.freeze
5
5
 
6
6
  class Version < Dry::CLI::Command
7
7
  desc 'Print version'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blend_spreadsheet_loan_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.41
4
+ version: 0.1.45
5
5
  platform: ruby
6
6
  authors:
7
7
  - MZiserman