Class: FE::Document::Summary

Inherits:
Element
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/facturacr/document/summary.rb

Instance Attribute Summary collapse

Attributes inherited from Element

#document, #version

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Summary

Returns a new instance of Summary.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/facturacr/document/summary.rb', line 21

def initialize(args={})
  @currency = args[:currency]
  @exchange_rate = args[:exchange_rate]
  @services_taxable_total = args[:services_taxable_total].to_f
  @services_exent_total = args[:services_exent_total].to_f
  @services_exonerate_total = args[:services_exonerate_total].to_f
  @goods_taxable_total = args[:goods_taxable_total].to_f
  @goods_exent_total = args[:goods_exent_total].to_f
  @goods_exonerate_total = args[:goods_exonerate_total].to_f
  @taxable_total = args[:taxable_total].to_f
  @exent_total = args[:exent_total].to_f
  @exonerate_total = args[:exonerate_total].to_f
  @subtotal = args[:subtotal].to_f
  @discount_total = args[:discount_total].to_f
  @gross_total = args[:gross_total].to_f
  @tax_total = args[:tax_total].to_f
  @total_iva_returned = args[:total_iva_returned].to_f
  @total_other_charges = args[:total_other_charges].to_f
  @net_total = args[:net_total].to_f
  @has_exoneration = args[:has_exoneration] || false
  @medical_services_condition = args[:medical_services_condition] || false
end

Instance Attribute Details

#currencyObject

Returns the value of attribute currency.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def currency
  @currency
end

#discount_totalObject

Returns the value of attribute discount_total.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def discount_total
  @discount_total
end

#document_typeObject

Returns the value of attribute document_type.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def document_type
  @document_type
end

#exchange_rateObject

Returns the value of attribute exchange_rate.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def exchange_rate
  @exchange_rate
end

#exent_totalObject

Returns the value of attribute exent_total.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def exent_total
  @exent_total
end

#exonerate_totalObject

Returns the value of attribute exonerate_total.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def exonerate_total
  @exonerate_total
end

#goods_exent_totalObject

Returns the value of attribute goods_exent_total.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def goods_exent_total
  @goods_exent_total
end

#goods_exonerate_totalObject

Returns the value of attribute goods_exonerate_total.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def goods_exonerate_total
  @goods_exonerate_total
end

#goods_taxable_totalObject

Returns the value of attribute goods_taxable_total.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def goods_taxable_total
  @goods_taxable_total
end

#gross_totalObject

Returns the value of attribute gross_total.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def gross_total
  @gross_total
end

#has_exonerationObject

Returns the value of attribute has_exoneration.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def has_exoneration
  @has_exoneration
end

#medical_services_conditionObject

Returns the value of attribute medical_services_condition.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def medical_services_condition
  @medical_services_condition
end

#net_totalObject

Returns the value of attribute net_total.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def net_total
  @net_total
end

#services_exent_totalObject

Returns the value of attribute services_exent_total.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def services_exent_total
  @services_exent_total
end

#services_exonerate_totalObject

Returns the value of attribute services_exonerate_total.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def services_exonerate_total
  @services_exonerate_total
end

#services_taxable_totalObject

Returns the value of attribute services_taxable_total.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def services_taxable_total
  @services_taxable_total
end

#subtotalObject

Returns the value of attribute subtotal.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def subtotal
  @subtotal
end

#tax_totalObject

Returns the value of attribute tax_total.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def tax_total
  @tax_total
end

#taxable_totalObject

Returns the value of attribute taxable_total.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def taxable_total
  @taxable_total
end

#total_iva_returnedObject

Returns the value of attribute total_iva_returned.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def total_iva_returned
  @total_iva_returned
end

#total_other_chargesObject

Returns the value of attribute total_other_charges.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def total_other_charges
  @total_other_charges
end

#with_credit_cardObject

Returns the value of attribute with_credit_card.



6
7
8
# File 'lib/facturacr/document/summary.rb', line 6

def with_credit_card
  @with_credit_card
end

Instance Method Details

#build_xml(node, document) ⇒ Object

Raises:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/facturacr/document/summary.rb', line 44

def build_xml(node, document)
  @document = document
  @document_type = document.document_type
  raise FE::Error.new("summary invalid: #{ errors.messages.map{|k,v| "#{k}=#{v.join(". ")}"}.join("; ")}",class: self.class, messages: errors.messages) unless valid?
  node = Nokogiri::XML::Builder.new if node.nil?

  node.ResumenFactura do |xml|
    if document.version_42?
      xml.CodigoMoneda @currency if @currency.present?
      xml.TipoCambio @exchange_rate if @exchange_rate.present?
    elsif document.version_43? && @currency.present? #&& @currency != "CRC"
      xml.CodigoTipoMoneda do |x|
        x.CodigoMoneda @currency
        x.TipoCambio @exchange_rate || 1
      end
    end

    xml.TotalServGravados @services_taxable_total
    xml.TotalServExentos @services_exent_total
    xml.TotalServExonerado @services_exonerate_total if @services_exonerate_total && document.version_43? && !document_type.eql?(FE::ExportInvoice::DOCUMENT_TYPE)
    xml.TotalMercanciasGravadas @goods_taxable_total
    xml.TotalMercanciasExentas @goods_exent_total
    xml.TotalMercExonerada @goods_exonerate_total if @goods_exonerate_total.present? && document.version_43? && !document_type.eql?(FE::ExportInvoice::DOCUMENT_TYPE)
    xml.TotalGravado @taxable_total
    xml.TotalExento @exent_total
    xml.TotalExonerado @exonerate_total if @exonerate_total.present? && document.version_43? && !document_type.eql?(FE::ExportInvoice::DOCUMENT_TYPE)
    xml.TotalVenta @subtotal
    xml.TotalDescuentos @discount_total
    xml.TotalVentaNeta @gross_total
    xml.TotalImpuesto @tax_total
    if document.version_43?
      xml.TotalIVADevuelto @total_iva_returned if @medical_services_condition && !document_type.eql?(FE::ExportInvoice::DOCUMENT_TYPE) && !document_type.eql?(FE::PurchaseInvoice::DOCUMENT_TYPE)
      xml.TotalOtrosCargos @total_other_charges if @total_other_charges > 0
    end
    xml.TotalComprobante @net_total
  end
end