Class: Afip::CTG

Inherits:
Object
  • Object
show all
Defined in:
lib/Afip/ctg.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ CTG

Returns a new instance of CTG.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/Afip/ctg.rb', line 7

def initialize(attrs = {})
  Afip::AuthData.fetch("wsctg")
  @client         = Savon.client(
    ssl_cert_key_file: Afip.pkey,
    ssl_cert_file: Afip.cert,
    env_namespace: :soapenv,
    namespace_identifier: :ctg,
    log: true,
    logger: Rails.logger,
    log_level: :debug,
    pretty_print_xml: true,
    encoding: 'UTF-8',
    ssl_version: :TLSv1,
    wsdl:  Afip.service_url
  )

  @ctg_num                = attrs[:ctg_num]
  @cp_num                 = attrs[:cp_num]
  @cod_especie            = attrs[:cod_especie]
  @cuit_canjeador         = attrs[:cuit_canjeador]
  @rccc                   = attrs[:rccc]
  @cuit_destino           = attrs[:cuit_destino]
  @cuit_destinatario      = attrs[:cuit_destinatario]
  @localidad_origen       = attrs[:localidad_origen]
  @localidad_destino      = attrs[:localidad_destino]
  @cosecha                = attrs[:cosecha]
  @peso                   = attrs[:peso]
  @cuit_transportista     = attrs[:cuit_transportista]
  @horas                  = attrs[:horas]
  @patente                = attrs[:patente]
  @km                     = attrs[:km]
  @cuit_corredor          = attrs[:cuit_corredor]
  @remitente_com          = attrs[:remitente_com]
  @cuit_chofer            = attrs[:cuit_chofer]
  @cant_kilos_carta_porte = attrs[:cant_kilos_carta_porte]
  @establecimiento        = attrs[:establecimiento]
  @cuit_solicitante       = attrs[:cuit_solicitante]
  @fecha_desde            = attrs[:fecha_desde]
  @fecha_hasta            = attrs[:fecha_hasta]

  @body               = {"request" =>{"auth" => Afip.auth_hash("wsctg")}}
end

Instance Attribute Details

#base_impObject (readonly)

Returns the value of attribute base_imp.



3
4
5
# File 'lib/Afip/ctg.rb', line 3

def base_imp
  @base_imp
end

#bodyObject

Returns the value of attribute body.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def body
  @body
end

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/Afip/ctg.rb', line 3

def client
  @client
end

#cod_especieObject

Returns the value of attribute cod_especie.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def cod_especie
  @cod_especie
end

#cosechaObject

Returns the value of attribute cosecha.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def cosecha
  @cosecha
end

#cp_numObject

Returns the value of attribute cp_num.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def cp_num
  @cp_num
end

#ctg_numObject

Returns the value of attribute ctg_num.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def ctg_num
  @ctg_num
end

#cuit_canjeadorObject

Returns the value of attribute cuit_canjeador.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def cuit_canjeador
  @cuit_canjeador
end

#cuit_corredorObject

Returns the value of attribute cuit_corredor.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def cuit_corredor
  @cuit_corredor
end

#cuit_destinatarioObject

Returns the value of attribute cuit_destinatario.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def cuit_destinatario
  @cuit_destinatario
end

#cuit_destinoObject

Returns the value of attribute cuit_destino.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def cuit_destino
  @cuit_destino
end

#cuit_transportistaObject

Returns the value of attribute cuit_transportista.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def cuit_transportista
  @cuit_transportista
end

#horasObject

Returns the value of attribute horas.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def horas
  @horas
end

#kmObject

Returns the value of attribute km.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def km
  @km
end

#localidad_destinoObject

Returns the value of attribute localidad_destino.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def localidad_destino
  @localidad_destino
end

#localidad_origenObject

Returns the value of attribute localidad_origen.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def localidad_origen
  @localidad_origen
end

#patenteObject

Returns the value of attribute patente.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def patente
  @patente
end

