blend_spreadsheet_loan_generator 0.1.43 → 0.1.100

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: 579b2d03b24b45a57e78c9c5ddf59b268e308bed4cc8430abe7d1c16ef0f1947
4
- data.tar.gz: c0ba98674ce0c1d2a77571969e30fd4dbdb4da04a7c38dff8fbce8e66dc939d7
3
+ metadata.gz: '094d6041671fe31e1d4065b08a380527d0c823a14921d1e240fe27668de71062'
4
+ data.tar.gz: 445f25c29e92de5b36dcd6a687f4a94fbfe0a2d30705dd623fb1f03315f3991a
5
5
  SHA512:
6
- metadata.gz: 839a032643e22e7445b1dfe06d3cc2bd97db8ee65c84bc2f4e18f157206a5a068b83825100595af093dde0925babfb3a119843ed321cb36a52f08974323e789a
7
- data.tar.gz: f17f59099f9ab23e65cbef14230c76bd17ce90aad022d9e433a4b3b53bf2ec4cafefc82c988ca478e0ceac8b606acade5c89845f0edecb254dfc5876db6f1971
6
+ metadata.gz: 12f8be613825bbf69472ea9332e72d77ef85d4cf53072f1734ac3be632b0ddcfa2d7a3b9f53e7cb6dc2fb719de90a364e7c76dee05995215753233f7d10f5d9c
7
+ data.tar.gz: 9c0735c99dcf516f92b9458dedd69e42e2c303df500dfaf809d0164cc35054f26dd34e9c48d2f6ba558aeb12e1a702253e2f3e6aacdc74456f23afac837ef577
@@ -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?(custom_early_repayment)
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,26 +168,23 @@ 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
- 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)}"
173
+ if loan.bullet_term?(term)
174
+ index = first_term_skip ? index(line - 1) : index(line)
176
175
 
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
176
  with_fees = "#{remaining_capital_start(line)} * (1 + #{period_fees_rate(line)} + #{period_rate(line)})^#{index}"
187
177
  without_fees = "#{remaining_capital_start(line)} * (1 + #{period_rate(line)})^#{index}"
188
178
  current = "#{with_fees} - #{without_fees}"
189
179
 
190
180
  "=#{current} - #{capitalized_fees_start(line)}"
181
+ elsif loan.deferred_and_capitalized > 0 && term > loan.deferred_and_capitalized
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)}"
186
+
187
+ "=#{with_fees} - #{without_fees}"
191
188
  else
192
189
  amount_to_capitalize = [
193
190
  '(',
@@ -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)"
@@ -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?
@@ -72,7 +72,7 @@ module BlendSpreadsheetLoanGenerator
72
72
  spreadsheet = session.create_spreadsheet(loan.name)
73
73
  worksheet = spreadsheet.add_worksheet(loan.type, loan.duration + 2, columns.count + 1, index: 0)
74
74
 
75
- @formula = Formula.new(loan: loan)
75
+ @formula = Formula.new(loan: loan, first_term_skip: true)
76
76
 
77
77
  apply_formulas(worksheet: worksheet)
78
78
  apply_formats(worksheet: worksheet)
@@ -1,7 +1,7 @@
1
1
  require 'dry/cli'
2
2
 
3
3
  module BlendSpreadsheetLoanGenerator
4
- VERSION = '0.1.43'.freeze
4
+ VERSION = '0.1.100'.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.43
4
+ version: 0.1.100
5
5
  platform: ruby
6
6
  authors:
7
7
  - MZiserman