Class: SunatInvoice::XmlDocument

Inherits:
Model
  • Object
show all
Includes:
Utils
Defined in:
lib/sunat_invoice/xml_document.rb

Direct Known Subclasses

DailySummary, TradeDocument

Constant Summary collapse

UBL_VERSION =
'2.0'.freeze
CUSTOMIZATION =
'1.0'.freeze

Constants included from Utils

Utils::COMMON_NAMESPACES, Utils::CREDIT_NOTE_NAMESPACES, Utils::DAILY_SUMMARY_NAMESPACES, Utils::DEBIT_NOTE_NAMESPACES, Utils::INVOICE_NAMESPACES, Utils::SUMMARY_NAMESPACES, Utils::TRADE_NAMESPACES, Utils::VOIDED_NAMESPACES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#amount_xml, #ubl_ext

Methods inherited from Model

#to_hash

Constructor Details

#initialize(*args) ⇒ XmlDocument

Returns a new instance of XmlDocument.



15
16
17
18
# File 'lib/sunat_invoice/xml_document.rb', line 15

def initialize(*args)
  super(*args)
  @date ||= Date.today
end

Instance Attribute Details

#currencyObject

Returns the value of attribute currency.



10
11
12
# File 'lib/sunat_invoice/xml_document.rb', line 10

def currency
  @currency
end

#dateObject

Returns the value of attribute date.



10
11
12
# File 'lib/sunat_invoice/xml_document.rb', line 10

def date
  @date
end

#linesObject

Returns the value of attribute lines.



10
11
12
# File 'lib/sunat_invoice/xml_document.rb', line 10

def lines
  @lines
end

#providerObject

Returns the value of attribute provider.



10
11
12
# File 'lib/sunat_invoice/xml_document.rb', line 10

def provider
  @provider
end

#signatureObject

Returns the value of attribute signature.



10
11
12
# File 'lib/sunat_invoice/xml_document.rb', line 10

def signature
  @signature
end

Instance Method Details

#build_ext(xml, &block) ⇒ Object



31
32
33
34
35
36
# File 'lib/sunat_invoice/xml_document.rb', line 31

def build_ext(xml, &block)
  xml['ext'].UBLExtensions do
    yield(xml) if block
    @signature.signature_ext(xml)
  end
end

#build_lines_xml(xml) ⇒ Object



46
47
48
49
50
# File 'lib/sunat_invoice/xml_document.rb', line 46

def build_lines_xml(xml)
  lines&.each_with_index do |line, index|
    line.xml(xml, index, currency)
  end
end

#build_number(xml) ⇒ Object



38
39
40
# File 'lib/sunat_invoice/xml_document.rb', line 38

def build_number(xml)
  xml['cbc'].ID document_number
end

#build_xml(&block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/sunat_invoice/xml_document.rb', line 20

def build_xml(&block)
  Nokogiri::XML::Builder.new do |xml|
    xml.send(root_name, namespaces) do
      build_ext(xml)
      xml['cbc'].UBLVersionID UBL_VERSION
      xml['cbc'].CustomizationID CUSTOMIZATION
      yield(xml) if block
    end
  end
end

#formatted_date(date) ⇒ Object



42
43
44
# File 'lib/sunat_invoice/xml_document.rb', line 42

def formatted_date(date)
  date.strftime('%Y-%m-%d')
end