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; } }
public void EnviarIBK(out eFact_RN.IBK.lote_response Lr, FeaEntidades.InterFacturas.lote_comprobantes lc, string certificado) { IBK.lote_comprobantes lcIBK = new IBK.lote_comprobantes(); lcIBK = Fea2Ibk(lc); IBK.FacturaWebServiceConSchema objIBK; objIBK = new IBK.FacturaWebServiceConSchema(); objIBK.Url = System.Configuration.ConfigurationManager.AppSettings["URLinterfacturas"]; objIBK.Timeout = 3900000; if (System.Configuration.ConfigurationManager.AppSettings["Proxy"] != null && 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.RequestEncoding = System.Text.Encoding.GetEncoding("iso-8859-1"); objIBK.ClientCertificates.Add(col[0]); System.Threading.Thread.Sleep(1000); IBK.lote_comprobantes_response lcr = objIBK.receiveFacturasConSchema(lcIBK); IBK.lote_response lr = new eFact_RN.IBK.lote_response(); try { lr = ((IBK.lote_response)lcr.Item); if (lr.estado == "OK") { Lr = lr; } else { Lr = lr; StringBuilder errorText = new StringBuilder(); if (Lr.errores_lote != null) { errorText.Append("Nro. de Lote: [" + Lr.id_lote + "] \r\n"); foreach (eFact_RN.IBK.error elote in Lr.errores_lote) { errorText.Append(elote.codigo_error + " - " + elote.descripcion_error + " \r\n"); } } if (Lr.comprobante_response != null) { foreach (eFact_RN.IBK.comprobante_response comprobante in Lr.comprobante_response) { if (comprobante.errores_comprobante != null) { if (Lr.errores_lote != null) { errorText.Append("\r\n"); } errorText.Append("Punto de Venta: [" + comprobante.punto_de_venta + "] Tipo de Comprobante: [" + comprobante.tipo_de_comprobante + "] Nro. de Comprobante: [" + comprobante.numero_comprobante + "] \r\n"); foreach (eFact_RN.IBK.error ecomprobante in comprobante.errores_comprobante) { errorText.Append(ecomprobante.codigo_error + " - " + ecomprobante.descripcion_error + " \r\n"); } } } } throw new Microsoft.ApplicationBlocks.ExceptionManagement.Validaciones.Lote.ProblemasEnvio(errorText.ToString()); } } catch (InvalidCastException) { StringBuilder errorText = new StringBuilder(); if (lcr.Item != null) { if (lcr.Item.GetType() == typeof(IBK.lote_comprobantes_responseErrores_response)) { IBK.lote_comprobantes_responseErrores_response lcrEr = new eFact_RN.IBK.lote_comprobantes_responseErrores_response(); errorText.Append("Nro. de Lote: [" + lc.cabecera_lote.id_lote + "] \r\n"); lcrEr = (IBK.lote_comprobantes_responseErrores_response)lcr.Item; foreach (IBK.error error in lcrEr.error) { errorText.Append(error.codigo_error + " - " + error.descripcion_error + " \r\n"); } } } throw new Exception(errorText.ToString()); } } else { throw new Exception("Su certificado no está disponible en nuestro repositorio"); } }