class SunatInvoice::Tax

Constants

TAXES

Attributes

amount[RW]
tax_exemption_reason[RW]
tax_type[RW]
tier_range[RW]

Public Class Methods

new(*args) click to toggle source
Calls superclass method SunatInvoice::Model::new
# File lib/sunat_invoice/tax.rb, line 18
def initialize(*args)
  super(*args)
  defaults_for_type(tax_type)
end

Public Instance Methods

defaults_for_type(type) click to toggle source
# File lib/sunat_invoice/tax.rb, line 23
def defaults_for_type(type)
  case type
  when :igv
    @tax_exemption_reason ||= Catalogs::CATALOG_07.first
  when :isc
    @tier_range ||= Catalogs::CATALOG_08.first
  end
end
tax_category(xml) click to toggle source
# File lib/sunat_invoice/tax.rb, line 42
def tax_category(xml)
  xml['cac'].TaxCategory do
    tax_exemption(xml)
    xml['cbc'].TierRange(tier_range) if tier_range
    tax_scheme(xml)
  end
end
tax_data(attribute) click to toggle source
# File lib/sunat_invoice/tax.rb, line 58
def tax_data(attribute)
  TAXES[tax_type][attribute]
end
tax_exemption(xml) click to toggle source
# File lib/sunat_invoice/tax.rb, line 62
def tax_exemption(xml)
  return unless tax_exemption_reason

  xml['cbc'].TaxExemptionReasonCode(tax_exemption_reason)
end
tax_scheme(xml) click to toggle source
# File lib/sunat_invoice/tax.rb, line 50
def tax_scheme(xml)
  xml['cac'].TaxScheme do
    xml['cbc'].ID tax_data(:id)
    xml['cbc'].Name tax_data(:name)
    xml['cbc'].TaxTypeCode tax_data(:tax_type_code)
  end
end
xml(xml, currency) click to toggle source
# File lib/sunat_invoice/tax.rb, line 32
def xml(xml, currency)
  xml['cac'].TaxTotal do
    amount_xml(xml['cbc'], 'TaxAmount', amount, currency)
    xml['cac'].TaxSubtotal do
      amount_xml(xml['cbc'], 'TaxAmount', amount, currency)
      tax_category(xml)
    end
  end
end