public FeaEntidades.InterFacturas.lote_response EnviarIBK(out List<FeaEntidades.InterFacturas.error> RespErroresLote, out List<FeaEntidades.InterFacturas.error> RespErroresComprobantes, FeaEntidades.InterFacturas.lote_comprobantes lc, string url, eFact_Tester.Entidades.Certificado Certificado, eFact_Tester.Entidades.Proxy Proxy) { FeaEntidades.InterFacturas.lote_response Lr = new FeaEntidades.InterFacturas.lote_response(); IBK.lote_comprobantes lcIBK = new IBK.lote_comprobantes(); lcIBK = Fea2Ibk(lc); IBK.error[] respErroresLote = new IBK.error[0]; IBK.error[] respErroresComprobantes = new IBK.error[0]; IBK.FacturaWebServiceConSchema objIBK; objIBK = new IBK.FacturaWebServiceConSchema(); objIBK.Url = url; if (Proxy != null) { System.Net.WebProxy wp = new System.Net.WebProxy(Proxy.Servidor, false); System.Net.NetworkCredential networkCredential = new System.Net.NetworkCredential(Proxy.Usuario, Proxy.Clave, Proxy.Dominio); wp.Credentials = networkCredential; objIBK.Proxy = wp; } X509Store store; if (Certificado.LugarDeAlmacenamiento == eFact_Tester.Entidades.Certificado.Almacenamiento.CurrentUser) { store = new X509Store(StoreLocation.CurrentUser); } else { store = new X509Store(StoreLocation.LocalMachine); } store.Open(OpenFlags.ReadOnly); X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySerialNumber, Certificado.Numero, true); if (col.Count.Equals(1)) { objIBK.ClientCertificates.Add(col[0]); IBK.lote_comprobantes_response lcr = objIBK.receiveFacturasConSchema(lcIBK); IBK.lote_response lr = new IBK.lote_response(); RespErroresLote = new List<FeaEntidades.InterFacturas.error>(); RespErroresComprobantes = new List<FeaEntidades.InterFacturas.error>(); try { lr = ((IBK.lote_response)lcr.Item); if (lr.estado == "OK") { Lr = Ibk2Fea(lr); } else { Lr = Ibk2Fea(lr); StringBuilder errorText = new StringBuilder(); if (lr.errores_lote != null) { errorText.Append("Nro. de Lote: [" + Lr.id_lote + "] \r\n"); foreach (IBK.error elote in lr.errores_lote) { errorText.Append(elote.codigo_error + " - " + elote.descripcion_error + " \r\n"); } RespErroresLote.AddRange(Ibk2Fea(lr.errores_lote)); } if (lr.comprobante_response != null) { foreach (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 (IBK.error ecomprobante in comprobante.errores_comprobante) { errorText.Append(ecomprobante.codigo_error + " - " + ecomprobante.descripcion_error + " \r\n"); } RespErroresComprobantes.AddRange(Ibk2Fea(comprobante.errores_comprobante)); } } } throw new Exception(errorText.ToString()); } return Lr; } 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 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"); } RespErroresLote = Ibk2Fea(lcrEr.error); } } throw new Exception(errorText.ToString()); } } else { throw new Exception("Su certificado no está disponible en nuestro repositorio"); } }
private FeaEntidades.InterFacturas.lote_response Ibk2Fea(IBK.lote_response lrIBK) { FeaEntidades.InterFacturas.lote_response lr = new FeaEntidades.InterFacturas.lote_response(); lr.cuit_canal = lrIBK.cuit_canal; lr.cuit_vendedor = lrIBK.cuit_vendedor; lr.punto_de_venta = lrIBK.punto_de_venta; lr.id_lote = lrIBK.id_lote; return lr; }
public static void DeserializarLr(out FeaEntidades.InterFacturas.lote_response Lr, string Cadena) { //Deserializar ( pasar de string XML a eFact_RN.IBK.lote_response ) System.Text.Encoding codificador; codificador = System.Text.Encoding.GetEncoding("iso-8859-1"); byte[] a = new byte[Cadena.Length]; a = codificador.GetBytes(Cadena); MemoryStream ms = new MemoryStream(a); ms.Seek(0, System.IO.SeekOrigin.Begin); FeaEntidades.InterFacturas.lote_response lr = new FeaEntidades.InterFacturas.lote_response(); System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(lr.GetType()); lr = (FeaEntidades.InterFacturas.lote_response)x.Deserialize(ms); ms.Close(); ms = null; Lr = lr; }
public static void GuardarItfTXTlr(out string NombreProcesado, eFact_Entidades.Lote Lote, string PreFijo, string Ruta, bool IF) { //Deserializar ( pasar de XML a FeaEntidades.InterFacturas.lote_comprobantes ) List<FeaEntidades.InterFacturas.lote_response> lLr = new List<FeaEntidades.InterFacturas.lote_response>(); FeaEntidades.InterFacturas.lote_response Lr = new FeaEntidades.InterFacturas.lote_response(); eFact_RN.Lote.DeserializarLr(out Lr, Lote.LoteXmlIF); lLr.Add(Lr); //Evento de escritura de txt FileHelperEngine e = new FileHelperEngine(typeof(FeaEntidades.InterFacturas.lote_response)); string nombreProcesado = ""; GenerarNombreArch(out nombreProcesado, Ruta, PreFijo, Lote, "txt"); NombreProcesado = nombreProcesado; e.WriteFile(NombreProcesado, lLr); foreach (FeaEntidades.InterFacturas.error elote in Lr.errores_lote) { if (elote != null) { List<FeaEntidades.InterFacturas.error> ierrores_lote = new List<FeaEntidades.InterFacturas.error>(); ierrores_lote.Add(elote); e = new FileHelperEngine(typeof(FeaEntidades.InterFacturas.error)); e.AppendToFile(NombreProcesado, ierrores_lote); } } if (Lr.comprobante_response != null) { foreach (FeaEntidades.InterFacturas.comprobante_response comprobante in Lr.comprobante_response) { List<FeaEntidades.InterFacturas.comprobante_response> icr = new List<FeaEntidades.InterFacturas.comprobante_response>(); icr.Add(comprobante); e = new FileHelperEngine(typeof(FeaEntidades.InterFacturas.comprobante_response)); e.AppendToFile(NombreProcesado, icr); if (comprobante.errores_comprobante != null) { foreach (FeaEntidades.InterFacturas.error ecomprobante in comprobante.errores_comprobante) { if (ecomprobante != null) { List<FeaEntidades.InterFacturas.error> ierrores_comprobante = new List<FeaEntidades.InterFacturas.error>(); ierrores_comprobante.Add(ecomprobante); e = new FileHelperEngine(typeof(FeaEntidades.InterFacturas.error)); e.AppendToFile(NombreProcesado, ierrores_comprobante); } } } } } }
private void ActualizarDB2(List<eFact_Entidades.Lote> lotes) { foreach (eFact_Entidades.Lote lote in lotes) { string fecha = DateTime.Now.ToString("yyyyMMdd"); string hora = DateTime.Now.ToString("HHmmss"); OleDbCommand myCommand; OleDbConnection cn; string myInsertQueryOK; string myInsertQueryER; eFact_Entidades.Novedades novedad = new eFact_Entidades.Novedades(); novedad.CuitVendedor = lote.CuitVendedor; novedad.IdLote = lote.IdLote; novedad.NumeroEnvio = lote.NumeroEnvio; novedad.PuntoVenta = lote.PuntoVenta; novedad.IdLog = lote.WF.Log[lote.WF.Log.Count - 1].IdLog; novedad.IdOp = lote.IdOp; novedad.NumeroLote = lote.NumeroLote; novedad.IdEstado = lote.IdEstado; novedad.Comentario = lote.WF.Log[lote.WF.Log.Count - 1].Comentario; novedad.FechaAlta = DateTime.Now; novedad.CantidadRegistros = lote.Comprobantes.Count; eFact_RN.Lote.GuardarNovedades(novedad, Aplicacion.Sesion); string errorSoloXMail = ""; if (lote.WF.IdEstado == "AceptadoAFIP" || lote.WF.IdEstado == "AceptadoAFIPO" || lote.WF.IdEstado == "AceptadoAFIPP") { cn = new OleDbConnection(Aplicacion.Sesion.CnnStrAplicExterna); cn.Open(); //Aceptados por AFIP foreach (eFact_Entidades.Comprobante c in lote.Comprobantes) { //Grabar CAEs if (c.EstadoIFoAFIP == "A") { // Tabla: "BECCL" - Comprobante OK myInsertQueryOK = "insert into BECCL (BCCID, BCCCOM, BCCIDL, BCCTCO, BCCCLA, "; myInsertQueryOK += "BCCTCA, BCCSUC, BCCNED, BCCCAE, BCCFVC, BCCFOC, BCCFPR, BCCHPR) "; myInsertQueryOK += "values ('BC', 0, " + lote.NumeroLote + ", '', '', "; myInsertQueryOK += "'" + c.IdTipoComprobante + "', '" + lote.PuntoVenta + "', '" + c.NumeroComprobante + "', '" + c.NumeroCAE + "', '" + c.FechaVtoCAE.ToString("yyyyMMdd") + "', '" + c.FechaCAE.ToString("yyyyMMdd") + "', '" + fecha + "', '" + hora + "') "; myCommand = new OleDbCommand(myInsertQueryOK); myCommand.Connection = cn; myCommand.ExecuteNonQuery(); // -------------------------------- } else { // Tabla: "BECCL" - Comprobante ER myInsertQueryER = "insert into BEEIL (BEIID, BEICOM, BEIIDL, BEITCO, BEICLA, BEITCA, BEISUC, BEINED, BEICOE, "; //Descripcion del 1 a 30 / del 31 a 60 / 61 a 90 / 91 a 120 / 121 a 150 myInsertQueryER += "BEIDE1, BEIDE2, BEIDE3, BEIDE4, BEIDE5, "; myInsertQueryER += "BEIFPR, BEIHPR) "; myInsertQueryER += "values ('BI', '0', '" + lote.NumeroLote + "', '', '', "; string codigoError = "99"; if (c.EstadoIFoAFIP != null && c.EstadoIFoAFIP != "") { codigoError = c.EstadoIFoAFIP; } myInsertQueryER += "'" + c.IdTipoComprobante + "', '" + lote.PuntoVenta + "', '" + c.NumeroComprobante + "', '" + codigoError + "'"; myInsertQueryER += Comentarios(c.ComentarioIFoAFIP); myInsertQueryER += ", '" + fecha + "', '" + hora + "') "; myCommand = new OleDbCommand(myInsertQueryER); myCommand.Connection = cn; myCommand.ExecuteNonQuery(); // -------------------------------- } } // Tabla: "BELLL" - Log //LOG indicando OK myInsertQueryER = "insert into BELLL (BLLID, BLLIDL, BLLCOD, BLLFPR, BLLHPR) "; myInsertQueryER += "values ('BL', '" + lote.NumeroLote + "', 'OK', '" + fecha + "', '" + hora + "') "; myCommand = new OleDbCommand(myInsertQueryER); myCommand.Connection = cn; myCommand.ExecuteNonQuery(); //LOG indicando ERROR if (lote.WF.IdEstado == "AceptadoAFIPP") { myInsertQueryER = "insert into BELLL (BLLID, BLLIDL, BLLCOD, BLLFPR, BLLHPR) "; myInsertQueryER += "values ('BL', '" + lote.NumeroLote + "', 'ER', '" + fecha + "', '" + hora + "') "; myCommand = new OleDbCommand(myInsertQueryER); myCommand.Connection = cn; myCommand.ExecuteNonQuery(); } // -------------------------------- cn.Close(); } else { cn = new OleDbConnection(Aplicacion.Sesion.CnnStrAplicExterna); cn.Open(); // Rechazados por IF o AFIP if (lote.WF.Log[lote.WF.Log.Count - 1].Comentario.Contains("Punto de Venta: [") && lote.WF.Log[lote.WF.Log.Count - 1].Comentario.Contains(" Comprobante: [")) { // Grabar errores a nivel de comprobante foreach (eFact_Entidades.Comprobante c in lote.Comprobantes) { if (c.ComentarioIFoAFIP != null && c.ComentarioIFoAFIP != "" && c.ComentarioIFoAFIP.Substring(0, 2) == "<?") { try { // Deserializar ( pasar de string XML a FeaEntidades.InterFacturas.lote_comprobantes ) System.Text.Encoding codificador; codificador = System.Text.Encoding.GetEncoding("iso-8859-1"); byte[] a = new byte[c.ComentarioIFoAFIP.Length]; a = codificador.GetBytes(c.ComentarioIFoAFIP); MemoryStream ms = new MemoryStream(a); ms.Seek(0, System.IO.SeekOrigin.Begin); FeaEntidades.InterFacturas.comprobante_response cr = new FeaEntidades.InterFacturas.comprobante_response(); System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(cr.GetType()); cr = (FeaEntidades.InterFacturas.comprobante_response)x.Deserialize(ms); foreach (FeaEntidades.InterFacturas.error ce in cr.errores_comprobante) { // Tabla: "BECCL" - Comprobante ER myInsertQueryER = "insert into BEEIL (BEIID, BEICOM, BEIIDL, BEITCO, BEICLA, BEITCA, BEISUC, BEINED, BEICOE, "; //Descripcion del 1 a 30 / del 31 a 60 / 61 a 90 / 91 a 120 / 121 a 150 myInsertQueryER += "BEIDE1, BEIDE2, BEIDE3, BEIDE4, BEIDE5, "; myInsertQueryER += "BEIFPR, BEIHPR) "; myInsertQueryER += "values ('BI', '0', '" + lote.NumeroLote + "', '', '', "; myInsertQueryER += "'" + c.IdTipoComprobante + "', '" + lote.PuntoVenta + "', '" + c.NumeroComprobante + "', '" + ce.codigo_error + "'"; myInsertQueryER += Comentarios(ce.descripcion_error); myInsertQueryER += ", '" + fecha + "', '" + hora + "') "; myCommand = new OleDbCommand(myInsertQueryER); myCommand.Connection = cn; myCommand.ExecuteNonQuery(); // -------------------------------- } } catch { // Tabla: "BECCL" - Comprobante ER myInsertQueryER = "insert into BEEIL (BEIID, BEICOM, BEIIDL, BEITCO, BEICLA, BEITCA, BEISUC, BEINED, BEICOE, "; //Descripcion del 1 a 30 / del 31 a 60 / 61 a 90 / 91 a 120 / 121 a 150 myInsertQueryER += "BEIDE1, BEIDE2, BEIDE3, BEIDE4, BEIDE5, "; myInsertQueryER += "BEIFPR, BEIHPR) "; myInsertQueryER += "values ('BI', '0', '" + lote.NumeroLote + "', '', '', "; myInsertQueryER += "'" + c.IdTipoComprobante + "', '" + lote.PuntoVenta + "', '" + c.NumeroComprobante + "', '99'"; myInsertQueryER += Comentarios(c.ComentarioIFoAFIP); myInsertQueryER += ", '" + fecha + "', '" + hora + "') "; myCommand = new OleDbCommand(myInsertQueryER); myCommand.Connection = cn; myCommand.ExecuteNonQuery(); // -------------------------------- } } else { // Tabla: "BECCL" - Comprobante ER myInsertQueryER = "insert into BEEIL (BEIID, BEICOM, BEIIDL, BEITCO, BEICLA, BEITCA, BEISUC, BEINED, BEICOE, "; //Descripcion del 1 a 30 / del 31 a 60 / 61 a 90 / 91 a 120 / 121 a 150 myInsertQueryER += "BEIDE1, BEIDE2, BEIDE3, BEIDE4, BEIDE5, "; myInsertQueryER += "BEIFPR, BEIHPR) "; myInsertQueryER += "values ('BI', '0', '" + lote.NumeroLote + "', '', '', "; myInsertQueryER += "'" + c.IdTipoComprobante + "', '" + lote.PuntoVenta + "', '" + c.NumeroComprobante + "', '99'"; myInsertQueryER += Comentarios(c.ComentarioIFoAFIP); myInsertQueryER += ", '" + fecha + "', '" + hora + "') "; myCommand = new OleDbCommand(myInsertQueryER); myCommand.Connection = cn; myCommand.ExecuteNonQuery(); // -------------------------------- } } } else { // Grabar errores a nivel de lote cn = new OleDbConnection(Aplicacion.Sesion.CnnStrAplicExterna); cn.Open(); try { // Deserializar ( pasar de string XML a FeaEntidades.InterFacturas.lote_comprobantes ) System.Text.Encoding codificador; codificador = System.Text.Encoding.GetEncoding("iso-8859-1"); byte[] a = new byte[lote.LoteXmlIF.Length]; a = codificador.GetBytes(lote.LoteXmlIF); MemoryStream ms = new MemoryStream(a); ms.Seek(0, System.IO.SeekOrigin.Begin); FeaEntidades.InterFacturas.lote_response lr = new FeaEntidades.InterFacturas.lote_response(); System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(lr.GetType()); lr = (FeaEntidades.InterFacturas.lote_response)x.Deserialize(ms); foreach (FeaEntidades.InterFacturas.error le in lr.errores_lote) { //if (le.codigo_error == 500 || le.codigo_error == 600) //{ // errorSoloXMail = lote.LoteXmlIF; // break; //} // Tabla: "BECCL" - Comprobante ER myInsertQueryER = "insert into BEEIL (BEIID, BEICOM, BEIIDL, BEITCO, BEICLA, BEITCA, BEISUC, BEINED, BEICOE, "; // Descripcion del 1 a 30 / del 31 a 60 / 61 a 90 / 91 a 120 / 121 a 150 myInsertQueryER += "BEIDE1, BEIDE2, BEIDE3, BEIDE4, BEIDE5, "; myInsertQueryER += "BEIFPR, BEIHPR) "; myInsertQueryER += "values ('BI', '0', '" + lote.NumeroLote + "', '', '', "; myInsertQueryER += "'0', '" + lote.PuntoVenta + "', '0', '" + le.codigo_error + "'"; myInsertQueryER += Comentarios(le.descripcion_error); myInsertQueryER += ", '" + fecha + "', '" + hora + "') "; myCommand = new OleDbCommand(myInsertQueryER); myCommand.Connection = cn; myCommand.ExecuteNonQuery(); } } catch { // Tabla: "BECCL" - Comprobante ER myInsertQueryER = "insert into BEEIL (BEIID, BEICOM, BEIIDL, BEITCO, BEICLA, BEITCA, BEISUC, BEINED, BEICOE, "; // Descripcion del 1 a 30 / del 31 a 60 / 61 a 90 / 91 a 120 / 121 a 150 myInsertQueryER += "BEIDE1, BEIDE2, BEIDE3, BEIDE4, BEIDE5, "; myInsertQueryER += "BEIFPR, BEIHPR) "; myInsertQueryER += "values ('BI', '0', '" + lote.NumeroLote + "', '', '', "; myInsertQueryER += "'0', '" + lote.PuntoVenta + "', '0', '99'"; myInsertQueryER += Comentarios(lote.WF.Log[lote.WF.Log.Count - 1].Comentario); myInsertQueryER += ", '" + fecha + "', '" + hora + "') "; myCommand = new OleDbCommand(myInsertQueryER); myCommand.Connection = cn; myCommand.ExecuteNonQuery(); } // -------------------------------- } if (errorSoloXMail != "") { Exception exSoloXMail = new Exception(errorSoloXMail); Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.Publish(exSoloXMail); } else { // Tabla: "BELLL" - Log myInsertQueryER = "insert into BELLL (BLLID, BLLIDL, BLLCOD, BLLFPR, BLLHPR) "; myInsertQueryER += "values ('BL', '" + lote.NumeroLote + "', 'ER', '" + fecha + "', '" + hora + "') "; myCommand = new OleDbCommand(myInsertQueryER); myCommand.Connection = cn; myCommand.ExecuteNonQuery(); // -------------------------------- cn.Close(); } } } }