blend_spreadsheet_loan_generator 0.1.37 → 0.1.41

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: 27190e62c6f022886585a05178b48b3145887fc2299d32dd184572d034f8a22f
4
- data.tar.gz: 4208f3be04bc68c700ad262fcd90e7e6130c3eb3414ef5ac8ae46035a6d7cb30
3
+ metadata.gz: 1357474c60cfb9e4c2856a80890d3d009fc78a66d38848e1b280ba3e1326dbd1
4
+ data.tar.gz: 6c7c524d35b0877d3d8a446142fc7c3e7bb5291af9fa9c07fc8343334e7dba6f
5
5
  SHA512:
6
- metadata.gz: 075fae95ddf44ce9ce1b360debd2942c5cfbb94a623f9f37519f74109db3f43cab3624953c383a14dfc829819a1e3d363e569aada4305ea63755313ccc58df3b
7
- data.tar.gz: 1c2721d5083b1e9e5bda9055dcc9ae3afe69744fb3b98036373a6b57f18e2d6dce2e0d34e0894cff7e21c8dd376b5fe9ea3e9790935e85cf721dc6456328327c
6
+ metadata.gz: 774098b91a0e32d71bfa251adf70f888e5a2447172da89fe6f8310d2e6dc460910c3c9e60cf05589e41fd03a95ad466b3ee1fc3a1f2c2e98d3713ef49a96736e
7
+ data.tar.gz: 269d14778cc7c31d65a900e6542cc2a0dfe101d07aa2670b11bf8ed22b9556cf13d97df81b2d64a3f615d7c03d5b50a52baf56927b7904c6b04d72c5e46bf009
@@ -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])
@@ -168,18 +168,26 @@ module BlendSpreadsheetLoanGenerator
168
168
  end
169
169
  end
170
170
 
171
- def period_calculated_fees_formula(line:)
171
+ def period_calculated_fees_formula(line:, early_repayment: false)
172
172
  term = line - 1
173
173
  if loan.deferred_and_capitalized > 0 && term > loan.deferred_and_capitalized
174
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
175
  without_fees = "#{remaining_capital_start(line)} * (1 + #{period_rate(line)})^#{loan.deferred_and_capitalized} * #{period_rate(line)}"
176
+
176
177
  "=#{with_fees} - #{without_fees}"
177
- elsif loan.bullet? && term == loan.duration
178
- with_fees = "#{remaining_capital_start(line)} * (1 + #{period_fees_rate(line)} + #{period_rate(line)})^#{index(line)}"
179
- without_fees = "#{remaining_capital_start(line)} * (1 + #{period_rate(line)})^#{index(line)}"
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}"
180
188
  current = "#{with_fees} - #{without_fees}"
181
189
 
182
- "=#{current} - #{capitalized_fees_end(line - 1)}"
190
+ "=#{current} - #{capitalized_fees_start(line)}"
183
191
  else
184
192
  amount_to_capitalize = [
185
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.37'.freeze
4
+ VERSION = '0.1.41'.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.37
4
+ version: 0.1.41
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-27 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