class NubeFact::Document::Item

Constants

AUTO_CALCULATED_FIELDS
DEFAULT_DATA
FIELDS
TYPES_SUBJECT_TO_IGV

Attributes

guia_serie_numero[RW]
guia_tipo[RW]
invoice[RW]

Public Class Methods

new(invoice, data_hash) click to toggle source
# File lib/nube_fact/document/item.rb, line 70
def initialize(invoice, data_hash)
  @invoice = invoice
  
  load_data_from_param data_hash

  validate!

  calculate_amounts
end

Public Instance Methods

calculate_amounts() click to toggle source
# File lib/nube_fact/document/item.rb, line 80
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?() click to toggle source
# File lib/nube_fact/document/item.rb, line 95
def should_add_igv?
  # Check description on FIELDS constant
  TYPES_SUBJECT_TO_IGV.include? tipo_de_igv
end