Class: SunatInvoice::Invoice

Inherits:
TradeDocument show all
Defined in:
lib/sunat_invoice/invoice.rb

Constant Summary

Constants inherited from TradeDocument

TradeDocument::INVOICE_TYPES

Constants inherited from XmlDocument

XmlDocument::CUSTOMIZATION, XmlDocument::UBL_VERSION

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

Attributes inherited from TradeDocument

#customer, #discount, #document_number, #document_type, #sale_totals, #taxes_totals, #total

Attributes inherited from XmlDocument

#currency, #date, #lines, #provider, #signature

Instance Method Summary collapse

Methods inherited from TradeDocument

#document_name, #operation

Methods included from TradeCalculations

#calculate_sale_totals, #calculate_taxes_totals, #calculate_total, #get_total_code, #get_total_igv_code, #prepare_totals

Methods inherited from XmlDocument

#build_ext, #build_lines_xml, #build_number, #build_xml, #formatted_date

Methods included from Utils

#amount_xml, #ubl_ext

Methods inherited from Model

#to_hash

Constructor Details

#initialize(*args) ⇒ Invoice



10
11
12
13
14
# File 'lib/sunat_invoice/invoice.rb', line 10

def initialize(*args)
  super(*args)
  opts = args[0] || {}
  init_defaults(opts)
end

Instance Method Details

#init_defaults(opts) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/sunat_invoice/invoice.rb', line 16

def init_defaults(opts)
  parties_default(opts)
  @document_type = opts[:document_type] || '01'
  @document_number = opts[:document_number] || 'F001-1'
  @currency = opts[:currency] || 'PEN'
  @lines ||= []
end

#parties_default(opts) ⇒ Object



24
25
26
27
# File 'lib/sunat_invoice/invoice.rb', line 24

def parties_default(opts)
  @provider = opts[:provider] || SunatInvoice::Provider.new
  @customer = opts[:customer] || SunatInvoice::Customer.new
end

#xmlObject



29
30
31
32
33
34
35
36
37
# File 'lib/sunat_invoice/invoice.rb', line 29

def xml
  build = build_xml do |xml|
    build_document_data(xml)
    build_common_content(xml)
  end

  invoice_xml = build.to_xml
  @signature.sign(invoice_xml)
end