Class: SunatInvoice::Tax
- Includes:
- Utils
- Defined in:
- lib/sunat_invoice/tax.rb
Constant Summary collapse
- TAXES =
{ igv: { id: '1000', name: 'IGV', tax_type_code: 'VAT' }, isc: { id: '2000', name: 'ISC', tax_type_code: 'EXC' }, other: { id: '9999', name: 'OTROS', tax_type_code: 'OTH' } }.freeze
Constants included from Utils
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#tax_exemption_reason ⇒ Object
Returns the value of attribute tax_exemption_reason.
-
#tax_type ⇒ Object
Returns the value of attribute tax_type.
-
#tier_range ⇒ Object
Returns the value of attribute tier_range.
Instance Method Summary collapse
- #defaults_for_type(type) ⇒ Object
-
#initialize(*args) ⇒ Tax
constructor
A new instance of Tax.
- #tax_category(xml) ⇒ Object
- #tax_data(attribute) ⇒ Object
- #tax_scheme(xml) ⇒ Object
- #xml(xml, currency) ⇒ Object
Methods included from Utils
Constructor Details
#initialize(*args) ⇒ Tax
Returns a new instance of Tax.
18 19 20 21 |
# File 'lib/sunat_invoice/tax.rb', line 18 def initialize(*args) super(*args) defaults_for_type(tax_type) end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
16 17 18 |
# File 'lib/sunat_invoice/tax.rb', line 16 def amount @amount end |
#tax_exemption_reason ⇒ Object
Returns the value of attribute tax_exemption_reason.
16 17 18 |
# File 'lib/sunat_invoice/tax.rb', line 16 def tax_exemption_reason @tax_exemption_reason end |
#tax_type ⇒ Object
Returns the value of attribute tax_type.
16 17 18 |
# File 'lib/sunat_invoice/tax.rb', line 16 def tax_type @tax_type end |
#tier_range ⇒ Object
Returns the value of attribute tier_range.
16 17 18 |
# File 'lib/sunat_invoice/tax.rb', line 16 def tier_range @tier_range end |
Instance Method Details
#defaults_for_type(type) ⇒ Object
23 24 25 26 27 28 29 30 |
# 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) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/sunat_invoice/tax.rb', line 42 def tax_category(xml) xml['cac'].TaxCategory do xml['cbc'].TaxExemptionReasonCode(tax_exemption_reason) if tax_exemption_reason xml['cbc'].TierRange(tier_range) if tier_range tax_scheme(xml) end end |
#tax_data(attribute) ⇒ Object
58 59 60 |
# File 'lib/sunat_invoice/tax.rb', line 58 def tax_data(attribute) TAXES[tax_type][attribute] end |
#tax_scheme(xml) ⇒ Object
50 51 52 53 54 55 56 |
# 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) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# 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 |