#pesoObject

Returns the value of attribute peso.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def peso
  @peso
end

#rcccObject

Returns the value of attribute rccc.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def rccc
  @rccc
end

#remitente_comObject

Returns the value of attribute remitente_com.



4
5
6
# File 'lib/Afip/ctg.rb', line 4

def remitente_com
  @remitente_com
end

#totalObject (readonly)

Returns the value of attribute total.



3
4
5
# File 'lib/Afip/ctg.rb', line 3

def total
  @total
end

Instance Method Details

#anular_ctgObject



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/Afip/ctg.rb', line 91

def anular_ctg
  request = {
              "datosAnularCTG" =>{
                "cartaPorte"  => @cp_num,
                "ctg"         => @ctg_num
              }
            }
  body["request"].merge(request)

  response = client.call(:anular_ctg, message: body)
end

#authorized?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/Afip/ctg.rb', line 87

def authorized?
    !response.nil?
end

#cambiar_destino_detinatario_ctg_rechazadoObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/Afip/ctg.rb', line 103

def cambiar_destino_detinatario_ctg_rechazado
  request = {
              "datosCambiarDestinoDestinatarioCTGRechazado" =>{
                "cartaPorte"                  => @cp_num,
                "ctg"                         => @ctg_num,
                "codigoLocalidadDestino"      => @destino,
                "codigoLocalidadDestinatario" => @destinatario,
                "kmARecorrer"                 => @km
              }
            }
  body["request"].merge(request)

  response = client.call(:cambiar_destino_detinatario_ctg_rechazado, message: body)
end

#confirmar_arriboObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/Afip/ctg.rb', line 118

def confirmar_arribo
  request = {
              "datosConfirmarArribo" =>{
                "cartaPorte"          => @cp_num,
                "ctg"                 => @ctg_num,
                "cuitTransportista"   => @cuit_transportista,
                "cuitChofer"          => @cuit_chofer,
                "cantKilosCartaPorte" => @cant_kilos_carta_porte
              }
            }
  body["request"].merge(request)

  response = client.call(:confirmar_arribo, message: body)
end

#confirmar_definitivoObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/Afip/ctg.rb', line 133

def confirmar_definitivo
  request = {
              "datosConfirmarDefinitivo" =>{
                "cartaPorte"          => @cp_num,
                "ctg"                 => @ctg_num,
                "establecimiento"     => @establecimiento,
                "codigoCosecha"       => @cosecha,
                "pesoNeto"            => @peso
              }
            }
  body["request"].merge(request)

  response = client.call(:confirmar_definitivo, message: body)
end

#consultar_constancia_ctg_pdfObject



153
154
155
156
157
158
159
160
161
# File 'lib/Afip/ctg.rb', line 153

def consultar_constancia_ctg_pdf
  request = {
              "ctg" => @ctg_num
            }

  body["request"].merge(request)

  pp response = client.call(:consultar_constancia_ctgpdf, message: body)
end

#consultar_cosechasObject



148
149
150
151
# File 'lib/Afip/ctg.rb', line 148

def consultar_cosechas
  response = client.call(:obtener_cosechas, message: body)
  return response["arrayCosechas"]
end

#consultar_ctgObject



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/Afip/ctg.rb', line 163

def consultar_ctg
  request = {
              "consultarCTGDatos" =>{
                "cartaPorte"          => @cp_num,
                "ctg"                 => @ctg_num,
                "patente"             => @patente,
                "cuitSolicitante"     => @cuit_solicitante,
                "cuitDestino"         => @destino,
                "fechaEmisionDesde"   => @fecha_desde,
                "fechaEmisionHsta"    => @fecha_hasta,
                "cuitCorredor"        => @cuit_corredor
              }
            }
  body["request"].merge(request)

  response = client.call(:consultar_ctg, message: body)
end

#consultar_ctg_rechazadosObject



181
182
183
184
# File 'lib/Afip/ctg.rb', line 181

