From ab6548c3a5a9d4ef1918dbd2c351032e7ab676e7 Mon Sep 17 00:00:00 2001 From: Jonathan Alexis Perez Morales Date: Wed, 23 Oct 2024 10:49:01 -0700 Subject: [PATCH 1/2] --GDiaz: timbrado de factura y NC en cobranza --- App_Code/Modelos.vb | 3 +- Ventas/PVCobranza.aspx.vb | 218 +++++++++++++++++++++++++++----------- 2 files changed, 159 insertions(+), 62 deletions(-) diff --git a/App_Code/Modelos.vb b/App_Code/Modelos.vb index 6f00aa0c8..416eb054c 100644 --- a/App_Code/Modelos.vb +++ b/App_Code/Modelos.vb @@ -381,6 +381,7 @@ Namespace Modelos Public Class MAnticipoRelacionado Public Property CveVenta As Integer Public Property FolioFiscal As String + Public Property Tipo As String End Class Public Class MVentaDetalleCotizacion @@ -1119,7 +1120,7 @@ Namespace Modelos 'MENSAJE PRINCIPAL If MostrarURL Then - MensajeAlert.AppendFormat("
La {0}: {1} se generó correctamente.

", If(Me.TipoDocumento = "Ingresos", "Factura", Me.TipoDocumento), Me.SerieFolio, Me.CveVenta) + MensajeAlert.AppendFormat("
La {0}: {1} se generó correctamente.

", If(Me.TipoDocumento = "Ingresos", "Factura", If(Me.TipoDocumento = "Egresos", "Nota de crédito", Me.TipoDocumento)), Me.SerieFolio, Me.CveVenta) Else MensajeAlert.AppendFormat(String.Format("
La {0}: {1} se generó correctamente.

