blend_spreadsheet_loan_generator 0.1.26 → 0.1.30

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: 46ffd519aaf8bc1d7b8bb2bb84c376e107f04cf2c8af6ee23ad028a563e63d8b
4
- data.tar.gz: da8b157b33839272a2647e201111a4349451a62c569195e95c293071c77800df
3
+ metadata.gz: c65bb8dcbc3561cd3fa134d4eac3153934937c0de336afd2f41054a87e87a1e0
4
+ data.tar.gz: d90db3f308d1b6580f70d3c898e9ff38c0dc2fdbb59cd5c688b08a12169b232d
5
5
  SHA512:
6
- metadata.gz: 3ba10779043886b9870cd78fbbda175362c231a9afd824fa4d0a2107284d16ce493dd76469f542f8508359efd57041306e1727f645c409100e16e50712cf74a9
7
- data.tar.gz: 6c497e6e9d39c7b537a5f07fb14306850b53cfe77b12653cb0ce6dd2b1e4329ce199fb73c007beb50c945e193146cddb7ad20cd1526f1beb15a5b3ee828f86b3
6
+ metadata.gz: 531b9805eb3433e1835010a33fda24014e7071b5a21692bf8e66c78aeebe6cd45a1d05048158d97ccb484c2e9b3b76315034aad73efd7923b6b511a5e695331d
7
+ data.tar.gz: 0c2e0a0d93fff9c3620abbf6cea28750f7375e1fb4becc799447e481ec655b02c94ca07907712aef2aed350bd5a798b03ffc22ce85a7f3d184294de0336ebaf8
@@ -27,24 +27,3 @@ module BlendSpreadsheetLoanGenerator
27
27
  end
28
28
  end
29
29
  end
30
-
31
-
32
- def generate_csv(data:, name:)
33
- CSV.open(name, 'wb') do |csv|
34
- data.each do |datum|
35
- row = []
36
- datum.each.with_index do |value, index|
37
- row << (
38
- if index == 0
39
- value.to_i
40
- elsif index == 1
41
- Date.parse(value).strftime('%m/%d/%Y')
42
- else
43
- value.gsub(',', '.').to_f
44
- end
45
- )
46
- end
47
- csv << row
48
- end
49
- end
50
- end
@@ -33,6 +33,7 @@ module BlendSpreadsheetLoanGenerator
33
33
  period_reimbursed_capitalized_fees
34
34
  period_fees_rate
35
35
  period_reimbursed_guaranteed_interests
36
+ period_reimbursed_guaranteed_fees
36
37
  ]
37
38
  end
38
39
 
@@ -54,6 +55,7 @@ module BlendSpreadsheetLoanGenerator
54
55
  capitalized_fees_end
55
56
  period_reimbursed_capitalized_fees
56
57
  period_reimbursed_guaranteed_interests
58
+ period_reimbursed_guaranteed_fees
57
59
  ]
58
60
  end
59
61
 
@@ -46,13 +46,14 @@ module BlendSpreadsheetLoanGenerator
46
46
 
47
47
  last_paid_line = values.index { |term| term[:index] == last_paid_term.to_i } || -1
48
48
  guaranteed_line = values.index { |term| term[:index] == options.fetch(:guaranteed_terms, -1).to_i } || nil
49
- total_guaranteed_interests = (
50
- if guaranteed_line.present? && guaranteed_line >= (last_paid_line + 2)
51
- values[(last_paid_line + 2)..guaranteed_line].sum { |value| value[:period_calculated_interests] }
52
- else
53
- 0
54
- end
55
- )
49
+
50
+ if guaranteed_line.present? && guaranteed_line >= (last_paid_line + 2)
51
+ total_guaranteed_interests = values[(last_paid_line + 2)..guaranteed_line].sum { |value| value[:period_calculated_interests] }
52
+ total_guaranteed_fees = values[(last_paid_line + 2)..guaranteed_line].sum { |value| value[:period_calculated_fees] }
53
+ else
54
+ total_guaranteed_interests = 0
55
+ total_guaranteed_fees = 0
56
+ end
56
57
 
57
58
  total_to_be_paid = (
58
59
  values[last_paid_line + 1][:remaining_capital_start] +
@@ -84,12 +85,20 @@ module BlendSpreadsheetLoanGenerator
84
85
  values[last_paid_line + 1][:period_calculated_interests] +
85
86
  values[last_paid_line + 1][:period_calculated_fees]
86
87
  )
