Class: NubeFact::Document::Item
- Inherits:
-
Object
- Object
- NubeFact::Document::Item
- Defined in:
- lib/nube_fact/document/guia.rb,
lib/nube_fact/document/item.rb
Constant Summary collapse
- FIELDS =
[ "unidad_de_medida", # NIU = PRODUCTO # ZZ = SERVICIO # Puedes crear mas unidades en tu cuenta de NUBEFACT. "codigo", "descripcion", "cantidad", "valor_unitario", # sin IGV "precio_unitario", # con IGV "descuento", "subtotal", # VALOR_UNITARIO * CANTIDAD - DESCUENTO "tipo_de_igv", # 1 = Gravado - Operación Onerosa # 2 = Gravado – Retiro por premio # 3 = Gravado – Retiro por donación # 4 = Gravado – Retiro # 5 = Gravado – Retiro por publicidad # 6 = Gravado – Bonificaciones # 7 = Gravado – Retiro por entrega a trabajadores # 8 = Exonerado - Operación Onerosa # 9 = Inafecto - Operación Onerosa # 10 = Inafecto – Retiro por Bonificación # 11 = Inafecto – Retiro # 12 = Inafecto – Retiro por Muestras Médicas # 13 = Inafecto - Retiro por Convenio Colectivo # 14 = Inafecto – Retiro por premio # 15 = Inafecto - Retiro por publicidad # 16 = Exportación "igv", # Total de IGV "total", # Total de la linea "anticipo_regularizacion", "anticipo_documento_serie", "anticipo_documento_numero" ]
- REQUIRED_FIELDS =
%i( unidad_de_medida descripcion cantidad valor_unitario tipo_de_igv )
- AUTO_CALCULATED_FIELDS =
%i( precio_unitario subtotal igv total )
- DEFAULT_DATA =
{ unidad_de_medida: 'ZZ', anticipo_regularizacion: false, descuento: 0 }
- TYPES_SUBJECT_TO_IGV =
[1, 2, 3, 4, 5, 6, 7]
Instance Attribute Summary collapse
-
#guia_serie_numero ⇒ Object
Returns the value of attribute guia_serie_numero.
-
#guia_tipo ⇒ Object
Returns the value of attribute guia_tipo.
-
#invoice ⇒ Object
Returns the value of attribute invoice.
Instance Method Summary collapse
- #calculate_amounts ⇒ Object
-
#initialize(invoice, data_hash) ⇒ Item
constructor
A new instance of Item.
- #should_add_igv? ⇒ Boolean
Methods included from Utils
Methods included from Validator
Constructor Details
#initialize(invoice, data_hash) ⇒ Item
Returns a new instance of Item.
69 70 71 72 73 74 75 76 77 |
# File 'lib/nube_fact/document/item.rb', line 69 def initialize(invoice, data_hash) @invoice = invoice load_data_from_param data_hash validate! calculate_amounts end |
Instance Attribute Details
#guia_serie_numero ⇒ Object
Returns the value of attribute guia_serie_numero.
2 3 4 |
# File 'lib/nube_fact/document/guia.rb', line 2 def guia_serie_numero @guia_serie_numero end |
#guia_tipo ⇒ Object
Returns the value of attribute guia_tipo.
2 3 4 |
# File 'lib/nube_fact/document/guia.rb', line 2 def guia_tipo @guia_tipo end |
#invoice ⇒ Object
Returns the value of attribute invoice.
68 69 70 |
# File 'lib/nube_fact/document/item.rb', line 68 def invoice @invoice end |
Instance Method Details
#calculate_amounts ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/nube_fact/document/item.rb', line 79 def calculate_amounts unit_igv = if should_add_igv? ( (valor_unitario / 100) * @invoice.porcentaje_de_igv ).round 2 else 0 end self.igv = unit_igv * cantidad # total IGV de la linea self.precio_unitario = valor_unitario + unit_igv self.subtotal = (valor_unitario * cantidad) - descuento self.total = subtotal + igv end |
#should_add_igv? ⇒ Boolean
94 95 96 97 |
# File 'lib/nube_fact/document/item.rb', line 94 def should_add_igv? # Check description on FIELDS constant TYPES_SUBJECT_TO_IGV.include? tipo_de_igv end |