Class: Snoopy::Bill

Inherits:
Object
  • Object
show all
Defined in:
lib/snoopy_afip/bill.rb

Constant Summary collapse

ATTRIBUTES =
[:total_net, :document_num, :document_type, :concept, :currency, :result,
:cbte_asoc_num, :cae, :service_date_to, :due_date,
:number, :alicivas, :cuit, :sale_point, :service_date_from,
:due_date_cae, :voucher_date, :process_date, :imp_iva, :cbte_asoc_to_sale_point,
:receiver_iva_cond, :issuer_iva_cond, :errors, :asoc_receiver_iva_cond, :receiver_iva_condition]
TAX_ATTRIBUTES =
[:id, :amount, :taxeable_base]
ATTRIBUTES_PRECENSE =
[:total_net, :concept, :receiver_iva_cond, :alicivas, :document_type, :service_date_from, :service_date_to, :sale_point, :issuer_iva_cond, :receiver_iva_condition]

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Bill

Returns a new instance of Bill.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/snoopy_afip/bill.rb', line 16

def initialize(attrs={})
  # attrs = attrs.deep_symbolize_keys
  @cuit                    = attrs[:cuit]
  @result                  = nil
  @number                  = attrs[:number]
  @errors                  = {}
  @concept                 = attrs[:concept] || Snoopy.default_concept
  @imp_iva                 = attrs[:imp_iva] # Monto total de impuestos
  @currency                = attrs[:currency] || Snoopy.default_currency
  @alicivas                = attrs[:alicivas]
  @total_net               = attrs[:total_net] || 0
  @sale_point              = attrs[:sale_point]
  @document_num            = attrs[:document_num]
  @cbte_asoc_num           = attrs[:cbte_asoc_num] # Esto es el numero de factura para la nota de credito
  @document_type           = attrs[:document_type] || Snoopy.default_document_type
  @issuer_iva_cond         = attrs[:issuer_iva_cond]
  @service_date_to         = attrs[:service_date_to]
  @service_date_from       = attrs[:service_date_from]
  @receiver_iva_cond       = attrs[:receiver_iva_cond] # Esto se usa para el cbte_type
  @asoc_receiver_iva_cond  = attrs[:asoc_receiver_iva_cond]
  @cbte_asoc_to_sale_point = attrs[:cbte_asoc_to_sale_point] # Esto es el punto de venta de la factura para la nota de credito
  @receiver_iva_condition  = attrs[:receiver_iva_condition] # La verdadera condicion de iva del receptor
end

Instance Method Details

#approved?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/snoopy_afip/bill.rb', line 86

def approved?
  result == 'A'
end

#cbte_asoc_typeObject



82
83
84
# File 'lib/snoopy_afip/bill.rb', line 82

def cbte_asoc_type
  Snoopy::BILL_TYPE[asoc_receiver_iva_cond.to_sym]
end

#cbte_typeObject



78
79
80
# File 'lib/snoopy_afip/bill.rb', line 78

def cbte_type
  Snoopy::BILL_TYPE[receiver_iva_cond.to_sym]
end

#exchange_rateObject

Para probar que la conexion con afip es correcta, si este metodo devuelve true, es posible realizar cualquier consulta al ws de la AFIP. def connection_valid?

result = client.call(:fe_dummy).body[:fe_dummy_result]

result = client_call(:fe_dummy)[:fe_dummy_response][:fe_dummy_result] @afip_observations = result @afip_observations = result @afip_observations = result result == 'OK' and result == 'OK' and result == 'OK' end



61
62
63
64
65
66
67
68
# File 'lib/snoopy_afip/bill.rb', line 61

def exchange_rate
  return 1 if currency == :peso
  # response = client.fe_param_get_cotizacion do |soap|
  #   soap.namespaces["xmlns"] = "http://ar.gov.afip.dif.FEV1/"
  #   soap.body = body.merge!({"MonId" => Snoopy::CURRENCY[currency][:code]})
  # end
  # response.to_hash[:fe_param_get_cotizacion_response][:fe_param_get_cotizacion_result][:result_get][:mon_cotiz].to_f
end

#iva_sumObject



74
75
76
# File 'lib/snoopy_afip/bill.rb', line 74

def iva_sum
  @iva_sum = alicivas.map{|aliciva| aliciva[:amount].to_f }.inject(:+).to_f.round_with_precision(2)
end

#partial_approved?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/snoopy_afip/bill.rb', line 94

def partial_approved?
  result == 'P'
end

#receiver_iva_condition_idObject



109
110
111
112
113
# File 'lib/snoopy_afip/bill.rb', line 109

def receiver_iva_condition_id
  return '' if @receiver_iva_condition.nil?

  Snoopy::IVA_COND_RECEIVER[@receiver_iva_condition.to_sym]
end

#rejected?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/snoopy_afip/bill.rb', line 90

def rejected?
  result == 'R'
end

#to_hObject Also known as: to_hash



102
103
104
105
106
# File 'lib/snoopy_afip/bill.rb', line 102

def to_h
  Hash[*instance_variables.map { |v|
    [v.to_s.sub('@', '').to_sym, instance_variable_get(v)]
  }.flatten]
end

#totalObject



70
71
72
# File 'lib/snoopy_afip/bill.rb', line 70

def total
  @total = total_net.zero? ? 0 : (total_net + iva_sum).round(2)
end

#valid?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/snoopy_afip/bill.rb', line 98

def valid?
  validate!
end