Class: Einvoicing::Invoice
- Inherits:
-
Data
- Object
- Data
- Einvoicing::Invoice
- Defined in:
- lib/einvoicing/invoice.rb
Overview
Core invoice model. All monetary values are in the invoice currency.
Instance Attribute Summary collapse
-
#bic ⇒ Object
readonly
Returns the value of attribute bic.
-
#buyer ⇒ Object
readonly
Returns the value of attribute buyer.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#document_type ⇒ Object
readonly
Returns the value of attribute document_type.
-
#due_date ⇒ Object
readonly
Returns the value of attribute due_date.
-
#iban ⇒ Object
readonly
Returns the value of attribute iban.
-
#invoice_number ⇒ Object
readonly
Returns the value of attribute invoice_number.
-
#issue_date ⇒ Object
readonly
Returns the value of attribute issue_date.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#note ⇒ Object
readonly
Returns the value of attribute note.
-
#original_invoice_date ⇒ Object
readonly
Returns the value of attribute original_invoice_date.
-
#original_invoice_number ⇒ Object
readonly
Returns the value of attribute original_invoice_number.
-
#payment_means_code ⇒ Object
readonly
Returns the value of attribute payment_means_code.
-
#payment_reference ⇒ Object
readonly
Returns the value of attribute payment_reference.
-
#prepaid_amount ⇒ Object
readonly
Returns the value of attribute prepaid_amount.
-
#seller ⇒ Object
readonly
Returns the value of attribute seller.
-
#tax_breakdown ⇒ Object
readonly
Returns the value of attribute tax_breakdown.
-
#tax_currency ⇒ Object
readonly
Returns the value of attribute tax_currency.
Instance Method Summary collapse
-
#due_amount ⇒ Object
Amount due after deducting any retained/prepaid amount (BT-113).
-
#gross_total ⇒ Object
Grand total including VAT — computed from per-line gross amounts to avoid double-rounding through already-rounded net_total/tax_total (EN 16931 BR-CO-13).
-
#initialize(invoice_number:, issue_date:, seller:, buyer:, lines:, due_date: nil, currency: "EUR", tax_currency: nil, tax_breakdown: nil, payment_reference: nil, note: nil, payment_means_code: nil, iban: nil, bic: nil, document_type: :invoice, original_invoice_number: nil, original_invoice_date: nil, prepaid_amount: BigDecimal(0)) ⇒ Invoice
constructor
A new instance of Invoice.
-
#net_total ⇒ Object
Sum of all line net amounts (excl. VAT).
-
#tax_total ⇒ Object
Total VAT across all lines.
Constructor Details
#initialize(invoice_number:, issue_date:, seller:, buyer:, lines:, due_date: nil, currency: "EUR", tax_currency: nil, tax_breakdown: nil, payment_reference: nil, note: nil, payment_means_code: nil, iban: nil, bic: nil, document_type: :invoice, original_invoice_number: nil, original_invoice_date: nil, prepaid_amount: BigDecimal(0)) ⇒ Invoice
Returns a new instance of Invoice.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/einvoicing/invoice.rb', line 41 def initialize(invoice_number:, issue_date:, seller:, buyer:, lines:, due_date: nil, currency: "EUR", tax_currency: nil, tax_breakdown: nil, payment_reference: nil, note: nil, payment_means_code: nil, iban: nil, bic: nil, document_type: :invoice, original_invoice_number: nil, original_invoice_date: nil, prepaid_amount: BigDecimal(0)) computed_breakdown = tax_breakdown || compute_tax_breakdown(lines) super( invoice_number: invoice_number, issue_date: issue_date, due_date: due_date, currency: currency, tax_currency: tax_currency, seller: seller, buyer: buyer, lines: lines, tax_breakdown: computed_breakdown, payment_reference: payment_reference, note: note, payment_means_code: payment_means_code, iban: iban, bic: bic, document_type: document_type, original_invoice_number: original_invoice_number, original_invoice_date: original_invoice_date, prepaid_amount: prepaid_amount.nil? ? BigDecimal(0) : BigDecimal(prepaid_amount.to_s) ) end |
Instance Attribute Details
#bic ⇒ Object (readonly)
Returns the value of attribute bic
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def bic @bic end |
#buyer ⇒ Object (readonly)
Returns the value of attribute buyer
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def buyer @buyer end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def currency @currency end |
#document_type ⇒ Object (readonly)
Returns the value of attribute document_type
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def document_type @document_type end |
#due_date ⇒ Object (readonly)
Returns the value of attribute due_date
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def due_date @due_date end |
#iban ⇒ Object (readonly)
Returns the value of attribute iban
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def iban @iban end |
#invoice_number ⇒ Object (readonly)
Returns the value of attribute invoice_number
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def invoice_number @invoice_number end |
#issue_date ⇒ Object (readonly)
Returns the value of attribute issue_date
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def issue_date @issue_date end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def lines @lines end |
#note ⇒ Object (readonly)
Returns the value of attribute note
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def note @note end |
#original_invoice_date ⇒ Object (readonly)
Returns the value of attribute original_invoice_date
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def original_invoice_date @original_invoice_date end |
#original_invoice_number ⇒ Object (readonly)
Returns the value of attribute original_invoice_number
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def original_invoice_number @original_invoice_number end |
#payment_means_code ⇒ Object (readonly)
Returns the value of attribute payment_means_code
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def payment_means_code @payment_means_code end |
#payment_reference ⇒ Object (readonly)
Returns the value of attribute payment_reference
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def payment_reference @payment_reference end |
#prepaid_amount ⇒ Object (readonly)
Returns the value of attribute prepaid_amount
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def prepaid_amount @prepaid_amount end |
#seller ⇒ Object (readonly)
Returns the value of attribute seller
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def seller @seller end |
#tax_breakdown ⇒ Object (readonly)
Returns the value of attribute tax_breakdown
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def tax_breakdown @tax_breakdown end |
#tax_currency ⇒ Object (readonly)
Returns the value of attribute tax_currency
21 22 23 |
# File 'lib/einvoicing/invoice.rb', line 21 def tax_currency @tax_currency end |
Instance Method Details
#due_amount ⇒ Object
Amount due after deducting any retained/prepaid amount (BT-113). VAT remains due on the full gross_total — only the payable balance is reduced (EN 16931 BR-CO-16: DuePayableAmount = GrandTotal − TotalPrepaidAmount).
89 90 91 |
# File 'lib/einvoicing/invoice.rb', line 89 def due_amount gross_total - prepaid_amount end |
#gross_total ⇒ Object
Grand total including VAT — computed from per-line gross amounts to avoid double-rounding through already-rounded net_total/tax_total (EN 16931 BR-CO-13).
82 83 84 |
# File 'lib/einvoicing/invoice.rb', line 82 def gross_total lines.sum(BigDecimal("0"), &:gross_amount).round(2, :half_up) end |
#net_total ⇒ Object
Sum of all line net amounts (excl. VAT).
71 72 73 |
# File 'lib/einvoicing/invoice.rb', line 71 def net_total lines.sum(BigDecimal("0"), &:net_amount).round(2, :half_up) end |
#tax_total ⇒ Object
Total VAT across all lines.
76 77 78 |
# File 'lib/einvoicing/invoice.rb', line 76 def tax_total tax_breakdown.sum(BigDecimal("0"), &:tax_amount).round(2, :half_up) end |