blend_spreadsheet_loan_generator 0.1.15 → 0.1.16

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: 41bd051665f94b48954cb0d2067a075a9740eb8da3e72b672be25a724ffdeee2
4
- data.tar.gz: 17a1bbd4686e4a92a7da7720de63f71a5387455563e1853b1bce25508556187b
3
+ metadata.gz: bbb638c6b9da3b44d76b3c6bdcd25ff0c72c859e1f972e5f032b58e202bbb411
4
+ data.tar.gz: b104a0c811a1cc485a9914831db47e613af2a7f873aeffa0cb5dfc45859ba8b7
5
5
  SHA512:
6
- metadata.gz: '08a55ddabdf7e9b46f56a66cb6c9a2aafd02144a3776ad6ad575f90e922636c08a08448037941e16996ac5794cd51dc046e250a5c147dfa1e352f858fef78817'
7
- data.tar.gz: 2ae1b8b409995fef289f60148cbdd73d44a9402664d5b894f2fc83f556bee1055f0bcd1eff56f085773b095cc173f09ca9529425517f6060b1b1f2d974b543fd
6
+ metadata.gz: af51b53a9b4073e41d898ee41d8ca6725b04ce50c16300d00f25a0867af0c3ce874290343ac66d3edb5e2096d7210b287b91b77640ce2cd1304557125146dc08
7
+ data.tar.gz: 22b8948a0826f7f184672a3a0741514f17a7f133f61c46f7699f73dcd78b27dccf31b0cd24cd531a946b6addc404b6e1ee4b72d24cd555cf2d00bcac6ab17238
@@ -3,7 +3,7 @@ module BlendSpreadsheetLoanGenerator
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
-
6
+
7
7
  def columns
8
8
  %w[
9
9
  index
@@ -12,6 +12,7 @@ module BlendSpreadsheetLoanGenerator
12
12
  argument :from_path, type: :string, required: true, desc: 'csv to restructure'
13
13
  argument :rate, type: :float, required: true, desc: 'year rate post restructuration'
14
14
 
15
+ option :guaranteed_terms, type: :integer, default: 0
15
16
  option :duration, type: :integer, desc: 'duration'
16
17
  option :period_duration, type: :integer, default: 1, desc: 'duration of a period in months'
17
18
  option :due_on, type: :date, default: Date.today, desc: 'date of the pay day of the first period DD/MM/YYYY'
@@ -43,6 +44,14 @@ module BlendSpreadsheetLoanGenerator
43
44
  values.map! { |r| set_types([columns, r].transpose.to_h.with_indifferent_access) }
44
45
 
45
46
  last_paid_line = values.index { |term| term[:index] == last_paid_term.to_i }
47
+ guaranteed_line = values.index { |term| term[:index] == options.fetch(:guaranteed_terms, nil) } || nil
48
+ total_guaranteed_interests = (
49
+ if guaranteed_line.present? && guaranteed_line > last_paid_line
50
+ values[last_paid_line..guaranteed_line].sum(:period_calculated_interests)
51
+ else
52
+ 0
53
+ end
54
+ )
46
55
 
47
56
  total_to_be_paid = (
48
57
  values[last_paid_line + 1][:remaining_capital_start] +
@@ -59,15 +68,17 @@ module BlendSpreadsheetLoanGenerator
59
68
  end
60
69
  )
61
70
 
62
- starting_capitalized_interests = 0.0
63
- starting_capitalized_fees = 0.0
64
-
65
71
  due_on = values[last_paid_line + 1][:due_on] + 1.month
66
72
 
67
73
  capital_paid = amount_paid.to_f - (
68
74
  values[last_paid_line + 1][:capitalized_interests_start] +
69
75
  values[last_paid_line + 1][:capitalized_fees_start]
70
76
  )
77
+ guaranteed_interests_paid = (
78
+ (capital_paid.to_f / values[last_paid_line + 1][:remaining_capital_start]) *
79
+ total_guaranteed_interests
80
+ )
81
+ capital_paid -= guaranteed_interests_paid
71
82
 
72
83
  @loan = Loan.new(
73
84
  amount: values[last_paid_line][:remaining_capital_end],
@@ -80,8 +91,8 @@ module BlendSpreadsheetLoanGenerator
80
91
  deferred: options.fetch(:deferred),
81
92
  type: options.fetch(:type),
82
93
  interests_type: options.fetch(:interests_type),
83
- starting_capitalized_interests: starting_capitalized_interests,
84
- starting_capitalized_fees: starting_capitalized_fees
94
+ starting_capitalized_interests: 0.0,
95
+ starting_capitalized_fees: 0.0
85
96
  )
86
97
 
87
98
  spreadsheet = session.create_spreadsheet(loan.name)
@@ -98,7 +109,7 @@ module BlendSpreadsheetLoanGenerator
98
109
  "=#{excel_float(values[last_paid_line][:remaining_capital_end])} - #{period_capital(2)}"
99
110
 
100
111
  worksheet[2, columns.index('period_interests') + 1] =
101
- "=ARRONDI(#{period_theoric_interests(2)}; 2)"
112
+ "=ARRONDI(#{period_theoric_interests(2)} + #{guaranteed_interests_paid}; 2)"
102
113
 
103
114
  worksheet[2, columns.index('period_theoric_interests') + 1] =
104
115
  "=#{excel_float(values[last_paid_line + 1][:period_calculated_interests])}"
@@ -1,7 +1,7 @@
1
1
  require 'dry/cli'
2
2
 
3
3
  module BlendSpreadsheetLoanGenerator
4
- VERSION = '0.1.15'.freeze
4
+ VERSION = '0.1.16'.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.15
4
+ version: 0.1.16
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-06 00:00:00.000000000 Z
11
+ date: 2021-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport