Class: FE::Document::Item
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/facturacr/document/item.rb
Constant Summary collapse
- UNITS =
%w[ Al Alc Cm I Os Spe St Sp m kg s A K mol cd m² m³ m/s m/s² 1/m kg/m³ A/m² A/m mol/m³ cd/m² 1 rad sr Hz N Pa J W C V F Ω S Wb T H °C lm lx Bq Gy Sv kat Pa·s N·m N/m rad/s rad/s² W/m² J/K J/(kg·K) J/kg W/(m·K) J/m³ V/m C/m³ C/m² F/m H/m J/mol J/(mol·K) C/kg Gy/s W/sr W/(m²·sr) kat/m³ min h d º ´ ´´ L t Np B eV u ua Unid Gal g Km ln cm mL mm Oz Otros].freeze
- SERVICE_UNITS =
%w[Al Alc Os Spe Sp St min h I Cm]
- CODE_TYPES =
{ '01' => 'Código del producto del vendedor', '02' => 'Código del producto del comprador', '03' => 'Código del producto asignado por la industria', '04' => 'Código uso interno', '99' => 'Otros' }.freeze
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#comercial_code ⇒ Object
Returns the value of attribute comercial_code.
-
#comercial_code_type ⇒ Object
Returns the value of attribute comercial_code_type.
-
#description ⇒ Object
Returns the value of attribute description.
-
#discount ⇒ Object
Returns the value of attribute discount.
-
#discount_reason ⇒ Object
Returns the value of attribute discount_reason.
-
#document_type ⇒ Object
Returns the value of attribute document_type.
-
#exoneration ⇒ Object
Returns the value of attribute exoneration.
-
#line_number ⇒ Object
Returns the value of attribute line_number.
-
#net_tax ⇒ Object
Returns the value of attribute net_tax.
-
#net_total ⇒ Object
Returns the value of attribute net_total.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#subtotal ⇒ Object
Returns the value of attribute subtotal.
-
#tariff_item ⇒ Object
Returns the value of attribute tariff_item.
-
#taxable_base ⇒ Object
Returns the value of attribute taxable_base.
-
#taxes ⇒ Object
Returns the value of attribute taxes.
-
#total ⇒ Object
Returns the value of attribute total.
-
#unit ⇒ Object
Returns the value of attribute unit.
-
#unit_price ⇒ Object
Returns the value of attribute unit_price.
Attributes inherited from Element
Instance Method Summary collapse
- #build_xml(node, document) ⇒ Object
- #calculations_ok? ⇒ Boolean
- #code_is_mandatory? ⇒ Boolean
-
#initialize(args = {}) ⇒ Item
constructor
A new instance of Item.
Constructor Details
#initialize(args = {}) ⇒ Item
Returns a new instance of Item.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/facturacr/document/item.rb', line 41 def initialize(args = {}) @document_type = args[:document_type] @line_number = args[:line_number] @code = args[:code] @comercial_code_type = args[:comercial_code_type].presence || '01' @comercial_code = args[:comercial_code] @quantity = args[:quantity] @unit = args[:unit] @description = args[:description] @unit_price = args[:unit_price] @total = args[:total] @discount = args[:discount] @discount_reason = args[:discount_reason] @subtotal = args[:subtotal] @taxes = args[:taxes] || [] @net_total = args[:net_total] @exoneration = args[:exoneration] @net_tax = args[:net_tax] @tariff_item = args[:tariff_item] @taxable_base = args[:taxable_base] end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def code @code end |
#comercial_code ⇒ Object
Returns the value of attribute comercial_code.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def comercial_code @comercial_code end |
#comercial_code_type ⇒ Object
Returns the value of attribute comercial_code_type.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def comercial_code_type @comercial_code_type end |
#description ⇒ Object
Returns the value of attribute description.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def description @description end |
#discount ⇒ Object
Returns the value of attribute discount.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def discount @discount end |
#discount_reason ⇒ Object
Returns the value of attribute discount_reason.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def discount_reason @discount_reason end |
#document_type ⇒ Object
Returns the value of attribute document_type.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def document_type @document_type end |
#exoneration ⇒ Object
Returns the value of attribute exoneration.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def exoneration @exoneration end |
#line_number ⇒ Object
Returns the value of attribute line_number.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def line_number @line_number end |
#net_tax ⇒ Object
Returns the value of attribute net_tax.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def net_tax @net_tax end |
#net_total ⇒ Object
Returns the value of attribute net_total.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def net_total @net_total end |
#quantity ⇒ Object
Returns the value of attribute quantity.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def quantity @quantity end |
#subtotal ⇒ Object
Returns the value of attribute subtotal.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def subtotal @subtotal end |
#tariff_item ⇒ Object
Returns the value of attribute tariff_item.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def tariff_item @tariff_item end |
#taxable_base ⇒ Object
Returns the value of attribute taxable_base.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def taxable_base @taxable_base end |
#taxes ⇒ Object
Returns the value of attribute taxes.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def taxes @taxes end |
#total ⇒ Object
Returns the value of attribute total.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def total @total end |
#unit ⇒ Object
Returns the value of attribute unit.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def unit @unit end |
#unit_price ⇒ Object
Returns the value of attribute unit_price.
18 19 20 |
# File 'lib/facturacr/document/item.rb', line 18 def unit_price @unit_price end |
Instance Method Details
#build_xml(node, document) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/facturacr/document/item.rb', line 64 def build_xml(node, document) @document = document @document_type = document.document_type raise FE::Error.new("item invalid: #{ errors..map{|k,v| "#{k}=#{v.join(". ")}"}.join("; ")}",class: self.class, messages: errors.) unless valid? node = Nokogiri::XML::Builder.new if node.nil? node.LineaDetalle do |x| x.NumeroLinea @line_number x.PartidaArancelaria @tariff_item if @tariff_item.present? && document.version_43? if document.version_43? x.Codigo @code if @code.present? end if @comercial_code.present? && document.version_43? x.CodigoComercial do |x2| x2.Tipo @comercial_code_type x2.Codigo @comercial_code end end if @comercial_code.present? && document.version_42? x.Codigo do |x2| x2.Tipo @comercial_code_type x2.Codigo @comercial_code end end x.Cantidad @quantity x.UnidadMedida @unit x.Detalle @description x.PrecioUnitario @unit_price x.MontoTotal @total if document.version_42? x.MontoDescuento @discount if @discount.present? x.NaturalezaDescuento @discount_reason if @discount_reason.present? end if @discount.present? && document.version_43? x.Descuento do |x2| x2.MontoDescuento @discount x2.NaturalezaDescuento @discount_reason end end x.SubTotal @subtotal x.BaseImponible @taxable_base if @taxable_base.present? && document.version_43? @taxes.each do |tax| tax.build_xml(x,document) end x.ImpuestoNeto @net_tax if @net_tax.present? x.MontoTotalLinea @net_total end end |
#calculations_ok? ⇒ Boolean
124 125 126 |
# File 'lib/facturacr/document/item.rb', line 124 def calculations_ok? errors.add :total, :invalid_amount, message: 'invalid amount' if (@total - (@quantity * @unit_price).round(5)).abs > 1 end |
#code_is_mandatory? ⇒ Boolean
128 129 130 131 132 133 134 |
# File 'lib/facturacr/document/item.rb', line 128 def code_is_mandatory? if Time.zone.now >= Time.zone.parse("2020-12-01").beginning_of_day true else false end end |