diff --git a/App_Code/ClsVentas.vb b/App_Code/ClsVentas.vb index ae57244f9..21be0f560 100644 --- a/App_Code/ClsVentas.vb +++ b/App_Code/ClsVentas.vb @@ -838,7 +838,7 @@ Public Class ClsVentas Return Retorno End Function - Public Function UpdateEstatusVenta(CveVenta As Integer, CveEstatusFactura As Integer, CveEmpresa As Integer, Optional Num2 As Integer = -1) As Boolean + Public Function UpdateEstatusVenta(CveVenta As Integer, CveEstatusFactura As Integer, CveEmpresa As Integer, Optional Num2 As Integer = -1, Optional CveEstatusRefacturacion As Integer = -1, Optional CveMotivoCancelacion As Integer = -1) As Boolean Dim Retorno As Boolean = False DataAdapter("PA_Vta_VentasEstatusUpdate") @@ -848,6 +848,8 @@ Public Class ClsVentas .Add("@CveEstatusFactura", SqlDbType.Int).Value = CveEstatusFactura .Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa .Add("@Num2", SqlDbType.Float).Value = Num2 + .Add("@CveEstatusRefacturacion", SqlDbType.Int).Value = CveEstatusRefacturacion + .Add("@CveMotivoCancelacion", SqlDbType.Int).Value = CveMotivoCancelacion End With Try diff --git a/App_Code/Modelos.vb b/App_Code/Modelos.vb index b49be482e..e6fbe82fd 100644 --- a/App_Code/Modelos.vb +++ b/App_Code/Modelos.vb @@ -4845,7 +4845,8 @@ Namespace Modelos End If 'SI YA ESTA TIMBRADA, NUEVO PROCESO REFACTURACION, ASIGNA LA CANCELACION PENDIENTE - If EsRefacturacion AndAlso Me.CveEstatusFactura = 3 AndAlso CveMotivoCancelacion > 0 Then + 'EL ESTATUS REFACTURACION 4 ES PARA LAS QUE NO SE PUDIERON CANCELAR, DEBE OBLIGAR A CANCELAR ANTE EL SAT + If EsRefacturacion AndAlso Me.CveEstatusFactura = 3 AndAlso CveMotivoCancelacion > 0 AndAlso CveEstatusRefacturacion <> 4 Then CveEstatusFacturaAsignado = 23 End If diff --git a/Compras/PopUpVerFactura.aspx.vb b/Compras/PopUpVerFactura.aspx.vb index 70fed873b..e18d8db03 100644 --- a/Compras/PopUpVerFactura.aspx.vb +++ b/Compras/PopUpVerFactura.aspx.vb @@ -1011,14 +1011,17 @@ Partial Class PopUpVerFactura Dim Usuario As String = $" Usuario: {Nombre}" If DtCortesVentas.Rows.Count > 0 Or DtCortesVentasResumen.Rows.Count > 0 Then Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) - Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + + + 'params.Add(New ReportParameter("LogoPath", If(Imagen.Exists, ImageToBase64(Drawing.Image.FromFile(Imagen.FullName), Drawing.Imaging.ImageFormat.Png), ""))) + Dim LogoRuta As String = String.Format("file://{0}", Imagen.FullName) Dim params As New List(Of ReportParameter) params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa)) params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre)) params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToShortDateString)) params.Add(New ReportParameter("AgrupoPor", $"{FechaCorte}{Usuario}")) If Imagen.Exists Then - params.Add(New ReportParameter("LogoPath", logouri)) + params.Add(New ReportParameter("LogoPath", LogoRuta)) Else params.Add(New ReportParameter("LogoPath", "")) End If @@ -1124,7 +1127,7 @@ Partial Class PopUpVerFactura Private Sub ImprimeGastoContrato(CveContrato As Integer, CveContratoGasto As Integer) Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) - Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + 'Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) Dim Dr As DataRow = Nothing Dim ObjContratos As New ClsContratos @@ -1158,7 +1161,9 @@ Partial Class PopUpVerFactura End If params.Add(New ReportParameter("Utilidad", $"$ {(SumaUtilidad - SumaGasto).ToString.FormatoNumero()}")) If Imagen.Exists Then - params.Add(New ReportParameter("LogoPath", logouri)) + + Dim LogoRuta As String = String.Format("file://{0}", Imagen.FullName) + params.Add(New ReportParameter("LogoPath", LogoRuta)) Else params.Add(New ReportParameter("LogoPath", "")) End If @@ -1306,14 +1311,9 @@ Partial Class PopUpVerFactura If Dt.Rows.Count > 0 Then Dim params As New List(Of ReportParameter) Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) - Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) - - 'params.Add(New ReportParameter("LogoPath", If(Imagen.Exists, ImageToBase64(Drawing.Image.FromFile(Imagen.FullName), Drawing.Imaging.ImageFormat.Png), ""))) Dim LogoRuta As String = String.Format("file://{0}", Imagen.FullName) - - If Imagen.Exists Then params.Add(New ReportParameter("LogoPath", LogoRuta)) Else @@ -1733,7 +1733,7 @@ Partial Class PopUpVerFactura If DtConceptos.Rows.Count > 0 Then Dim params As New List(Of ReportParameter) Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) - Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + 'Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) If Imagen.Exists Then Dim LogoRuta As String = String.Format("file://{0}", Imagen.FullName) @@ -3250,8 +3250,15 @@ Partial Class PopUpVerFactura params.Add(New ReportParameter("NombreEntrego", Personal)) params.Add(New ReportParameter("Responsable", Personal)) params.Add(New ReportParameter("NombreRecibio", Capturo.ToUpper)) - Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) - params.Add(New ReportParameter("LogoPath", logouri)) + 'Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) + If Imagen.Exists Then + Dim LogoRuta As String = String.Format("file://{0}", Imagen.FullName) + params.Add(New ReportParameter("LogoPath", LogoRuta)) + Else + params.Add(New ReportParameter("LogoPath", "")) + End If + If DtMovimientos.COUNT("Serie") > 0 Then params.Add(New ReportParameter("MostrarSerieLote", "1")) Else @@ -3336,8 +3343,14 @@ Partial Class PopUpVerFactura params.Add(New ReportParameter("NombreEntrego", Capturo.ToUpper)) params.Add(New ReportParameter("Responsable", Personal)) params.Add(New ReportParameter("NombreRecibio", Personal)) - Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) - params.Add(New ReportParameter("LogoPath", logouri)) + 'Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) + If Imagen.Exists Then + Dim LogoRuta As String = String.Format("file://{0}", Imagen.FullName) + params.Add(New ReportParameter("LogoPath", LogoRuta)) + Else + params.Add(New ReportParameter("LogoPath", "")) + End If If DtMovimientos.COUNT("Serie") > 0 Then params.Add(New ReportParameter("MostrarSerieLote", "1")) Else @@ -4775,7 +4788,8 @@ Partial Class PopUpVerFactura End If Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) - Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + 'Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + 'Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) If Not ReporteEmpresa.Exists Then params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa)) @@ -4783,7 +4797,8 @@ Partial Class PopUpVerFactura params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToShortDateString)) If Imagen.Exists Then - params.Add(New ReportParameter("LogoPath", logouri)) + Dim LogoRuta As String = String.Format("file://{0}", Imagen.FullName) + params.Add(New ReportParameter("LogoPath", LogoRuta)) Else params.Add(New ReportParameter("LogoPath", "")) End If @@ -4979,10 +4994,9 @@ Partial Class PopUpVerFactura ObjAF.Dispose() Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) - Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) - If Imagen.Exists Then - params.Add(New ReportParameter("LogoPath", logouri)) + Dim LogoRuta As String = String.Format("file://{0}", Imagen.FullName) + params.Add(New ReportParameter("LogoPath", LogoRuta)) Else params.Add(New ReportParameter("LogoPath", "")) End If @@ -6070,7 +6084,9 @@ Partial Class PopUpVerFactura params.Add(New ReportParameter("CodigoTD", CodigoTD)) If Imagen.Exists Then - params.Add(New ReportParameter("LogoPath", logouri)) + + Dim LogoRuta As String = String.Format("file://{0}", Imagen.FullName) + params.Add(New ReportParameter("LogoPath", LogoRuta)) Else params.Add(New ReportParameter("LogoPath", "")) End If @@ -6128,7 +6144,7 @@ Partial Class PopUpVerFactura ObjPS.Dispose() Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) - Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) + 'Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa) Dim DtDatos As New DataTable Dim params As New List(Of ReportParameter) @@ -6207,7 +6223,9 @@ Partial Class PopUpVerFactura params.Add(New ReportParameter("CodigoTD", CodigoTD)) If Imagen.Exists Then - params.Add(New ReportParameter("LogoPath", logouri)) + + Dim LogoRuta As String = String.Format("file://{0}", Imagen.FullName) + params.Add(New ReportParameter("LogoPath", LogoRuta)) Else params.Add(New ReportParameter("LogoPath", "")) End If diff --git a/Ventas/RepCancelacionesPorRespuesta.aspx b/Ventas/RepCancelacionesPorRespuesta.aspx index 3c079264a..a159d3b16 100644 --- a/Ventas/RepCancelacionesPorRespuesta.aspx +++ b/Ventas/RepCancelacionesPorRespuesta.aspx @@ -41,7 +41,7 @@
-
+
" style="display: inline-block; margin-right: -20px; width: 150px;" /> " style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"> @@ -49,12 +49,12 @@
- +
- + @@ -70,7 +70,7 @@ - + @@ -88,7 +88,7 @@
-
+
" style="display: inline-block; margin-right: -20px; width: 150px;" /> " style="margin-top: -3px;" class="btn btn-circle btn-sm label-info"> @@ -96,14 +96,14 @@
- +
- + @@ -115,7 +115,7 @@ - + @@ -123,10 +123,19 @@ - +
+
+ +
+
+
+
+ +
+
- +
diff --git a/Ventas/RepCancelacionesPorRespuesta.aspx.cs b/Ventas/RepCancelacionesPorRespuesta.aspx.cs index f00369605..e86360122 100644 --- a/Ventas/RepCancelacionesPorRespuesta.aspx.cs +++ b/Ventas/RepCancelacionesPorRespuesta.aspx.cs @@ -68,9 +68,9 @@ public partial class Ventas_RepCancelacionesPorRespuesta : ClsPaginas } ObjVentas.Dispose(); - GvDatos.DataSource = DtVentas.FiltraParametros("(CveEstatusFactura = 20 AND CveEstatusRefacturacion = 0)"); + GvDatos.DataSource = DtVentas.FiltraParametros("(CveEstatusFactura = 20 AND CveEstatusRefacturacion IN (0,4))"); - var DtRefacturar = DtVentas.FiltraParametros("CveEstatusRefacturacion IN (1,3) OR (CveEstatusFactura = 20 AND CveEstatusRefacturacion > 0) OR CveEstatusFactura = 23"); + var DtRefacturar = DtVentas.FiltraParametros("CveEstatusRefacturacion IN (1,3) OR (CveEstatusFactura = 20 AND CveEstatusRefacturacion IN (1,2,3)) OR CveEstatusFactura = 23"); if (DtRefacturar != null && DtRefacturar.Rows.Count > 0) { DivRefacturar.Visible = true; @@ -177,9 +177,25 @@ public partial class Ventas_RepCancelacionesPorRespuesta : ClsPaginas string Nombre = GvRow.DataKey("Nombre"); string FolioSustitucion = GvRow.DataKey("FolioFiscalSustitucion"); + int CveMotivoCancelacion = -1; + int CveEstatusRefacturacion = GvRow.DataKey("CveEstatusRefacturacion").ToEntero(); + + //SI NO SE PUDO CANCELAR, CANCELAR CON EL 02 + if (CveEstatusRefacturacion == 4) + { + FolioSustitucion = ""; + //CUANDO LAS REFACTURACIONES NO SE PUEDEN CANCELAR, DEBE SER CANCELADO CON EL MOTIVO 02 + CveMotivoCancelacion = get_GlobalDTMotivosCancelacionEmpresa(UsuarioActual.CveEmpresa, CveSATMotivoCancelacion: 2).FiltroPrimeroValor("CveMotivoCancelacion").ToEntero(); + } + else + { + CveEstatusRefacturacion = 2; + } + + if (CveVenta > 0 && Uuid != "") { - var respCancelacion = CancelarDocumento(CveVenta, -1, CveCliente, Folio, Uuid, "", DateTime.Now, TipoDocto, Total.ToDouble(), UsuarioActual.Empresa.CvePAC, EsRefacturacion: true, FolioSustitucion: FolioSustitucion, CveEstatusRefacturacion: 2); + var respCancelacion = CancelarDocumento(CveVenta, -1, CveCliente, Folio, Uuid, "", DateTime.Now, TipoDocto, Total.ToDouble(), UsuarioActual.Empresa.CvePAC, EsRefacturacion: true, FolioSustitucion: FolioSustitucion, CveEstatusRefacturacion: CveEstatusRefacturacion); if (!respCancelacion.HuboError) { @@ -463,7 +479,7 @@ public partial class Ventas_RepCancelacionesPorRespuesta : ClsPaginas retorno.Mensaje = sb.ToString(); return retorno; } - private Modelos.Factura.MCancelacionVentaMensaje CancelarDocumento(int CveVenta, int CveEstatus, int CveCliente, string Folio, string FolioFiscal, string CancelacionAcuse, DateTime CancelacionFecha, string TipoComprobante, double Total, int CvePACCancelacion, bool EsRefacturacion = false, string FolioSustitucion = "", int CveEstatusRefacturacion = 0) + private Modelos.Factura.MCancelacionVentaMensaje CancelarDocumento(int CveVenta, int CveEstatus, int CveCliente, string Folio, string FolioFiscal, string CancelacionAcuse, DateTime CancelacionFecha, string TipoComprobante, double Total, int CvePACCancelacion, bool EsRefacturacion = false, string FolioSustitucion = "", int CveEstatusRefacturacion = 0, int CveMotivoCancelacion = 0) { Modelos.Factura.MCancelacionVentaMensaje retorno = null; var factura = new Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa, EsCancelacion: true); @@ -480,12 +496,22 @@ public partial class Ventas_RepCancelacionesPorRespuesta : ClsPaginas factura.CveEstatusRefacturacion = CveEstatusRefacturacion; } + if (CveMotivoCancelacion > 0) + { + factura.CveMotivoCancelacion = CveMotivoCancelacion; + } + int CveEstatusFactura = -1; //SI LA FACTURA YA ESTA CANCELADA, LA ASIGNA YA COMO CANCELADA if (CveEstatus == 5) { CveEstatusFactura = CveEstatus; } + //NO DEBE DE ASIGNAR ESTATUS + if (CveEstatus == -2) + { + CveEstatusFactura = -1; + } retorno = factura.CancelarPorRefacturacion(factura.CveMotivoCancelacion, factura.MotivoCancelacion, FolioSustitucion: FolioSustitucion, CveEstatusFacturaAsignado: CveEstatusFactura); } @@ -561,6 +587,11 @@ public partial class Ventas_RepCancelacionesPorRespuesta : ClsPaginas if (e.Row.DBCampo("PuedeRefacturar").ToString().ToEntero() == 0 && e.Row.DBCampo("CveEstatusFactura").ToString().ToEntero() == 23 && e.Row.DBCampo("CveVentaSustitucion").ToEntero() > 0) { e.Row.FCLinkButton("LnkCancelar").Visible = true; + //SOLO MOSTRAR SI LA FACTURA NUEVA ESTA EMITIDA + if (e.Row.DBCampo("CveEstatusRefacturacion").ToString().ToEntero() != 4 && e.Row.DBCampo("CveEstatusFacturaSustitucion").ToString().ToEntero() == 3) + { + e.Row.FCLinkButton("LnkCancelarFolioSustitucion").Visible = true; + } } } } @@ -708,40 +739,127 @@ public partial class Ventas_RepCancelacionesPorRespuesta : ClsPaginas } + protected void LnkCancelarFolioSustitucion_Click(object sender, EventArgs e) + { + //this.HdnLigaRefacturar.Value = ""; + this.CveVenta = -1; - //protected void BtnAcuse_Click(object sender, EventArgs e) - //{ - // GridViewRow GvRow = (GridViewRow)(((LinkButton)sender).NamingContainer); - // string UsuarioServicio = "rene.molina@adsistemas.mx"; - // string ClaveServicio = "rene2018"; - // string UrlServicio = "https://cfdi.gofac.com.mx/timbrado.asmx?WSDL"; + GridViewRow GvRow = (GridViewRow)(((LinkButton)sender).NamingContainer); + this.CveVenta = GvRow.DataKey("CveVentaSustitucion").ToEntero(); - // this.CveVenta = GvRow.DataKey("CveVenta").ToEntero(); + int CveCliente = GvRow.DataKey("CveClienteSustitucion").ToEntero(); + string Total = GvRow.DataKey("TotalSustitucion"); + string RFCReceptor = GvRow.DataKey("RFCReceptorSustitucion"); + string TipoDocto = GvRow.DataKey("TipoDocto"); + string Nombre = GvRow.DataKey("Nombre"); + string FolioSustitucion = GvRow.DataKey("FolioFiscalSustitucion"); + string SerieFolioSustitucion = GvRow.DataKey("SerieFolioSustitucion"); - // string Uuid = GvRow.DataKey("FolioFiscal"); - // decimal Total = GvRow.DataKey("Total").ToDecimal(); - // string RFCCliente = GvRow.DataKey("RFCCliente"); - // string FolioFiscalSustitucion = GvRow.DataKey("FolioFiscalSustitucion"); - // Cancelacion2022.AcuseSat resp = new Cancelacion2022.AcuseSat(); - // GoFac.GoCfdi a = new GoFac.GoCfdi(); - // a.ObtenerAcuse(UrlServicio, UsuarioActual.Empresa.RFC, UsuarioServicio, ClaveServicio, Uuid); + int CveVentaOriginal = GvRow.DataKey("CveVenta").ToEntero(); + string SerieFolioOriginal = GvRow.DataKey("SerieFolio"); - // if (a.CodigoError != 0) - // { - // //no se pudo obtener, la mandamos cancelar - // Timbrado ObjCancelacion = new Timbrado(); + //CUANDO LAS REFACTURACIONES NO SE PUEDEN CANCELAR, DEBE SER CANCELADO CON EL MOTIVO 02 + int CveMotivoCancelacion = get_GlobalDTMotivosCancelacionEmpresa(UsuarioActual.CveEmpresa, CveSATMotivoCancelacion: 2).FiltroPrimeroValor("CveMotivoCancelacion").ToEntero(); - // if (ObjCancelacion.CFDICancelar(UsuarioActual.Empresa, Uuid, Total, RFCCliente, UsuarioActual.Empresa.RFC, 4, ValidaFactura:false, CveSATMotivoCancelacion: 1, FolioSustitucion: FolioFiscalSustitucion )) - // { - // string b = ObjCancelacion.CancelacionAcuse; - // //falta actualizar - // Alert("Se regeneró la solicitud de cancelación"); - // } + if (CveVenta > 0 && FolioSustitucion != "") + { + var respCancelacion = CancelarDocumento(CveVenta, -2, CveCliente, "", FolioSustitucion, "", DateTime.Now, TipoDocto, Total.ToDouble(), UsuarioActual.Empresa.CvePAC, EsRefacturacion: true, FolioSustitucion: "", CveEstatusRefacturacion: 4, CveMotivoCancelacion: CveMotivoCancelacion); + if (!respCancelacion.HuboError) + { + var sb = new StringBuilder(); + var EnviarAcuse = false; + if (respCancelacion.CveEstatus > 0) + { + if (respCancelacion.CveEstatus.Contiene(5, 20)) + { + EnviarAcuse = true; + } - // } + var CveEstatus = respCancelacion.CveEstatus; + var ObjVentas = new ClsVentas(); + if (ObjVentas.UpdateEstatusVenta(CveVenta, CveEstatus, UsuarioActual.CveEmpresa)) + { + if (respCancelacion.CveEstatus == 20) + { + sb.Append($"El estatus de la factura {SerieFolioSustitucion} fue cambiado a 'Cancelación en proceso'."); + sb.Append("El documento se canceló correctamente."); + sb.Append($"
Imprimir Acuse"); + } + else if (respCancelacion.CveEstatus == 23) + { + sb.Append("La solicitud de cancelación no la aplicó el SAT, intente cancelar de nuevo."); + } + else if (respCancelacion.CveEstatus == 5) + { + sb.Append($"El estatus de la factura {SerieFolioSustitucion} fue cambiado a 'Cancelada'."); + sb.Append("El documento se canceló correctamente."); + sb.Append($"
Imprimir Acuse"); + } - //} + if (respCancelacion.CveEstatus.Contiene(5,20)) + { + if (ObjVentas.UpdateEstatusVenta(CveVentaOriginal, 23, UsuarioActual.CveEmpresa, CveEstatusRefacturacion:4, CveMotivoCancelacion: CveMotivoCancelacion)) + { + sb.Append($"
La Factura {SerieFolioOriginal} fue desligada."); + } + } + + } + else + { + sb.Append("Ocurrió un error al cambiar el estatus de la factura."); + } + ObjVentas.Dispose(); + + if (respCancelacion.CveEstatus == 23) + { + var resp = Timbrado.VerificarVigenciaSAT(FolioSustitucion, UsuarioActual.Empresa.RFC, RFCReceptor, Total, true); + if (resp != null) + { + sb.AppendFormat("
Folio Fiscal: {0}
", FolioSustitucion); + sb.AppendFormat("Código Estado: {0}
", resp.CodigoEstatus); + sb.AppendFormat("Estado: {0}
", resp.Estado); + sb.AppendFormat("Es Cancelable: {0}
", string.IsNullOrEmpty(resp.EsCancelable) ? "Desconocido" : resp.EsCancelable); + sb.AppendFormat("Estatus de Cancelación: {0}

", string.IsNullOrEmpty(resp.EsCancelable) ? "Desconocido" : resp.EstatusCancelacion); + } + } + } + else + { + var resp = Timbrado.VerificarVigenciaSAT(FolioSustitucion, UsuarioActual.Empresa.RFC, RFCReceptor, Total, true); + if (resp != null) + { + sb.AppendFormat("Folio Fiscal: {0}
", FolioSustitucion); + sb.AppendFormat("Código Estado: {0}
", resp.CodigoEstatus); + sb.AppendFormat("Estado: {0}
", resp.Estado); + sb.AppendFormat("Es Cancelable: {0}
", string.IsNullOrEmpty(resp.EsCancelable) ? "Desconocido" : resp.EsCancelable); + sb.AppendFormat("Estatus de Cancelación: {0}

", string.IsNullOrEmpty(resp.EsCancelable) ? "Desconocido" : resp.EstatusCancelacion); + } + + sb.Append(respCancelacion.Mensaje); + } + + if (EnviarAcuse) + { + sb.Append("

¿Desea enviar el Acuse de Cancelación al Cliente?"); + Alert(sb.ToString(), TipoMensaje.MsgConfirmacion, "BtnEnviarMailCancelacion();", TextoConfirmacion: "Enviar", TextoSegundoBoton: "Cancelar"); + } + else + { + Alert(sb.ToString()); + } + } + else + { + Alert(respCancelacion.Mensaje, TipoMensaje.MsgError); + } + + CargaDatos(); + } + UPDatos.Update(); + + } } public class MRespuestaSAT { diff --git a/Ventas/Ventas.aspx.vb b/Ventas/Ventas.aspx.vb index 308a2f093..60ba09742 100644 --- a/Ventas/Ventas.aspx.vb +++ b/Ventas/Ventas.aspx.vb @@ -1266,6 +1266,14 @@ Partial Class Ventas ViewState("CveEstatusRefacturacion") = value End Set End Property + Private Property RefacturarCancelada As Boolean + Get + Return If(IsNothing(ViewState("RefacturarCancelada")), False, CBool(ViewState("RefacturarCancelada"))) + End Get + Set(value As Boolean) + ViewState("RefacturarCancelada") = value + End Set + End Property Private Property CveEstadoCancelacion As Integer Get @@ -4393,10 +4401,13 @@ Partial Class Ventas 'End If - If Not CveEstatus.Contiene(4, 5, 12, 13, 20, 23) AndAlso DdlTipoComprobante.SelectedValue.Contiene("Ing", "Egs", "Ant") AndAlso UsuarioActual.TienePermisoProceso(159) Then + If (Not CveEstatus.Contiene(4, 5, 12, 13, 20, 23) OrElse (CveEstatus = 5 AndAlso DbRowVenta("CveEstatusRefacturacion").ToString().ToEntero() = 4)) AndAlso DdlTipoComprobante.SelectedValue.Contiene("Ing", "Egs", "Ant") AndAlso UsuarioActual.TienePermisoProceso(159) Then Dim TienePermiso As String = GlobalDTSubProyectosUsuarios(UsuarioActual.CveUsuario, -1, UsuarioActual.CveEmpresa, -1, -1).FiltroPrimeroValor("CveSubProyecto", String.Format("CveSubProyecto = {0}", DbRowVenta("CveSubProyecto"))) If TienePermiso <> "" Then LkRefacturacion.Visible = True + If (CveEstatus = 5 AndAlso DbRowVenta("CveEstatusRefacturacion").ToString().ToEntero() = 4) Then + RefacturarCancelada = True + End If End If End If @@ -9106,6 +9117,15 @@ Partial Class Ventas End If End If + 'MARCAR LA FACTURA ANTERIOR + If (Me.CveDevolucion > 0 AndAlso Me.NuevaFactura = 1) Then + If Me.ObjFacturaNC IsNot Nothing Then + If Me.ObjFacturaNC.CveEstatusRefacturacion = 4 AndAlso Not ObjVentas.UpdateEstatusVenta(ObjFacturaNC.CveVenta, ObjFacturaNC.CveEstatusFactura, UsuarioActual.CveEmpresa, CveEstatusRefacturacion:=5) Then + ErrorList.Add("No se actualizó el estatus de la factura anterior.") + End If + End If + End If + If ObjFactura.CveVenta > 0 AndAlso ErrorList.Count = 0 AndAlso (SeGuardoPrePoliza Or ObjFactura.TipoDocto.Contiene("Ped", "Cot", "DPe", "PeC", "PA", "Pd2")) Then ObjVentas.Commit() @@ -9138,13 +9158,14 @@ Partial Class Ventas End If Else Alert(String.Format("Falta asignación de las siguientes cuentas contables: {0}", CuentasContablesInvalidas), TipoMensaje.MsgAdvertencia) + End If + Else + If UsuarioActual.Empresa.UsaAC Then + If ObjContPaq IsNot Nothing Then ObjContPaq.Commit() End If End If - - 'If ObjContPaq IsNot Nothing Then ObjContPaq.RollBack() - 'RMF, cuando es pedido, se manda autorización. If ObjFactura.TipoDocto.Contiene("PA") Then @@ -9268,7 +9289,7 @@ Partial Class Ventas 'CANCELAR FACTURA ANTERIOR If SeTimbro AndAlso (Me.CveDevolucion > 0 AndAlso Me.NuevaFactura = 1) Then - If Me.ObjFacturaNC IsNot Nothing Then + If Me.ObjFacturaNC IsNot Nothing AndAlso Me.ObjFacturaNC.CveEstatusFactura <> 5 Then Me.ObjFacturaNC.CveEstatusRefacturacion = 2 'MARCAR COMO REFACTURADA MsgCancelacionRefacturacion = Me.ObjFacturaNC.CancelarPorRefacturacion(Me.ObjFacturaNC.CveMotivoCancelacion, Me.ObjFacturaNC.MotivoCancelacion, FolioFiscalFactura) End If @@ -12167,9 +12188,33 @@ Partial Class Ventas 'Si es devolucion se agregan a la tabla de Vta_VentasDetalleDevolucion If factura.AplicaDevolucion Then - If Not ObjVentas.AddVentaDetalleDevolucion(Row("CveVentaDetalle").ToString().ToEntero(), ObjVentas.CveVentaDetalle, Row("Cantidad").ToString().ToDouble) Then + Try + Dim EsCargo As Integer = If(Row("EsCargo").ToString() = "True", 1, 0) + If EsCargo = 1 Then + If Me.ObjFacturaNC IsNot Nothing Then + Dim CveVentaDetalleUsado As Integer = -1 + For Each RowIng As DataRow In Me.ObjFacturaNC.DtDetalle.Rows + If RowIng("Cantidad").ToString().ToDecimal() = Row("Cantidad").ToString().ToDecimal() AndAlso RowIng("CvePS").ToString().ToEntero() = Row("CvePS").ToString().ToEntero() Then + CveVentaDetalleUsado = RowIng("CveVentaDetalle").ToString().ToEntero() + Exit For + End If + Next + If CveVentaDetalleUsado > 0 Then + If Not ObjVentas.AddVentaDetalleDevolucion(CveVentaDetalleUsado, ObjVentas.CveVentaDetalle, Row("Cantidad").ToString().ToDouble) Then + ErrorList.Add("Ocurrió un error al agregar la venta detalle devolución.") + End If + End If + + End If + Else + If Not ObjVentas.AddVentaDetalleDevolucion(Row("CveVentaDetalle").ToString().ToEntero(), ObjVentas.CveVentaDetalle, Row("Cantidad").ToString().ToDouble) Then + ErrorList.Add("Ocurrió un error al agregar la venta detalle devolución.") + End If + End If + Catch ex As Exception ErrorList.Add("Ocurrió un error al agregar la venta detalle devolución.") - End If + End Try + If ErrorList.Count = 0 Then If Not ObjEventos.AddEventoBitacora(String.Format("Se aplicó una devolución en Folio: {1}", factura.CveVenta, factura.SerieFolio), "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveVenta:=CveVentaDevolucion) Then ErrorList.Add("Ocurrió un error al agregar la bitacora de devolución.") @@ -20886,129 +20931,134 @@ Partial Class Ventas 'End Sub Private Sub BtnNuevaFactura_Click(sender As Object, e As EventArgs) Handles LkRefacturacion.Click 'Nos vamos a la nueva factura - Dim script As String = "" - If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Dev", "Egs") Then - Dim sb As New StringBuilder() + If RefacturarCancelada Then + Response.Redirect($"Ventas.aspx?CveDevolucion={CveVenta}&NuevaFactura=1") + Else + Dim script As String = "" + If DdlTipoComprobante.SelectedValue.Contiene("Ing", "Ant", "Dev", "Egs") Then + Dim sb As New StringBuilder() - If Not String.IsNullOrEmpty(FolioFiscal) AndAlso Not (UsuarioActual.Empresa.Funcionalidad(529) = "1") Then - sb.Append("La factura se encuentra en el siguiente estatus del SAT:
") + If Not String.IsNullOrEmpty(FolioFiscal) AndAlso Not (UsuarioActual.Empresa.Funcionalidad(529) = "1") Then + sb.Append("La factura se encuentra en el siguiente estatus del SAT:
") - Dim TotalT As Decimal = TxtTotal.Text.ToDecimal - Dim RFCReceptor As String = LblRFC.Text.Trim + Dim TotalT As Decimal = TxtTotal.Text.ToDecimal + Dim RFCReceptor As String = LblRFC.Text.Trim - 'SI SE FACTURO LA SUCURSAL DEL CLIENTE TOMA EL RFC DE ESTA - If FacturarSucursal AndAlso Me.ClienteSucursal IsNot Nothing Then - RFCReceptor = Me.ClienteSucursal.RFC - End If + 'SI SE FACTURO LA SUCURSAL DEL CLIENTE TOMA EL RFC DE ESTA + If FacturarSucursal AndAlso Me.ClienteSucursal IsNot Nothing Then + RFCReceptor = Me.ClienteSucursal.RFC + End If - Dim SWatch As New Stopwatch - SWatch.Start() + Dim SWatch As New Stopwatch + SWatch.Start() - Dim Vigencia = Timbrado.VerificarVigenciaSAT(FolioFiscal, UsuarioActual.Empresa.RFC, RFCReceptor, TotalT.ToString(), True) - SWatch.Stop() + Dim Vigencia = Timbrado.VerificarVigenciaSAT(FolioFiscal, UsuarioActual.Empresa.RFC, RFCReceptor, TotalT.ToString(), True) + SWatch.Stop() - Dim SegundosRespuesta As Double = SWatch.ElapsedMilliseconds / 1000 - SegundosRespuesta = SegundosRespuesta.ToEntero + Dim SegundosRespuesta As Double = SWatch.ElapsedMilliseconds / 1000 + SegundosRespuesta = SegundosRespuesta.ToEntero - If SegundosRespuesta >= 5 Then - Alert($"Los servicios de validacion del SAT presentan lentitud en la respuesta [{ SegundosRespuesta } s].", TipoMensaje.ToastError, "") - End If + If SegundosRespuesta >= 5 Then + Alert($"Los servicios de validacion del SAT presentan lentitud en la respuesta [{ SegundosRespuesta } s].", TipoMensaje.ToastError, "") + End If - If Vigencia IsNot Nothing Then + If Vigencia IsNot Nothing Then - If Vigencia.EsCancelable.ToUpper() = "NO CANCELABLE" Then - sb.AppendFormat("{0}
", Vigencia.EsCancelable) + If Vigencia.EsCancelable.ToUpper() = "NO CANCELABLE" Then + sb.AppendFormat("{0}
", Vigencia.EsCancelable) - DivRelacionadasRefacturacion.Visible = True - BtnMotivoRefacturacion.Visible = False - DivMotivoRefacturacionTexto.Visible = False + DivRelacionadasRefacturacion.Visible = True + BtnMotivoRefacturacion.Visible = False + DivMotivoRefacturacionTexto.Visible = False - Dim Relacionados = Timbrado.ConsultarUUIDRelacionados(UsuarioActual.Empresa, FolioFiscal, UsuarioActual.Empresa.FacturaProduccion) - If Relacionados IsNot Nothing Then - Dim sbExtra As New StringBuilder() - If Relacionados.Codigo = 500 Then - sbExtra.Append("El servicio de verificación de documentos relacionados no esta disponible.") - Else - sbExtra.Append(Relacionados.Mensaje) + Dim Relacionados = Timbrado.ConsultarUUIDRelacionados(UsuarioActual.Empresa, FolioFiscal, UsuarioActual.Empresa.FacturaProduccion) + If Relacionados IsNot Nothing Then + Dim sbExtra As New StringBuilder() + If Relacionados.Codigo = 500 Then + sbExtra.Append("El servicio de verificación de documentos relacionados no esta disponible.") + Else + sbExtra.Append(Relacionados.Mensaje) - Dim SbHijos = New StringBuilder() - Dim SbPadres = New StringBuilder() + Dim SbHijos = New StringBuilder() + Dim SbPadres = New StringBuilder() - 'If Relacionados.RelacionadosHijo IsNot Nothing Then - ' For Each hijo In Relacionados.RelacionadosHijo - ' SbHijos.AppendFormat("{0};", hijo.Uuid) - ' Next - ' If SbHijos.Length > 0 Then - ' SbHijos.Remove(SbHijos.Length - 1, 1) - ' End If - 'End If - - If Relacionados.RelacionadosPadre IsNot Nothing Then - For Each padre In Relacionados.RelacionadosPadre - SbPadres.AppendFormat("{0};", padre.Uuid) - Next - If SbPadres.Length > 0 Then - SbPadres.Remove(SbPadres.Length - 1, 1) - End If - End If - - Using ObjVentas As New ClsVentas - - 'If SbHijos.Length > 0 Then - ' If ObjVentas.GetFacturasRelacionadasPorFolioFiscal(SbHijos.ToString(), UsuarioActual.CveEmpresa) Then - ' GvFacturasHijosCancelar.DataSource = ObjVentas.DtResultados.Copy() + 'If Relacionados.RelacionadosHijo IsNot Nothing Then + ' For Each hijo In Relacionados.RelacionadosHijo + ' SbHijos.AppendFormat("{0};", hijo.Uuid) + ' Next + ' If SbHijos.Length > 0 Then + ' SbHijos.Remove(SbHijos.Length - 1, 1) ' End If 'End If - If SbPadres.Length > 0 Then - If ObjVentas.GetFacturasRelacionadasPorFolioFiscal(SbPadres.ToString(), UsuarioActual.CveEmpresa) Then - GvFacturasPadreRefacturar.DataSource = ObjVentas.DtResultados.FiltraParametros($"CveVenta <> {CveVenta}") + If Relacionados.RelacionadosPadre IsNot Nothing Then + For Each padre In Relacionados.RelacionadosPadre + SbPadres.AppendFormat("{0};", padre.Uuid) + Next + If SbPadres.Length > 0 Then + SbPadres.Remove(SbPadres.Length - 1, 1) End If End If - End Using + Using ObjVentas As New ClsVentas + + 'If SbHijos.Length > 0 Then + ' If ObjVentas.GetFacturasRelacionadasPorFolioFiscal(SbHijos.ToString(), UsuarioActual.CveEmpresa) Then + ' GvFacturasHijosCancelar.DataSource = ObjVentas.DtResultados.Copy() + ' End If + 'End If + + If SbPadres.Length > 0 Then + If ObjVentas.GetFacturasRelacionadasPorFolioFiscal(SbPadres.ToString(), UsuarioActual.CveEmpresa) Then + GvFacturasPadreRefacturar.DataSource = ObjVentas.DtResultados.FiltraParametros($"CveVenta <> {CveVenta}") + End If + End If + + End Using + + 'GvFacturasHijosCancelar.DataBind() + GvFacturasPadreRefacturar.DataBind() + End If + + If sbExtra.Length > 0 Then + LbExtraRefacturacion.Text = $"
*{sbExtra.ToString()}" + End If - 'GvFacturasHijosCancelar.DataBind() - GvFacturasPadreRefacturar.DataBind() End If - - If sbExtra.Length > 0 Then - LbExtraRefacturacion.Text = $"
*{sbExtra.ToString()}" - End If - End If - End If - If Vigencia.EsCancelable = "Cancelable sin aceptación" Then - 'script = "BtnRefacturacionConfirmarAceptacion();" - Me.CveEstadoCancelacion = 1 - sb.AppendFormat("{0}
", Vigencia.EsCancelable) - sb.Append("Está seguro de realizar la refacturación?.") - End If + If Vigencia.EsCancelable = "Cancelable sin aceptación" Then + 'script = "BtnRefacturacionConfirmarAceptacion();" + Me.CveEstadoCancelacion = 1 + sb.AppendFormat("{0}
", Vigencia.EsCancelable) + sb.Append("Está seguro de realizar la refacturación?.") + End If - If Vigencia.EsCancelable = "Cancelable con aceptación" OrElse String.IsNullOrEmpty(Vigencia.EsCancelable) Then - 'script = "BtnRefacturacionConfirmar();" - Me.CveEstadoCancelacion = 2 - sb.AppendFormat("{0}
", "Cancelable con aceptación") - sb.Append("Está seguro de cancelar el documento para realizar la refacturación?.") + If Vigencia.EsCancelable = "Cancelable con aceptación" OrElse String.IsNullOrEmpty(Vigencia.EsCancelable) Then + 'script = "BtnRefacturacionConfirmar();" + Me.CveEstadoCancelacion = 2 + sb.AppendFormat("{0}
", "Cancelable con aceptación") + sb.Append("Está seguro de cancelar el documento para realizar la refacturación?.") + End If + Else + 'If Not UsuarioActual.Empresa.FacturaProduccion Then + ' script = "BtnRefacturacionConfirmar();" + 'End If + sb.Append("No encontrado
") End If Else - 'If Not UsuarioActual.Empresa.FacturaProduccion Then - ' script = "BtnRefacturacionConfirmar();" - 'End If - sb.Append("No encontrado
") + 'sb.Append("¿Desea realizar la refacturación?
") + script = "BtnRefacturacionConfirmarAceptacion();" End If - Else - 'sb.Append("¿Desea realizar la refacturación?
") - script = "BtnRefacturacionConfirmarAceptacion();" + + LblEstatusRefacturacion.Text = sb.ToString() + UpMotivoRefac.Update() + + RegistraScript("$('#DivMotivoRefacturacion').modal({ backdrop: 'static', keyboard: false });", "R1") + 'Alert(sb.ToString(), TipoMensaje.MsgConfirmacion, JSBtnAceptar:=script, TextoConfirmacion:="    Si    ", TextoCancelacion:="    No    ") End If - - LblEstatusRefacturacion.Text = sb.ToString() - UpMotivoRefac.Update() - - RegistraScript("$('#DivMotivoRefacturacion').modal({ backdrop: 'static', keyboard: false });", "R1") - 'Alert(sb.ToString(), TipoMensaje.MsgConfirmacion, JSBtnAceptar:=script, TextoConfirmacion:="    Si    ", TextoCancelacion:="    No    ") End If + End Sub Private Sub BtnMotivoRefacturacion_Click(sender As Object, e As System.EventArgs) Handles BtnMotivoRefacturacion.Click @@ -21758,7 +21808,7 @@ Partial Class Ventas DdlCuentaCheque.DataSource = DtCC.FiltraParametros(String.Format("CveMoneda = {0} AND CveTipoCuenta = 1", If(DdlMoneda.SelectedValue.ToEntero() <= 0, 1, DdlMoneda.SelectedValue.ToEntero()))) End If - If UsuarioActual.Empresa.Funcionalidad(558) = "1" Then + If UsuarioActual.Empresa.Funcionalidad(558) = "1" OrElse UsuarioActual.Empresa.Funcionalidad(531) = "1" Then DdlCuentaTarjetaCredito.DataSource = DtCC.FiltraParametros(String.Format("CveMoneda = {0} AND CveTipoCuenta = 1 AND TieneTerminal = 1", If(DdlMoneda.SelectedValue.ToEntero() <= 0, 1, DdlMoneda.SelectedValue.ToEntero()))) DdlCuentaTarjetaDebito.DataSource = DtCC.FiltraParametros(String.Format("CveMoneda = {0} AND CveTipoCuenta = 1 AND TieneTerminal = 1", If(DdlMoneda.SelectedValue.ToEntero() <= 0, 1, DdlMoneda.SelectedValue.ToEntero()))) Else @@ -29661,6 +29711,11 @@ Partial Class Ventas CargaVendedores() + If UsuarioActual.Empresa.Funcionalidad(572) = "1" AndAlso Not TbDescuentosRNC.Visible Then + TbDescuentosRNC.Visible = True + LnkDescuentosRNC.Visible = UsuarioActual.TienePermisoProceso(328) + End If + UpPS.Update() UPPDescuento.Update() UPObservaciones.Update() @@ -31534,6 +31589,11 @@ Partial Class Ventas End Function Private Sub EmitirDocumentoNuevo(TipoDoctoNuevo As String) + If DdlVendedor.SelectedValue.ToEntero() <= 0 AndAlso UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso TipoDoctoNuevo = "Ing" Then + Alert("Debe seleccionar un vendedor.", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + If (FacturarSucursal AndAlso DdlSucursalCliente.SelectedValue.ToEntero() > 0 AndAlso (Me.ClienteSucursal IsNot Nothing AndAlso String.IsNullOrEmpty(Me.ClienteSucursal.RFC))) Then Alert("La sucursal no tiene asignada un RFC.", TipoMensaje.MsgAdvertencia) Exit Sub