class SunatInvoice::SummaryLine

Constants

CHARGES

Attributes

charge_type[RW]
document_serial[RW]
document_type[RW]
end_document_number[RW]
exempt[RW]
non_taxable[RW]
other_charge[RW]
start_document_number[RW]
taxable[RW]
total_amount[RW]

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/sunat_invoice/summary_line.rb, line 16
def initialize(*args)
  super(*args)
  @taxable ||= 0.01
  @non_taxable ||= 0.01
  @exempt ||= 0.01
  @other_charge ||= 0.01
end

Public Instance Methods

xml(xml, index, currency) click to toggle source
# File lib/sunat_invoice/summary_line.rb, line 24
def xml(xml, index, currency)
  xml['sac'].SummaryDocumentsLine do
    xml['cbc'].LineID(index + 1)
    build_documents_info(xml)
    amount_xml(xml['sac'], 'TotalAmount', total_amount, currency)
    build_payments(xml, currency)
    build_other_charge(xml, currency)
    build_taxes_xml(xml, currency)
  end
end

Private Instance Methods

build_documents_info(xml) click to toggle source
# File lib/sunat_invoice/summary_line.rb, line 43
def build_documents_info(xml)
  xml['cbc'].DocumentTypeCode document_type
  xml['sac'].DocumentSerialID document_serial
  xml['sac'].StartDocumentNumberID start_document_number
  xml['sac'].EndDocumentNumberID end_document_number
end
build_other_charge(xml, currency) click to toggle source
# File lib/sunat_invoice/summary_line.rb, line 64
def build_other_charge(xml, currency)
  xml['cac'].AllowanceCharge do
    xml['cbc'].ChargeIndicator CHARGES.values.last
    amount_xml(xml['cbc'], 'Amount', other_charge, currency)
  end
end
build_payments(xml, currency) click to toggle source
# File lib/sunat_invoice/summary_line.rb, line 55
def build_payments(xml, currency)
  payments.each do |payment|
    xml['sac'].BillingPayment do
      amount_xml(xml['cbc'], 'PaidAmount', payment[:amount], currency)
      xml['cbc'].InstructionID payment[:code]
    end
  end
end
calculate_total_amount() click to toggle source
# File lib/sunat_invoice/summary_line.rb, line 50
def calculate_total_amount
  return if total_amount
  # TODO: sum(billing payments) + allowance charge + sum(taxes)
end
payments() click to toggle source
# File lib/sunat_invoice/summary_line.rb, line 37
def payments
  [{ amount: taxable, code: '01' },
   { amount: exempt, code: '02' },
   { amount: non_taxable, code: '03' }]
end
resolve_charge_type() click to toggle source
# File lib/sunat_invoice/summary_line.rb, line 71
def resolve_charge_type
  charge_type ? CHARGES[charge_type] : CHARGES.values.first
end