From 7d6fd2cf07867f8f75fbd8cb7b6aff8c9020a664 Mon Sep 17 00:00:00 2001 From: Jonathan Alexis Perez Morales Date: Sat, 22 Feb 2025 14:38:02 -0700 Subject: [PATCH] --FIX validar condiciones comerciales --- Ventas/Ventas.aspx.vb | 134 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) diff --git a/Ventas/Ventas.aspx.vb b/Ventas/Ventas.aspx.vb index e5cc8fd16..bc0e3cf97 100644 --- a/Ventas/Ventas.aspx.vb +++ b/Ventas/Ventas.aspx.vb @@ -9310,7 +9310,8 @@ Partial Class Ventas End If 'SI ESTA HABILITADO LA OPCION DE DESCUENTO, SE AGREGO UN DESCUENTO MANUAL Y NO TIENE PROMOCION - If GvPS.Rows(e.RowIndex).FCTextBox("TxtDescuento").Enabled AndAlso CvePSAnterior = CvePSNuevo Then 'AndAlso (ObjDescuento.CvePromocionDetalle <= 0 AndAlso ObjDescuento.ImporteDescuento <= 0) Then + + If GvPS.Rows(e.RowIndex).FCTextBox("TxtDescuento").Enabled AndAlso CvePSAnterior = CvePSNuevo AndAlso Not (ObjDescuento.NombrePromo = "CONDICIONES COMERCIALES") Then ObjDescuento.ImporteDescuento = DescuentoManual End If @@ -10577,6 +10578,31 @@ Partial Class Ventas Exit Sub End If + 'VALIDAR CONDICONES COMERCIALES + If UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso DdlTipoComprobante.SelectedValue.Contiene("Ing", "Rem", "Cot") Then + CargaPorcentajeMarcas() + Dim ValidoDescuentos As Boolean = True + + If DtPorcentajeMarcas IsNot Nothing AndAlso DtPorcentajeMarcas.Rows.Count > 0 Then + For Each Row As DataRow In TmpDT.Rows + Dim CvePS As Integer = Row("CvePS").ToString().ToEntero() + Dim Cantidad As Decimal = Row("Cantidad").ToString().ToDecimal() + Dim PU As Decimal = Row("PU").ToString().ToDecimal() + Dim Descuento As Decimal = Row("Descuento").ToString().ToDecimal() + + If Not ValidaPorcentajeMarcas(CvePS, Cantidad, PU, Descuento) Then + ValidoDescuentos = False + Exit For + End If + Next + End If + + If Not ValidoDescuentos Then + Exit Sub + End If + + End If + 'validaciones, si es Anticipo solo permitir "servicios de facturación" y si es ingreso todos menos serv. factu If UsuarioActual.Empresa.Funcionalidad(601) <> "" Then If UsuarioActual.Empresa.Funcionalidad(601) = "1" AndAlso DdlTipoComprobante.SelectedValue = "Ant" Then 'valida anticipo que tenga conceptos válidos @@ -20429,6 +20455,8 @@ Partial Class Ventas If PorcentajeProducto > 0 Then Descuento += ((Cantidad * PU) - TotalFinal) + + ObjDescuento.NombrePromo = "CONDICIONES COMERCIALES" End If 'SI TIENE PRONTO PAGO CALCULA EL IMPORTE @@ -20493,6 +20521,110 @@ Partial Class Ventas Return ObjDescuento End Function + + Public Function ValidaPorcentajeMarcas(CvePS As Integer, Cantidad As Decimal, PU As Decimal, DescPS As Decimal) As Boolean + Dim Retorno As Boolean = False + + Dim Descuento As Decimal = 0 + + Dim ValidaCondicionesComerciales As Boolean = True + + Dim CveMarcaPS As Integer = -1 + Dim CveClasifPS As Integer = -1 + Dim CveRinTamañoPS As Integer = -1 + Dim PSCodigo As String = "" + + Dim DrPS As DataRow = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CvePS:=CvePS).FiltroPrimero("") + If DrPS IsNot Nothing Then + + CveMarcaPS = DrPS("CveMarca").ToString().ToEntero() + CveClasifPS = DrPS("CveClasificacion").ToString().ToEntero() + CveRinTamañoPS = DrPS("CveRinTamaño").ToString().ToEntero() + PSCodigo = DrPS("PSCodigo").ToString() + + If CveClasifPS = 20636 Then + ValidaCondicionesComerciales = False + End If + + 'CAMBIO DE VIGENCIA NO SE APLICAN DESCUENTOS + If CveClasifPS = 20637 Then + Descuento = 0 + Retorno = True + Return Retorno + End If + End If + + + If ValidaCondicionesComerciales Then + 'VERIFICA SI APLICAN CONDICIONES COMERCIALES + If DtPorcentajeMarcas IsNot Nothing AndAlso DtPorcentajeMarcas.Rows.Count > 0 Then + 'VERIFICA SI EL PRODUCTO TIENE ESPECIFICADA UNA MARCA + If Not String.IsNullOrEmpty(DrPS("CveMarca").ToString()) AndAlso DrPS("CveMarca").ToString().ToEntero() > 0 Then + Dim RowPorcentaje As DataRow = DtPorcentajeMarcas.FiltroPrimero($"CveMarca={DrPS("CveMarca").ToString()}") + 'REALIZA LOS DESCUENTOS DE ACUERDO AL PORCENTAJE POR MARCA + If RowPorcentaje IsNot Nothing Then + '(AHORA LOS DESCUENTOS SON ACUMULABLES) + 'Descuento = 0 + Dim PorcentajeProducto As Decimal = RowPorcentaje("PorcentajeProducto").ToString().ToDecimal() / 100D + Dim PorcentajeProducto2 As Decimal = RowPorcentaje("PorcentajeProducto2").ToString().ToDecimal() / 100D + Dim PorcentajeProducto3 As Decimal = RowPorcentaje("PorcentajeProducto3").ToString().ToDecimal() / 100D + + Dim TotalInicial As Decimal = (Cantidad * (PU)) '- Descuento + Dim TotalFinal As Decimal = TotalInicial + 'SI APLICA EL PRIMER DESCUENTO + If PorcentajeProducto > 0 Then + Dim Descuento1 As Decimal = (TotalInicial * PorcentajeProducto).RoundSQL(2) + Dim Total2 As Decimal = (TotalInicial - Descuento1) + + 'SI APLICA EL SEGUNDO DESCUENTO + If PorcentajeProducto2 > 0 Then + Dim Descuento2 As Decimal = (Total2 * PorcentajeProducto2).RoundSQL(2) + Dim Total3 As Decimal = (Total2 - Descuento2) + + 'SI APLICA EL TERCER DESCUENTO + If PorcentajeProducto3 > 0 Then + Dim Descuento3 As Decimal = (Total3 * PorcentajeProducto3).RoundSQL(2) + TotalFinal = Total3 - Descuento3 + Else + TotalFinal = Total3 + End If + Else + TotalFinal = Total2 + End If + Else + TotalFinal = TotalInicial + End If + + If PorcentajeProducto > 0 Then + Descuento += ((Cantidad * PU) - TotalFinal) + End If + + If Descuento.RoundSQL(2) <> DescPS.RoundSQL(2) Then + Retorno = False + Else + Retorno = True + End If + + Else + Retorno = True + End If + Else + Retorno = True + End If + Else + Retorno = True + End If + Else + Retorno = True + End If + + If Not Retorno Then + Alert($"No coinciden las condiciones comerciales con el descuento.
Cantidad: {Cantidad.FormatoNumero()}
Producto: '{PSCodigo}'
Precio: {PU.FormatoNumero()}
Descuento: {DescPS.FormatoNumero()}
Descuento por condiciones comerciales: {Descuento.FormatoNumero()}", TipoMensaje.MsgError) + End If + + Return Retorno + End Function + 'Private ReadOnly Property ClasificacionesDescuentos As Dictionary(Of Integer, Decimal) ' Get ' Return New Dictionary(Of Integer, Decimal) From {