class Xrechnung::Document

Public Instance Methods

to_xml(indent: 2, target: "") click to toggle source
# File lib/xrechnung.rb, line 243
def to_xml(indent: 2, target: "")
  xml = Builder::XmlMarkup.new(indent: indent, target: target)
  xml.instruct! :xml, version: "1.0", encoding: "UTF-8"

  xml.ubl :Invoice, \
    "xmlns:ubl"          => "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2",
    "xmlns:cac"          => "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2",
    "xmlns:cbc"          => "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2",
    "xmlns:xsi"          => "http://www.w3.org/2001/XMLSchema-instance",
    "xsi:schemaLocation" => "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd" do
    xml.cbc :CustomizationID, "urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.0"
    xml.cbc :ID, id
    xml.cbc :IssueDate, issue_date
    xml.cbc :DueDate, due_date
    xml.cbc :InvoiceTypeCode, invoice_type_code

    notes.each do |note|
      xml.cbc :Note, note
    end

    xml.cbc :TaxPointDate, tax_point_date
    xml.cbc :DocumentCurrencyCode, document_currency_code
    xml.cbc :TaxCurrencyCode, tax_currency_code
    xml.cbc :BuyerReference, buyer_reference

    xml.cac :OrderReference do
      xml.cbc :ID, purchase_order_reference
      unless members[:sales_order_reference][:optional] && sales_order_reference.nil?
        xml.cbc :SalesOrderID, sales_order_reference
      end
    end

    unless members[:billing_reference][:optional] && billing_reference.nil?
      xml.cac :BillingReference do
        billing_reference&.to_xml(xml)
      end
    end

    xml.cac :ContractDocumentReference do
      xml.cbc :ID, contract_document_reference_id
    end

    xml.cac :ProjectReference do
      xml.cbc :ID, project_reference_id
    end

    xml.cac :AccountingSupplierParty do
      accounting_supplier_party&.to_xml(xml)
    end

    xml.cac :AccountingCustomerParty do
      accounting_customer_party&.to_xml(xml)
    end

    unless members[:tax_representative_party][:optional] && tax_representative_party.nil?
      xml.cac :TaxRepresentativeParty do
        tax_representative_party&.to_xml(xml)
      end
    end

    xml.cac :PaymentMeans do
      payment_means&.to_xml(xml)
    end

    xml.cac :PaymentTerms do
      xml.cbc :Note, payment_terms_note
    end

    xml.cac :TaxTotal do
      tax_total&.to_xml(xml)
    end

    xml.cac :LegalMonetaryTotal do
      legal_monetary_total&.to_xml(xml)
    end

    invoice_lines.each do |invoice_line|
      invoice_line&.to_xml(xml)
    end
  end

  target
end