descuento condiciones comerciales

This commit is contained in:
2022-01-18 15:38:13 -07:00
parent 6b3f0e6c95
commit aded3fea18

View File

@@ -34,7 +34,7 @@ Partial Class PV
Private Property FolioXML As String Private Property FolioXML As String
Private Property SubTotal As Decimal Private Property SubTotal As Decimal
Private Property Total As Decimal = 0 Private Property Total As Decimal = 0
Private Property Descuentos As Decimal = 0 'Private Property Descuentos As Decimal = 0
Private Property EmisorRFC As String Private Property EmisorRFC As String
Private Property ReceptorRFC As String Private Property ReceptorRFC As String
Private Property TrasladoIVA As Decimal = 0 Private Property TrasladoIVA As Decimal = 0
@@ -83,6 +83,15 @@ Partial Class PV
End Set End Set
End Property End Property
Private Property DtPorcentajeMarcas As DataTable
Get
Return If(IsNothing(ViewState("DtPorcentajeMarcas")), Nothing, CType(ViewState("DtPorcentajeMarcas"), DataTable))
End Get
Set(value As DataTable)
ViewState("DtPorcentajeMarcas") = value
End Set
End Property
Private Property RemisionesLista As List(Of Integer) Private Property RemisionesLista As List(Of Integer)
Get Get
Return If(IsNothing(ViewState("RemisionesLista")), Nothing, CType(ViewState("RemisionesLista"), List(Of Integer))) Return If(IsNothing(ViewState("RemisionesLista")), Nothing, CType(ViewState("RemisionesLista"), List(Of Integer)))
@@ -2576,6 +2585,12 @@ Partial Class PV
If Not String.IsNullOrEmpty(ObjCliente.Vendedor) Then If Not String.IsNullOrEmpty(ObjCliente.Vendedor) Then
LbVendedor.Text = GlobalDTVendedores(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Vendedor", $"CveVendedor = {ObjCliente.Vendedor}") LbVendedor.Text = GlobalDTVendedores(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Vendedor", $"CveVendedor = {ObjCliente.Vendedor}")
End If End If
' si es empresa acumuladores
If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then
CargaPorcentajeMarcas()
End If
Else Else
TrEsDistribuidor.Visible = False TrEsDistribuidor.Visible = False
End If End If
@@ -2697,6 +2712,14 @@ Partial Class PV
UPCondicionesPago.Update() UPCondicionesPago.Update()
End Sub End Sub
Private Sub CargaPorcentajeMarcas()
Dim ObjPS As New ClsProductosServicios
If ObjPS.GetPorcentajeMarcas(CveCliente) Then
DtPorcentajeMarcas = ObjPS.DtResultados.Copy()
End If
ObjPS.Dispose()
End Sub
Private Sub CambiaSucursal() Private Sub CambiaSucursal()
CargaFormatoSucursal() CargaFormatoSucursal()
CargaFolios() CargaFolios()
@@ -4134,6 +4157,176 @@ Partial Class PV
UpAddVenta.Update() UpAddVenta.Update()
UPPDescuento.Update() UPPDescuento.Update()
End Sub End Sub
Partial Class Descuentos
Public ImporteDescuento As Decimal = 0
Public CvePromocionDetalle As Integer = -1
Public PU As Decimal = 0
Public EsPUModificado As Boolean = False
Public ImporteProntoPago As Decimal = 0
End Class
Private Function CalcularDescuentos(CvePS As Integer, Cantidad As Decimal, PU As Decimal) As Descuentos
Dim Descuento As Decimal = HdnDescuento.Value.ToDecimal
If HdnTipoDescuento.Value = "0" Then
Descuento = HdnDescuento.Value.ToDecimal * Cantidad
End If
Dim ValidaCondicionesComerciales As Boolean = True
'AGREGA PROMOCION EN EL DESCUENTO
Dim TipoPromo As Integer = 0
Dim TotalPromocion As Decimal = 0
Dim PromocionPorcentaje As Decimal = 0
Dim PUModificado As Decimal = 0
Dim SeAjustoPU As Boolean = False
Dim PUPromocion As Decimal = 0
Dim CantMinima As Integer = 0
Dim CveMarcaPS As Integer = 0
Dim CveClasifPS As Integer = 0
Dim CveRinTamañoPS As Integer = 0
Dim CvePromocionDetalle As Integer = 0
Dim IncluyeImpuestos As Boolean = False
Dim TipoAplicacion As Integer = 1 ' 1 - descuento, 2 en PU
Dim ObjDescuento As New Descuentos
If DdlSubProyectoDatos.SelectedValue = "11842" Then '' E141, el subproyecto: Franquicia, no proceden las promociones
Return ObjDescuento
End If
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()
If CveClasifPS = 20636 Then
ValidaCondicionesComerciales = False
End If
End If
Dim dr As DataRow = Nothing
If DtPromociones IsNot Nothing AndAlso DtPromociones.Rows.Count > 0 Then
dr = DtPromociones.FiltroPrimero(String.Format("CvePS = {0} AND (CveSubProyecto = {1} OR CveSubProyecto IS NULL) AND (CveRinTamaño = {2} OR CveRinTamaño IS NULL) AND ((TipoPromocion <> 3 AND (CantidadMinima <= {3} OR CantidadMinima IS NULL)) OR (TipoPromocion = 3 AND CantidadMinima <= {3} ))", CvePS, DdlSubProyectoDatos.SelectedValue, CveRinTamañoPS, Cantidad), Orderby:="CantidadMinima desc ")
If dr Is Nothing Then
'verifica marca, si tiene asignada la promocion
dr = DtPromociones.FiltroPrimero(String.Format("CvePS IS NULL AND CveClasificacion = {0} AND (CveMarca = {1} OR CveMarca IS NULL) AND (CveSubProyecto = {2} OR CveSubProyecto IS NULL) AND (CveRinTamaño = {3} OR CveRinTamaño IS NULL) AND ((TipoPromocion <> 3 AND (CantidadMinima <= {4} OR CantidadMinima IS NULL)) OR (TipoPromocion = 3 AND CantidadMinima <= {4} )) ", CveClasifPS, CveMarcaPS, DdlSubProyectoDatos.SelectedValue, CveRinTamañoPS, Cantidad), Orderby:="CantidadMinima desc")
End If
End If
Dim Cant As Integer = 1
If dr IsNot Nothing Then
TipoPromo = dr("TipoPromocion").ToString().ToEntero()
CantMinima = dr("CantidadMinima").ToString().ToEntero()
IncluyeImpuestos = dr("IncluyeImpuestos").ToString() = "True"
PromocionPorcentaje = dr("Promocion").ToString().ToDecimal
PUPromocion = dr("PUPromocion").ToString().ToDecimal
CvePromocionDetalle = dr("CvePromocionDetalle").ToString().ToEntero()
TipoAplicacion = dr("TipoAplicacion").ToString().ToEntero()
If CantMinima > 0 Then
Cant = Math.Floor(Cantidad / CantMinima).ToEntero()
End If
End If
Dim PorcentajeIVA As Decimal = ViewState("SubProyectoPorcentajeIVA").ToString.ToDecimal ''Math.Round(ViewState("SubProyectoPorcentajeIVA").ToString.ToDecimal, 2).ToDecimal
TotalPromocion = Math.Round(PUPromocion * Cant / (1 + If(IncluyeImpuestos, PorcentajeIVA, 0)), 6)
If TipoPromo = 1 Then 'Promocion por Importe $
If TipoAplicacion = 2 Then
Descuento = 0
SeAjustoPU = True
PUModificado = Math.Round(PUPromocion / (1 + If(IncluyeImpuestos, PorcentajeIVA, 0)), 6)
Else
Descuento = Descuento + PU - TotalPromocion
End If
ElseIf TipoPromo = 2 Then 'Promocion por %
Descuento = Descuento + ((PU * PromocionPorcentaje / 100) * Cantidad)
ElseIf TipoPromo = 3 Then 'Promocion por Cantidad
If Cantidad >= CantMinima Then
Descuento = Descuento + TotalPromocion
Else
CvePromocionDetalle = -1
End If
End If
'VERIFICA SI APLICAN CONDICIONES COMERCIALES
If ValidaCondicionesComerciales AndAlso 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 = 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 = RowPorcentaje("PorcentajeProducto").ToString().ToDecimal() / 100D
Dim PorcentajeProducto2 = RowPorcentaje("PorcentajeProducto2").ToString().ToDecimal() / 100D
Dim PorcentajeProducto3 = RowPorcentaje("PorcentajeProducto3").ToString().ToDecimal() / 100D
Dim TotalInicial As Decimal = (Cantidad * (PU)) '- Descuento
Dim TotalFinal = TotalInicial
'SI APLICA EL PRIMER DESCUENTO
If PorcentajeProducto > 0 Then
Dim Descuento1 As Decimal = (TotalInicial * PorcentajeProducto).RoundSQL(2)
Dim Total2 = (TotalInicial - Descuento1)
'SI APLICA EL SEGUNDO DESCUENTO
If PorcentajeProducto2 > 0 Then
Dim Descuento2 As Decimal = (Total2 * PorcentajeProducto2).RoundSQL(2)
Dim Total3 = (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
'SI TIENE PRONTO PAGO CALCULA EL IMPORTE
If DdlTipoComprobante.SelectedValue = "Ing" AndAlso RowPorcentaje("ProntoPago").ToString().ToDecimal() > 0 Then
Dim TotalProntoPago As Decimal = (Cantidad * (PU)) - Descuento
Dim PorcentajeProntoPago = RowPorcentaje("ProntoPago").ToString().ToDecimal() / 100D
ObjDescuento.ImporteProntoPago = (TotalProntoPago * PorcentajeProntoPago).RoundSQL(2)
End If
End If
End If
End If
ObjDescuento.ImporteDescuento = Descuento
ObjDescuento.CvePromocionDetalle = CvePromocionDetalle
If SeAjustoPU Then
ObjDescuento.PU = PUModificado
ObjDescuento.EsPUModificado = True
End If
Return ObjDescuento
End Function
Protected Sub DdlPS_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DdlPS.selectedindexchange Protected Sub DdlPS_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DdlPS.selectedindexchange
DdlPSIndexChange(DdlPS.SelectedValue.ToEntero, DdlPS) DdlPSIndexChange(DdlPS.SelectedValue.ToEntero, DdlPS)
End Sub End Sub
@@ -5114,15 +5307,22 @@ Partial Class PV
Descuento = HdnDescuento.Value.ToDecimal * TxtCantidad.Text.ToDecimal Descuento = HdnDescuento.Value.ToDecimal * TxtCantidad.Text.ToDecimal
End If End If
Dim ObjDescuento As New Descuentos
If DrPS("CveClasificacion").ToString.ToEntero.Contiene(20516, 20515) Then If DrPS("CveClasificacion").ToString.ToEntero.Contiene(20516, 20515) Then
Descuento = ((Cantidad * PU) * ClasificacionesDescuentos(DrPS("CveClasificacion").ToString.ToEntero)) ObjDescuento.ImporteDescuento = ((Cantidad * PU) * ClasificacionesDescuentos(DrPS("CveClasificacion").ToString.ToEntero))
End If End If
ObjDescuento = CalcularDescuentos(CvePS, Cantidad, PU)
If ObjDescuento.EsPUModificado Then
PU = ObjDescuento.PU
End If
Dim CveProyecto As Integer = GlobalDTSubProyectos(-1, CveSubProyecto:=DdlSubProyectoDatos.SelectedValue.ToEntero, CveEmpresa:=UsuarioActual.CveEmpresa).Rows(0)("CveProyecto").ToString.ToEntero Dim CveProyecto As Integer = GlobalDTSubProyectos(-1, CveSubProyecto:=DdlSubProyectoDatos.SelectedValue.ToEntero, CveEmpresa:=UsuarioActual.CveEmpresa).Rows(0)("CveProyecto").ToString.ToEntero
Dim Proyecto As String = GlobalDTSubProyectos(-1, CveSubProyecto:=DdlSubProyectoDatos.SelectedValue.ToEntero, CveEmpresa:=UsuarioActual.CveEmpresa).Rows(0)("Proyecto").ToString Dim Proyecto As String = GlobalDTSubProyectos(-1, CveSubProyecto:=DdlSubProyectoDatos.SelectedValue.ToEntero, CveEmpresa:=UsuarioActual.CveEmpresa).Rows(0)("Proyecto").ToString
Dim Consec = AgregarProductoServicio(Cantidad, DdlUnidadMedida.SelectedValue.ToEntero, DdlUnidadMedida.SelectedItem.Text, DdlClasificacion.SelectedValue.ToEntero, DdlClasificacion.SelectedItem.Text, Dim Consec = AgregarProductoServicio(Cantidad, DdlUnidadMedida.SelectedValue.ToEntero, DdlUnidadMedida.SelectedItem.Text, DdlClasificacion.SelectedValue.ToEntero, DdlClasificacion.SelectedItem.Text,
CvePS, "", TxtObsPS.Text.Trim, PU, Descuento, CvePS, "", TxtObsPS.Text.Trim, PU, ObjDescuento.ImporteDescuento,
CveProyecto, Proyecto, DdlSubProyectoDatos.SelectedValue.ToEntero, DdlSubProyectoDatos.SelectedItem.Text, CveProyecto, Proyecto, DdlSubProyectoDatos.SelectedValue.ToEntero, DdlSubProyectoDatos.SelectedItem.Text,
Serie:="", TiempoEntrega:="", CuentaPredial:="", RegeneraIEPS:=ClienteDesglosaIEPS, CveVentaDetalle:=CveVentaDetalle, EsCargo:=EsCargo) Serie:="", TiempoEntrega:="", CuentaPredial:="", RegeneraIEPS:=ClienteDesglosaIEPS, CveVentaDetalle:=CveVentaDetalle, EsCargo:=EsCargo)