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_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_errors ⇒ Array<Hash>
Validate the invoice using the configured validator.
99 100 101 |
# File 'lib/einvoicing/invoiceable.rb', line 99 def einvoicing_errors self.class.einvoicing_validator.validate(to_einvoice) end |
#einvoicing_valid? ⇒ Boolean
104 105 106 |
# File 'lib/einvoicing/invoiceable.rb', line 104 def einvoicing_valid? einvoicing_errors.empty? end |
#to_cii_xml ⇒ String
Generate CII D16B XML string.
79 80 81 |
# File 'lib/einvoicing/invoiceable.rb', line 79 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 |
# 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 ) end |
#to_facturx(pdf_data) ⇒ String
Generate Factur-X PDF by embedding CII XML into an existing PDF blob.
92 93 94 95 |
# File 'lib/einvoicing/invoiceable.rb', line 92 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.
85 86 87 |
# File 'lib/einvoicing/invoiceable.rb', line 85 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.
115 116 117 118 |
# File 'lib/einvoicing/invoiceable.rb', line 115 def transmit!(adapter: nil) raise NotImplementedError, "Configure a transmission adapter or override #transmit! in #{self.class}" end |
#validate_einvoice! ⇒ Object
Raise ValidationError unless valid.
109 110 111 |
# File 'lib/einvoicing/invoiceable.rb', line 109 def validate_einvoice! self.class.einvoicing_validator.validate!(to_einvoice) end |