Class: SunatInvoice::Item
Direct Known Subclasses
Constant Summary
Constants included from Utils
Utils::COMMON_NAMESPACES, Utils::CREDIT_NOTE_NAMESPACES, Utils::DAILY_SUMMARY_NAMESPACES, Utils::DEBIT_NOTE_NAMESPACES, Utils::INVOICE_NAMESPACES, Utils::SUMMARY_NAMESPACES, Utils::TRADE_NAMESPACES, Utils::VOIDED_NAMESPACES
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.
-
#price_included_tax ⇒ Object
Returns the value of attribute price_included_tax.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#unit_code ⇒ Object
Returns the value of attribute unit_code.
Attributes inherited from Line
Instance Method Summary collapse
- #bi_value ⇒ Object
-
#initialize(*args) ⇒ Item
constructor
A new instance of Item.
- #line_tag_name ⇒ Object
- #quantity_tag_name ⇒ Object
- #sale_price ⇒ Object
- #sale_taxes ⇒ Object
- #set_price ⇒ Object
- #xml(xml, index, currency) ⇒ Object
Methods inherited from Line
Methods included from Utils
Methods inherited from Model
Constructor Details
#initialize(*args) ⇒ Item
Returns a new instance of Item.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/sunat_invoice/item.rb', line 10 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 # * price_included_tax - price with taxes super(*args) @taxes ||= [] end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/sunat_invoice/item.rb', line 7 def description @description end |
#price ⇒ Object
Returns the value of attribute price.
7 8 9 |
# File 'lib/sunat_invoice/item.rb', line 7 def price @price end |
#price_code ⇒ Object
Returns the value of attribute price_code.
7 8 9 |
# File 'lib/sunat_invoice/item.rb', line 7 def price_code @price_code end |
#price_included_tax ⇒ Object
Returns the value of attribute price_included_tax.
7 8 9 |
# File 'lib/sunat_invoice/item.rb', line 7 def price_included_tax @price_included_tax end |
#quantity ⇒ Object
Returns the value of attribute quantity.
7 8 9 |
# File 'lib/sunat_invoice/item.rb', line 7 def quantity @quantity end |
#unit_code ⇒ Object
Returns the value of attribute unit_code.
7 8 9 |
# File 'lib/sunat_invoice/item.rb', line 7 def unit_code @unit_code end |
Instance Method Details
#bi_value ⇒ Object
49 50 51 52 53 |
# File 'lib/sunat_invoice/item.rb', line 49 def bi_value # bi of sale = price without taxes * quantity set_price (@price.to_f * @quantity.to_f).round(2) end |
#line_tag_name ⇒ Object
24 25 26 |
# File 'lib/sunat_invoice/item.rb', line 24 def line_tag_name 'InvoiceLine' end |
#quantity_tag_name ⇒ Object
28 29 30 |
# File 'lib/sunat_invoice/item.rb', line 28 def quantity_tag_name 'InvoicedQuantity' end |
#sale_price ⇒ Object
65 66 67 68 |
# File 'lib/sunat_invoice/item.rb', line 65 def sale_price # unit price with tax @price_included_tax || (@price.to_f + sum_taxes).round(2) end |
#sale_taxes ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/sunat_invoice/item.rb', line 55 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 |
#set_price ⇒ Object
43 44 45 46 47 |
# File 'lib/sunat_invoice/item.rb', line 43 def set_price return unless @price_included_tax @price ||= (@price_included_tax - sum_taxes).round(2) end |
#xml(xml, index, currency) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sunat_invoice/item.rb', line 32 def xml(xml, index, currency) xml['cac'].send(line_tag_name) do build_basic_line_xml(xml, index) amount_xml(xml['cbc'], 'LineExtensionAmount', bi_value, currency) build_pricing_reference(xml, currency) build_taxes_xml(xml, currency) build_item(xml) build_price(xml, currency) end end |