", If(Me.TipoDocumento = "Ingresos", "Factura", Me.TipoDocumento), Me.SerieFolio)) End If diff --git a/Ventas/PVCobranza.aspx.vb b/Ventas/PVCobranza.aspx.vb index 58a0c8a6d..eb276ac57 100644 --- a/Ventas/PVCobranza.aspx.vb +++ b/Ventas/PVCobranza.aspx.vb @@ -512,7 +512,7 @@ Partial Class Ventas_PVCobranza Dim respFactura As Modelos.Factura.MMensajeFactura = Nothing Dim respNC As Modelos.Factura.MMensajeFactura = Nothing - + Dim RegistrarPago As Boolean = True Try 'FACTURAR LA REMISION PARA HACER EL PAGO If UsuarioActual.CveEmpresa.Contiene(189, 197) AndAlso VentaActual.TipoDocto = "Rem" Then @@ -563,73 +563,78 @@ Partial Class Ventas_PVCobranza End If If MsgError = "" Then - CvePrePoliza = ObjConta.AddPrePolizas("PVCobranza", 11, 0, 0, 1, Fecha, $"Pago {VentaActual.SerieFolio}", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveTipoPoliza:=3) + If SaldoPendiente > 0 Then + CvePrePoliza = ObjConta.AddPrePolizas("PVCobranza", 11, 0, 0, 1, Fecha, $"Pago {VentaActual.SerieFolio}", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveTipoPoliza:=3) - If CvePrePoliza > 0 Then + If CvePrePoliza > 0 Then - If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteCredito.Text.ToDecimal > 0 Then - MsgError = RegistraIE(12, DdlCuentaTarjetaCredito.SelectedValue.ToEntero, TxtImporteCredito.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto) - SaldoPendiente -= TxtImporteCredito.Text.ToDecimal - PagoAplicado += TxtImporteCredito.Text.ToDecimal - End If - - If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteDebito.Text.ToDecimal > 0 Then - MsgError = RegistraIE(11, DdlCuentaTarjetaDebito.SelectedValue.ToEntero, TxtImporteDebito.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto) - SaldoPendiente -= TxtImporteDebito.Text.ToDecimal - PagoAplicado += TxtImporteDebito.Text.ToDecimal - End If - - If SaldoPendiente > 0 AndAlso TxtImporteCheque.Text.ToDecimal > 0 Then - Dim Obs As String = "" - If DivDatosCheque.Visible Then - Obs = $"{VentaActual.SerieFolio} - Autorizó: {TxtAutorizo.Text}" + If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteCredito.Text.ToDecimal > 0 Then + MsgError = RegistraIE(12, DdlCuentaTarjetaCredito.SelectedValue.ToEntero, TxtImporteCredito.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto) + SaldoPendiente -= TxtImporteCredito.Text.ToDecimal + PagoAplicado += TxtImporteCredito.Text.ToDecimal End If - MsgError = RegistraIE(3, DdlCuentaCheque.SelectedValue.ToEntero, TxtImporteCheque.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, Obs:=Obs, CveAutorizacion:=TxtClaveAutorizacion.Text.Trim(), CveSubProyecto:=VentaActual.CveSubProyecto) - SaldoPendiente -= TxtImporteCheque.Text.ToDecimal - PagoAplicado += TxtImporteCheque.Text.ToDecimal - End If - - If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteTransferencia.Text.ToDecimal > 0 Then - MsgError = RegistraIE(8, DdlCuentaTransferencia.SelectedValue.ToEntero, TxtImporteTransferencia.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto) - SaldoPendiente -= TxtImporteTransferencia.Text.ToDecimal - PagoAplicado += TxtImporteTransferencia.Text.ToDecimal - End If - - If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteEfectivo.Text.ToDecimal > 0 Then - Dim PagoEfectivo As Decimal = TxtImporteEfectivo.Text.ToDecimal - - PagoAplicado += PagoEfectivo - If PagoAplicado >= SaldoTotalInicial Then - TxtCambio.Text = (PagoAplicado - SaldoTotalInicial).FormatoNumero - PagoEfectivo = SaldoPendiente + If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteDebito.Text.ToDecimal > 0 Then + MsgError = RegistraIE(11, DdlCuentaTarjetaDebito.SelectedValue.ToEntero, TxtImporteDebito.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto) + SaldoPendiente -= TxtImporteDebito.Text.ToDecimal + PagoAplicado += TxtImporteDebito.Text.ToDecimal End If - MsgError = RegistraIE(13, DdlCuentaEfectivo.SelectedValue.ToEntero, PagoEfectivo, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto) - SaldoPendiente -= PagoEfectivo - End If - If SaldoPendiente > 0 Then - MsgError = "Tiene saldo pendiente por aplicar" - End If + If SaldoPendiente > 0 AndAlso TxtImporteCheque.Text.ToDecimal > 0 Then + Dim Obs As String = "" + If DivDatosCheque.Visible Then + Obs = $"{VentaActual.SerieFolio} - Autorizó: {TxtAutorizo.Text}" + End If - If UsuarioActual.CveRol <> 1 Then - If MsgError = "" AndAlso Not ObjVentas2.UpdateVentaCorte(CveVenta, UsuarioActual.CveEmpresa, tCveCorte) Then - MsgError = "Error al aplicar el corte" + MsgError = RegistraIE(3, DdlCuentaCheque.SelectedValue.ToEntero, TxtImporteCheque.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, Obs:=Obs, CveAutorizacion:=TxtClaveAutorizacion.Text.Trim(), CveSubProyecto:=VentaActual.CveSubProyecto) + SaldoPendiente -= TxtImporteCheque.Text.ToDecimal + PagoAplicado += TxtImporteCheque.Text.ToDecimal End If - End If - If MsgError = "" AndAlso Not ObjVentas2.UpdateVentaTicketImpreso(CveVenta, 0) Then - MsgError = "No se pudo desmarcar la impresión" - End If + If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteTransferencia.Text.ToDecimal > 0 Then + MsgError = RegistraIE(8, DdlCuentaTransferencia.SelectedValue.ToEntero, TxtImporteTransferencia.Text.ToDecimal, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto) + SaldoPendiente -= TxtImporteTransferencia.Text.ToDecimal + PagoAplicado += TxtImporteTransferencia.Text.ToDecimal + End If - If CveVentaRemision > 0 Then - If MsgError = "" AndAlso Not ObjVentas2.UpdateVentaTicketImpreso(CveVentaRemision, 0) Then + If MsgError = "" AndAlso SaldoPendiente > 0 AndAlso TxtImporteEfectivo.Text.ToDecimal > 0 Then + Dim PagoEfectivo As Decimal = TxtImporteEfectivo.Text.ToDecimal + + PagoAplicado += PagoEfectivo + If PagoAplicado >= SaldoTotalInicial Then + TxtCambio.Text = (PagoAplicado - SaldoTotalInicial).FormatoNumero + PagoEfectivo = SaldoPendiente + End If + MsgError = RegistraIE(13, DdlCuentaEfectivo.SelectedValue.ToEntero, PagoEfectivo, Fecha, CvePrePoliza, VentaActual, ObjIE, ObjConta, ObjVentas2, tCveCorte, CveSubProyecto:=VentaActual.CveSubProyecto) + SaldoPendiente -= PagoEfectivo + End If + + If SaldoPendiente > 0 Then + MsgError = "Tiene saldo pendiente por aplicar" + End If + + If UsuarioActual.CveRol <> 1 Then + If MsgError = "" AndAlso Not ObjVentas2.UpdateVentaCorte(CveVenta, UsuarioActual.CveEmpresa, tCveCorte) Then + MsgError = "Error al aplicar el corte" + End If + End If + + If MsgError = "" AndAlso Not ObjVentas2.UpdateVentaTicketImpreso(CveVenta, 0) Then MsgError = "No se pudo desmarcar la impresión" End If - End If + If CveVentaRemision > 0 Then + If MsgError = "" AndAlso Not ObjVentas2.UpdateVentaTicketImpreso(CveVentaRemision, 0) Then + MsgError = "No se pudo desmarcar la impresión" + End If + End If + + Else + MsgError = "Error al registrar prepólizas" + End If Else - MsgError = "Error al registrar prepólizas" + 'SI NO TIENE SALDO PENDIENTE NO GENERAR POLIZA PARA EL PAGO + RegistrarPago = False End If End If Catch ex As Exception @@ -640,15 +645,25 @@ Partial Class Ventas_PVCobranza If MsgError = "" Then ObjVentas2.Commit() Dim msBuild As New StringBuilder() + Dim MsgTimbrado As String = "" + 'SI SE GENERO FACTURA DE INGRESO, TIMBRARLA DESPUES DE REALIZAR EL PAGO - 'If respFactura IsNot Nothing Then - ' If Not respFactura.Factura.TimbrarFactura() Then - ' msBuild.Append("La factura no se pudo timbrar
") - ' End If - 'End If + If respFactura IsNot Nothing Then + 'VERIFICA SI SE GENERO NC + If respNC IsNot Nothing Then + AjustarTimbre(respFactura.Factura, respNC.Factura) + MsgTimbrado = TimbrarFactura(respFactura.Factura, respNC.Factura) + Else + AjustarTimbre(respFactura.Factura, Nothing) + MsgTimbrado = TimbrarFactura(respFactura.Factura, Nothing) + End If + End If If respFactura IsNot Nothing Then - msBuild.Append($"Pago Registrado correctamente.") + If RegistrarPago Then + msBuild.Append($"Pago Registrado correctamente.") + End If + For Each m In respFactura.Mensajes msBuild.AppendFormat("
{0}", m) Next @@ -663,6 +678,10 @@ Partial Class Ventas_PVCobranza msBuild.Append($"Pago Registrado correctamente.

