Class: Facturae::Invoice

Inherits:
Object
  • Object
show all
Includes:
Validatable
Defined in:
lib/facturae/models/invoice.rb

Overview

Represents an invoice.

Constant Summary collapse

INVOICE_HEADER_KEYS =
%i[invoice_number invoice_series_code invoice_document_type invoice_class].freeze
ISSUE_DATA_KEYS =
%i[issue_date language_name invoice_currency_code tax_currency_code].freeze
TOTALS_KEYS =
%i[total_gross_amount total_gross_amount_before_taxes total_tax_outputs total_taxes_withheld
invoice_total total_outstanding_amount total_executable_amount].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validatable

#errors, #valid?

Constructor Details

#initialize(invoice_header: nil, issue_data: nil, totals: nil, taxes_output: nil, taxes_withheld: nil, invoice_lines: nil) ⇒ Invoice

rubocop:disable Metrics/ParameterLists



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/facturae/models/invoice.rb', line 27

def initialize(invoice_header: nil,
               issue_data: nil,
               totals: nil,
               taxes_output: nil,
               taxes_withheld: nil,
               invoice_lines: nil)
  @invoice_header = invoice_header || {
    invoice_number: "unset",
    invoice_series_code: "unset",
    invoice_document_type: "unset",
    invoice_class: "unset"
  }
  @issue_data = issue_data || {
    issue_date: Date.today,
    invoice_currency_code: "unset",
    language_name: "unset"
  }
  @totals = totals || {
    total_gross_amount: 0.0,
    total_gross_amount_before_taxes: 0.0,
    total_tax_outputs: 0.0,
    total_taxes_withheld: 0.0,
    invoice_total: 0.0,
    total_outstanding_amount: 0.0,
    total_executable_amount: 0.0
  }
  @taxes_output = taxes_output || []
  @taxes_withheld = taxes_withheld || []
  @invoice_lines = invoice_lines || []
end

Instance Attribute Details

#invoice_headerHash

The invoice header.

Returns:

  • (Hash)

    the current value of invoice_header



11
12
13
# File 'lib/facturae/models/invoice.rb', line 11

def invoice_header
  @invoice_header
end

#invoice_lineArray<Facturae::InvoiceLine>

The invoice lines.

Returns:

  • (Array<Facturae::InvoiceLine>)

    the current value of invoice_line



11
12
13
# File 'lib/facturae/models/invoice.rb', line 11

def invoice_line
  @invoice_line
end

#invoice_linesObject

Returns the value of attribute invoice_lines.



19
20
21
# File 'lib/facturae/models/invoice.rb', line 19

def invoice_lines
  @invoice_lines
end

#issue_dataHash

The issue data.

Returns:

  • (Hash)

    the current value of issue_data



11
12
13
# File 'lib/facturae/models/invoice.rb', line 11

def issue_data
  @issue_data
end

#taxes_outputArray<Facturae::Tax>

The taxes output.

Returns:



11
12
13
# File 'lib/facturae/models/invoice.rb', line 11

def taxes_output
  @taxes_output
end

#taxes_withheldArray<Facturae::Tax>

The taxes withheld.

Returns:



11
12
13
# File 'lib/facturae/models/invoice.rb', line 11

def taxes_withheld
  @taxes_withheld
end

#totalsHash

The totals.

Returns:

  • (Hash)

    the current value of totals



11
12
13
# File 'lib/facturae/models/invoice.rb', line 11

def totals
  @totals
end

Instance Method Details

#add_invoice_line(invoice_line) ⇒ Object

rubocop:enable Metrics/ParameterLists



59
60
61
# File 'lib/facturae/models/invoice.rb', line 59

def add_invoice_line(invoice_line)
  @invoice_lines << invoice_line
end

#add_tax_output(tax) ⇒ Object



63
64
65
# File 'lib/facturae/models/invoice.rb', line 63

def add_tax_output(tax)
  @taxes_output << tax
end

#add_tax_withheld(tax) ⇒ Object



67
68
69
# File 'lib/facturae/models/invoice.rb', line 67

def add_tax_withheld(tax)
  @taxes_withheld << tax
end