private eFact_RN.IBK.lote_response ArmarLoteResponse(FeaEntidades.InterFacturas.lote_comprobantes Lc) { eFact_RN.IBK.lote_response lrCompleto = new eFact_RN.IBK.lote_response(); eFact_RN.IBK.error[] errores = new eFact_RN.IBK.error[1]; lrCompleto.cantidad_reg = Lc.cabecera_lote.cantidad_reg; lrCompleto.cuit_canal = Lc.cabecera_lote.cuit_canal; lrCompleto.cuit_vendedor = Lc.cabecera_lote.cuit_vendedor; lrCompleto.estado = Lc.cabecera_lote.resultado; lrCompleto.fecha_envio_lote = Lc.cabecera_lote.fecha_envio_lote; lrCompleto.id_lote = Lc.cabecera_lote.id_lote; lrCompleto.presta_serv = Lc.cabecera_lote.presta_serv; lrCompleto.presta_servSpecified = Lc.cabecera_lote.presta_servSpecified; lrCompleto.punto_de_venta = Lc.cabecera_lote.punto_de_venta; if (Lc.cabecera_lote.motivo != null && Lc.cabecera_lote.motivo.Trim() != "00" && Lc.cabecera_lote.motivo.Trim() != "") { errores[0] = new eFact_RN.IBK.error(); errores[0].codigo_error = 0; errores[0].descripcion_error = Lc.cabecera_lote.motivo.Trim(); lrCompleto.errores_lote = errores; } int CantMotivoError = 0; for (int i = 0; i < Lc.comprobante.Length; i++) { if (Lc.comprobante[i].cabecera.informacion_comprobante.motivo != null && Lc.comprobante[i].cabecera.informacion_comprobante.motivo.Trim() != "00" && Lc.comprobante[i].cabecera.informacion_comprobante.motivo.Trim() != "") { CantMotivoError++; } } int NroMotivo = 0; for (int i = 0; i < Lc.comprobante.Length; i++) { eFact_RN.IBK.error[] erroresComprobante = new eFact_RN.IBK.error[1]; if (Lc.comprobante[i].cabecera.informacion_comprobante.motivo != null && Lc.comprobante[i].cabecera.informacion_comprobante.motivo.Trim() != "00" && Lc.comprobante[i].cabecera.informacion_comprobante.motivo.Trim() != "") { if (lrCompleto.comprobante_response == null) { lrCompleto.comprobante_response = new eFact_RN.IBK.comprobante_response[CantMotivoError]; } erroresComprobante[NroMotivo] = new eFact_RN.IBK.error(); erroresComprobante[NroMotivo].codigo_error = 0; erroresComprobante[NroMotivo].descripcion_error = Lc.comprobante[i].cabecera.informacion_comprobante.motivo; lrCompleto.comprobante_response[NroMotivo] = new eFact_RN.IBK.comprobante_response(); lrCompleto.comprobante_response[NroMotivo].numero_comprobante = Lc.comprobante[i].cabecera.informacion_comprobante.numero_comprobante; lrCompleto.comprobante_response[NroMotivo].punto_de_venta = Lc.comprobante[i].cabecera.informacion_comprobante.punto_de_venta; lrCompleto.comprobante_response[NroMotivo].tipo_de_comprobante = Lc.comprobante[i].cabecera.informacion_comprobante.tipo_de_comprobante; lrCompleto.comprobante_response[NroMotivo].estado = Lc.comprobante[i].cabecera.informacion_comprobante.resultado; lrCompleto.comprobante_response[NroMotivo].errores_comprobante = erroresComprobante; NroMotivo++; } } return lrCompleto; }
private void EnviarAIF() { try { Cursor=System.Windows.Forms.Cursors.WaitCursor; EventosComboBox.Enabled = false; if (BandejaSDataGridView.SelectedRows.Count != 0) { eFact_Entidades.Lote l = new eFact_Entidades.Lote(); List<eFact_Entidades.Lote> llotes = new List<eFact_Entidades.Lote>(); for (int i = 0; i < BandejaSDataGridView.SelectedRows.Count; i++) { int renglon = BandejaSDataGridView.SelectedRows[i].Index; l = dtBandejaSalida[renglon]; llotes.Add(l); } llotes = SortListaLotes(llotes); for (int i = 0; i < llotes.Count; i++) { //Envio del lote a IF eFact_Entidades.Lote lote = new eFact_Entidades.Lote(); lote = llotes[i]; List<CedEntidades.Evento> eventosposibles = new List<CedEntidades.Evento>(); eventosposibles = lote.WF.EventosPosibles.FindAll((delegate(CedEntidades.Evento e1) { return e1.IdEstadoDsd.IdEstado.ToString() == "PteEnvio"; })); if (eventosposibles.Count == 0) { MessageBox.Show("Imposible enviar el lote: " + lote.NumeroLote + " en el estado actual.", "Envio de Lotes", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); break; } FeaEntidades.InterFacturas.lote_comprobantes lc = new FeaEntidades.InterFacturas.lote_comprobantes(); eFact_RN.Lote.DeserializarLc(out lc, lote, false); //Antes de ejecutar el envio a Interfacturas, cambiar el estado. EjecutarEventoBandejaS("EnviarAIF", "", lote); //Actualizar el WF del lote. eFact_RN.Lote.Leer(lote, Aplicacion.Sesion); //Consultar si exite el lote en Interfacturas FeaEntidades.InterFacturas.lote_comprobantes Lc = new FeaEntidades.InterFacturas.lote_comprobantes(); eFact_RN.IBK.error[] respErroresLote = new eFact_RN.IBK.error[0]; eFact_RN.IBK.error[] respErroresComprobantes = new eFact_RN.IBK.error[0]; eFact_RN.IBK.consulta_lote_responseErrores_consulta RespErroresLote = new eFact_RN.IBK.consulta_lote_responseErrores_consulta(); eFact_RN.IBK.consulta_lote_comprobantes_responseErrores_response RespErroresComprobantes = new eFact_RN.IBK.consulta_lote_comprobantes_responseErrores_response(); //Enviar a Interfacturas si el lote no existe. eFact_RN.Comprobante eFact_RNComprobante = new eFact_RN.Comprobante(); eFact_RN.IBK.lote_response Lr = new eFact_RN.IBK.lote_response(); try { eFact_Entidades.Vendedor v = Aplicacion.Vendedores.Find(delegate(eFact_Entidades.Vendedor e1) { return e1.CuitVendedor == lc.cabecera_lote.cuit_vendedor.ToString(); }); if (v == null) { throw new Microsoft.ApplicationBlocks.ExceptionManagement.Vendedor.Inexistente("CUIT " + lc.cabecera_lote.cuit_vendedor.ToString()); } eFact_RNComprobante.EnviarIBK(out Lr, lc, v.NumeroSerieCertificado.ToString()); EjecutarEventoBandejaS("RegAceptIF", "", lote); } catch (Exception ex2) { //Si el lote tiene errores al ser enviado, grabar el rechazo. string edescr = ""; if (Lr.estado == null && Lr.errores_lote == null && Lr.comprobante_response == null) { //Cuando el error es local, previo a la respuesta de IF se usa el código 99 (Cedeira) para mostrar el error. //Ejemplo: cuando no está instalado el certificado. Lr.estado = "99"; Lr.errores_lote = new eFact_RN.IBK.error[1]; Lr.errores_lote[0] = new eFact_RN.IBK.error(); Lr.errores_lote[0].codigo_error = 99; edescr = ex2.Message.Replace("'", "''"); Lr.errores_lote[0].descripcion_error = edescr; //------ Datos del lote, que genera el error ------ Lr.id_lote = Convert.ToInt64(lote.NumeroLote); Lr.cuit_vendedor = Convert.ToInt64(lote.CuitVendedor); Lr.punto_de_venta = Convert.ToInt32(lote.PuntoVenta); Lr.cantidad_reg = lote.CantidadRegistros; //------------------------------------------------- if (edescr.IndexOf("500 - error") != -1) { Lr.errores_lote[0].codigo_error = 500; } if (edescr.IndexOf("600 - error") != -1) { Lr.errores_lote[0].codigo_error = 600; } } eFact_RN.Lote.ActualizarDatosError(lote, Lr); edescr = ex2.Message.Replace("'", "''"); EjecutarEventoBandejaS("RegRechIF", edescr, lote); //Va a revertir el rechazo (si el error es "Timed Out" hasta 10 ocurrencias. if (Lr.estado == "99" && Lr.errores_lote != null && Lr.errores_lote[0].descripcion_error.ToUpper().Trim() == "THE OPERATION HAS TIMED OUT") { eFact_Entidades.Lote loteAux = new eFact_Entidades.Lote(); loteAux.IdLote = lote.IdLote; eFact_RN.Lote.Leer(loteAux, Aplicacion.Sesion); List<CedEntidades.Log> log = loteAux.WF.Log.FindAll(delegate(CedEntidades.Log e1) { return e1.Comentario.ToUpper().Trim() == "THE OPERATION HAS TIMED OUT"; }); if (log != null && log.Count > 0 && log.Count < 10) { //Actualizar el WF del lote. eFact_RN.Lote.Leer(lote, Aplicacion.Sesion); EjecutarEventoBandejaS("RevertirRechIFA", "", lote); } } throw new Exception(ex2.Message); } } } } catch (Exception ex) { Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.Publish(ex); } finally { RefreshBandejaSalida(); EventosComboBox.Enabled = true; Cursor = System.Windows.Forms.Cursors.Default; } }
private void ActualizarBandejaS() { Cursor = System.Windows.Forms.Cursors.WaitCursor; DateTime FechaDsd; DateTime FechaHst; VerificarServicio(); if (TipoConsulta == eFact_Entidades.Lote.TipoConsulta.FechaAlta) { FechaDsd = FechaDsdLoteFecAltaDTP.Value; FechaHst = FechaHstLoteFecAltaDTP.Value; } else { FechaDsd = FechaDsdLoteFecEnvioDTP.Value; FechaHst = FechaHstLoteFecEnvioDTP.Value; } OtrosFiltrosFiltrarBS(); string otrosFiltrosCuitvendedor = ""; string otrosFiltrosPuntoVenta = ""; string otrosFiltrosNumeroLote = ""; if (OtrosFiltrosBandejaSCheckBox.Checked) { otrosFiltrosCuitvendedor = CuitVendedorTextBox.Text; otrosFiltrosNumeroLote = NumeroLoteTextBox.Text; otrosFiltrosPuntoVenta = PuntoVentaTextBox.Text; } List<CedEntidades.Evento> eventosXLote = new List<CedEntidades.Evento>(); InicializarEventosComboBox(out eventosXLote); ExportarItfComboBox.Items.Clear(); ExportarItfComboBox.Items.Add("( Elegir una opción para Exportar )"); ExportarItfComboBox.SelectedIndex = 0; BandejaSDataGridView.AutoGenerateColumns = false; eFact_RN.Tablero.ActualizarBandejaSalida(out dtBandejaSalida, TipoConsulta, FechaDsd, FechaHst, otrosFiltrosCuitvendedor, otrosFiltrosNumeroLote, otrosFiltrosPuntoVenta, PtesDiasAntCheckBox.Checked, eFact_R.Aplicacion.Sesion); BandejaSDataGridView.DataSource = dtBandejaSalida; if (Aplicacion.Modalidad != "Automatica" || ServicioOK == false) { //Verificar Ptes.Respuesta AFIP. List<eFact_Entidades.Lote> dtBandejaSalidaFind = dtBandejaSalida.FindAll((delegate(eFact_Entidades.Lote e1) { return e1.WF.IdEstado == "PteRespAFIP"; })); foreach (eFact_Entidades.Lote l in dtBandejaSalidaFind) { FeaEntidades.InterFacturas.lote_comprobantes Lc = new FeaEntidades.InterFacturas.lote_comprobantes(); eFact_RN.IBK.error[] respErroresLote = new eFact_RN.IBK.error[0]; eFact_RN.IBK.error[] respErroresComprobantes = new eFact_RN.IBK.error[0]; try { //Consultar si exite el lote en Interfacturas eFact_RN.Lote.ConsultarLoteIF(out Lc, out respErroresLote, out respErroresComprobantes, l, Aplicacion.Vendedores.Find(delegate(eFact_Entidades.Vendedor e1) { return e1.CuitVendedor == l.CuitVendedor; }).NumeroSerieCertificado); //Ejecutar evento ( cambia el estado ) if (Lc.cabecera_lote.resultado == "A") { eFact_RN.Lote.ActualizarDatosCAE(l, Lc); string comentario = ArmarTextoMotivo(Lc); EjecutarEventoBandejaS("RegAceptAFIP", comentario, l); } else if (Lc.cabecera_lote.resultado == "O") { eFact_RN.Lote.ActualizarDatosCAE(l, Lc); string comentario = ArmarTextoMotivo(Lc); EjecutarEventoBandejaS("RegAceptAFIPO", comentario, l); } else if (Lc.cabecera_lote.resultado == "P") { eFact_RN.Lote.ActualizarDatosCAE(l, Lc); string comentario = ArmarTextoMotivo(Lc); EjecutarEventoBandejaS("RegAceptAFIPP", comentario, l); } else if (Lc.cabecera_lote.resultado == "R") { eFact_RN.IBK.lote_response lr = ArmarLoteResponse(Lc); eFact_RN.Lote.ActualizarDatosError(l, lr); string comentario = ArmarTextoMotivo(Lc); EjecutarEventoBandejaS("RegRechAFIP", comentario, l); } else { throw new Microsoft.ApplicationBlocks.ExceptionManagement.Validaciones.Lote.ProblemasConsulta("Estado del lote [" + Lc.cabecera_lote.resultado + "] no definido."); } } catch (Exception ex) { if (respErroresLote.Length != 0) { if (respErroresLote[0].codigo_error != Convert.ToInt32("401")) { EjecutarEventoBandejaS("RegRechAFIP", ex.Message, l); } } else { Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.Publish(ex); } } } eFact_RN.Tablero.ActualizarBandejaSalida(out dtBandejaSalida, TipoConsulta, FechaDsd, FechaHst, otrosFiltrosCuitvendedor, otrosFiltrosNumeroLote, otrosFiltrosPuntoVenta, PtesDiasAntCheckBox.Checked, eFact_R.Aplicacion.Sesion); BandejaSDataGridView.DataSource = new List<eFact_Entidades.Lote>(); BandejaSDataGridView.DataSource = dtBandejaSalida; } BandejaSDataGridView.Refresh(); Cursor = System.Windows.Forms.Cursors.Default; }
private void ConsultarLoteIFButton_Click(object sender, EventArgs e) { try { Cursor = System.Windows.Forms.Cursors.WaitCursor; NumeroLoteTextBox.ReadOnly = true; CuitVendedorTextBox.ReadOnly = true; PuntoVentaTextBox.ReadOnly = true; FeaEntidades.InterFacturas.lote_comprobantes Lc = new FeaEntidades.InterFacturas.lote_comprobantes(); eFact_RN.IBK.error[] respErroresLote = new eFact_RN.IBK.error[0]; eFact_RN.IBK.error[] respErroresComprobantes = new eFact_RN.IBK.error[0]; eFact_Entidades.Vendedor v = Aplicacion.Vendedores.Find(delegate(eFact_Entidades.Vendedor e1) { return e1.CuitVendedor == CuitVendedorTextBox.Text; }); if (v == null) { throw new Microsoft.ApplicationBlocks.ExceptionManagement.Vendedor.Inexistente("CUIT " + CuitVendedorTextBox.Text); } if (modoActual == Modo.Contingencia) { lote = new eFact_Entidades.Lote(); if (NumeroLoteTextBox.Text == "") { throw new Microsoft.ApplicationBlocks.ExceptionManagement.Validaciones.ValorNoInfo("Número de lote"); } if (!(Cedeira.SV.Fun.IsNumeric(NumeroLoteTextBox.Text))) { throw new Microsoft.ApplicationBlocks.ExceptionManagement.Validaciones.ValorInvalido("Número de lote"); } lote.NumeroLote = NumeroLoteTextBox.Text; if (CuitVendedorTextBox.Text == "") { throw new Microsoft.ApplicationBlocks.ExceptionManagement.Validaciones.ValorNoInfo("Cuit vendedor"); } if (!(Cedeira.SV.Fun.IsNumeric(CuitVendedorTextBox.Text))) { throw new Microsoft.ApplicationBlocks.ExceptionManagement.Validaciones.ValorInvalido("Cuit vendedor"); } lote.CuitVendedor = CuitVendedorTextBox.Text; if (PuntoVentaTextBox.Text == "") { throw new Microsoft.ApplicationBlocks.ExceptionManagement.Validaciones.ValorNoInfo("Punto de Venta"); } if (!(Cedeira.SV.Fun.IsNumeric(PuntoVentaTextBox.Text))) { throw new Microsoft.ApplicationBlocks.ExceptionManagement.Validaciones.ValorInvalido("Punto de Venta"); } lote.PuntoVenta = PuntoVentaTextBox.Text; eFact_RN.Lote.ConsultarLoteIF(out Lc, out respErroresLote, out respErroresComprobantes, lote, v.NumeroSerieCertificado.ToString()); //Verificar si existe en la base de datos como AceptadaAFIP eFact_Entidades.Lote loteAceptadoAFIP = new eFact_Entidades.Lote(); List<eFact_Entidades.Lote> lotes = new List<eFact_Entidades.Lote>(); eFact_RN.Lote.Consultar(out lotes, eFact_Entidades.Lote.TipoConsulta.SinAplicarFechas, DateTime.Today, DateTime.Today, CuitVendedorTextBox.Text, NumeroLoteTextBox.Text, PuntoVentaTextBox.Text, false, Aplicacion.Sesion); loteAceptadoAFIP = lotes.Find(delegate(eFact_Entidades.Lote e1) { return e1.IdEstado == "AceptadoAFIP" || e1.IdEstado == "AceptadoAFIPO" || e1.IdEstado == "AceptadoAFIPP"; }); if (loteAceptadoAFIP != null && loteAceptadoAFIP.IdOp != 0) { //Verificar si cambio el XML de respuesta string loteXml = ""; eFact_RN.Lote.SerializarLc(out loteXml, Lc); if (!(loteAceptadoAFIP.LoteXmlIF.Equals(loteXml))) { MessageBox.Show("El XML de respuesta actual, difiere del XML de respuesta obtenido en esta consulta. Si actualiza los datos, quedará registrado este último XML de respuesta.", "ATENCION", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); } lote = loteAceptadoAFIP; lote.LoteXmlIF = loteXml; for (int i = 0; i < lote.Comprobantes.Count; i++) { if (Lc.comprobante[i].cabecera.informacion_comprobante.cae != null) { lote.Comprobantes[i].NumeroCAE = Lc.comprobante[i].cabecera.informacion_comprobante.cae; lote.Comprobantes[i].FechaCAE = eFact_RN.Archivo.ConvertirStringToDateTime(Lc.comprobante[i].cabecera.informacion_comprobante.fecha_obtencion_cae.Trim()); lote.Comprobantes[i].FechaVtoCAE = eFact_RN.Archivo.ConvertirStringToDateTime(Lc.comprobante[i].cabecera.informacion_comprobante.fecha_vencimiento_cae.Trim()); } lote.Comprobantes[i].EstadoIFoAFIP = Lc.comprobante[i].cabecera.informacion_comprobante.resultado; lote.Comprobantes[i].ComentarioIFoAFIP = Lc.comprobante[i].cabecera.informacion_comprobante.motivo; } } else { eFact_RN.Lote.Lc2Lote(out lote, Lc, Aplicacion.Aplic, Aplicacion.Sesion); eventoContingencia = new CedEntidades.Evento(); CedEntidades.Flow flow = new CedEntidades.Flow(); flow.IdFlow = "eFact"; eventoContingencia.Flow = flow; string resultado = ""; string resultadoTexto = ""; if (Lc.cabecera_lote.resultado != null && Lc.cabecera_lote.resultado.ToString().Trim() != "") { resultado = Lc.cabecera_lote.resultado.ToString(); resultadoTexto = "\r\nEl lote consultado se encuentra en estado: " + Lc.cabecera_lote.resultado.ToString(); } switch (resultado) { case "A": eventoContingencia.Id = "RegContAFIP"; break; case "O": eventoContingencia.Id = "RegContAFIPO"; break; case "P": eventoContingencia.Id = "RegContAFIPP"; break; default: throw new Microsoft.ApplicationBlocks.ExceptionManagement.Validaciones.Lote.EstadoNoPermitido("Solo es posible operar en contingencia con lotes Aceptados por AFIP." + resultadoTexto); } Cedeira.SV.WF.LeerEvento(eventoContingencia, Aplicacion.Sesion); lote.WF.EventosPosibles.Clear(); lote.WF.EventosPosibles.Add(eventoContingencia); } lote.WF.EsquemaSegEventosPosibles = Cedeira.SV.WF.EsquemaSegEventosPosibles(lote.WF); eFact_RN.Lote.MuestroEsquemaSegEventosPosibles(EsquemaSegEventosPosiblesTreeView, lote); BindingControles(); DetalleLoteDataGridView.AutoGenerateColumns = false; DetalleLoteDataGridView.DataSource = new List<eFact_Entidades.Comprobante>(); DetalleLoteDataGridView.DataSource = lote.Comprobantes; CancelarButton.Visible = true; ActualizarButton.Visible = true; ConsultarLoteIFButton.Enabled = false; } else { eFact_RN.Lote.ConsultarLoteIF(out Lc, out respErroresLote, out respErroresComprobantes, lote, v.NumeroSerieCertificado.ToString()); MessageBox.Show("Lote de comprobantes número " + lote.NumeroLote + " encontrado satisfactoriamente en Interfacturas.", "Consulta de Lotes", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Consulta de Lotes", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); if (modoActual == Modo.Contingencia) { Cancelar(); } } finally { Cursor = System.Windows.Forms.Cursors.Default; } }
public static void ConsultarLoteIF(out FeaEntidades.InterFacturas.lote_comprobantes Lc, out eFact_RN.IBK.error[] RespErroresLote, out eFact_RN.IBK.error[] RespErroresComprobantes, eFact_Entidades.Lote Lote, string WSCertificado) { eFact_RN.IBK.error[] respErroresLote = new eFact_RN.IBK.error[0]; eFact_RN.IBK.error[] respErroresComprobantes = new eFact_RN.IBK.error[0]; FeaEntidades.InterFacturas.lote_comprobantes lcIBK = new FeaEntidades.InterFacturas.lote_comprobantes(); eFact_RN.IBK.consulta_lote_comprobantes clc = new eFact_RN.IBK.consulta_lote_comprobantes(); try { eFact_RN.Comprobante eFact_RNComprobante = new eFact_RN.Comprobante(); if (Lote.LoteXml != null || Lote.LoteXmlIF != null) { FeaEntidades.InterFacturas.lote_comprobantes lc = new FeaEntidades.InterFacturas.lote_comprobantes(); if (Lote.LoteXmlIF != null && (Lote.LoteXmlIF != "" && (Lote.IdEstado != null && (Lote.IdEstado == "AceptadoAFIP" || Lote.IdEstado == "AceptadoAFIPO" || Lote.IdEstado == "AceptadoAFIPP")))) { eFact_RN.Lote.DeserializarLc(out lc, Lote, true); } else { eFact_RN.Lote.DeserializarLc(out lc, Lote, false); } clc.cod_interno_canal = lc.cabecera_lote.cod_interno_canal; clc.cuit_canal = lc.cabecera_lote.cuit_canal; clc.cuit_vendedor = lc.cabecera_lote.cuit_vendedor; clc.punto_de_venta = lc.cabecera_lote.punto_de_venta; clc.punto_de_ventaSpecified = true; clc.id_lote = lc.cabecera_lote.id_lote; } else { clc.cuit_canal = Convert.ToInt64(@System.Configuration.ConfigurationManager.AppSettings["CuitCanal"]); clc.id_lote = Convert.ToInt64(Lote.NumeroLote); clc.cuit_vendedor = Convert.ToInt64(Lote.CuitVendedor); clc.punto_de_venta = Convert.ToInt32(Lote.PuntoVenta); clc.punto_de_ventaSpecified = true; } lcIBK = eFact_RNComprobante.ConsultarIBK(out respErroresLote, out respErroresComprobantes, clc, WSCertificado); RespErroresLote = respErroresLote; RespErroresComprobantes = respErroresComprobantes; } catch (Exception ex) { RespErroresLote = respErroresLote; RespErroresComprobantes = respErroresComprobantes; throw new Exception(ex.Message); } Lc = lcIBK; }
private void ActualizarEstadoAFIPLotes() { List<eFact_Entidades.Lote> lotes = new List<eFact_Entidades.Lote>(); //eFact_RN.Tablero.ActualizarBandejaSalida(out lotes, eFact_Entidades.Lote.TipoConsulta.SinAplicarFechas, Convert.ToDateTime("01/01/1980"), Convert.ToDateTime("31/12/2064"), "", "", "", false, Aplicacion.Sesion); //Consultar Ptes.Respuesta AFIP. eFact_RN.Lote.ConsultarXEstado(out lotes, "'PteRespAFIP'", Aplicacion.Sesion); //List<eFact_Entidades.Lote> lotesFind = lotes.FindAll((delegate(eFact_Entidades.Lote e1) { return e1.WF.IdEstado == "PteRespAFIP"; })); foreach (eFact_Entidades.Lote l in lotes) { FeaEntidades.InterFacturas.lote_comprobantes Lc = new FeaEntidades.InterFacturas.lote_comprobantes(); eFact_RN.IBK.error[] respErroresLote = new eFact_RN.IBK.error[0]; eFact_RN.IBK.error[] respErroresComprobantes = new eFact_RN.IBK.error[0]; try { //Consultar si exite el lote en Interfacturas eFact_RN.Lote.ConsultarLoteIF(out Lc, out respErroresLote, out respErroresComprobantes, l, Aplicacion.Vendedores.Find(delegate(eFact_Entidades.Vendedor e1) { return e1.CuitVendedor == l.CuitVendedor; }).NumeroSerieCertificado); //Ejecutar evento ( cambia el estado ) if (Lc.cabecera_lote.resultado == "A") { eFact_RN.Lote.ActualizarDatosCAE(l, Lc); string comentario = ArmarTextoMotivo(Lc); EjecutarEventoBandejaS("RegAceptAFIP", comentario, l); } else if (Lc.cabecera_lote.resultado == "O") { eFact_RN.Lote.ActualizarDatosCAE(l, Lc); string comentario = ArmarTextoMotivo(Lc); EjecutarEventoBandejaS("RegAceptAFIPO", comentario, l); } else if (Lc.cabecera_lote.resultado == "P") { eFact_RN.Lote.ActualizarDatosCAE(l, Lc); string comentario = ArmarTextoMotivo(Lc); EjecutarEventoBandejaS("RegAceptAFIPP", comentario, l); } else if (Lc.cabecera_lote.resultado == "R") { eFact_RN.IBK.lote_response lr = ArmarLoteResponse(Lc); eFact_RN.Lote.ActualizarDatosError(l, lr); string comentario = ArmarTextoMotivo(Lc); EjecutarEventoBandejaS("RegRechAFIP", comentario, l); } } catch (Exception ex) { if (respErroresLote.Length != 0) { if (respErroresLote[0].codigo_error != Convert.ToInt32("401")) { EjecutarEventoBandejaS("RegRechAFIP", ex.Message, l); } } else { Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.Publish(ex); } } } }
public FeaEntidades.InterFacturas.lote_comprobantes ConsultarIBK(out IBK.error[] RespErroresLote, out IBK.error[] RespErroresComprobantes, IBK.consulta_lote_comprobantes clc, string certificado) { FeaEntidades.InterFacturas.lote_comprobantes lc = new FeaEntidades.InterFacturas.lote_comprobantes(); lc.cabecera_lote = new FeaEntidades.InterFacturas.cabecera_lote(); lc.comprobante = new FeaEntidades.InterFacturas.comprobante[1]; IBK.error[] respErroresLote = new eFact_RN.IBK.error[0]; IBK.error[] respErroresComprobantes = new eFact_RN.IBK.error[0]; IBK.FacturaWebServiceConSchema objIBK; objIBK = new IBK.FacturaWebServiceConSchema(); objIBK.Url = System.Configuration.ConfigurationManager.AppSettings["URLinterfacturas"]; if (System.Configuration.ConfigurationManager.AppSettings["Proxy"] != "") { System.Net.WebProxy wp = new System.Net.WebProxy(System.Configuration.ConfigurationManager.AppSettings["Proxy"], false); string usuarioProxy = System.Configuration.ConfigurationManager.AppSettings["UsuarioProxy"]; string claveProxy = System.Configuration.ConfigurationManager.AppSettings["ClaveProxy"]; string dominioProxy = System.Configuration.ConfigurationManager.AppSettings["DominioProxy"]; System.Net.NetworkCredential networkCredential = new System.Net.NetworkCredential(usuarioProxy, claveProxy, dominioProxy); wp.Credentials = networkCredential; objIBK.Proxy = wp; } string storeLocation = System.Configuration.ConfigurationManager.AppSettings["StoreLocation"]; X509Store store; if (storeLocation == "CurrentUser") { store = new X509Store(StoreLocation.CurrentUser); } else { store = new X509Store(StoreLocation.LocalMachine); } store.Open(OpenFlags.ReadOnly); X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySerialNumber, certificado, true); if (col.Count.Equals(1)) { objIBK.ClientCertificates.Add(col[0]); System.Threading.Thread.Sleep(1000); IBK.consulta_lote_comprobantes_response clcr = objIBK.getLoteFacturasConSchema(clc); IBK.consulta_lote_response clr; try { clr = (IBK.consulta_lote_response)clcr.Item; IBK.lote_comprobantes lcIBK = (IBK.lote_comprobantes)clr.Item; lc = Ibk2Fea(lcIBK); } catch (InvalidCastException) { StringBuilder errorText = new StringBuilder(); if (clcr.Item != null) { errorText.Append("Nro. de Lote: [" + clc.id_lote + "] \r\n"); if (clcr.Item.GetType() == typeof(IBK.consulta_lote_response)) { clr = (IBK.consulta_lote_response)clcr.Item; IBK.consulta_lote_responseErrores_consulta errores = (IBK.consulta_lote_responseErrores_consulta)clr.Item; foreach (IBK.error elote in errores.error) { errorText.Append(elote.codigo_error + " - " + elote.descripcion_error + " \r\n"); } RespErroresLote = errores.error; } else { IBK.consulta_lote_comprobantes_responseErrores_response clcrEr; clcrEr = (IBK.consulta_lote_comprobantes_responseErrores_response)clcr.Item; foreach (IBK.error elote in clcrEr.error) { errorText.Append(elote.codigo_error + " - " + elote.descripcion_error + " \r\n"); } RespErroresComprobantes = clcrEr.error; } } throw new Exception(errorText.ToString()); } RespErroresLote = respErroresLote; RespErroresComprobantes = respErroresComprobantes; return lc; } else { throw new Exception("Su certificado no está disponible en nuestro repositorio"); } }