Imprimir ticket") End If + If Not String.IsNullOrEmpty(MsgTimbrado) Then + msBuild.AppendFormat("
{0}", MsgTimbrado) + End If + Alert(msBuild.ToString(), TipoMensaje.MsgInformacion) Else ObjVentas2.RollBack() @@ -996,6 +1015,79 @@ Partial Class Ventas_PVCobranza Return Retorno End Function + Private Sub AjustarTimbre(ByRef ObjFactura As Modelos.Factura, ByRef ObjNC As Modelos.Factura) + ObjFactura.Timbre.CFDIRelacionados.UUID.Clear() + If HdnTipoAmortizacion.Value = "2" Then + Dim Anticipos = ListaAnticiposAplicados.Where(Function(Obj) Obj.Tipo = "Ant") + For Each Ant As Modelos.MAnticipoRelacionado In Anticipos + ObjFactura.Timbre.CFDIRelacionados.UUID.Add(Ant.FolioFiscal) + Next + + ObjFactura.Timbre.CFDIRelacionados.TipoRelacion = "07" + ObjFactura.Timbre.CFDIRelacionados.TipoRelacionTexto = "07-CFDI por aplicación de anticipo" + + 'AJUSTAR NC + If ObjNC IsNot Nothing Then + ObjNC.Timbre.CFDIRelacionados.UUID.Clear() + + ObjNC.Timbre.CFDIRelacionados.TipoRelacion = "07" + ObjNC.Timbre.CFDIRelacionados.TipoRelacionTexto = "07-CFDI por aplicación de anticipo" + End If + End If + + 'DEVOLUCIONES DE OTRA VENTA, APLICADAS EN UNA NUEVA + If HdnTipoAmortizacion.Value = "4" Then + Dim DevolucionesNC = ListaAnticiposAplicados.Where(Function(Obj) Obj.Tipo = "NC") + For Each Ant As Modelos.MAnticipoRelacionado In DevolucionesNC + ObjFactura.Timbre.CFDIRelacionados.UUID.Add(Ant.FolioFiscal) + Next + + 'TEMPORAL- DEBE SER TIPO RELACION "01 - Nota de crédito de los documentos relacionados" + Dim CveTipoRelacion As Integer = 1 + + ObjFactura.CveTipoRelacion = CveTipoRelacion + + Dim RowTipoRelacion As DataRow = GlobalDTVtaTiposRelacion().FiltroPrimero($"CveTipoRelacion = {CveTipoRelacion}") + + ObjFactura.Timbre.CFDIRelacionados.TipoRelacion = RowTipoRelacion("SATClaveTipoRelacion").ToString() + ObjFactura.Timbre.CFDIRelacionados.TipoRelacionTexto = RowTipoRelacion("SATTipoRelacion").ToString() + + End If + + End Sub + + Private Function TimbrarFactura(ByRef ObjFactura As Modelos.Factura, ByRef ObjNC As Modelos.Factura) As String + Dim MsgErrorTimbrado As String = "" + Dim SeTimbro As Boolean = False + Dim ObjTimbrado As New Timbrado + Try + SeTimbro = ObjTimbrado.TimbrarFactura(UsuarioActual, ObjFactura) + Dim FolioFiscalFactura As String = ObjTimbrado.UUID + MsgErrorTimbrado = ObjTimbrado.MensajeErrorCFDI + ObjTimbrado = Nothing + + If SeTimbro AndAlso ObjNC IsNot Nothing Then + If ObjNC.Timbre IsNot Nothing Then + ObjNC.Timbre.CFDIRelacionados.UUID.Clear() + ObjNC.Timbre.CFDIRelacionados.UUID.Add(FolioFiscalFactura) + + Dim ObjTimbradoNC As New Timbrado + Dim TimbroNC As Boolean = ObjTimbradoNC.TimbrarFactura(UsuarioActual, ObjNC) + + If Not TimbroNC Then + MsgErrorTimbrado = ObjTimbradoNC.MensajeErrorCFDI + End If + ObjTimbradoNC = Nothing + End If + End If + + Catch ex As Exception + OnError("Ocurrió un error al generar el timbrado", ex) + End Try + + Return MsgErrorTimbrado + End Function + Private Function RegistraIE(Metodo As Integer, CveBancoCuenta As Integer, ImportePago As Decimal, Fecha As Date, CvePrePoliza As Integer, VentaActual As Venta, ByRef ObjIE As ClsBancos, ByRef ObjConta As ClsContabilidad, ByRef ObjVentas As ClsVentas, tCveCorte As Integer, Optional Obs As String = "", Optional CveAutorizacion As String = "", Optional CveSubProyecto As Integer = -1) As String Dim Retorno As String = "" Dim CveIEPago As Integer = 0 @@ -1751,7 +1843,11 @@ Partial Class Ventas_PVCobranza Amortizacion += gvr.FCTextBox(String.Format("TxtAnticipo{0}", gvr.RowIndex)).Text.ToDecimal() If DdlTipoAmortizacionAnticipo.SelectedValue = "2" Then - ListaAnticiposAplicados.Add(New Modelos.MAnticipoRelacionado() With {.CveVenta = gvr.DataKey("CveVenta").ToEntero(), .FolioFiscal = gvr.DataKey("FolioFiscal")}) + ListaAnticiposAplicados.Add(New Modelos.MAnticipoRelacionado() With {.CveVenta = gvr.DataKey("CveVenta").ToEntero(), .FolioFiscal = gvr.DataKey("FolioFiscal"), .Tipo = gvr.DataKey("Tipo")}) + End If + + If DdlTipoAmortizacionAnticipo.SelectedValue = "4" Then + ListaAnticiposAplicados.Add(New Modelos.MAnticipoRelacionado() With {.CveVenta = gvr.DataKey("CveVenta").ToEntero(), .FolioFiscal = gvr.DataKey("FolioFiscal"), .Tipo = gvr.DataKey("Tipo")}) End If End If End If From ee1f63551bfa0ea75d287136144a027c1b08346b Mon Sep 17 00:00:00 2001 From: Jonathan Alexis Perez Morales Date: Wed, 23 Oct 2024 15:30:25 -0700 Subject: [PATCH 2/2] --Cambios visuales --- Ventas/PVCobranza.aspx | 240 ++++++++++++++++++++--------------------- 1 file changed, 120 insertions(+), 120 deletions(-) diff --git a/Ventas/PVCobranza.aspx b/Ventas/PVCobranza.aspx index 6e34641e4..a233aa62b 100644 --- a/Ventas/PVCobranza.aspx +++ b/Ventas/PVCobranza.aspx @@ -393,7 +393,11 @@
-
Nombre:
+
+ +   + Nombre: +
         
Folio:
@@ -411,10 +415,6 @@
-
- -
-
@@ -1272,153 +1272,153 @@