From d72e54241501257d322bbb38eba47e1c3b479339 Mon Sep 17 00:00:00 2001 From: Jonathan Alexis Perez Morales Date: Mon, 28 Dec 2020 12:41:41 -0700 Subject: [PATCH] Cancelar movimientos de usados --- App_Code/Modelos.vb | 32 ++++++++++++++++++++ Ventas/Ventas.aspx | 5 ++-- Ventas/Ventas.aspx.vb | 70 +++++++++++++++++++++++++++++++++---------- 3 files changed, 89 insertions(+), 18 deletions(-) diff --git a/App_Code/Modelos.vb b/App_Code/Modelos.vb index 732c68020..a01edf317 100644 --- a/App_Code/Modelos.vb +++ b/App_Code/Modelos.vb @@ -1912,6 +1912,27 @@ Namespace Modelos DtVentasNC.Rows.Add(Dr) End If End Sub + Private Function CancelarMovimientosUsados(factura As Modelos.Factura, UsuarioActual As Usuario, ByRef ObjAcum As ClsAcumuladores) As Boolean + Dim Retorno As Boolean = True + If ObjAcum.DistribuidorMovtosGet(factura.CveCliente, UsuarioActual.CveEmpresa, CveVentaRNCCargo:=factura.CveVenta, CveConcepto:=2) Then + Dim CveConceptoSalida As Integer = 2 + + Dim DtSalidas As DataTable = ObjAcum.DtResultados.FiltraParametros("Cantidad > 0") + If DtSalidas IsNot Nothing AndAlso DtSalidas.Rows.Count > 0 Then + For Each RowSalida As DataRow In DtSalidas.Rows + Dim Cantidad As Decimal = RowSalida("Cantidad").ToString().ToDecimal() * -1 + + If Not ObjAcum.DistribuidorMovtosAdd(factura.CveCliente, Cantidad, RowSalida("CveTamaño").ToString.ToEntero, CveConceptoSalida, factura.CveVenta, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 0D, "") Then + Retorno = False + Exit For + End If + Next + DtSalidas.Dispose() + End If + + End If + Return Retorno + End Function Private Function GuardarUsados(ByRef ObjAcum As ClsAcumuladores, ByRef ObjVentas As ClsVentas, ByRef ObjInventario As ClsInventarios, factura As Modelos.Factura, ByRef Optional Resp As MMensajeFactura = Nothing) As Boolean Dim Resultado As Boolean = True @@ -4574,6 +4595,7 @@ Namespace Modelos Dim ObjInventario As New ClsInventarios(ObjVentas.IniciaTransacSQL()) Dim ObjContrato As New ClsContratos(ObjVentas.IniciaTransacSQL()) Dim ObjEventos As New ClsOIEventos(ObjVentas.IniciaTransacSQL()) + Dim ObjAcum As New ClsAcumuladores(ObjVentas.IniciaTransacSQL()) Dim ObjAC As ClsContPAQi = Nothing If UsuarioActual.Empresa.UsaAC Or UsuarioActual.Empresa.Funcionalidad(200) = "1" Then @@ -4990,6 +5012,16 @@ Namespace Modelos End If End If + 'CANCELA MOVIMIENTOS DE USADOS + If Not ErrorCancelar Then + If ObjFactura.TipoDocto = "Ing" Then + If Not CancelarMovimientosUsados(ObjFactura, UsuarioActual, ObjAcum) Then + ErrorCancelar = True + MensajeError = "Ocurrió un error al cancelar los movimientos de usados" + End If + End If + End If + End If 'MARCA LA VENTA PARA REALIZAR LA DEVOLUCION POSTERIORMENTE diff --git a/Ventas/Ventas.aspx b/Ventas/Ventas.aspx index 940dd9a15..be2b24622 100644 --- a/Ventas/Ventas.aspx +++ b/Ventas/Ventas.aspx @@ -7791,6 +7791,7 @@ var totalCheque = ToDouble($get("TxtImporteCheque").value); var totalTransferencia = ToDouble($get("TxtImporteTransferencia").value); var totalRNC = ToDouble($get("HdnTotalRNC").value); + var totalAmortizado = ToDouble($get("HdnAnticipos").value); var TotalOtrosContado = 0; @@ -7800,7 +7801,7 @@ } } catch (e) { } - var total = totalEfectivo + totalCredito + totalDebito + totalCheque + totalTransferencia + TotalOtrosContado + totalRNC; + var total = totalEfectivo + totalCredito + totalDebito + totalCheque + totalTransferencia + TotalOtrosContado + totalRNC + totalAmortizado; var totalVenta = ToDouble($get('TxtTotal').value); if (total > totalVenta) { @@ -7809,7 +7810,7 @@ $get("TxtCambio").value = "0.00"; } - $get("TxtImporteContado").value = total - totalRNC; + $get("TxtImporteContado").value = total - totalRNC - totalAmortizado; } // **************************************************************************************************************************************************************************** diff --git a/Ventas/Ventas.aspx.vb b/Ventas/Ventas.aspx.vb index 52c048cd1..f7cd4ecd5 100644 --- a/Ventas/Ventas.aspx.vb +++ b/Ventas/Ventas.aspx.vb @@ -10084,8 +10084,9 @@ Partial Class Ventas End If End If - If tPS.Length > 1000 Then - tPS = tPS.Remove(999, tPS.Length - 1) + If tPS.Length >= 1000 Then + Dim tPSRecortado = tPS.Remove(999, tPS.Length - 999) + tPS = tPSRecortado End If 'condicionante, especial @@ -10690,8 +10691,14 @@ Partial Class Ventas factura.Timbre.Comprobante.Serie = ObjVentas.Serie factura.Timbre.Comprobante.Folio = ObjVentas.Folio.ToString() - If Not GuardarUsados(ObjVentas.IniciaTransacSQL, factura) Then - ErrorList.Add("Error al guardar usados") + If ObjFactura.TipoDocto = "Ing" Then + If Not GuardarUsados(2, ObjVentas.IniciaTransacSQL, factura) Then + ErrorList.Add("Error al guardar usados") + End If + ElseIf ObjFactura.TipoDocto = "Dev" Then + If Not GuardarUsados(1, ObjVentas.IniciaTransacSQL, factura) Then + ErrorList.Add("Error al guardar usados") + End If End If If factura.TipoDocto = "Egs" AndAlso NuevaFactura = 1 Then @@ -12109,7 +12116,7 @@ Partial Class Ventas importeMovimiento = 0 Case 103 'Descuento - If ObjFactura.Descuento <> 0 AndAlso Not ObjFactura.TipoDocto.Contiene("Rem", "RNC") AndAlso DdlTipoAmortizacionAnticipo.SelectedValue = "-1" Then + If ObjFactura.Descuento <> 0 AndAlso Not ObjFactura.TipoDocto.Contiene("Rem", "RNC") AndAlso (DdlTipoAmortizacionAnticipo.SelectedValue = "-1" OrElse UsuarioActual.CveEmpresa = 141) Then importeMovimiento = ObjFactura.Descuento * Multiplicador * ValorMultiplicador importeMX = Math.Round(importeMovimiento, 2) * tipoCambio * Multiplicador * ValorMultiplicador @@ -14319,6 +14326,7 @@ Partial Class Ventas 'cuando es amortización por NOTA DE CREDITO If DdlTipoAmortizacionAnticipo.SelectedValue = "2" Then LblAntAplicados.Text = String.Format("Amortización por Nota de Crédito: {0:C}", Amortizacion) : LblAntAplicados.Visible = True + HdnAnticipos.Value = Amortizacion.RoundSQL(2).ToString() Amortizacion = 0 HdnTipoDescuento.Value = "-1" HdnDescuento.Value = "0" @@ -16425,7 +16433,7 @@ Partial Class Ventas Dim Row As DataRow = Nothing Dim TotalCalculableImpuestos As Decimal = 0 Dim TotalCalculableImpuestosIVA As Decimal = 0 - PU = PU.RoundAD(6) ' el precio unitario puede llevar hasta 6 decimales permitidos + PU = PU.RoundSQL(6) ' el precio unitario puede llevar hasta 6 decimales permitidos If Not TmpDT.Columns.Contains("RetIVA") Then TmpDT.Columns.Add("RetIVA", GetType(Decimal)) @@ -16555,24 +16563,24 @@ Partial Class Ventas Row("IVA") = Row("PorcentajeIVA") - Row("ImporteIVA") = (Row("PorcentajeIVA").ToString().ToDecimal * TotalCalculableImpuestosIVA).RoundAD(NumeroDecimales) - Row("ImporteRetIVA") = (ClienteRetIVA * TotalCalculableImpuestos).RoundAD(NumeroDecimales) + Row("ImporteIVA") = (Row("PorcentajeIVA").ToString().ToDecimal * TotalCalculableImpuestosIVA).RoundSQL(NumeroDecimales) + Row("ImporteRetIVA") = (ClienteRetIVA * TotalCalculableImpuestos).RoundSQL(NumeroDecimales) - Row("RetIVA") = (ClienteRetIVA * TotalCalculableImpuestos).RoundAD(NumeroDecimales) + Row("RetIVA") = (ClienteRetIVA * TotalCalculableImpuestos).RoundSQL(NumeroDecimales) - Row("ImporteRetISR") = (ClienteRetISR * TotalCalculableImpuestos).RoundAD(NumeroDecimales) + Row("ImporteRetISR") = (ClienteRetISR * TotalCalculableImpuestos).RoundSQL(NumeroDecimales) Row("PorcentajeRetIVA") = ClienteRetIVA Row("PorcentajeRetISR") = ClienteRetISR Row("PorcentajeIEPS") = DrPS("IEPSPorcentaje") - Row("ImporteIEPS") = (DrPS("IEPSPorcentaje").ToString().ToDecimal * TotalCalculableImpuestos).RoundAD(NumeroDecimales) + Row("ImporteIEPS") = (DrPS("IEPSPorcentaje").ToString().ToDecimal * TotalCalculableImpuestos).RoundSQL(NumeroDecimales) Row("IEPS") = Row("ImporteIEPS") - Row("Descuento") = (Descuento).RoundAD(NumeroDecimales) + Row("Descuento") = (Descuento).RoundSQL(NumeroDecimales) Row("TipoDescuento") = HdnTipoDescuento.Value Row("CvePromocionDetalle") = CvePromocionDetalle Row("Total") = (Cantidad * PU) - Row("TotalImporte") = (Cantidad * PU).RoundAD(NumeroDecimales) + Row("TotalImporte") = (Cantidad * PU).RoundSQL(NumeroDecimales) 'Row("AsientoContableVentas") = DrPS("AsientoContableVentas") ' Row("IdCtaContVentas") = IdCtaContable @@ -26545,6 +26553,12 @@ Partial Class Ventas Return Nothing End Function Private Function AgregaPSCotizacion() As Boolean + 'Dim ObjFactCotizacion As New Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa) + + 'Dim TotalCotizacion As Decimal = ObjFactCotizacion.Total 'TmpDT.SUM("TotalImporte").ToDecimal() + TmpDT.SUM("ImporteIVA").ToDecimal() + TmpDT.SUM("ImporteIEPS").ToDecimal() - TmpDT.SUM("ImporteRetIVA").ToDecimal() - TmpDT.SUM("ImporteRetISR").ToDecimal() + + 'ObjFactCotizacion.Dispose() + If DtCotizacionesPS IsNot Nothing Then Dim tCantidad As Decimal = 0 For Each Dr As DataRow In DtCotizacionesPS.Select() @@ -26554,6 +26568,15 @@ Partial Class Ventas Dr("CveProyecto").ToString().ToEntero(), Dr("Proyecto").ToString(), Dr("CveSubProyecto").ToString().ToEntero(), Dr("SubProyecto").ToString(), CveContratoDetalle:=Dr("CveContratoDetalle").ToString().ToEntero(), CveVentaDetalleCotizacion:=Dr("CveVentaDetalle").ToString().ToEntero(), SeActualiza:=True) Next + 'Dim TotalFactura = TmpDT.SUM("TotalImporte").ToDecimal() + TmpDT.SUM("ImporteIVA").ToDecimal() + TmpDT.SUM("ImporteIEPS").ToDecimal() - TmpDT.SUM("ImporteRetIVA").ToDecimal() - TmpDT.SUM("ImporteRetISR").ToDecimal() + + 'Dim Diferencia As Decimal = TotalCotizacion - TotalFactura + + 'If Diferencia <> 0 Then + ' Dim LastRow As DataRow = TmpDT.Rows(TmpDT.Rows.Count - 1) + ' LastRow("ImporteIVA") = LastRow("ImporteIVA").ToString().ToDecimal() - Diferencia + 'End If + CalculaTotalesVenta() Return True Else @@ -26566,6 +26589,9 @@ Partial Class Ventas #Region " COTIZACIONES - FACTURAR " Private Function PreparaFacturarCotizacion() As Boolean 'LIMPIAMOS + + 'Dim TotalCotizacion As Decimal = TxtTotal.Text.Replace(",", "").ToDecimal() + TmpDT.Rows.Clear() TxtSubTotal.Text = "0.00" TxtSubTotal2.Text = "0.00" @@ -26594,6 +26620,18 @@ Partial Class Ventas Return False End If + 'Dim TotalFactura As Decimal = TmpDT.SUM("TotalImporte").ToDecimal() + TmpDT.SUM("ImporteIVA").ToDecimal() + TmpDT.SUM("ImporteIEPS").ToDecimal() - TmpDT.SUM("ImporteRetIVA").ToDecimal() - TmpDT.SUM("ImporteRetISR").ToDecimal() + + 'Dim Diferencia As Decimal = TotalCotizacion - TotalFactura + + 'If Diferencia <> 0 Then + ' Dim LastRow As DataRow = TmpDT.Rows(TmpDT.Rows.Count - 1) + + ' LastRow("ImporteIVA") = LastRow("ImporteIVA").ToString().ToDecimal() + Diferencia + + ' CalculaTotalesVenta() + 'End If + If TmpDT.Rows.Count = 0 Then Alert("No hay conceptos por facturar de esta cotización o ha sido cambiada su información. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) Return False @@ -27985,17 +28023,17 @@ Partial Class Ventas End If End Sub - Private Function GuardarUsados(SqlTransaccion As SqlClient.SqlTransaction, factura As Modelos.Factura) As Boolean + Private Function GuardarUsados(CveConcepto As Integer, SqlTransaccion As SqlClient.SqlTransaction, factura As Modelos.Factura) As Boolean Dim Resultado As Boolean = True - If ClienteEsDistribuidor AndAlso factura.TipoDocto.Contiene("Ing") Then + If ClienteEsDistribuidor Then Dim ObjAcum As New ClsAcumuladores(SqlTransaccion) Dim CvePSPSA As Integer = UsuarioActual.Empresa.Funcionalidad(533).ToEntero For Each drow As DataRow In factura.DtDetalle.Rows If drow("CveTamaño").ToString.ToEntero > 0 And (CvePSPSA <> drow("CvePS").ToString.ToEntero) Then - If Not ObjAcum.DistribuidorMovtosAdd(factura.CveCliente, drow("Cantidad").ToString.ToEntero, drow("CveTamaño").ToString.ToEntero, 2, factura.CveVenta, UsuarioActual.CveUsuario, + If Not ObjAcum.DistribuidorMovtosAdd(factura.CveCliente, drow("Cantidad").ToString.ToEntero, drow("CveTamaño").ToString.ToEntero, CveConcepto, factura.CveVenta, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 0D, "") Then Resultado = False Exit For