Class: VerifactuRails::Consulta
- Inherits:
-
Object
- Object
- VerifactuRails::Consulta
- Defined in:
- lib/verifactu_rails/consulta.rb
Overview
Consulta de los registros ya anotados (ConsultaLR.xsd).
Por qué hace falta un servicio aparte: la respuesta al ENVÍO dice si la AEAT aceptó el registro, no qué queda almacenado, y los estados NO son los mismos. RespuestaSuministro solo conoce Correcto, AceptadoConErrores e Incorrecto; la consulta añade "Anulado", que el canal de envío no sabe expresar. Es decir: que una anulación se anote correctamente y que la factura quede anulada son dos hechos distintos, y el segundo solo se observa desde aquí.
Consultar es de solo lectura: no crea registros ni toca la cadena.
Va al MISMO endpoint que el envío (VerifactuSOAP): lo que cambia es el
elemento del Body, no la URL, así que Transporte sirve tal cual.
Constant Summary collapse
- PERIODOS =
TipoPeriodoType es mensual: 01-12. No hay periodos trimestrales.
%w[01 02 03 04 05 06 07 08 09 10 11 12].freeze
- PATRON_EJERCICIO =
sf:YearType
/\A\d{4}\z/
Instance Attribute Summary collapse
-
#clave_paginacion ⇒ Object
readonly
Returns the value of attribute clave_paginacion.
-
#desde ⇒ Object
readonly
Returns the value of attribute desde.
-
#ejercicio ⇒ Object
readonly
Returns the value of attribute ejercicio.
-
#fecha_expedicion ⇒ Object
readonly
Returns the value of attribute fecha_expedicion.
-
#hasta ⇒ Object
readonly
Returns the value of attribute hasta.
-
#nif_obligado ⇒ Object
readonly
Returns the value of attribute nif_obligado.
-
#nombre_obligado ⇒ Object
readonly
Returns the value of attribute nombre_obligado.
-
#num_serie ⇒ Object
readonly
Returns the value of attribute num_serie.
-
#periodo ⇒ Object
readonly
Returns the value of attribute periodo.
-
#sistema_informatico ⇒ Object
readonly
Returns the value of attribute sistema_informatico.
Instance Method Summary collapse
-
#initialize(nif_obligado:, nombre_obligado:, ejercicio:, periodo:, num_serie: nil, fecha_expedicion: nil, desde: nil, hasta: nil, sistema_informatico: nil, clave_paginacion: nil) ⇒ Consulta
constructor
A new instance of Consulta.
- #to_xml ⇒ Object
Constructor Details
#initialize(nif_obligado:, nombre_obligado:, ejercicio:, periodo:, num_serie: nil, fecha_expedicion: nil, desde: nil, hasta: nil, sistema_informatico: nil, clave_paginacion: nil) ⇒ Consulta
Returns a new instance of Consulta.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/verifactu_rails/consulta.rb', line 39 def initialize(nif_obligado:, nombre_obligado:, ejercicio:, periodo:, num_serie: nil, fecha_expedicion: nil, desde: nil, hasta: nil, sistema_informatico: nil, clave_paginacion: nil) @nif_obligado = Formato.nif(nif_obligado, 'NIF del obligado') @nombre_obligado = Formato.limitar(nombre_obligado, 'NombreRazon del obligado', 120) @ejercicio = validar_ejercicio(ejercicio) @periodo = Formato.enumerado(formatear_periodo(periodo), 'Periodo', PERIODOS) @num_serie = num_serie && Formato.num_serie(num_serie) @fecha_expedicion = fecha_expedicion && Formato.fecha(fecha_expedicion) @desde = desde && Formato.fecha(desde) @hasta = hasta && Formato.fecha(hasta) @sistema_informatico = sistema_informatico && Formato.objeto(sistema_informatico, 'sistema_informatico', SistemaInformatico) @clave_paginacion = clave_paginacion && Formato.objeto(clave_paginacion, 'clave_paginacion', IdFactura) validar_fechas! end |
Instance Attribute Details
#clave_paginacion ⇒ Object (readonly)
Returns the value of attribute clave_paginacion.
30 31 32 |
# File 'lib/verifactu_rails/consulta.rb', line 30 def clave_paginacion @clave_paginacion end |
#desde ⇒ Object (readonly)
Returns the value of attribute desde.
30 31 32 |
# File 'lib/verifactu_rails/consulta.rb', line 30 def desde @desde end |
#ejercicio ⇒ Object (readonly)
Returns the value of attribute ejercicio.
30 31 32 |
# File 'lib/verifactu_rails/consulta.rb', line 30 def ejercicio @ejercicio end |
#fecha_expedicion ⇒ Object (readonly)
Returns the value of attribute fecha_expedicion.
30 31 32 |
# File 'lib/verifactu_rails/consulta.rb', line 30 def fecha_expedicion @fecha_expedicion end |
#hasta ⇒ Object (readonly)
Returns the value of attribute hasta.
30 31 32 |
# File 'lib/verifactu_rails/consulta.rb', line 30 def hasta @hasta end |
#nif_obligado ⇒ Object (readonly)
Returns the value of attribute nif_obligado.
30 31 32 |
# File 'lib/verifactu_rails/consulta.rb', line 30 def nif_obligado @nif_obligado end |
#nombre_obligado ⇒ Object (readonly)
Returns the value of attribute nombre_obligado.
30 31 32 |
# File 'lib/verifactu_rails/consulta.rb', line 30 def nombre_obligado @nombre_obligado end |
#num_serie ⇒ Object (readonly)
Returns the value of attribute num_serie.
30 31 32 |
# File 'lib/verifactu_rails/consulta.rb', line 30 def num_serie @num_serie end |
#periodo ⇒ Object (readonly)
Returns the value of attribute periodo.
30 31 32 |
# File 'lib/verifactu_rails/consulta.rb', line 30 def periodo @periodo end |
#sistema_informatico ⇒ Object (readonly)
Returns the value of attribute sistema_informatico.
30 31 32 |
# File 'lib/verifactu_rails/consulta.rb', line 30 def sistema_informatico @sistema_informatico end |
Instance Method Details
#to_xml ⇒ Object
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 90 91 92 93 94 |
# File 'lib/verifactu_rails/consulta.rb', line 59 def to_xml constructor = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| xml['con'].ConsultaFactuSistemaFacturacion('xmlns:con' => NS_LRC, 'xmlns:sum1' => NS_SF) do # Cabecera se declara en ConsultaLR, pero su CONTENIDO es de # SuministroInformacion: por eso el prefijo cambia al entrar. Con # elementFormDefault="qualified" en ambos esquemas, equivocarse aquí # invalida el documento aunque el árbol "se vea" bien. xml['con'].Cabecera do xml['sum1'].IDVersion IDVERSION xml['sum1'].ObligadoEmision do xml['sum1'].NombreRazon nombre_obligado xml['sum1'].NIF nif_obligado end end xml['con'].FiltroConsulta do xml['con'].PeriodoImputacion do xml['sum1'].Ejercicio ejercicio xml['sum1'].Periodo periodo end xml['con'].NumSerieFactura num_serie if num_serie construir_fechas(xml) if sistema_informatico xml['con'].SistemaInformatico do sistema_informatico.a_pares.each { |campo, valor| xml['sum1'].send(campo, valor) } end end if clave_paginacion xml['con'].ClavePaginacion do clave_paginacion.a_pares.each { |campo, valor| xml['sum1'].send(campo, valor) } end end end end end constructor.to_xml end |