Class: Bravo::Bill
- Inherits:
-
Object
- Object
- Bravo::Bill
- Defined in:
- lib/bravo/bill.rb
Instance Attribute Summary collapse
-
#aliciva_id ⇒ Object
Returns the value of attribute aliciva_id.
-
#base_imp ⇒ Object
readonly
Returns the value of attribute base_imp.
-
#body ⇒ Object
Returns the value of attribute body.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#concepto ⇒ Object
Returns the value of attribute concepto.
-
#doc_num ⇒ Object
Returns the value of attribute doc_num.
-
#documento ⇒ Object
Returns the value of attribute documento.
-
#due_date ⇒ Object
Returns the value of attribute due_date.
-
#fch_serv_desde ⇒ Object
Returns the value of attribute fch_serv_desde.
-
#fch_serv_hasta ⇒ Object
Returns the value of attribute fch_serv_hasta.
-
#iva_cond ⇒ Object
Returns the value of attribute iva_cond.
-
#moneda ⇒ Object
Returns the value of attribute moneda.
-
#net ⇒ Object
Returns the value of attribute net.
-
#response ⇒ Object
Returns the value of attribute response.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
-
.header(cbte_type) ⇒ Object
todo sacado de la factura.
Instance Method Summary collapse
- #authorize ⇒ Object
- #authorized? ⇒ Boolean
- #cbte_type ⇒ Object
- #exchange_rate ⇒ Object
-
#initialize(attrs = {}) ⇒ Bill
constructor
A new instance of Bill.
- #iva_sum ⇒ Object
- #next_bill_number ⇒ Object
- #setup_bill ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Bill
Returns a new instance of Bill.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/bravo/bill.rb', line 8 def initialize(attrs = {}) Bravo::AuthData.fetch @client = Savon::Client.new(Bravo.service_url) @body = {"Auth" => Bravo.auth_hash} @net = attrs[:net] || 0 self.documento = attrs[:documento] || Bravo.default_documento self.moneda = attrs[:moneda] || Bravo.default_moneda self.iva_cond = attrs[:iva_cond] self.concepto = attrs[:concepto] || Bravo.default_concepto end |
Instance Attribute Details
#aliciva_id ⇒ Object
Returns the value of attribute aliciva_id.
4 5 6 |
# File 'lib/bravo/bill.rb', line 4 def aliciva_id @aliciva_id end |
#base_imp ⇒ Object (readonly)
Returns the value of attribute base_imp.
3 4 5 |
# File 'lib/bravo/bill.rb', line 3 def base_imp @base_imp end |
#body ⇒ Object
Returns the value of attribute body.
4 5 6 |
# File 'lib/bravo/bill.rb', line 4 def body @body end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/bravo/bill.rb', line 3 def client @client end |
#concepto ⇒ Object
Returns the value of attribute concepto.
4 5 6 |
# File 'lib/bravo/bill.rb', line 4 def concepto @concepto end |
#doc_num ⇒ Object
Returns the value of attribute doc_num.
4 5 6 |
# File 'lib/bravo/bill.rb', line 4 def doc_num @doc_num end |
#documento ⇒ Object
Returns the value of attribute documento.
4 5 6 |
# File 'lib/bravo/bill.rb', line 4 def documento @documento end |
#due_date ⇒ Object
Returns the value of attribute due_date.
4 5 6 |
# File 'lib/bravo/bill.rb', line 4 def due_date @due_date end |
#fch_serv_desde ⇒ Object
Returns the value of attribute fch_serv_desde.
4 5 6 |
# File 'lib/bravo/bill.rb', line 4 def fch_serv_desde @fch_serv_desde end |
#fch_serv_hasta ⇒ Object
Returns the value of attribute fch_serv_hasta.
4 5 6 |
# File 'lib/bravo/bill.rb', line 4 def fch_serv_hasta @fch_serv_hasta end |
#iva_cond ⇒ Object
Returns the value of attribute iva_cond.
4 5 6 |
# File 'lib/bravo/bill.rb', line 4 def iva_cond @iva_cond end |
#moneda ⇒ Object
Returns the value of attribute moneda.
4 5 6 |
# File 'lib/bravo/bill.rb', line 4 def moneda @moneda end |
#net ⇒ Object
Returns the value of attribute net.
4 5 6 |
# File 'lib/bravo/bill.rb', line 4 def net @net end |
#response ⇒ Object
Returns the value of attribute response.
4 5 6 |
# File 'lib/bravo/bill.rb', line 4 def response @response end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
3 4 5 |
# File 'lib/bravo/bill.rb', line 3 def total @total end |
Class Method Details
.header(cbte_type) ⇒ Object
todo sacado de la factura
107 108 109 |
# File 'lib/bravo/bill.rb', line 107 def header(cbte_type)#todo sacado de la factura {"CantReg" => "1", "CbteTipo" => cbte_type, "PtoVta" => Bravo.sale_point} end |
Instance Method Details
#authorize ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bravo/bill.rb', line 42 def setup_bill response = client.fecae_solicitar do |soap| soap.namespaces["xmlns"] = "http://ar.gov.afip.dif.FEV1/" soap.body = body end setup_response(response.to_hash) self. end |
#authorized? ⇒ Boolean
100 101 102 |
# File 'lib/bravo/bill.rb', line 100 def !response.nil? && response.header_result == "A" && response.detail_result == "A" end |
#cbte_type ⇒ Object
19 20 21 22 |
# File 'lib/bravo/bill.rb', line 19 def cbte_type Bravo::BILL_TYPE[Bravo.own_iva_cond][iva_cond] || raise(NullOrInvalidAttribute.new, "Please choose a valid document type.") end |
#exchange_rate ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/bravo/bill.rb', line 24 def exchange_rate return 1 if moneda == :peso response = client.fe_param_get_cotizacion do |soap| soap.namespaces["xmlns"] = "http://ar.gov.afip.dif.FEV1/" soap.body = body.merge!({"MonId" => Bravo::MONEDAS[moneda][:codigo]}) end response.to_hash[:fe_param_get_cotizacion_response][:fe_param_get_cotizacion_result][:result_get][:mon_cotiz].to_f end |
#iva_sum ⇒ Object
37 38 39 40 |
# File 'lib/bravo/bill.rb', line 37 def iva_sum @iva_sum = net * Bravo::ALIC_IVA[aliciva_id][1] @iva_sum.round_up_with_precision(2) end |
#next_bill_number ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/bravo/bill.rb', line 91 def next_bill_number resp = client.fe_comp_ultimo_autorizado do |s| s.namespaces["xmlns"] = "http://ar.gov.afip.dif.FEV1/" s.body = {"Auth" => Bravo.auth_hash, "PtoVta" => Bravo.sale_point, "CbteTipo" => cbte_type} end resp.to_hash[:fe_comp_ultimo_autorizado_response][:fe_comp_ultimo_autorizado_result][:cbte_nro].to_i + 1 end |
#setup_bill ⇒ Object
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 81 82 83 84 85 86 87 88 89 |
# File 'lib/bravo/bill.rb', line 53 def setup_bill today = Time.new.strftime('%Y%m%d') fecaereq = {"FeCAEReq" => { "FeCabReq" => Bravo::Bill.header(cbte_type), "FeDetReq" => { "FECAEDetRequest" => { "Concepto" => Bravo::CONCEPTOS[concepto], "DocTipo" => Bravo::DOCUMENTOS[documento], "CbteFch" => today, "ImpTotConc" => 0.00, "MonId" => Bravo::MONEDAS[moneda][:codigo], "MonCotiz" => exchange_rate, "ImpOpEx" => 0.00, "ImpTrib" => 0.00, "Iva" => { "AlicIva" => { "Id" => "5", "BaseImp" => net, "Importe" => iva_sum}}}}}} detail = fecaereq["FeCAEReq"]["FeDetReq"]["FECAEDetRequest"] detail["DocNro"] = doc_num detail["ImpNeto"] = net.to_f detail["ImpIVA"] = iva_sum detail["ImpTotal"] = total detail["CbteDesde"] = detail["CbteHasta"] = next_bill_number unless concepto == 0 detail.merge!({"FchServDesde" => fch_serv_desde || today, "FchServHasta" => fch_serv_hasta || today, "FchVtoPago" => due_date || today}) end body.merge!(fecaereq) end |