Class: Snoopy::Bill
- Inherits:
-
Object
- Object
- Snoopy::Bill
- 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]
- 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
- #approved? ⇒ Boolean
- #cbte_asoc_type ⇒ Object
- #cbte_type ⇒ Object
-
#exchange_rate ⇒ Object
Para probar que la conexion con afip es correcta, si este metodo devuelve true, es posible realizar cualquier consulta al ws de la AFIP.
-
#initialize(attrs = {}) ⇒ Bill
constructor
A new instance of Bill.
- #iva_sum ⇒ Object
- #partial_approved? ⇒ Boolean
- #rejected? ⇒ Boolean
- #to_h ⇒ Object (also: #to_hash)
- #total ⇒ Object
- #valid? ⇒ Boolean
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 |
# 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] @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 end |
Instance Method Details
#approved? ⇒ Boolean
85 86 87 |
# File 'lib/snoopy_afip/bill.rb', line 85 def approved? result == 'A' end |
#cbte_asoc_type ⇒ Object
81 82 83 |
# File 'lib/snoopy_afip/bill.rb', line 81 def cbte_asoc_type Snoopy::BILL_TYPE[asoc_receiver_iva_cond.to_sym] end |
#cbte_type ⇒ Object
77 78 79 |
# File 'lib/snoopy_afip/bill.rb', line 77 def cbte_type Snoopy::BILL_TYPE[receiver_iva_cond.to_sym] end |
#exchange_rate ⇒ Object
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
60 61 62 63 64 65 66 67 |
# File 'lib/snoopy_afip/bill.rb', line 60 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_sum ⇒ Object
73 74 75 |
# File 'lib/snoopy_afip/bill.rb', line 73 def iva_sum @iva_sum = alicivas.map{|aliciva| aliciva[:amount].to_f }.inject(:+).to_f.round_with_precision(2) end |
#partial_approved? ⇒ Boolean
93 94 95 |
# File 'lib/snoopy_afip/bill.rb', line 93 def partial_approved? result == 'P' end |
#rejected? ⇒ Boolean
89 90 91 |
# File 'lib/snoopy_afip/bill.rb', line 89 def rejected? result == 'R' end |
#to_h ⇒ Object Also known as: to_hash
101 102 103 104 105 |
# File 'lib/snoopy_afip/bill.rb', line 101 def to_h Hash[*instance_variables.map { |v| [v.to_s.sub('@', '').to_sym, instance_variable_get(v)] }.flatten] end |
#total ⇒ Object
69 70 71 |
# File 'lib/snoopy_afip/bill.rb', line 69 def total @total = total_net.zero? ? 0 : (total_net + iva_sum).round(2) end |
#valid? ⇒ Boolean
97 98 99 |
# File 'lib/snoopy_afip/bill.rb', line 97 def valid? validate! end |