示例#1
0
        public static empresa ValidarUsuarioSinSaldo(string rfc)
        {
            NtLinkEmpresa em      = new NtLinkEmpresa();
            empresa       empresa = em.GetByRfc(rfc);
            empresa       result;

            if (empresa == null)
            {
                TimbradoUtils.Logger.Info(rfc + " No encontrado");
                result = null;
            }
            else
            {
                if (empresa.Bloqueado)
                {
                    TimbradoUtils.Logger.Info(empresa.RFC + "-> Bloqueado");
                    throw new FaultException("El RFC del emisor se encuentra bloqueado, favor de ponerse en contacto con atención al cliente");
                }
                if (empresa.Baja)
                {
                    TimbradoUtils.Logger.Info(empresa.RFC + "-> Baja");
                    throw new FaultException("El RFC del emisor se encuentra dado de baja, favor de ponerse en contacto con atención a clientes");
                }
                NtLinkSistema nls     = new NtLinkSistema();
                Sistemas      sistema = nls.GetSistema((int)empresa.idSistema.Value);
                if (sistema.Bloqueado)
                {
                    TimbradoUtils.Logger.Info(sistema.Rfc + "-> Bloqueado");
                    throw new FaultException("El RFC del emisor se encuentra dado de baja, favor de ponerse en contacto con atención a clientes");
                }
                result = empresa;
            }
            return(result);
        }
示例#2
0
        public string ConsultaCFDIRelacionadosRequest(string RfcPacEnviaSolicitud, string RfcReceptor, string RfcEmisor, string Uuid)
        {
            AccesoServicios ser           = new AccesoServicios();
            IList           uuidsCancelar = new List <string>();

            uuidsCancelar.Add(Uuid.ToUpper());
            string result;

            using (new NtLinkLocalServiceEntities())
            { string        path = "";
              NtLinkEmpresa nle  = new NtLinkEmpresa();
              if (!string.IsNullOrEmpty(RfcEmisor))
              {
                  empresa empresa = nle.GetByRfc(RfcEmisor);
                  SAT.CFDI.Cliente.Procesamiento.Encabezado encLMetadata2 = new SAT.CFDI.Cliente.Procesamiento.Encabezado(RfcEmisor, this.FechaHoy(), uuidsCancelar);
                  path = Path.Combine(ConfigurationManager.AppSettings["Resources"], RfcEmisor);
                  string pathCer = Path.Combine(path, "Certs", "csd.cer");
                  string pathKey = Path.Combine(path, "Certs", "csd.key");
                  string pass    = empresa.PassKey;
                  SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType asignature = ser.Asignature(pathKey, encLMetadata2, pass, pathCer);
                  result = ser.ConsultaCFDIRelacionadosRequest(RfcPacEnviaSolicitud, RfcReceptor, RfcEmisor, Uuid, asignature);
              }
              else
              {
                  empresa empresa = nle.GetByRfc(RfcReceptor);
                  SAT.CFDI.Cliente.Procesamiento.Encabezado encLMetadata2 = new SAT.CFDI.Cliente.Procesamiento.Encabezado(RfcReceptor, this.FechaHoy(), uuidsCancelar);
                  path = Path.Combine(ConfigurationManager.AppSettings["Resources"], RfcReceptor);
                  string pathCer = Path.Combine(path, "Certs", "csd.cer");
                  string pathKey = Path.Combine(path, "Certs", "csd.key");
                  string pass    = empresa.PassKey;
                  SAT.CFDI.Cliente.Procesamiento.ServicioRelacionados.SignatureType asignature = ser.Asignature(pathKey, encLMetadata2, pass, pathCer);
                  result = ser.ConsultaCFDIRelacionadosRequest(RfcPacEnviaSolicitud, RfcReceptor, RfcEmisor, Uuid, asignature);
              } }
            return(result);
        }
