Module: Einvoicing::Invoiceable
- Defined in:
- lib/einvoicing/invoiceable.rb
Overview
ActiveSupport::Concern that adds e-invoicing capabilities to an ActiveRecord model.
The model must respond to the following methods (columns or Ruby methods):
invoice_number, issue_date, due_date, currency,
einvoicing_seller, einvoicing_buyer, einvoicing_lines
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#einvoicing_allowances ⇒ Object
Document-level allowances (BG-20).
-
#einvoicing_charges ⇒ Object
Document-level charges (BG-21).
-
#einvoicing_errors ⇒ Array<Hash>
Validate the invoice using the configured validator.
- #einvoicing_valid? ⇒ Boolean
-
#to_cii_xml ⇒ String
Generate CII D16B XML string.
-
#to_einvoice ⇒ Einvoicing::Invoice
Build an Einvoicing::Invoice from this record.
-
#to_facturx(pdf_data) ⇒ String
Generate Factur-X PDF by embedding CII XML into an existing PDF blob.
-
#to_ubl_xml ⇒ String
Generate UBL 2.1 XML string.
-
#transmit!(adapter: nil) ⇒ Object
Stub: override in your model or configure an adapter.
-
#validate_einvoice! ⇒ Object
Raise ValidationError unless valid.
Class Method Details
.included(base) ⇒ Object
42 43 44 |
# File 'lib/einvoicing/invoiceable.rb', line 42 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#einvoicing_allowances ⇒ Object
Document-level allowances (BG-20). Override to return ArrayEinvoicing::AllowanceCharge.
81 82 83 |
# File 'lib/einvoicing/invoiceable.rb', line 81 def einvoicing_allowances [] end |
#einvoicing_charges ⇒ Object
Document-level charges (BG-21). Override to return ArrayEinvoicing::AllowanceCharge.
87 88 89 |
# File 'lib/einvoicing/invoiceable.rb', line 87 def einvoicing_charges [] end |
#einvoicing_errors ⇒ Array<Hash>
Validate the invoice using the configured validator.
113 114 115 |
# File 'lib/einvoicing/invoiceable.rb', line 113 def einvoicing_errors self.class.einvoicing_validator.validate(to_einvoice) end |
#einvoicing_valid? ⇒ Boolean
118 119 120 |
# File 'lib/einvoicing/invoiceable.rb', line 118 def einvoicing_valid? einvoicing_errors.empty? end |
#to_cii_xml ⇒ String
Generate CII D16B XML string.
93 94 95 |
# File 'lib/einvoicing/invoiceable.rb', line 93 def to_cii_xml Einvoicing::Formats::CII.generate(to_einvoice) end |
#to_einvoice ⇒ Einvoicing::Invoice
Build an Einvoicing::Invoice from this record.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/einvoicing/invoiceable.rb', line 61 def to_einvoice has_due_date = self.class.respond_to?(:column_names) \ ? self.class.column_names.include?("due_date") \ : respond_to?(:due_date) Einvoicing::Invoice.new( invoice_number: invoice_number, issue_date: issue_date, due_date: has_due_date ? due_date : nil, currency: respond_to?(:currency) ? (currency || "EUR") : "EUR", seller: einvoicing_seller, buyer: einvoicing_buyer, lines: einvoicing_lines, allowances: einvoicing_allowances, charges: einvoicing_charges ) end |
#to_facturx(pdf_data) ⇒ String
Generate Factur-X PDF by embedding CII XML into an existing PDF blob.
106 107 108 109 |
# File 'lib/einvoicing/invoiceable.rb', line 106 def to_facturx(pdf_data) xml = to_cii_xml Einvoicing::Formats::FacturX.(pdf_data, xml) end |
#to_ubl_xml ⇒ String
Generate UBL 2.1 XML string.
99 100 101 |
# File 'lib/einvoicing/invoiceable.rb', line 99 def to_ubl_xml Einvoicing::Formats::UBL.generate(to_einvoice) end |
#transmit!(adapter: nil) ⇒ Object
Stub: override in your model or configure an adapter. Returns a hash with :status and optionally :reference.
129 130 131 132 |
# File 'lib/einvoicing/invoiceable.rb', line 129 def transmit!(adapter: nil) raise NotImplementedError, "Configure a transmission adapter or override #transmit! in #{self.class}" end |
#validate_einvoice! ⇒ Object
Raise ValidationError unless valid.
123 124 125 |
# File 'lib/einvoicing/invoiceable.rb', line 123 def validate_einvoice! self.class.einvoicing_validator.validate!(to_einvoice) end |