def consultar_ctg_rechazados
  response = client.call(:consultar_ctg_rechazados, message: body)
  return response.to_hash["response"]["arrayConsultarCTGRechazados"]
end

#consultar_detalle_ctgObject



186
187
188
189
190
191
192
193
194
195
# File 'lib/Afip/ctg.rb', line 186

def consultar_detalle_ctg
  request = {
              "ctg" => @ctg_num
            }

  body["request"].merge(request)

  response = client.call(:consultar_constancia_ctg_pdf, message: body)
  return response.to_hash["response"]["consultarDetalleCTGDatos"]
end

#consultar_especiesObject



197
198
199
200
# File 'lib/Afip/ctg.rb', line 197

def consultar_especies
  response = client.call(:consultar_especies, message: body)
  response.body[:consultar_especies_response][:response][:array_especies][:especie].map{|c| [c[:codigo],c[:descripcion]]}
end

#consultar_establecimientosObject



202
203
204
205
# File 'lib/Afip/ctg.rb', line 202

def consultar_establecimientos
  response = client.call(:consultar_establecimientos, message: body)
  response.body[:consultar_especies_response][:response][:array_establecimientos][:establecimiento].map{|c| [c]}
end

#consultar_localidades(city) ⇒ Object



217
218
219
220
221
222
223
224
225
# File 'lib/Afip/ctg.rb', line 217

def consultar_localidades(city)
  body["request"]["codigoProvincia"] = city
  response = client.call(:consultar_localidades_por_provincia, message: body)
  if response.body[:consultar_localidades_por_provincia_response][:response][:array_localidades][:localidad].class.name != "Array"
    [response.body[:consultar_localidades_por_provincia_response][:response][:array_localidades][:localidad]].map{|c| [c[:codigo],c[:descripcion]]}
  else
    response.body[:consultar_localidades_por_provincia_response][:response][:array_localidades][:localidad].map{|c| [c[:codigo],c[:descripcion]]}
  end
end

#consultar_provinciasObject



207
208
209
210
# File 'lib/Afip/ctg.rb', line 207

def consultar_provincias
  response = client.call(:consultar_provincias, message: body)
  response.body[:consultar_provincias_response][:consultar_provincias_response][:array_provincias][:provincia].map{|c| [c[:codigo],c[:descripcion]]}
end

#setup_ctgObject



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
# File 'lib/Afip/ctg.rb', line 60

def setup_ctg

  datos = {
              "datosSolicitarCTGInicial" =>{
                  "cartaPorte"                        => @cp_num, #long
                  "codigoEspecie"                     => @cod_especie, #int
                  #"cuitCanjeador"                     => @cuit_canjeador.to_i, #long
                  #"remitenteComercialComoCanjeador"   => @rccc,
                  "cuitDestino"                       => @cuit_destino, #long
                  "cuitDestinatario"                  => @cuit_destinatario, #long
                  "codigoLocalidadOrigen"             => @localidad_origen, #int
                  "codigoLocalidadDestino"            => @localidad_destino, #int
                  "codigoCosecha"                     => @cosecha, #string
                  "pesoNeto"                          => @peso.to_i, #long
                  #"cuitTransportista"                 => @cuit_transportista.to_i, #long
                  #"cantHoras"                         => @horas, #int
                  #"patente"                           => @patente, #string
                  "kmARecorrer"                       => @km, #unsignedint
                  #"cuitCorredor"                      => @cuit_corredor.to_i, #long
                  #"remitenteComercialcomoProductor"   => @remitente_com
                }
            }

  @body["request"].merge!(datos)
  return @body
end

#solicitar_ctg_inicialObject



50
51
52
53
54
55
56
57
58
# File 'lib/Afip/ctg.rb', line 50

def solicitar_ctg_inicial
  pp body = setup_ctg

  pp response = client.call(:solicitar_ctg_inicial,message: body)

  setup_response(response.to_hash)

  self.authorized?
end