Class: StarkInfra::CreditNotePreview

Inherits:
StarkCore::Utils::SubResource
  • Object
show all
Defined in:
lib/credit_preview/credit_note_preview.rb

Overview

# CreditNotePreview object

A CreditNotePreview is used to preview a CCB contract between the borrower and lender with a specific table type.

When you initialize a CreditPreview, the entity will not be automatically created in the Stark Infra API. The ‘create’ function sends the objects to the Stark Infra API and returns the list of created objects.

## Parameters (required):

  • type [string]: table type that defines the amortization system. Options: ‘sac’, ‘price’, ‘american’, ‘bullet’, ‘custom’

  • nominal_amount [integer]: amount in cents transferred to the credit receiver, before deductions. ex: 11234 (= R$ 112.34)

  • scheduled [DateTime, Date or string]: date of transfer execution. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)

  • tax_id [string]: credit receiver’s tax ID (CPF or CNPJ). ex: ‘20.018.183/0001-80’

## Parameters (conditionally required):

  • invoices [list of CreditNote::Invoice objects]: list of CreditNote.Invoice objects to be created and sent to the credit receiver.

  • nominal_interest [float]: yearly nominal interest rate of the credit note, in percentage. ex: 12.5

  • initial_due [DateTime, Date or string]: date of the first invoice. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0), Date.new(2020, 3, 10) or ‘2020-03-10’

  • count [integer]: quantity of invoices for payment. ex: 12

  • initial_amount [integer]: value of the first invoice in cents. ex: 1234 (= R$12.34)

  • interval [string]: interval between invoices. ex: ‘year’, ‘month’

## Parameters (optional):

  • rebate_amount [integer, default nil]: credit analysis fee deducted from lent amount. ex: 11234 (= R$ 112.34)

## Attributes (return-only):

  • amount [integer]: credit note value in cents. ex: 1234 (= R$ 12.34)

  • interest [float]: yearly effective interest rate of the credit note, in percentage. ex: 12.5

  • tax_amount [integer]: tax amount included in the credit note. ex: 100

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, nominal_amount:, scheduled:, tax_id:, invoices: nil, nominal_interest: nil, initial_due: nil, count: nil, initial_amount: nil, interval: nil, rebate_amount: nil, amount: nil, interest: nil, tax_amount: nil) ⇒ CreditNotePreview

Returns a new instance of CreditNotePreview.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/credit_preview/credit_note_preview.rb', line 39

def initialize(
  type:, nominal_amount:, scheduled:, tax_id:, invoices: nil, nominal_interest: nil,
  initial_due: nil, count: nil, initial_amount: nil, interval: nil, rebate_amount: nil,
  amount: nil, interest: nil, tax_amount: nil
)
  @type = type
  @nominal_amount = nominal_amount
  @scheduled = scheduled
  @tax_id = tax_id
  @invoices = Invoice.parse_invoices(invoices)
  @nominal_interest = nominal_interest
  @initial_due = initial_due
  @count = count
  @initial_amount = initial_amount
  @interval = interval
  @rebate_amount = rebate_amount
  @amount = amount
  @interest = interest
  @tax_amount = tax_amount
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



37
38
39
# File 'lib/credit_preview/credit_note_preview.rb', line 37

def amount
  @amount
end

#countObject (readonly)

Returns the value of attribute count.



37
38
39
# File 'lib/credit_preview/credit_note_preview.rb', line 37

def count
  @count
end

#initial_amountObject (readonly)

Returns the value of attribute initial_amount.



37
38
39
# File 'lib/credit_preview/credit_note_preview.rb', line 37

def initial_amount
  @initial_amount
end

#initial_dueObject (readonly)

Returns the value of attribute initial_due.



37
38
39
# File 'lib/credit_preview/credit_note_preview.rb', line 37

def initial_due
  @initial_due
end

#interestObject (readonly)

Returns the value of attribute interest.



37
38
39
# File 'lib/credit_preview/credit_note_preview.rb', line 37

def interest
  @interest
end

#intervalObject (readonly)

Returns the value of attribute interval.



37
38
39
# File 'lib/credit_preview/credit_note_preview.rb', line 37

def interval
  @interval
end

#invoicesObject (readonly)

Returns the value of attribute invoices.



37
38
39
# File 'lib/credit_preview/credit_note_preview.rb', line 37

def invoices
  @invoices
end

#nominal_amountObject (readonly)

Returns the value of attribute nominal_amount.



37
38
39
# File 'lib/credit_preview/credit_note_preview.rb', line 37

def nominal_amount
  @nominal_amount
end

#nominal_interestObject (readonly)

Returns the value of attribute nominal_interest.



37
38
39
# File 'lib/credit_preview/credit_note_preview.rb', line 37

def nominal_interest
  @nominal_interest
end

#rebate_amountObject (readonly)

Returns the value of attribute rebate_amount.



37
38
39
# File 'lib/credit_preview/credit_note_preview.rb', line 37

def rebate_amount
  @rebate_amount
end

#scheduledObject (readonly)

Returns the value of attribute scheduled.



37
38
39
# File 'lib/credit_preview/credit_note_preview.rb', line 37

def scheduled
  @scheduled
end

#tax_amountObject (readonly)

Returns the value of attribute tax_amount.



37
38
39
# File 'lib/credit_preview/credit_note_preview.rb', line 37

def tax_amount
  @tax_amount
end

#tax_idObject (readonly)

Returns the value of attribute tax_id.



37
38
39
# File 'lib/credit_preview/credit_note_preview.rb', line 37

def tax_id
  @tax_id
end

#typeObject (readonly)

Returns the value of attribute type.



37
38
39
# File 'lib/credit_preview/credit_note_preview.rb', line 37

def type
  @type
end

Class Method Details

.resourceObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/credit_preview/credit_note_preview.rb', line 60

def self.resource
  {
    resource_name: 'CreditNotePreview',
    resource_maker: proc { |json|
      CreditNotePreview.new(
        type: json['type'],
        nominal_amount: json['nominal_amount'],
        scheduled: json['scheduled'],
        tax_id: json['tax_id'],
        invoices: json['invoices'],
        nominal_interest: json['nominal_interest'],
        initial_due: json['initial_due'],
        count: json['count'],
        initial_amount: json['initial_amount'],
        interval: json['interval'],
        rebate_amount: json['rebate_amount'],
        amount: json['amount'],
        interest: json['interest'],
        tax_amount: json['tax_amount']
      )
    }
  }
end