From 877476625da2c3ed04cae8dd84cf2f7ef574d871 Mon Sep 17 00:00:00 2001 From: rrene Date: Tue, 21 Jan 2025 09:17:31 -0700 Subject: [PATCH] =?UTF-8?q?--=20generaci=C3=B3n=20de=20anticipos=20timbrad?= =?UTF-8?q?o,=20mejora?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ventas/ClientesAbonar.aspx | 21 ++++-- Ventas/ClientesAbonar.aspx.vb | 117 +++++++++++++++++++++++++++++++++- 2 files changed, 132 insertions(+), 6 deletions(-) diff --git a/Ventas/ClientesAbonar.aspx b/Ventas/ClientesAbonar.aspx index 349c86a99..bae240e5f 100644 --- a/Ventas/ClientesAbonar.aspx +++ b/Ventas/ClientesAbonar.aspx @@ -205,10 +205,14 @@
Anticipo:
-
+
-
+
Sucursal:
+
+ + +
@@ -831,7 +835,7 @@ var chkPesosBancos = $get("ChkPagarPesos"); var chkDolaresBancos = $get("ChkPagarDolares"); - + debugger; if (t.checked) { txt.value = FormatoNumero(importe, 2); @@ -853,8 +857,15 @@ } } - function SumaValores(pagoMultiple, monedaPago) { + function FnRecalcula(pagoMultiple,monedaPago) + { + var Suma = SumaValores(pagoMultiple, monedaPago); + $get('TxtImporte').value = FormatoNumero(Suma, 2); + $('#LtlTotalMXN').text(FormatoNumero(Suma, 2)) + } + function SumaValores(pagoMultiple, monedaPago) { + var Importe = 0; var Comision = 0.00; var topLevelElem = document.getElementById("form1"); @@ -945,7 +956,7 @@ $get('TxtAnticipo').value = 0.00 } else { - Importe = Importe + ToDouble($get('TxtAnticipo').value); + Importe = Importe + ToDouble($get('TxtAnticipo').value); } } if ($get('TxtPrestamoImporte') != null) { diff --git a/Ventas/ClientesAbonar.aspx.vb b/Ventas/ClientesAbonar.aspx.vb index 6a927a74e..bad559dc2 100644 --- a/Ventas/ClientesAbonar.aspx.vb +++ b/Ventas/ClientesAbonar.aspx.vb @@ -4,6 +4,7 @@ Imports System.Data Imports ADSTimbrado Imports Extensiones +Imports Org.BouncyCastle.Ocsp Partial Class Ventas_ClientesAbonar Inherits ClsPaginas @@ -343,6 +344,13 @@ Partial Class Ventas_ClientesAbonar DtPrestamos = CargaPrestamos(1) End If + If UsuarioActual.Empresa.Funcionalidad(382) = "1" Then 'GDIaz + divAnticipo.Visible = True + TxtAnticipo.Attributes.Add("onKeyUp", "FnRecalcula(0,1);") + DivAntSubProyecto.Visible = True + DivAntSubProyectoTexto.visible = True + CargarCentrosDeCosto(Nothing, DdlSubProyectos, Nothing, Nothing, AplicaTodos:="") + End If CargaDatos(tCveMoneda) Else Alert("El Cliente Solicitado no existe, por favor revise su búsqueda.", TipoMensaje.MsgAdvertencia) @@ -758,7 +766,8 @@ Partial Class Ventas_ClientesAbonar Dim MsgError As String = "" Dim NCGeneradas As New List(Of RespuestaNotaCredrito) Dim ListaFacturasGenerarNC As New List(Of Modelos.Factura) - + Dim ObjFacturaAnt As Modelos.Factura = Nothing + Dim RespAnt As Modelos.Factura.MMensajeFactura = Nothing Dim ImporteSeleccionado As Decimal = 0 '02-05-2018 MANDAMOS CANCELAR EL COMPLEMENTO A SUSTITUIR @@ -1176,12 +1185,79 @@ Partial Class Ventas_ClientesAbonar End If End If + If UsuarioActual.Empresa.Funcionalidad(382) = "1" AndAlso MsgError = "" Then '' si es empresa GDiaz + 'generar un anticipo y registrarle el pago. + + Dim tCveMoneda As Integer = 1 + Dim tCveFormaPago As Integer = GlobalDTTipoTransacciones().FiltroPrimeroValor("CveFormaPago", $"CveTipoTransaccion={DdlTipoTransaccion.SelectedValue}").ToEntero + Dim tCvePS As Integer + Dim tCveUM As Integer = 0 + Dim tCveSub As Integer = DdlSubProyectos.SelectedValue.ToEntero + ObjFacturaAnt = Modelos.Factura.CrearVentaNueva(UsuarioActual, tCveSub, CveCliente, tCveMoneda, "Ant") + ObjFacturaAnt.CveMoneda = tCveMoneda + ObjFacturaAnt.CveFormaPago = tCveFormaPago + ObjFacturaAnt.CveMetodoPago = 1 + ObjFacturaAnt.ClaveMetodoPagoSAT = "PUE" + ObjFacturaAnt.ClaveFormaPagoSAT = GlobalDTVtaFormaPago.FiltroPrimeroValor("ClaveFormaPagoSAT", $"CveFormaPago = {ObjFacturaAnt.CveFormaPago}") + ObjFacturaAnt.ClaveUsoCFDISAT = GlobalDTSATUsosCFDI.FiltroPrimeroValor("UsoCFDI", $"CveUsoCFDI = {ObjFacturaAnt.CveUsoCFDI}") + + Dim drPS As DataRow = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CodigoSATPS:="84111506").FiltroPrimero("PSCodigo LIKE '%ANTICIPO%' OR PSCodigo LIKE '%anticipo%' OR PSCodigo LIKE '%Anticipo%'") + Dim tPorIVA As Decimal = GlobalDTSubProyectos(UsuarioActual.CveEmpresa, CveSubProyecto:=tCveSub).FiltroPrimeroValor("IVA").ToDecimal + Dim tPU As Decimal = (TxtAnticipo.Text.ToDecimal / (1 + tPorIVA)).RoundSQL(6) + If drPS IsNot Nothing Then + tCvePS = drPS("CvePS").ToString.ToEntero + tCveUM = drPS("CveUnidadMedida").ToString.ToEntero + End If + ObjFacturaAnt.AgregarPS(tCvePS, 1, tPU, 0, "", CveUM:=tCveUM, CveSubProyecto:=tCveSub, PorcentajeIVA:=tPorIVA) + ObjFacturaAnt.CalculaTotales() + RespAnt = ObjFacturaAnt.EmitirFactura(False, Transac:=ObjMov.IniciaTransacSQL(), Modulo:="Ventas/ClientesAbonarAnt", MostrarURL:=True) + RespAnt.Factura = ObjFacturaAnt + + If RespAnt IsNot Nothing AndAlso RespAnt.Factura IsNot Nothing Then + + Dim VentaActual As New Venta(UsuarioActual) + VentaActual.CveVenta = RespAnt.Factura.CveVenta + VentaActual.Fecha = RespAnt.Factura.Fecha + VentaActual.CveCliente = CveCliente + VentaActual.CveMoneda = tCveMoneda + VentaActual.TipoDocto = "Ant" + VentaActual.SerieFolio = RespAnt.Factura.SerieFolio + VentaActual.ClienteNombre = NombreComercial + VentaActual.TC = 1 + VentaActual.Total = TxtAnticipo.Text.ToDecimal + VentaActual.IVA = (tPorIVA * tPU).RoundSQL(2) + + VentaActual.PorcentajeIVA = tPorIVA + VentaActual.CveSubProyecto = tCveSub + 'Importe de pago + Dim Pago As New VentaPago + Pago.TipoPago = "XXX" + Pago.Fecha = TxtFechaDocumento.Text.ToDate + Pago.CveIE = CveIE + Pago.CveMonedaPago = tCveMoneda + Pago.ImportePago = TxtAnticipo.Text.ToDecimal + Pago.ImportePagoVenta = TxtAnticipo.Text.ToDecimal + Pago.Referencia = TxtFolio.Text + Pago.TipoPago = "XXX" + 'If RblTipoPago.SelectedValue = "3" Then + ' Pago.TipoPago = "I" + ' Pago.FechaDocumentoRelacionado = FechaIngreso + ' Pago.CveClientePago = CveCliente + 'End If + 'MsgError = RespAnt.Mensajes.ToString + If MsgError = "" AndAlso AplicaPrePolizaPagoVenta(VentaActual, Pago, CvePrePoliza, ObjMov) Then + MsgError = "No se pudo insertar la póliza" + End If + End If + End If + If MsgError = "" AndAlso Not ObjMov.ValidacionesPrePoliza(CvePrePoliza, UsuarioActual, Opcion:=3) Then MsgError = ObjMov.MensajePolizaDescuadre & " La diferencia es de: " & ObjMov.ValorDiferencia 'If ObjMov.ValorPolizaDescuadre > 0 Then ' MsgError = ObjMov.MensajePolizaDescuadre & " La diferencia es de: " & ObjMov.ValorDiferencia 'End If End If + Else MsgError = "No se pudo insertar la póliza" End If @@ -1326,6 +1402,25 @@ Partial Class Ventas_ClientesAbonar End If Next + If ObjFacturaAnt IsNot Nothing Then + Dim MsgTimbrado As String = "" + Try + ObjFacturaAnt.PreparaTimbre() + MsgTimbrado = TimbrarFactura(ObjFacturaAnt, True) + StrMsg.AppendFormat("

Anticipo generado correctamente.
Folio: {1}
", ObjFacturaAnt.CveVenta, ObjFacturaAnt.SerieFolio) + + If Not String.IsNullOrEmpty(MsgTimbrado) Then + Dim StrEr As String = $"
Comprobante no emitido :
{MsgTimbrado}
Por favor inténtelo de nuevo a través del botón 'Emitir' en ventas.
" + StrMsg.AppendFormat("
{0}
", StrEr) + End If + + Catch ex As Exception + GuardaLogAD(ex.ToString()) + StrMsg.AppendFormat("
{0}
", MsgTimbrado) + End Try + + End If + If ChkComplementoPago.Checked Then Dim TextoComplementoPago As String = EmitirComplementoPago(CveIE, CveVentasPago, SeriesPago) StrMsg.AppendFormat("

{0}", TextoComplementoPago) @@ -1352,6 +1447,26 @@ Partial Class Ventas_ClientesAbonar End Sub + Private Function TimbrarFactura(ByRef ObjFactura As Modelos.Factura, ByRef SeTimbro As Boolean) As String + Dim MsgErrorTimbrado As String = "" + + Dim ObjTimbrado As New Timbrado + Try + SeTimbro = ObjTimbrado.TimbrarFactura(UsuarioActual, ObjFactura) + Dim FolioFiscalFactura As String = ObjTimbrado.UUID + MsgErrorTimbrado = ObjTimbrado.MensajeErrorCFDI + ObjTimbrado = Nothing + + Catch ex As Exception + OnError("Ocurrió un error al generar el timbrado", ex) + End Try + + If Not String.IsNullOrEmpty(MsgErrorTimbrado) Then + GuardaLogAD(MsgErrorTimbrado, Archivo:="LogTimbrado") + End If + + Return MsgErrorTimbrado + End Function Private Function RegistraAmortizacionAnticipo(ByRef ObjMov As ClsContabilidad, CvePrePoliza As Integer, CveIE As Integer, Importe As Decimal, tipoCambioPago As Decimal, CveVenta As Integer, ReferenciaVenta As String, ReferenciaPago As String) As String Dim MsgError As String = "" If CveMonedaPago = 2 Then