class SunatInvoice::TradeDocument

Constants

INVOICE_TYPES

Attributes

customer[RW]
discount[RW]
document_number[RW]
document_type[RW]
sale_totals[R]

a hash with totals without taxes for any kind of sale

taxes_totals[R]

a hash with taxes totals by tax type

total[R]

total for document (sale totals + taxes - discounts)

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/sunat_invoice/trade_document.rb, line 23
def initialize(*args)
  super(*args)
  @signature ||= SunatInvoice::Signature.new(provider: @provider)
end

Public Instance Methods

document_name() click to toggle source
# File lib/sunat_invoice/trade_document.rb, line 32
def document_name
  "#{@provider.ruc}-#{document_type}-#{document_number}"
end
operation() click to toggle source
# File lib/sunat_invoice/trade_document.rb, line 28
def operation
  :send_bill
end

Private Instance Methods

build_common_content(xml) click to toggle source
# File lib/sunat_invoice/trade_document.rb, line 74
def build_common_content(xml)
  @signature.signer_data(xml)
  @provider.info(xml)
  @customer.info(xml)
  build_taxes_totals(xml)
  build_total(xml)
  build_lines_xml(xml)
end
build_document_data(xml) click to toggle source
# File lib/sunat_invoice/trade_document.rb, line 42
def build_document_data(xml)
  build_number(xml)
  xml['cbc'].IssueDate formatted_date(date)
  xml['cbc'].InvoiceTypeCode document_type if invoice?
  xml['cbc'].DocumentCurrencyCode currency
end
build_ext(xml) click to toggle source
Calls superclass method
# File lib/sunat_invoice/trade_document.rb, line 49
def build_ext(xml)
  super(xml) do |xml_|
    build_sale_totals(xml_)
  end
end
build_monetary_total(xml, code, amount) click to toggle source
# File lib/sunat_invoice/trade_document.rb, line 67
def build_monetary_total(xml, code, amount)
  xml['sac'].AdditionalMonetaryTotal do
    xml['cbc'].ID code
    amount_xml(xml['cbc'], 'PayableAmount', amount, @currency)
  end
end
build_sale_totals(xml) click to toggle source
# File lib/sunat_invoice/trade_document.rb, line 55
def build_sale_totals(xml)
  prepare_totals
  ubl_ext(xml) do
    xml['sac'].AdditionalInformation do
      @sale_totals&.each do |code, amount|
        build_monetary_total(xml, code, amount)
      end
      build_monetary_total(xml, '2005', discount) if discount
    end
  end
end
build_taxes_totals(xml) click to toggle source
# File lib/sunat_invoice/trade_document.rb, line 83
def build_taxes_totals(xml)
  @taxes_totals.each do |key, value|
    SunatInvoice::Tax.new(tax_type: key, amount: value).xml(xml, @currency)
  end
end
build_total(xml) click to toggle source
# File lib/sunat_invoice/trade_document.rb, line 93
def build_total(xml)
  xml['cac'].send(total_tag) do
    amount_xml(xml['cbc'], 'PayableAmount', @total, @currency)
  end
end
invoice?() click to toggle source
# File lib/sunat_invoice/trade_document.rb, line 38
def invoice?
  INVOICE_TYPES.include?(document_type)
end
total_tag() click to toggle source
# File lib/sunat_invoice/trade_document.rb, line 89
def total_tag
  'LegalMonetaryTotal'
end