Class: SunatInvoice::Item
- Includes:
- Utils
- Defined in:
- lib/sunat_invoice/item.rb
Constant Summary
Constants included from Utils
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#price ⇒ Object
Returns the value of attribute price.
-
#price_code ⇒ Object
Returns the value of attribute price_code.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#taxes ⇒ Object
Returns the value of attribute taxes.
-
#unit_code ⇒ Object
Returns the value of attribute unit_code.
Instance Method Summary collapse
- #bi_value ⇒ Object
- #build_item(xml) ⇒ Object
-
#initialize(*args) ⇒ Item
constructor
A new instance of Item.
- #sale_price ⇒ Object
- #sale_taxes ⇒ Object
- #sum_taxes ⇒ Object
- #taxes_xml(xml, currency) ⇒ Object
- #xml(xml, index, currency) ⇒ Object
Methods included from Utils
Constructor Details
#initialize(*args) ⇒ Item
Returns a new instance of Item.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/sunat_invoice/item.rb', line 11 def initialize(*args) # * quantity - quantity of item # * description - name or description of product or service # * price - unit price without taxes # * price_code - type unit price (Catalogs::CATALOG_16) # * unit_code - unit of measure # UN/ECE rec 20- Unit Of Measure # http://www.unece.org/fileadmin/DAM/cefact/recommendations/rec20/rec20_rev3_Annex2e.pdf # * taxes - An array of SunatInvoice::Tax super(*args) @taxes ||= [] end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
8 9 10 |
# File 'lib/sunat_invoice/item.rb', line 8 def description @description end |
#price ⇒ Object
Returns the value of attribute price.
8 9 10 |
# File 'lib/sunat_invoice/item.rb', line 8 def price @price end |
#price_code ⇒ Object
Returns the value of attribute price_code.
8 9 10 |
# File 'lib/sunat_invoice/item.rb', line 8 def price_code @price_code end |
#quantity ⇒ Object
Returns the value of attribute quantity.
8 9 10 |
# File 'lib/sunat_invoice/item.rb', line 8 def quantity @quantity end |
#taxes ⇒ Object
Returns the value of attribute taxes.
8 9 10 |
# File 'lib/sunat_invoice/item.rb', line 8 def taxes @taxes end |
#unit_code ⇒ Object
Returns the value of attribute unit_code.
8 9 10 |
# File 'lib/sunat_invoice/item.rb', line 8 def unit_code @unit_code end |
Instance Method Details
#bi_value ⇒ Object
24 25 26 27 |
# File 'lib/sunat_invoice/item.rb', line 24 def bi_value # bi of sale = price without taxes * quantity (@price.to_f * @quantity.to_f).round(2) end |
#build_item(xml) ⇒ Object
67 68 69 70 71 |
# File 'lib/sunat_invoice/item.rb', line 67 def build_item(xml) xml['cac'].Item do xml['cbc'].Description description end end |
#sale_price ⇒ Object
39 40 41 42 |
# File 'lib/sunat_invoice/item.rb', line 39 def sale_price # unit price with tax (@price.to_f + sum_taxes).round(2) end |
#sale_taxes ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/sunat_invoice/item.rb', line 29 def sale_taxes # generate and object with taxes sum by type sums = {} taxes.each do |tax| sums[tax.tax_type] ||= 0 sums[tax.tax_type] = (tax.amount.to_f * quantity.to_f).round(2) end sums end |
#sum_taxes ⇒ Object
44 45 46 |
# File 'lib/sunat_invoice/item.rb', line 44 def sum_taxes taxes.map(&:amount).sum end |
#taxes_xml(xml, currency) ⇒ Object
73 74 75 76 77 |
# File 'lib/sunat_invoice/item.rb', line 73 def taxes_xml(xml, currency) taxes&.each do |tax| tax.xml(xml, currency) end end |
#xml(xml, index, currency) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sunat_invoice/item.rb', line 48 def xml(xml, index, currency) xml['cac'].InvoiceLine do xml['cbc'].ID(index + 1) xml['cbc'].InvoicedQuantity(@quantity, unitCode: unit_code) amount_xml(xml['cbc'], 'LineExtensionAmount', bi_value, currency) xml['cac'].PricingReference do xml['cac'].AlternativeConditionPrice do amount_xml(xml['cbc'], 'PriceAmount', sale_price, currency) xml['cbc'].PriceTypeCode price_code end end taxes_xml(xml, currency) build_item(xml) xml['cac'].Price do amount_xml(xml['cbc'], 'PriceAmount', price, currency) end end end |