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 ]
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]

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
# 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]
  @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
end

Instance Method Details

#approved?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/snoopy_afip/bill.rb', line 80

def approved?
  result == 'A'
end

#cbte_typeObject



76
77
78
# File 'lib/snoopy_afip/bill.rb', line 76

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_response][:fe_dummy_result]
result = client_call(:fe_dummy)[:fe_dummy_response][:fe_dummy_result]
@afip_observations[:db_server]   = result[:db_server]
@afip_observations[:app_server]  = result[:app_server]
@afip_observations[:auth_server] = result[:auth_server]
result[:app_server] == 'OK' and result[:db_server] == 'OK' and result[:auth_server] == 'OK'

end



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

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



72
73
74
# File 'lib/snoopy_afip/bill.rb', line 72

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)


88
89
90
# File 'lib/snoopy_afip/bill.rb', line 88

def partial_approved?
  result == 'P'
end

#rejected?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/snoopy_afip/bill.rb', line 84

def rejected?
  result == 'R'
end

#to_hObject Also known as: to_hash



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

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

#totalObject



68
69
70
# File 'lib/snoopy_afip/bill.rb', line 68

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

#valid?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/snoopy_afip/bill.rb', line 92

def valid?
  validate!
end