示例#3
0
        /// <summary>
        /// Cancela un cfdi
        /// </summary>
        /// <param name="uuid">uuid del comprobante a cancelar</param>
        /// <param name="rfc">RFC del emisor</param>
        /// <returns>Acuse de cancelación del SAT</returns>
        public string CancelaCfdi(string uuid, string rfcEmisor, string expresion, string rfcReceptor)
        {
            Cancelador cancelador         = new Cancelador();
            string     respuesta          = null;
            string     acuse              = null;
            Cancelador canceladorConsulta = new Cancelador();
            string     consulta           = canceladorConsulta.ConsultaCFDI(expresion, uuid, rfcReceptor);
            string     result;

            if (consulta != "OK")
            {
                result = "Error al cancelar el comprobante: " + consulta;
            }
            else
            {
                NtLinkEmpresa nle = new NtLinkEmpresa(); //
                int           resultado;

                //int numero = 0;
                //if (!int.TryParse(rfcEmisor, out numero))
                //{
                empresa empresa = nle.GetByRfc(rfcEmisor);    //
                resultado = cancelador.Cancelar(uuid, rfcEmisor, ref respuesta, ref acuse);

                //}
                //else
                //{
                //    var emp = nle.GetById(numero);
                //    resultado = cancelador.CancelarPorID(uuid, emp.IdEmpresa, ref respuesta, ref acuse);//para repetidos rfc

                //}



                // int resultado = cancelador.Cancelar(uuid, rfcEmisor, ref respuesta, ref acuse);
                // int resultado = cancelador.Cancelar(uuid, empresa.IdEmpresa, ref respuesta, ref acuse);

                CertificadorService.Logger.Info(respuesta);
                CertificadorService.Logger.Info(acuse);
                CertificadorService.Logger.Info(resultado);
                if (resultado == 201 || resultado == 202)
                {
                    result = acuse;
                }
                else
                {
                    result = respuesta;
                }
            }
            return(result);
        }
示例#4
0
        public static empresa ValidarAplicacion(string hash, string rfc)
        {
            empresa result;

            if (hash == null)
            {
                result = null;
            }
            else if (hash != ConfigurationManager.AppSettings["HashFacturacion"])
            {
                result = null;
            }
            else
            {
                NtLinkEmpresa em      = new NtLinkEmpresa();
                empresa       empresa = em.GetByRfc(rfc);
                if (empresa == null)
                {
                    TimbradoUtils.Logger.Info(rfc + " No encontrado");
                    result = null;
                }
                else
                {
                    if (empresa.Bloqueado)
                    {
                        TimbradoUtils.Logger.Info(empresa.RFC + "-> Bloqueado");
                        throw new FaultException("El RFC del emisor se encuentra bloqueado, favor de ponerse en contacto con atención al cliente");
                    }
                    if (empresa.Baja)
                    {
                        TimbradoUtils.Logger.Info(empresa.RFC + "-> Baja");
                        throw new FaultException("El RFC del emisor se encuentra dado de baja, favor de ponerse en contacto con atención a clientes");
                    }
                    NtLinkSistema nls     = new NtLinkSistema();
                    Sistemas      sistema = nls.GetSistema((int)empresa.idSistema.Value);
                    if (sistema.Bloqueado)
                    {
                        TimbradoUtils.Logger.Info(sistema.Rfc + "-> Bloqueado");
                        throw new FaultException("El RFC del emisor se encuentra bloqueado, favor de ponerse en contacto con atención a clientes");
                    }
                    if ((sistema.TipoSistema != 3 || sistema.TipoSistema != 0) && sistema.SaldoTimbrado <= 0)
                    {
                        TimbradoUtils.Logger.Info("Saldo: " + sistema.SaldoTimbrado);
                        throw new FaultException("No cuentas con saldo suficiente para timbrar documentos, contacta a tu ejecutivo de ventas");
                    }
                    result = empresa;
                }
            }
            return(result);
        }
示例#5
0
        public int CancelarOtrosPACs(string uuid, string rfc, ref string respuesta, ref string acuse, string Base64Cer, string Base64Key, string PasswordKey)
        {
            int result;

            try
            {
                Cancelador.Logger.Info("Cancelando comprobante: " + uuid);
                IList uuidsCancelar = new List <string>();
                uuidsCancelar.Add(uuid.ToUpper());
                using (new NtLinkLocalServiceEntities())
                {
                    NtLinkEmpresa nle = new NtLinkEmpresa();


                    string pass = PasswordKey;
                    SAT.CFDI.Cliente.Procesamiento.Encabezado encLMetadata2          = new SAT.CFDI.Cliente.Procesamiento.Encabezado(rfc, this.FechaHoy(), uuidsCancelar);
                    SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.Acuse ac2 = null;
                    acuse = this.EnviarCancelacionSATOtrosPACs(encLMetadata2, Base64Key, pass, Base64Cer, ref ac2);
                    if (string.IsNullOrEmpty(acuse))
                    {
                        acuse = "No se pudo conectar al servicio de cancelación del SAT";
                    }
                    int intEstatus2 = this.TraerEstatusSAT(uuid, ac2);
                    if (intEstatus2 != 201 && intEstatus2 != 202)
                    {
                        Cancelador.Logger.Error(acuse);
                        respuesta = intEstatus2 + " - " + Constantes.ErroresValidacion[intEstatus2];
                        throw new FaultException(respuesta);
                    }
                    Cancelador.Logger.Info(acuse);
                    string directorio = Path.Combine(ConfigurationManager.AppSettings["RutaTimbrado"], ac2.RfcEmisor, ac2.Fecha.ToString("yyyyMMdd"));
                    if (!Directory.Exists(directorio))
                    {
                        Directory.CreateDirectory(directorio);
                    }
                    string fileName = Path.Combine(directorio, "Cancelacion_" + uuid.ToString() + ".xml");
                    File.WriteAllText(fileName, acuse, Encoding.UTF8);
                    respuesta = intEstatus2 + " - " + Constantes.ErroresValidacion[intEstatus2];
                    result    = intEstatus2;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                Cancelador.Logger.Error("(cancelar) Error: " + ex.Message + ((ex.InnerException == null) ? "" : ("\nExcepción Interna:" + ex.InnerException.Message)));
                throw;
            }
        }
示例#6
0
        public void RegistraEmpresa(EmpresaNtLink nuevaEmpresa, byte[] llave, byte[] certificado, string userName, string password)
        {
            Logger.Debug(userName);
            var x = NtLinkLogin.ValidateUser(userName, password);

            if (x == null)
            {
                throw new FaultException("Nombre de usuario o contraseña incorrecta");
            }
            NtLinkEmpresa nle = new NtLinkEmpresa();

            try
            {
                empresa emp = new empresa
                {
                    RazonSocial = nuevaEmpresa.RazonSocial,
                    RFC         = nuevaEmpresa.Rfc,
                    CURP        = nuevaEmpresa.Curp,
                    Ciudad      = nuevaEmpresa.Ciudad,
                    Colonia     = nuevaEmpresa.Colonia,
                    CP          = nuevaEmpresa.Cp,
                    Contacto    = nuevaEmpresa.Contacto,
                    Direccion   = nuevaEmpresa.Direccion,
                    Email       = nuevaEmpresa.Email,
                    Estado      = nuevaEmpresa.Estado,
                    Linea       = "A",

                    RegimenFiscal = nuevaEmpresa.RegimenFiscal,
                    Telefono      = nuevaEmpresa.Telefono
                };
                nle.Save(emp, certificado, llave, null, null);
            }
            catch (FaultException ee)
            {
                Logger.Warn(ee);
                throw;
            }
            catch (Exception ee)
            {
                Logger.Error(ee);
                if (ee.InnerException != null)
                {
                    Logger.Error(ee.InnerException);
                }
                throw new FaultException("Error al registrar la empresa");
            }
        }
示例#7
0
 public List <EmpresaNtLink> ObtenerEmpresas(string userName, string password)
 {
     try
     {
         Logger.Debug(userName);
         var x = NtLinkLogin.ValidateUser(userName, password);
         if (x == null)
         {
             throw new FaultException("Nombre de usuario o contraseña incorrecta");
         }
         var           empresa = NtLinkUsuarios.GetEmpresaByUserId(x.ProviderUserKey.ToString());
         NtLinkSistema sis     = new NtLinkSistema();
         var           sistema = sis.GetSistema((int)empresa.idSistema.Value);
         var           nle     = new NtLinkEmpresa();
         var           lista   = nle.GetList("Administrador", empresa.IdEmpresa, sistema.IdSistema);
         if (lista != null)
         {
             return(lista.Select(p => new EmpresaNtLink()
             {
                 Ciudad = p.Ciudad,
                 Colonia = p.Colonia,
                 Estado = p.Estado,
                 Contacto = p.Contacto,
                 Cp = p.CP,
                 RazonSocial = p.RazonSocial,
                 Direccion = p.Direccion,
                 Email = p.Email,
                 RegimenFiscal = p.RegimenFiscal,
                 Rfc = p.RFC,
                 Telefono = p.Telefono,
                 //PassKey = p.PassKey
             }).ToList());
         }
         return(null);
     }
     catch (Exception ee)
     {
         Logger.Error(ee);
         if (ee.InnerException != null)
         {
             Logger.Error(ee.InnerException);
         }
         return(null);
     }
 }
示例#8
0
        public string ProcesarRespuestaAceptacionRechazo(string RfcReceptor, string RfcPacEnviaSolicitud, List <Folios> F)
        {
            AccesoServicios ser           = new AccesoServicios();
            IList           uuidsCancelar = new List <string>();

            foreach (Folios f in F)
            {
                uuidsCancelar.Add(f.UUDI.ToUpper());
            }
            List <SolicitudAceptacionRechazoFolios> Folio = new List <SolicitudAceptacionRechazoFolios>();

            foreach (Folios f in F)
            {
                SolicitudAceptacionRechazoFolios x = new SolicitudAceptacionRechazoFolios();
                x.UUID = f.UUDI;
                if (f.Respuesta.ToString() == "Aceptacion")
                {
                    x.Respuesta = TipoAccionPeticionCancelacion.Aceptacion;
                }
                else
                {
                    x.Respuesta = TipoAccionPeticionCancelacion.Rechazo;
                }
                Folio.Add(x);
            }
            string result;

            using (new NtLinkLocalServiceEntities())
            {
                NtLinkEmpresa nle     = new NtLinkEmpresa();
                empresa       empresa = nle.GetByRfc(RfcReceptor);
                string        fecha   = this.FechaHoy();
                SAT.CFDI.Cliente.Procesamiento.Encabezado encLMetadata2 = new SAT.CFDI.Cliente.Procesamiento.Encabezado(RfcReceptor, fecha, uuidsCancelar);
                string path    = Path.Combine(ConfigurationManager.AppSettings["Resources"], RfcReceptor);
                string pathCer = Path.Combine(path, "Certs", "csd.cer");
                string pathKey = Path.Combine(path, "Certs", "csd.key");
                string pass    = empresa.PassKey;
                SAT.CFDI.Cliente.Procesamiento.ServicioAceptacionRechazo.SignatureType asignature = ser.AsignatureProceso(pathKey, encLMetadata2, pass, pathCer);
                result = ser.ProcesarRespuestaAceptacionRechazo(RfcReceptor, fecha, RfcPacEnviaSolicitud, Folio, asignature);
            }
            return(result);
        }
示例#9
0
        public int CancelarRet(string uuid, string rfc, ref string respuesta, ref string acuse)
        {
            int result;

            try
            {
                Cancelador.Logger.Info("Cancelando comprobante: " + uuid);
                CanceladorRetenciones can = new CanceladorRetenciones();
                IList uuidsCancelar       = new List <string>();
                uuidsCancelar.Add(uuid.ToUpper());
                using (new NtLinkLocalServiceEntities())
                {
                    NtLinkEmpresa nle     = new NtLinkEmpresa();
                    empresa       empresa = nle.GetByRfc(rfc);
                    if (empresa == null)
                    {
                        respuesta = "300 - El usuario con el que se quiere conectar es inválido";
                        acuse     = "";
                        result    = 300;
                    }
                    else
                    {
                        NtLinkTimbrado tim    = new NtLinkTimbrado();
                        TimbreWs33     timbre = tim.ObtenerTimbre(uuid);
                        if (timbre == null)
                        {
                            TimbreWsHistorico timbreHist = tim.ObtenerTimbreHist(uuid);
                            if (timbreHist == null)
                            {
                                string path    = Path.Combine(ConfigurationManager.AppSettings["Resources"], rfc);
                                string pathCer = Path.Combine(path, "Certs", "csd.cer");
                                string pathKey = Path.Combine(path, "Certs", "csd.key");
                                string pass    = empresa.PassKey;
                                if (File.Exists(pathKey + ".pem"))
                                {
                                    pathKey += ".pem";
                                }
                                string ext = Path.GetExtension(pathKey);
                                RSACryptoServiceProvider key2 = OpensslKey.DecodePrivateKey(File.ReadAllBytes(pathKey), pass, ext);
                                string ac2 = can.CancelaCfdi(uuid, key2, rfc, pathCer);
                                if (string.IsNullOrEmpty(ac2))
                                {
                                    acuse     = "No se pudo conectar al servicio de cancelación del SAT";
                                    respuesta = "1205 - No se pudo conectar al servicio de cancelación del SAT";
                                    result    = 1205;
                                    return(result);
                                }
                                acuse = ac2;
                                AcuseCancelacion acuseCan2 = AcuseCancelacion.Parse(ac2);
                                if (acuseCan2.Status == null)
                                {
                                    Cancelador.Logger.Error(acuse);
                                    respuesta = "1300 - XML mal formado";
                                    result    = 1300;
                                    return(result);
                                }
                                if (acuseCan2.Status != "1201" && acuseCan2.Status != "1202")
                                {
                                    Cancelador.Logger.Error(acuse);
                                    respuesta = acuseCan2.Status;
                                    throw new FaultException(respuesta);
                                }
                                Cancelador.Logger.Info(acuse);
                                string directorio = Path.Combine(ConfigurationManager.AppSettings["RutaTimbrado"], rfc, acuseCan2.FechaCancelacion);
                                if (!Directory.Exists(directorio))
                                {
                                    Directory.CreateDirectory(directorio);
                                }
                                string fileName = Path.Combine(directorio, "Cancelacion_" + uuid.ToString() + ".xml");
                                File.WriteAllText(fileName, acuse, Encoding.UTF8);
                                respuesta = acuseCan2.Status + " - " + Constantes.ErroresValidacion[int.Parse(acuseCan2.Status)];
                                result    = Convert.ToInt32(acuseCan2.Status);
                                return(result);
                            }
                            else
                            {
                                timbre                  = new TimbreWs33();
                                timbre.RfcEmisor        = timbreHist.RfcEmisor;
                                timbre.RfcReceptor      = timbreHist.RfcReceptor;
                                timbre.AcuseCancelacion = timbreHist.AcuseCancelacion;
                                timbre.IdTimbre         = timbreHist.IdTimbre;
                                timbre.Uuid             = timbreHist.Uuid;
                                timbre.StrError         = "Hist";
                            }
                        }
                        if (timbre.RfcEmisor != rfc)
                        {
                            respuesta = "203 - UUID No corresponde el RFC del emisor y de quien solicita la cancelación.";
                            acuse     = "";
                            result    = 203;
                        }
                        else if (timbre.AcuseCancelacion != null)
                        {
                            respuesta = "202 - UUID Previamente cancelado";
                            acuse     = timbre.AcuseCancelacion;
                            result    = 202;
                        }
                        else
                        {
                            string path    = Path.Combine(ConfigurationManager.AppSettings["Resources"], rfc);
                            string pathCer = Path.Combine(path, "Certs", "csd.cer");
                            string pathKey = Path.Combine(path, "Certs", "csd.key");
                            string pass    = empresa.PassKey;
                            if (File.Exists(pathKey + ".pem"))
                            {
                                pathKey += ".pem";
                            }
                            string ext = Path.GetExtension(pathKey);
                            RSACryptoServiceProvider key3 = OpensslKey.DecodePrivateKey(File.ReadAllBytes(pathKey), pass, ext);
                            string ac3 = can.CancelaCfdi(uuid, key3, rfc, pathCer);
                            if (string.IsNullOrEmpty(ac3))
                            {
                                acuse     = "No se pudo conectar al servicio de cancelación del SAT";
                                respuesta = "1205 - No se pudo conectar al servicio de cancelación del SAT";
                                result    = 1205;
                            }
                            else
                            {
                                acuse = ac3;
                                AcuseCancelacion acuseCan3 = AcuseCancelacion.Parse(ac3);
                                if (acuseCan3.Status == null)
                                {
                                    Cancelador.Logger.Error(acuse);
                                    respuesta = "1300 - XML mal formado";
                                    result    = 1300;
                                }
                                else
                                {
                                    if (acuseCan3.Status != "1201" && acuseCan3.Status != "1202")
                                    {
                                        Cancelador.Logger.Error(acuse);
                                        respuesta = acuseCan3.Status;
                                        throw new FaultException(respuesta);
                                    }
                                    Cancelador.Logger.Info(acuse);
                                    timbre.Status = new int?(2);
                                    string directorio = Path.Combine(ConfigurationManager.AppSettings["RutaTimbrado"], timbre.RfcEmisor, timbre.FechaFactura.ToString("yyyyMMdd"));
                                    if (!Directory.Exists(directorio))
                                    {
                                        Directory.CreateDirectory(directorio);
                                    }
                                    string fileName = Path.Combine(directorio, "Cancelacion_" + timbre.Uuid.ToString() + ".xml");
                                    File.WriteAllText(fileName, acuse, Encoding.UTF8);
                                    tim.GuardarTimbre(timbre);
                                    respuesta = acuseCan3.Status + " - " + Constantes.ErroresValidacion[int.Parse(acuseCan3.Status)];
                                    result    = Convert.ToInt32(acuseCan3.Status);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Cancelador.Logger.Error("(cancelar) Error: " + ex.Message + ((ex.InnerException == null) ? "" : ("\nExcepción Interna:" + ex.InnerException.Message)));
                throw;
            }
            return(result);
        }
示例#10
0
        public int Cancelar(string uuid, string rfc, ref string respuesta, ref string acuse)
        //  public int Cancelar(string uuid, int idempresa, ref string respuesta, ref string acuse)
        {
            int result;

            try
            {
                Cancelador.Logger.Info("Cancelando comprobante: " + uuid);
                IList uuidsCancelar = new List <string>();
                uuidsCancelar.Add(uuid.ToUpper());
                using (new NtLinkLocalServiceEntities())
                {
                    NtLinkEmpresa nle     = new NtLinkEmpresa();
                    empresa       empresa = nle.GetByRfc(rfc);
                    // empresa empresa = nle.GetById(idempresa);
                    if (empresa == null)
                    {
                        respuesta = "300 - El usuario con el que se quiere conectar es inválido";
                        acuse     = "";
                        result    = 300;
                    }
                    else
                    {
                        NtLinkTimbrado tim    = new NtLinkTimbrado();
                        TimbreWs33     timbre = tim.ObtenerTimbre(uuid);
                        if (timbre == null)
                        {
                            TimbreWsHistorico timbreHist = tim.ObtenerTimbreHist(uuid);
                            if (timbreHist == null)
                            {
                                string path    = Path.Combine(ConfigurationManager.AppSettings["Resources"], empresa.RFC);
                                string pathCer = Path.Combine(path, "Certs", "csd.cer");
                                string pathKey = Path.Combine(path, "Certs", "csd.key");
                                string pass    = empresa.PassKey;
                                SAT.CFDI.Cliente.Procesamiento.Encabezado encLMetadata2          = new SAT.CFDI.Cliente.Procesamiento.Encabezado(empresa.RFC, this.FechaHoy(), uuidsCancelar);
                                SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.Acuse ac2 = null;
                                acuse = this.EnviarCancelacionSAT(encLMetadata2, pathKey, pass, pathCer, ref ac2);
                                if (string.IsNullOrEmpty(acuse))
                                {
                                    acuse = "No se pudo conectar al servicio de cancelación del SAT";
                                }
                                int intEstatus2 = this.TraerEstatusSAT(uuid, ac2);
                                if (intEstatus2 != 201 && intEstatus2 != 202)
                                {
                                    Cancelador.Logger.Error(acuse);
                                    respuesta = intEstatus2 + " - " + Constantes.ErroresValidacion[intEstatus2];
                                    throw new FaultException(respuesta);
                                }
                                Cancelador.Logger.Info(acuse);
                                string directorio = Path.Combine(ConfigurationManager.AppSettings["RutaTimbrado"], ac2.RfcEmisor, ac2.Fecha.ToString("yyyyMMdd"));
                                if (!Directory.Exists(directorio))
                                {
                                    Directory.CreateDirectory(directorio);
                                }
                                string fileName = Path.Combine(directorio, "Cancelacion_" + uuid.ToString() + ".xml");
                                File.WriteAllText(fileName, acuse, Encoding.UTF8);
                                respuesta = intEstatus2 + " - " + Constantes.ErroresValidacion[intEstatus2];
                                result    = intEstatus2;
                                return(result);
                            }
                            else
                            {
                                timbre                  = new TimbreWs33();
                                timbre.RfcEmisor        = timbreHist.RfcEmisor;
                                timbre.RfcReceptor      = timbreHist.RfcReceptor;
                                timbre.AcuseCancelacion = timbreHist.AcuseCancelacion;
                                timbre.IdTimbre         = timbreHist.IdTimbre;
                                timbre.Uuid             = timbreHist.Uuid;
                                timbre.StrError         = "Hist";
                            }
                        }
                        if (timbre.RfcEmisor != empresa.RFC)
                        {
                            respuesta = "203 - UUID No corresponde el RFC del emisor y de quien solicita la cancelación.";
                            acuse     = "";
                            result    = 203;
                        }
                        else if (timbre.AcuseCancelacion != null)
                        {
                            respuesta = "202 - UUID Previamente cancelado";
                            acuse     = timbre.AcuseCancelacion;
                            result    = 202;
                        }
                        else
                        {
                            string path    = Path.Combine(ConfigurationManager.AppSettings["Resources"], empresa.RFC);
                            string pathCer = Path.Combine(path, "Certs", "csd.cer");
                            string pathKey = Path.Combine(path, "Certs", "csd.key");
                            string pass    = empresa.PassKey;
                            SAT.CFDI.Cliente.Procesamiento.Encabezado encLMetadata3          = new SAT.CFDI.Cliente.Procesamiento.Encabezado(empresa.RFC, this.FechaHoy(), uuidsCancelar);
                            SAT.CFDI.Cliente.Procesamiento.ServicioCancelacionCFDI.Acuse ac3 = null;
                            acuse = this.EnviarCancelacionSAT(encLMetadata3, pathKey, pass, pathCer, ref ac3);
                            if (string.IsNullOrEmpty(acuse))
                            {
                                acuse = "No se pudo conectar al servicio de cancelación del SAT";
                            }
                            int intEstatus3 = this.TraerEstatusSAT(uuid, ac3);
                            if (intEstatus3 != 201 && intEstatus3 != 202)
                            {
                                Cancelador.Logger.Error(acuse);
                                respuesta = intEstatus3 + " - " + Constantes.ErroresValidacion[intEstatus3];
                                throw new FaultException(respuesta);
                            }
                            Cancelador.Logger.Info(acuse);
                            timbre.Status = new int?(2);
                            string directorio = Path.Combine(ConfigurationManager.AppSettings["RutaTimbrado"], timbre.RfcEmisor, timbre.FechaFactura.ToString("yyyyMMdd"));
                            if (!Directory.Exists(directorio))
                            {
                                Directory.CreateDirectory(directorio);
                            }
                            string fileName = Path.Combine(directorio, "Cancelacion_" + timbre.Uuid.ToString() + ".xml");
                            File.WriteAllText(fileName, acuse, Encoding.UTF8);
                            tim.GuardarTimbre(timbre);
                            respuesta = intEstatus3 + " - " + Constantes.ErroresValidacion[intEstatus3];
                            result    = intEstatus3;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Cancelador.Logger.Error("(cancelar) Error: " + ex.Message + ((ex.InnerException == null) ? "" : ("\nExcepción Interna:" + ex.InnerException.Message)));
                throw;
            }
            return(result);
        }
示例#11
0
        public static bool EmpresaMultipleRFC(string RFC)
        {
            NtLinkEmpresa em = new NtLinkEmpresa();

            return(em.GetByRfcMultiple(RFC));
        }