blend_spreadsheet_loan_generator 0.1.45 → 0.1.102

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: cca84a8a3514638dbbdf412c9c3847f2e5ec299c6a057fe31bf64bed84214d5b
4
- data.tar.gz: bbcea0582d8d49b4deeb03fd18e7485d2c721c74c63625fc0b7b5319d5ff870f
3
+ metadata.gz: bfe713bbe1e4e57601559e592fc0a5fc621b5e72e151bb100ac341c6e29b8690
4
+ data.tar.gz: 409a0e1d8cc8a91926638577fb97d18794b25338c786547550f18dd849f525ef
5
5
  SHA512:
6
- metadata.gz: 1040a0c2b2c5e7a2fbfc4bbb2b277ffa136ce4b57b849a1e96a5f7710aa84125940c779be295ae1cee150427d9c5d4c56b301497d3afcd2cedf079f73177e537
7
- data.tar.gz: 4736c7b12ec0202759f72a953f81da8001c317d6183dfb8846ed0b3695c56a6a55bb58566e7ebdfd1bc85ff1965ee0c9c2bd141bf6dc9e6e6e86e236a13b3aa5
6
+ metadata.gz: 1b4e6474624e79661081ab0ef187b8518d22e8ba79a3840aa30d4b7ef111db9442a367902621358b70f4cd37579516e526551a4b7603a6100e158c1097baf668
7
+ data.tar.gz: 3cb5ee2b57bf520c54ac42e35f43a33da737c1df2a6a2ea3714a2a34cb2e97a224d74f402dc797880f49773abd046885177fbd79af4be44505904703ac5f2358
@@ -87,21 +87,21 @@ module BlendSpreadsheetLoanGenerator
87
87
  end
88
88
  end
89
89
 
90
- def custom_early_repayment
90
+ def first_term_skip_columns
91
91
  %w[
92
92
  period_calculated_fees
93
93
  capitalized_fees_end
94
94
  ]
95
95
  end
96
96
 
97
- def apply_formulas(worksheet:, early_repayment: false)
97
+ def apply_formulas(worksheet:, first_term_skip: false)
98
98
  columns.each.with_index do |title, column|
99
99
  worksheet[1, column + 1] = title
100
100
  end
101
101
  loan.duration.times do |line|
102
102
  columns.each.with_index do |title, column|
103
- if early_repayment && title.in?(custom_early_repayment)
104
- worksheet[line + 2, column + 1] = @formula.send("#{title}_formula", line: line + 2, early_repayment: true)
103
+ if first_term_skip && title.in?(first_term_skip_columns)
104
+ worksheet[line + 2, column + 1] = @formula.send("#{title}_formula", line: line + 2, first_term_skip: true)
105
105
  else
106
106
  worksheet[line + 2, column + 1] = @formula.send("#{title}_formula", line: line + 2)
107
107
  end
@@ -127,7 +127,7 @@ module BlendSpreadsheetLoanGenerator
127
127
 
128
128
  @formula = Formula.new(loan: loan)
129
129
 
130
- apply_formulas(worksheet: worksheet, early_repayment: true)
130
+ apply_formulas(worksheet: worksheet, first_term_skip: 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])
@@ -168,24 +168,21 @@ module BlendSpreadsheetLoanGenerator
168
168
  end
169
169
  end
170
170
 
171
- def period_calculated_fees_formula(line:, early_repayment: false)
171
+ def period_calculated_fees_formula(line:, first_term_skip: false)
172
172
  term = line - 1
173
173
  if loan.bullet_term?(term)
174
- index = (
175
- if early_repayment
176
- index(line - 1)
177
- else
178
- index(line)
179
- end
180
- )
174
+ index = first_term_skip ? index(line - 1) : index(line)
175
+
181
176
  with_fees = "#{remaining_capital_start(line)} * (1 + #{period_fees_rate(line)} + #{period_rate(line)})^#{index}"
182
177
  without_fees = "#{remaining_capital_start(line)} * (1 + #{period_rate(line)})^#{index}"
183
178
  current = "#{with_fees} - #{without_fees}"
184
179
 
185
180
  "=#{current} - #{capitalized_fees_start(line)}"
186
181
  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)}"
182
+ index = first_term_skip ? loan.deferred_and_capitalized : loan.deferred_and_capitalized - 1
183
+
184
+ with_fees = "#{remaining_capital_start(line)} * (1 + #{period_rate(line)} + #{period_fees_rate(line)})^#{index} * (#{period_rate(line)} + #{period_fees_rate(line)})"
185
+ without_fees = "#{remaining_capital_start(line)} * (1 + #{period_rate(line)})^#{index} * #{period_rate(line)}"
189
186
 
190
187
  "=#{with_fees} - #{without_fees}"
191
188
  else
@@ -207,10 +204,10 @@ module BlendSpreadsheetLoanGenerator
207
204
  "=ARRONDI(#{capitalized_fees_end(line - 1)}; 2)"
208
205
  end
209
206
 
210
- def capitalized_fees_end_formula(line:, early_repayment: false)
207
+ def capitalized_fees_end_formula(line:, first_term_skip: false)
211
208
  term = line - 1
212
209
  if term <= loan.deferred_and_capitalized
213
- index = early_repayment ? index(line - 1) : index(line)
210
+ index = first_term_skip ? index(line - 1) : index(line)
214
211
  with_fees = "#{remaining_capital_start(line)} * (1 + #{period_fees_rate(line)} + #{period_rate(line)})^#{index}"
215
212
  without_fees = "#{remaining_capital_start(line)} * (1 + #{period_rate(line)})^#{index}"
216
213
  "=ARRONDI(#{with_fees} - #{without_fees}; 2)"
@@ -74,7 +74,7 @@ module BlendSpreadsheetLoanGenerator
74
74
 
75
75
  @formula = Formula.new(loan: loan)
76
76
 
77
- apply_formulas(worksheet: worksheet)
77
+ apply_formulas(worksheet: worksheet, first_term_skip: true)
78
78
  apply_formats(worksheet: worksheet)
79
79
 
80
80
  worksheet.save
@@ -1,7 +1,7 @@
1
1
  require 'dry/cli'
2
2
 
3
3
  module BlendSpreadsheetLoanGenerator
4
- VERSION = '0.1.45'.freeze
4
+ VERSION = '0.1.102'.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.45
4
+ version: 0.1.102
5
5
  platform: ruby
6
6
  authors:
7
7
  - MZiserman