87
-
88
- ratio = options.fetch(:ratio, (capital_paid.to_f / values[last_paid_line + 1][:remaining_capital_start])).to_f
89
- guaranteed_interests_paid = (
90
- ratio * total_guaranteed_interests
88
+ capital_paid_for_ratio = amount_paid.to_f - (
89
+ values[last_paid_line + 1][:capitalized_fees_start] +
90
+ values[last_paid_line + 1][:period_calculated_fees]
91
+ )
92
+ remaining_capital_for_ratio = (
93
+ values[last_paid_line + 1][:remaining_capital_start] +
94
+ values[last_paid_line + 1][:capitalized_interests_start] +
95
+ values[last_paid_line + 1][:period_calculated_interests]
91
96
  )
92
97
 
98
+ ratio = options.fetch(:ratio, capital_paid_for_ratio.to_f / remaining_capital_for_ratio).to_f
99
+ guaranteed_interests_paid = ratio * total_guaranteed_interests
100
+ guaranteed_fees_paid = ratio * total_guaranteed_fees
101
+
93
102
  amount = (
94
103
  if last_paid_line == -1
95
104
  values[0][:remaining_capital_start]
@@ -156,6 +165,9 @@ module BlendSpreadsheetLoanGenerator
156
165
  worksheet[2, columns.index('period_reimbursed_guaranteed_interests') + 1] =
157
166
  excel_float(guaranteed_interests_paid)
158
167
 
168
+ worksheet[2, columns.index('period_reimbursed_guaranteed_fees') + 1] =
169
+ excel_float(guaranteed_fees_paid)
170
+
159
171
  apply_formats(worksheet: worksheet)
160
172
 
161
173
  worksheet.save
@@ -196,6 +208,7 @@ module BlendSpreadsheetLoanGenerator
196
208
  h[:period_reimbursed_capitalized_fees] = h[:period_reimbursed_capitalized_fees].to_f
197
209
  h[:period_fees_rate] = h[:period_fees_rate].to_f
198
210
  h[:period_reimbursed_guaranteed_interests] = h[:period_reimbursed_guaranteed_interests].to_f
211
+ h[:period_reimbursed_guaranteed_fees] = h[:period_reimbursed_guaranteed_fees].to_f
199
212
 
200
213
  h
201
214
  end
@@ -191,7 +191,9 @@ module BlendSpreadsheetLoanGenerator
191
191
  def capitalized_fees_end_formula(line:)
192
192
  term = line - 1
193
193
  if term <= loan.deferred_and_capitalized
194
- "=ARRONDI(#{capitalized_fees_start(line)} + #{period_calculated_fees(line)}; 2)"
194
+ with_fees = "#{remaining_capital_start_formula(line)} * (1 + #{period_fees_rate(line)} + #{period_rate(line)})^#{index(line)}"
195
+ without_fees = "#{remaining_capital_start_formula(line)} * (1 + #{period_rate(line)})^#{index(line)}"
196
+ "=ARRONDI(#{with_fees} - #{without_fees})"
195
197
  else
196
198
  "=ARRONDI(#{capitalized_fees_start(line)} - #{period_reimbursed_capitalized_fees(line)}; 2)"
197
199
  end
@@ -213,5 +215,9 @@ module BlendSpreadsheetLoanGenerator
213
215
  def period_reimbursed_guaranteed_interests_formula(line:)
214
216
  excel_float(0.0)
215
217
  end
218
+
219
+ def period_reimbursed_guaranteed_fees_formula(line:)
220
+ excel_float(0.0)
221
+ end
216
222
  end
217
223
  end
@@ -24,12 +24,6 @@ module BlendSpreadsheetLoanGenerator
24
24
 
25
25
  def call(amount:, duration:, rate:, **options)
26
26
  begin
27
- # session = GoogleDrive::Session.from_service_account_key(
28
- # File.join(
29
- # ENV['SPREADSHEET_LOAN_GENERATOR_DIR'],
30
- # 'loan-spreadsheet-generator-6c27a42bdda7.json'
31
- # )
32
- # )
33
27
  session = GoogleDrive::Session.from_config(
34
28
  File.join(ENV['SPREADSHEET_LOAN_GENERATOR_DIR'], 'config.json')
35
29
  )
@@ -71,9 +65,6 @@ module BlendSpreadsheetLoanGenerator
71
65
  generate_csv(worksheet: worksheet, target_path: options.fetch(:target_path))
72
66
 
73
67
  puts worksheet.human_url
74
- rescue => e
75
- require 'pry'
76
- binding.pry
77
68
  end
78
69
  end
79
70
  end
@@ -1,7 +1,7 @@
1
1
  require 'dry/cli'
2
2
 
3
3
  module BlendSpreadsheetLoanGenerator
4
- VERSION = '0.1.26'.freeze
4
+ VERSION = '0.1.30'.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.26
4
+ version: 0.1.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - MZiserman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-15 00:00:00.000000000 Z
11
+ date: 2021-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport