diff --git a/App_Code/Modelos.vb b/App_Code/Modelos.vb index e9bdcbea7..7a03c7d0b 100644 --- a/App_Code/Modelos.vb +++ b/App_Code/Modelos.vb @@ -4820,24 +4820,55 @@ Namespace Modelos Return Retorno End If + If Vigencia.Estado.ToUpper().Contains("CANCELADO") Then ContinuarCancelacion = False ObtenerAcuse = True - Dim solicitud = New WSGF.Service1SoapClient() - Dim acuse = solicitud.GetAcuse(UsuarioActual.Empresa.RFC, "rene.molina@adsistemas.mx", "rene2018", FolioFiscal) + RequiereAceptacion = False - If acuse.Estado = 0 Then - Dim xmlAcuse = New System.Xml.XmlDocument() - xmlAcuse.LoadXml(DecodeBase64(acuse.CfdiB64)) - CancelacionAcuse = xmlAcuse.GetElementsByTagName("SignatureValue")(0).InnerText - CancelacionFecha = xmlAcuse.SelectSingleNode("Acuse").Attributes("Fecha").Value.ToDate() - CveEstatus = 5 - Else + 'VERIFICA EN EL SERVICIO SI SE CANCELO + Try + Dim solicitud = New WSGF.Service1SoapClient() + Dim acuse = solicitud.GetAcuse(UsuarioActual.Empresa.RFC, "rene.molina@adsistemas.mx", "rene2018", FolioFiscal) + + If acuse.Estado = 0 Then + Dim xmlAcuse = New System.Xml.XmlDocument() + xmlAcuse.LoadXml(DecodeBase64(acuse.CfdiB64)) + CancelacionAcuse = xmlAcuse.GetElementsByTagName("SignatureValue")(0).InnerText + CancelacionFecha = xmlAcuse.SelectSingleNode("Acuse").Attributes("Fecha").Value.ToDate() + CveEstatus = 5 + Else + CancelacionFecha = Now.Date + CancelacionAcuse = "" + CveEstatus = 5 + End If + Catch ex As Exception + GuardaLog(ex.ToString()) CancelacionFecha = Now.Date CancelacionAcuse = "" - CveEstatus = 5 + End Try + + 'SI NO SE PUDO OBTENER DEL SERVICIO, UTILIZA EL METODO DE CANCELACION PARA OBTENER EL ACUSE + If CancelacionAcuse = "" Then + If ObjCancelacion.CFDICancelar(UsuarioActual.Empresa, FolioFiscal, TotalT, RFCReceptor, UsuarioActual.Empresa.RFC, CvePACCancelacion, CveSATMotivoCancelacion:=CveSATMotivoCancelacion, FolioSustitucion:=FolioSustitucion) Then + 'GENERAMOS EL ACUSE Y MANDAMOS MAIL DE CON EL ACUSE DE CANCELACIÓN + If RequiereAceptacion Then + CancelacionFecha = Now.Date + CveEstatus = 20 + Else + CancelacionFecha = ObjCancelacion.CancelacionFecha + CveEstatus = 5 + End If + CancelacionAcuse = ObjCancelacion.CancelacionAcuse + Else + Retorno.Mensaje = "Los servicios de cancelación del SAT no se encuentran disponibles o presentan time out. Intente de nuevo en unos minutos.
Origen del error: WebService www.sat.gob.mx" + Retorno.TipoMensaje = TipoMensaje.MsgError + + Return Retorno + End If End If + ElseIf Vigencia.Estado.ToUpper().Contains("VIGENTE") Then If Vigencia.EstatusCancelacion.ToUpper() = "EN PROCESO" Then @@ -9304,21 +9335,28 @@ Namespace Modelos End Set End Property - - - Property GlobalDTContaConceptosContables(CvePlantillaPoliza As Integer) As DataTable + Property GlobalDTContaConceptosContables(CveConceptoContable As Integer) As DataTable Get - If CvePlantillaPoliza <> -1 Then - Dim Dv As New DataView(DirectCast(HttpContext.Current.Application("GlobalDTContaConceptosContables"), DataTable), String.Format("CvePlantillaPoliza = {0}", CvePlantillaPoliza), "", DataViewRowState.CurrentRows) + Dim AppNombre As String = String.Format("GlobalDTContaConceptosContables") + 'sino existe, recarga los datos + If HttpContext.Current.Application(AppNombre) Is Nothing Then + Using ObjContabilidad As New ClsContabilidad + If ObjContabilidad.GetConta_ConceptosContables() Then HttpContext.Current.Application(AppNombre) = ObjContabilidad.DtResultados Else HttpContext.Current.Application(AppNombre) = Nothing + End Using + + End If + If CveConceptoContable <> -1 Then + Dim Dv As New DataView(DirectCast(HttpContext.Current.Application(AppNombre), DataTable), String.Format("CveConceptoContable = {0}", CveConceptoContable), "", DataViewRowState.CurrentRows) GlobalDTContaConceptosContables = Dv.ToTable Dv.Dispose() Else - GlobalDTContaConceptosContables = DirectCast(HttpContext.Current.Application("GlobalDTContaConceptosContables"), DataTable) + GlobalDTContaConceptosContables = DirectCast(HttpContext.Current.Application(AppNombre), DataTable) End If End Get Set(value As DataTable) - HttpContext.Current.Application("GlobalDTContaConceptosContables") = value + Dim AppNombre As String = String.Format("GlobalDTContaConceptosContables") + HttpContext.Current.Application(AppNombre) = value End Set End Property #End Region diff --git a/App_Code/Timbrado.vb b/App_Code/Timbrado.vb index 141331bbf..191c38d6e 100644 --- a/App_Code/Timbrado.vb +++ b/App_Code/Timbrado.vb @@ -133,6 +133,10 @@ Public Class Timbrado Dim Retorno As Boolean = False Dim MsgCancelacion As New StringBuilder + If CvePACCancelacion = 3 Then + ValidaFactura = False + End If + If Not (Empresa.Funcionalidad(529) = "1") Then If ValidaFactura Then Dim Vigencia = VerificarVigenciaSAT(FolioFiscal, RFCEmisor, RFCReceptor, Total.ToString(), True) @@ -448,28 +452,42 @@ Public Class Timbrado Dim resp As Profact.TimbraCFDI.ResultadoConsulta resp = conector.ObtieneCFDI(RFCEmisor, FolioFiscal) MsgCancelacion.AppendFormat("-3.3") - If resultadoCancelacion.Exitoso Then + + 'VERIFICA SI SE CANCELO O FUE CANCELADO PREVIAMENTE + If resultadoCancelacion.Exitoso OrElse resultadoCancelacion.NumeroError = "202" Then MsgCancelacion.AppendFormat("-3.4") CancelacionMensaje = resultadoCancelacion.Descripcion Dim xmlDoc As New System.Xml.XmlDocument() + MsgCancelacion.AppendFormat("-3.4.1") Try xmlDoc.LoadXml(Encoding.UTF8.GetString(Convert.FromBase64String(resp.Xml))) Catch ex As Exception - xmlDoc.LoadXml(resp.Xml) + If resp.NumeroError.ToEntero() > 0 Then + CancelacionMensaje = resp.Descripcion + Else + Try + xmlDoc.LoadXml(resp.Xml) + Catch ex2 As Exception + Me.OnError("Ocurrió un error al leer el xml", ex) + End Try + End If End Try - MsgCancelacion.AppendFormat("-3.4.1") + If xmlDoc.HasChildNodes Then + Dim xpath As String = "Acuse/Folios" + Dim nodes = xmlDoc.SelectNodes(xpath) + CancelacionState = xmlDoc.GetElementsByTagName("EstatusUUID")(0).InnerText.ToEntero + MsgCancelacion.AppendFormat("-3.4.2") + xpath = "Acuse/Signature" + nodes = xmlDoc.SelectNodes(xpath) + MsgCancelacion.AppendFormat("-3.4.3") + CancelacionAcuse = xmlDoc.GetElementsByTagName("SignatureValue")(0).InnerText + CancelacionFecha = xmlDoc.SelectSingleNode("Acuse").Attributes("Fecha").Value.ToDate + Else + CancelacionFecha = Now + End If - Dim xpath As String = "Acuse/Folios" - Dim nodes = xmlDoc.SelectNodes(xpath) - CancelacionState = xmlDoc.GetElementsByTagName("EstatusUUID")(0).InnerText.ToEntero - MsgCancelacion.AppendFormat("-3.4.2") - xpath = "Acuse/Signature" - nodes = xmlDoc.SelectNodes(xpath) - MsgCancelacion.AppendFormat("-3.4.3") - CancelacionAcuse = xmlDoc.GetElementsByTagName("SignatureValue")(0).InnerText - CancelacionFecha = xmlDoc.SelectSingleNode("Acuse").Attributes("Fecha").Value.ToDate Retorno = True Else MsgCancelacion.AppendFormat("-3.5")