diff --git a/App_Code/ClsPaginas.vb b/App_Code/ClsPaginas.vb
index b7c9bd027..4d2fd0a71 100644
--- a/App_Code/ClsPaginas.vb
+++ b/App_Code/ClsPaginas.vb
@@ -5083,7 +5083,7 @@ Public Class ClsPaginas
PaginaDict.Add("/Ventas/RepAuxiliarFacturas.aspx".ToUpper(), 567)
PaginaDict.Add("/Ventas/CatAutorizacionLimites.aspx".ToUpper(), 781)
PaginaDict.Add("/Ventas/RepComisionesServec.aspx".ToUpper(), 782)
- PaginaDict.Add("/Ventas/RepComisionesServecDetalle.aspx".ToUpper(), 783)
+ PaginaDict.Add("/Ventas/RepComisionesServecDetalle.aspx".ToUpper(), 782)
#End Region
diff --git a/App_Code/ClsVentas.vb b/App_Code/ClsVentas.vb
index 576c9b935..cc953d4a8 100644
--- a/App_Code/ClsVentas.vb
+++ b/App_Code/ClsVentas.vb
@@ -5170,7 +5170,7 @@ Public Class ClsVentas
#End Region
- Public Function AddAutorizacionLimite(CveEmpresa As Integer, CveCliente As Integer, CveVendedor As Integer, Importe As Decimal, CveEstatus As Integer, CveUsuario As Integer, TipoAutorizacion As Integer, TipoDocumento As String) As Boolean
+ Public Function AddAutorizacionLimite(CveEmpresa As Integer, CveCliente As Integer, CveVendedor As Integer, Importe As Decimal, CveEstatus As Integer, CveUsuario As Integer, TipoAutorizacion As Integer, TipoDocumento As String, Optional DiasVencidos As Integer = 0) As Boolean
Dim Retorno As Boolean = False
DataAdapter("PA_Vta_AutorizacionLimitesAdd")
With SqlAdapter.SelectCommand.Parameters
@@ -5182,6 +5182,7 @@ Public Class ClsVentas
.Add("@CveUsuario", SqlDbType.Int).Value = CveUsuario
.Add("@TipoAutorizacion", SqlDbType.Int).Value = TipoAutorizacion
.Add("@TipoDocumento", SqlDbType.VarChar).Value = TipoDocumento
+ .Add("@DiasVencidos", SqlDbType.Int).Value = DiasVencidos
End With
Try
SqlAdapter.Fill(Data)
diff --git a/Ventas/Ventas.aspx b/Ventas/Ventas.aspx
index 5e89c8bcc..02584370f 100644
--- a/Ventas/Ventas.aspx
+++ b/Ventas/Ventas.aspx
@@ -6317,7 +6317,8 @@
@@ -7748,6 +7768,74 @@
}
+ }
+
+ function CalculaSaldoRNCChkDetalleBonificacion(TxtCantidad, CantidadPendiente, ImporteTotal, Chk) {
+ //ImportesRNCCargo
+ let Importe = 0;
+ if (Chk.checked) {
+ let SaldoMaximoUtilizable = 999999999;
+ let ImportesAsignados = 0;
+
+ $('.ImportesRNCDetalleBonificacion').each(function () {
+
+ if (Chk.id != $(this).find("td").eq(0).find(":checkbox").attr('id')) {
+ let seleccionado = $(this).find("td").eq(0).find(":checkbox").is(':checked');
+
+ if (seleccionado) {
+ let cantidad = ToDouble($(this).find("td").eq(1).find(":text").val());
+ let porcentajeIVA = ToDouble($(this).find("td").eq(0).find(":hidden").val());
+ let precio = ToDouble($(this).find("td").eq(5).find(":hidden").val());
+
+ let totalcalculableImpuestos = (cantidad * precio);
+ let iva = ToDouble((totalcalculableImpuestos * porcentajeIVA).toFixed(2));
+
+ ImportesAsignados += totalcalculableImpuestos + iva;
+ }
+ }
+
+ });
+
+ Importe = SaldoMaximoUtilizable - ImportesAsignados;
+
+ if (Importe > 0) {
+
+ } else {
+ if (SaldoMaximoUtilizable > 0) {
+ Importe = 0;
+ Chk.checked = false;
+ } else {
+ Importe = 0;
+ }
+ }
+
+ } else {
+ Importe = 0;
+ }
+
+ Importe = ToDouble(Importe.toFixed(2));
+
+ if (Importe > 0) {
+
+ let pu = (ImporteTotal / CantidadPendiente);
+
+ if (pu > 0) {
+ const cantidadSugerida = (Importe / pu);
+ if (cantidadSugerida > CantidadPendiente) {
+ TxtCantidad.value = CantidadPendiente.toString();
+ }else {
+ TxtCantidad.value = cantidadSugerida.toString();
+ }
+
+ }else {
+ TxtCantidad.value = "0";
+ }
+
+ }else {
+ TxtCantidad.value = "0";
+ }
+
+
}
function LimitaSaldoRNCChk(TxtImporte, Saldo) {
diff --git a/Ventas/Ventas.aspx.vb b/Ventas/Ventas.aspx.vb
index 605da78a2..c0586c73d 100644
--- a/Ventas/Ventas.aspx.vb
+++ b/Ventas/Ventas.aspx.vb
@@ -160,6 +160,25 @@ Partial Class Ventas
ViewState("TmpDTRNCDetalleSelecciondas") = value
End Set
End Property
+
+ Private Property TmpDTRNCBonificacionDetalle As DataTable
+ Get
+ Return If(IsNothing(ViewState("TmpDTRNCBonificacionDetalle")), Nothing, CType(ViewState("TmpDTRNCBonificacionDetalle"), DataTable))
+ End Get
+ Set(value As DataTable)
+ ViewState("TmpDTRNCBonificacionDetalle") = value
+ End Set
+ End Property
+
+ Private Property TmpDTRNCBonificacionDetalleSeleccionadas As DataTable
+ Get
+ Return If(IsNothing(ViewState("TmpDTRNCBonificacionDetalleSeleccionadas")), Nothing, CType(ViewState("TmpDTRNCBonificacionDetalleSeleccionadas"), DataTable))
+ End Get
+ Set(value As DataTable)
+ ViewState("TmpDTRNCBonificacionDetalleSeleccionadas") = value
+ End Set
+ End Property
+
Private Property TmpDTError As DataTable
Get
Return If(IsNothing(ViewState("TmpDTError")), Nothing, CType(ViewState("TmpDTError"), DataTable))
@@ -1932,6 +1951,14 @@ Partial Class Ventas
ViewState("AplicaRNCXDetalle") = value
End Set
End Property
+ Private Property AplicaRNCBonificacionXDetalle As Boolean
+ Get
+ Return CBool(IfNull(ViewState("AplicaRNCBonificacionXDetalle"), "False", ViewState("AplicaRNCBonificacionXDetalle")))
+ End Get
+ Set(value As Boolean)
+ ViewState("AplicaRNCBonificacionXDetalle") = value
+ End Set
+ End Property
Private Property AplicaRelacionManual As Boolean
Get
Return CBool(IfNull(ViewState("AplicaRelacionManual"), "False", ViewState("AplicaRelacionManual")))
@@ -25054,7 +25081,16 @@ Partial Class Ventas
Case "2" 'BONIFICACIONES
DivRNCCargoDesc.Visible = False
DivRNCBonDesc.Visible = True
- CargaRNCDesc(True, False)
+ If ChkMostarProductosRNCDesBonificacion.Checked Then
+ DivRNCBonDescTotal.Visible = False
+ DivRNCBonDescDetalle.Visible = True
+ CargaRNCDetalleDescBonificacion()
+ Else
+ DivRNCBonDescTotal.Visible = True
+ DivRNCBonDescDetalle.Visible = False
+ CargaRNCDesc(True, False)
+ End If
+
Case "3" 'AJUSTE/GARANTIAS
LtlCargoDesc.Text = "AJUSTES/GARANTIAS"
DivRNCCargoDesc.Visible = True
@@ -25091,6 +25127,13 @@ Partial Class Ventas
UpModalRemisionesNC.Update()
End Sub
+
+ Protected Sub ChkMostarProductosRNCDesBonificacion_CheckedChanged(sender As Object, e As EventArgs)
+
+ RblRNCTipoDesc_SelectedIndexChanged(RblRNCTipo, EventArgs.Empty)
+
+ UpModalRemisionesNC.Update()
+ End Sub
Private Sub CargaRNC(Optional CveVentaUsado As Integer = -1, Optional CargarBonificaciones As Boolean = False, Optional CargarSoloGarantias As Boolean = False)
Dim DtNC As DataTable = Nothing
@@ -25291,6 +25334,37 @@ Partial Class Ventas
UpDescNC.Update()
End Sub
+ Private Sub CargaRNCDetalleDescBonificacion()
+ Dim DtNC As DataTable = Nothing
+
+ Dim ObjMovtos As New ClsMovimientos()
+ If ObjMovtos.GetRemisionesNCCliente(CveCliente, True, CveMoneda:=-1, CveClienteSucursal:=DdlSucursalCliente.SelectedValue.ToEntero()) Then
+ Me.TmpDTRNCBonificacionDetalle = ObjMovtos.DtResultados.Copy()
+ End If
+ ObjMovtos.Dispose()
+
+ Me.TmpDTRNCBonificacionDetalle.Columns.Add(New DataColumn("CveVentaDetalleNCGenerada", GetType(Integer)))
+
+ Me.TmpDTRNCBonificacionDetalleSeleccionadas = Nothing
+ Me.TmpDTRNCBonificacionDetalleSeleccionadas = TmpDTRNCBonificacionDetalle.Clone()
+ Me.TmpDTRNCBonificacionDetalleSeleccionadas.Clear()
+
+ GvDescNCBonDetalle.DataSource = TmpDTRNCBonificacionDetalle.FiltraParametros("TipoRNC = 2")
+ GvDescNCBonDetalle.DataBind()
+
+ 'Dim SaldoMaximoUsados As Decimal = Me.TmpDT.SUM("Total", "EsCargo = True").ToDecimal() + Me.TmpDT.SUM("ImporteIVA", "EsCargo = True").ToDecimal()
+
+ 'If SaldoMaximoUsados > 0 Then
+ ' HdnSaldoMaximoUsados.Value = SaldoMaximoUsados.ToString()
+ ' LblSaldoMaximoUsados.Text = String.Format("{0:N2}", SaldoMaximoUsados)
+ 'Else
+ ' HdnSaldoMaximoUsados.Value = "0"
+ ' LblSaldoMaximoUsados.Text = "0"
+ 'End If
+
+ UpDescNC.Update()
+ End Sub
+
Private Sub CargaBonificaciones(CveVentaRNCCargo As Integer, AplicarRNC As Boolean)
If TmpDTRNCBonificacionesSeleccionadas Is Nothing Then
TmpDTRNCBonificacionesSeleccionadas = Me.TmpDTRNCBonificacionesCliente.Clone()
@@ -25409,110 +25483,99 @@ Partial Class Ventas
Private Sub CargaBonificacionesDesc(CvesVentaRNCCargo As String, AplicarRNC As Boolean)
- If TmpDTRNCBonificacionesSeleccionadas Is Nothing Then
- TmpDTRNCBonificacionesSeleccionadas = Me.TmpDTRNCBonificacionesCliente.Clone()
+
+ If ChkMostarProductosRNCDesBonificacion.Checked Then
+ DivRNCBonDescTotal.Visible = False
+ DivRNCBonDescDetalle.Visible = True
+ CargaRNCDetalleDescBonificacion()
Else
- TmpDTRNCBonificacionesSeleccionadas.Clear()
- End If
+ DivRNCBonDescTotal.Visible = True
+ DivRNCBonDescDetalle.Visible = False
- Dim ListaVentasRNCCargos As String() = {}
+ If TmpDTRNCBonificacionesSeleccionadas Is Nothing Then
+ TmpDTRNCBonificacionesSeleccionadas = Me.TmpDTRNCBonificacionesCliente.Clone()
+ Else
+ TmpDTRNCBonificacionesSeleccionadas.Clear()
+ End If
- If CvesVentaRNCCargo <> "-1" OrElse Not String.IsNullOrEmpty(CvesVentaRNCCargo) Then
- ListaVentasRNCCargos = CvesVentaRNCCargo.Split(","c)
- End If
+ Dim ListaVentasRNCCargos As String() = {}
- Dim ListaBon As New List(Of VentasBonificaciones)
- Dim DtBon As DataTable = Nothing
- Dim SbFiltro As New StringBuilder()
- SbFiltro.Append("CveVenta IN(")
+ If CvesVentaRNCCargo <> "-1" OrElse Not String.IsNullOrEmpty(CvesVentaRNCCargo) Then
+ ListaVentasRNCCargos = CvesVentaRNCCargo.Split(","c)
+ End If
- Using ObjAcum As New ClsAcumuladores
- For Each CveVentaRNC As String In ListaVentasRNCCargos
- If ObjAcum.DistribuidorMovtosGet(CveCliente, UsuarioActual.CveEmpresa, CveVentaRNCCargo:=CveVentaRNC.ToEntero()) Then
- Dim DtDist = ObjAcum.DtResultados.Copy()
+ Dim ListaBon As New List(Of VentasBonificaciones)
+ Dim DtBon As DataTable = Nothing
+ Dim SbFiltro As New StringBuilder()
+ SbFiltro.Append("CveVenta IN(")
- If DtBon Is Nothing Then
- DtBon = DtDist.Clone()
+ Using ObjAcum As New ClsAcumuladores
+ For Each CveVentaRNC As String In ListaVentasRNCCargos
+ If ObjAcum.DistribuidorMovtosGet(CveCliente, UsuarioActual.CveEmpresa, CveVentaRNCCargo:=CveVentaRNC.ToEntero()) Then
+ Dim DtDist = ObjAcum.DtResultados.Copy()
+
+ If DtBon Is Nothing Then
+ DtBon = DtDist.Clone()
+ End If
+
+ DtBon.Merge(DtDist)
End If
+ Next
+ End Using
- DtBon.Merge(DtDist)
- End If
- Next
- End Using
+ If DtBon IsNot Nothing Then
+ Dim queryBonificacion = From dr In DtBon
+ Group By CveVentaBonificacion = dr("CveVentaBonificacion").ToString().ToEntero, CveVentaRNCCargo = dr("CveVentaRNCCargo").ToString().ToEntero
+ Into x = Group
+ Select New With {
+ .CveVentaRNCCargo = CveVentaRNCCargo,
+ .CveVentaBonificacion = CveVentaBonificacion,
+ .ImporteBonificacion = x.Sum(Function(s) s("ImporteBonificacion").ToString().ToDecimal),
+ .IVABonificacion = x.Sum(Function(s) s("IVABonificacion").ToString().ToDecimal)
+ }
- If DtBon IsNot Nothing Then
- Dim queryBonificacion = From dr In DtBon
- Group By CveVentaBonificacion = dr("CveVentaBonificacion").ToString().ToEntero, CveVentaRNCCargo = dr("CveVentaRNCCargo").ToString().ToEntero
- Into x = Group
- Select New With {
- .CveVentaRNCCargo = CveVentaRNCCargo,
- .CveVentaBonificacion = CveVentaBonificacion,
- .ImporteBonificacion = x.Sum(Function(s) s("ImporteBonificacion").ToString().ToDecimal),
- .IVABonificacion = x.Sum(Function(s) s("IVABonificacion").ToString().ToDecimal)
- }
+ For Each bon In queryBonificacion
+ SbFiltro.AppendFormat("'{0}',", bon.CveVentaBonificacion)
+ ListaBon.Add(New VentasBonificaciones() With {.CveVentaRNCCargo = bon.CveVentaRNCCargo, .CveVentaBonificacion = bon.CveVentaBonificacion, .ImporteBonificacion = bon.ImporteBonificacion, .IVABonificacion = bon.IVABonificacion})
+ Next
- For Each bon In queryBonificacion
- SbFiltro.AppendFormat("'{0}',", bon.CveVentaBonificacion)
- ListaBon.Add(New VentasBonificaciones() With {.CveVentaRNCCargo = bon.CveVentaRNCCargo, .CveVentaBonificacion = bon.CveVentaBonificacion, .ImporteBonificacion = bon.ImporteBonificacion, .IVABonificacion = bon.IVABonificacion})
- Next
+ SbFiltro.Remove(SbFiltro.Length - 1, 1)
+ SbFiltro.Append(")")
+ End If
- SbFiltro.Remove(SbFiltro.Length - 1, 1)
- SbFiltro.Append(")")
- End If
+ If ListaBon.Count > 0 Then
+ Dim Bonificaciones = Me.TmpDTRNCBonificacionesCliente.Select(SbFiltro.ToString())
- If ListaBon.Count > 0 Then
- Dim Bonificaciones = Me.TmpDTRNCBonificacionesCliente.Select(SbFiltro.ToString())
+ For Each RowBonificacion As DataRow In Bonificaciones
+ Dim RNCBonificacion = ListaBon.Where(Function(x) x.CveVentaBonificacion = RowBonificacion("CveVenta").ToString().ToEntero())
- For Each RowBonificacion As DataRow In Bonificaciones
- Dim RNCBonificacion = ListaBon.Where(Function(x) x.CveVentaBonificacion = RowBonificacion("CveVenta").ToString().ToEntero())
+ RowBonificacion("ImporteBonificacion") = RNCBonificacion.Sum(Function(x) x.ImporteBonificacion)
+ RowBonificacion("IVABonificacion") = RNCBonificacion.Sum(Function(x) x.IVABonificacion)
+ RowBonificacion("CveVentaRNCCargo") = RNCBonificacion(0).CveVentaRNCCargo
- RowBonificacion("ImporteBonificacion") = RNCBonificacion.Sum(Function(x) x.ImporteBonificacion)
- RowBonificacion("IVABonificacion") = RNCBonificacion.Sum(Function(x) x.IVABonificacion)
- RowBonificacion("CveVentaRNCCargo") = RNCBonificacion(0).CveVentaRNCCargo
+ If AplicarRNC Then
+ TmpDTRNCBonificacionesSeleccionadas.Rows.Add(RowBonificacion.ItemArray)
+ Else
+ For Each RowEliminar In Me.TmpDTRNCBonificacionesSeleccionadas.Select(SbFiltro.ToString())
+ RowEliminar.Delete()
+ Next
+ End If
+ Next
- If AplicarRNC Then
- TmpDTRNCBonificacionesSeleccionadas.Rows.Add(RowBonificacion.ItemArray)
- Else
- For Each RowEliminar In Me.TmpDTRNCBonificacionesSeleccionadas.Select(SbFiltro.ToString())
- RowEliminar.Delete()
- Next
- End If
- Next
+ End If
+
+ 'VERIFICA SI TIENE BONIFICACIONES PARA AGREGARLAS
+ If TmpDTRNCBonificacionesSeleccionadas IsNot Nothing AndAlso TmpDTRNCBonificacionesSeleccionadas.Rows.Count > 0 Then
+ DivRNCBonDesc.Visible = True
+ Else
+ DivRNCBonDesc.Visible = False
+ End If
+
+ GvDescNCBonificaciones.DataSource = TmpDTRNCBonificacionesSeleccionadas
+ GvDescNCBonificaciones.DataBind()
End If
- 'VERIFICA SI TIENE BONIFICACIONES PARA AGREGARLAS
- If TmpDTRNCBonificacionesSeleccionadas IsNot Nothing AndAlso TmpDTRNCBonificacionesSeleccionadas.Rows.Count > 0 Then
- DivRNCBonDesc.Visible = True
- Else
- DivRNCBonDesc.Visible = False
- End If
-
- GvDescNCBonificaciones.DataSource = TmpDTRNCBonificacionesSeleccionadas
- GvDescNCBonificaciones.DataBind()
-
- 'SI ES CREDITO
- 'If RBLPago.SelectedValue = "1" Then
- ' Dim ImporteUsados As Decimal = Me.TmpDTRNCBonificacionesSeleccionadas.SUM("ImporteBonificacion").ToDecimal() + Me.TmpDTRNCBonificacionesSeleccionadas.SUM("IVABonificacion").ToDecimal()
- ' HdnSMUBonDesc.Value = ImporteUsados.ToString()
- ' LblSaldoMaximoBonificacion.Text = String.Format("{0:N2}", ImporteUsados)
- ' 'SI ES CONTADO
- 'ElseIf RBLPago.SelectedValue = "2" Then
- ' Dim ImporteUsados As Decimal = 0
-
- ' For Each Row As DataRow In Me.TmpDT.FiltraParametros("EsCargo = True").Rows
- ' Dim PUBonificacion As Decimal = GlobalDTAcumTamaños().FiltroPrimeroValor("Bonificacion", $"CvePSCargo={Row("CvePS")}").ToDecimal()
-
- ' Dim TotalBonificacion As Decimal = (Row("Cantidad").ToString().ToDecimal() * PUBonificacion)
- ' Dim IVABonificacion As Decimal = (TotalBonificacion * Row("PorcentajeIVA").ToString().ToDecimal()).RoundSQL(2)
-
- ' ImporteUsados += TotalBonificacion + IVABonificacion
- ' Next
- ' HdnSMUBonDesc.Value = ImporteUsados.ToString()
- ' LblSaldoMaximoBonificacion.Text = String.Format("{0:N2}", ImporteUsados)
-
- 'End If
-
UpDescNC.Update()
End Sub
@@ -25538,6 +25601,22 @@ Partial Class Ventas
End If
End If
End Sub
+
+ Protected Sub GvDescNCBonDetalle_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDescNCBonDetalle.RowDataBound
+ If e.Row.RowType = DataControlRowType.DataRow Then
+
+ If e.Row.DBCampo("CveVentaDetalleRNC").ToEntero() = 0 Then
+ e.Row.CssClass = "Totales"
+ e.Row.FCCheckBox("ChkAplicar").Visible = False
+ e.Row.FCTextBox("TxtCantidadRNC").Visible = False
+ Else
+ e.Row.CssClass = "ImportesRNCDetalle"
+ e.Row.FCCheckBox("ChkAplicar").Attributes.Add("onclick", $"CalculaSaldoRNCChkDetalleBonificacion({e.Row.FCTextBox("TxtCantidadRNC").ClientID},{e.Row.DBCampo("CantidadPendiente").ToDouble},{e.Row.DBCampo("Total").ToDouble}, this);")
+ 'e.Row.FCTextBox("TxtImporte").Attributes.Add("onkeyup", $"LimitaSaldoRNCChk({e.Row.FCTextBox("TxtImporte").ClientID},{e.Row.DBCampo("Saldo").ToDouble});")
+
+ End If
+ End If
+ End Sub
Protected Sub GvRNCDevoluciones_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvRNCDevoluciones.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.FCCheckBox("ChkAplicar").Attributes.Add("onclick", $"CalculaSaldoRNCBonChkDesc({e.Row.FCTextBox("TxtImporte").ClientID},{e.Row.DBCampo("Saldo").ToDouble}, this);")
@@ -25866,13 +25945,21 @@ Partial Class Ventas
NCBonificacion = ArrayNC(4).ToEntero()
End If
+ Dim DrBonRef As DataRow = Nothing
+
'EN LA NC DE BONIFICACION EL CONCEPTO DEBE SER SIEMPRE 'BONIFICACION POR USADO'
Dim DrPSBonificacion = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=NCBonificacion).FiltroPrimero("")
If DrPSBonificacion IsNot Nothing Then
- CrearDTNCBonificacionDesc(DtImpuestosBonificacion, TmpDTDescNC, DrPSBonificacion, CveProyecto, Proyecto, CveSubProyecto, SubProyecto)
+ DrBonRef = DrPSBonificacion
Else
+ DrBonRef = DrPS
Alert("No se encontró el concepto de BONIFICACION POR USADO", TipoMensaje.MsgAdvertencia)
- CrearDTNCBonificacionDesc(DtImpuestosBonificacion, TmpDTDescNC, DrPS, CveProyecto, Proyecto, CveSubProyecto, SubProyecto)
+ End If
+
+ If AplicaRNCBonificacionXDetalle Then
+ CrearDTNCBonificacionDescDetalle(ListaNCBonificacion, TmpDTDescNC, DrBonRef, CveProyecto, Proyecto, CveSubProyecto, SubProyecto)
+ Else
+ CrearDTNCBonificacionDesc(DtImpuestosBonificacion, TmpDTDescNC, DrBonRef, CveProyecto, Proyecto, CveSubProyecto, SubProyecto)
End If
Else
@@ -26331,6 +26418,93 @@ Partial Class Ventas
Next
End If
End Sub
+ Private Sub CrearDTNCBonificacionDescDetalle(ListaNC As List(Of Modelos.Factura), ByRef TmpDTCargo As DataTable, DrPS As DataRow, CveProyecto As Integer, Proyecto As String, CveSubProyecto As Integer, SubProyecto As String)
+
+ TmpDTDescNCBonificacion = TmpDTCargo.Clone()
+ TmpDTDescNCBonificacion.Clear()
+
+ For Each RNC In ListaNC
+ Dim UltimoRenglonRNC As Integer = 1
+ Dim TotalAcumuladoRNC As Decimal = 0
+ Dim Terminar As Boolean = False
+
+ For Each RowUsado As DataRow In Me.TmpDTRNCBonificacionDetalleSeleccionadas.FiltraParametros($"CveVenta={RNC.CveVenta}", Orderby:="PU").Rows
+
+ Dim Cantidad As Decimal = RowUsado("Cantidad").ToString().ToDecimal()
+
+ Dim CvePSCargo As Integer = RowUsado("CvePS").ToString().ToEntero()
+ Dim Obs = ""
+ 'SI ES ACUMULADOR LAS OBSERVACIOENS DEBEN SER EL NOMBRE DEL ACUMULADOR
+ If GlobalDTAcumTamaños().FiltroPrimero($"CvePSCargo = {CvePSCargo}") IsNot Nothing Then
+ Obs = RowUsado("CodigoPS").ToString()
+ 'Else
+ ' Obs = RowUsado("Obs").ToString()
+ End If
+
+ If Not String.IsNullOrEmpty(TxtNCObservaciones.Text.Trim()) Then
+ Obs = String.Format("{0} - {1}", Obs, TxtNCObservaciones.Text.Trim())
+ End If
+
+ Dim ImportePU = RowUsado("PU").ToString().ToDecimal
+
+ Dim TotalCalculableImpuestos As Decimal = (Cantidad * ImportePU)
+
+ Dim ImporteIVA = (TotalCalculableImpuestos * RowUsado("PorcentajeIVA").ToString().ToDecimal).RoundSQL(2)
+ Dim ImporteIEPS = 0 '(TotalCalculableImpuestos * RowUsado("PorcentajeIEPS").ToString().ToDecimal).RoundSQL(2)
+ Dim ImporteRetIVA = 0 ' (TotalCalculableImpuestos * RowUsado("PorcentajeRetIVA").ToString().ToDecimal).RoundSQL(2)
+ Dim ImporteRetISR = 0 ' (TotalCalculableImpuestos * RowUsado("PorcentajeRetISR").ToString().ToDecimal).RoundSQL(2)
+ Dim ImporteTotal = TotalCalculableImpuestos
+
+ TotalAcumuladoRNC += (TotalCalculableImpuestos + ImporteIVA)
+
+
+ 'SI EL IMPORTE ES MAYOR REALIZA EL AJUSTE
+ If TotalAcumuladoRNC > RNC.TotalRemNCAplicado Then
+ Terminar = True
+ 'RESTA LO SUMANDO DEL ACUMULADO
+ TotalAcumuladoRNC -= (TotalCalculableImpuestos + ImporteIVA + ImporteIEPS - ImporteRetIVA - ImporteRetISR)
+
+ Dim Diferencia As Decimal = RNC.TotalRemNCAplicado - TotalAcumuladoRNC
+
+ Dim TotalPartida As Decimal = (TotalCalculableImpuestos + ImporteIVA + ImporteIEPS - ImporteRetIVA - ImporteRetISR)
+
+ Dim PorcentajePorAplicar As Decimal = (Diferencia / TotalPartida)
+
+ Cantidad = Cantidad * PorcentajePorAplicar
+
+ TotalCalculableImpuestos = (Cantidad * ImportePU)
+ ImporteIVA = (TotalCalculableImpuestos * RowUsado("PorcentajeIVA").ToString().ToDecimal).RoundSQL(2)
+
+
+ ImporteTotal = TotalCalculableImpuestos
+
+ TotalAcumuladoRNC += (TotalCalculableImpuestos + ImporteIVA + ImporteIEPS - ImporteRetIVA - ImporteRetISR)
+ End If
+
+ 'SI ES EL ULTIMO REGLON REALIZA UN AJUSTE
+ If UltimoRenglonRNC = Me.TmpDTRNCBonificacionDetalleSeleccionadas.FiltraParametros($"CveVenta={RNC.CveVenta}").Rows.Count OrElse Terminar Then
+ Dim Ajuste As Decimal = 0
+ If Math.Abs(RNC.TotalRemNCAplicado - TotalAcumuladoRNC) > 0.00 Then
+ Ajuste = RNC.TotalRemNCAplicado - TotalAcumuladoRNC
+
+ ImporteIVA += Ajuste
+ End If
+ End If
+ UltimoRenglonRNC += 1
+
+ AgregaTempDT(TmpDTDescNCBonificacion, DrPS("CvePS").ToString().ToEntero(), DrPS("PS").ToString(), DrPS("Codigo").ToString(), DrPS("PSCodigo").ToString(), DrPS("CveTipoPS").ToString().ToEntero(), DrPS("Inv_CveMetodoInventario").ToString().ToEntero(),
+ DrPS("CveUM").ToString().ToEntero(), DrPS("UnidadMedida").ToString(), DrPS("CveClasificacion").ToString().ToEntero(), DrPS("Clasificacion").ToString(), CveProyecto, Proyecto, CveSubProyecto, SubProyecto,
+ Obs, Cantidad, ImportePU, RowUsado("PorcentajeIVA").ToString().ToDecimal, ImporteIVA, 0, ImporteRetIVA,
+ 0, ImporteRetISR, 0, ImporteIEPS, -1, 0, ImporteTotal, "", "", -1, -1,
+ DrPS("SATClavePS").ToString(), DrPS("SATClaveUnidadMedida").ToString(), -1, -1, -1, -1, -1, -1, CveVentaDetalleRNC:=RowUsado("CveVentaDetalleRNC").ToString().ToEntero())
+
+ If Terminar Then
+ Exit For
+ End If
+ Next
+
+ Next
+ End Sub
Private Sub CrearDTNCDevolucion(ListaNC As List(Of Modelos.Factura), ByRef TmpDTCargo As DataTable, CveProyecto As Integer, Proyecto As String, CveSubProyecto As Integer, SubProyecto As String)
For Each RNC In ListaNC
@@ -29829,6 +30003,7 @@ Partial Class Ventas
#Region "D E S C U E N T O S X R E M I S I O N D E N O T A D E C R E D I T O"
Protected Sub BtnAplicarRemisionNC_Click(sender As Object, e As EventArgs)
Me.AplicaRNCXDetalle = False
+ Me.AplicaRNCBonificacionXDetalle = False
If ListaRemisionesNC Is Nothing Then
ListaRemisionesNC = New List(Of Modelos.Factura)
@@ -30027,6 +30202,7 @@ Partial Class Ventas
Protected Sub BtnAplicarDesc_Click(sender As Object, e As EventArgs)
Try
Me.AplicaRNCXDetalle = False
+ Me.AplicaRNCBonificacionXDetalle = False
Dim DrPS As DataRow = Nothing
Dim ArrayNC As String() = UsuarioActual.Empresa.Funcionalidad(591).Split(",".ToCharArray())
@@ -30215,34 +30391,98 @@ Partial Class Ventas
Exit Sub
End If
- For Each GvRow As GridViewRow In GvDescNCBonificaciones.Rows
- If GvRow.RowType = DataControlRowType.DataRow Then
- If GvRow.FCCheckBox("ChkAplicar").Checked Then
- Dim RemNC As New Modelos.Factura(UsuarioActual, GvRow.DataKey("CveVenta").ToEntero(), UsuarioActual.CveEmpresa)
- RemNC.TotalRemNCAplicado = GvRow.FCTextBox("TxtImporte").Text.ToDecimal()
- RemNC.CveVentaRNCCargo = GvRow.DataKey("CveVentaRNCCargo").ToEntero()
- TotalRemNCAplicado += RemNC.TotalRemNCAplicado
+ 'BONIFICACIONES
+ If ChkMostarProductosRNCDesBonificacion.Checked Then
- If RemNC.TotalRemNCAplicado <= 0 Then
- Alert($"Debe asignar un importe en la siguiente remisión: {RemNC.SerieFolio}", TipoMensaje.MsgAdvertencia)
- ListaNCBonificacion.Clear()
- Exit Sub
+ TmpDTRNCBonificacionDetalleSeleccionadas.Clear()
+ Me.AplicaRNCBonificacionXDetalle = True
+
+ For Each GvRow As GridViewRow In GvDescNCBonDetalle.Rows
+ If GvRow.RowType = DataControlRowType.DataRow Then
+ If GvRow.FCCheckBox("ChkAplicar").Checked Then
+ Dim Rows = TmpDTRNCBonificacionDetalle.Select($"CveVentaDetalleRNC = {GvRow.DataKey("CveVentaDetalleRNC").ToEntero()}")
+ For Each row In Rows
+ row("Cantidad") = GvRow.FCTextBox("TxtCantidadRNC").Text.ToDecimal()
+
+ Dim TotalCalculableImpuestos As Decimal = row("Cantidad").ToString().ToDecimal() * row("PU").ToString().ToDecimal()
+ Dim IVA As Decimal = (TotalCalculableImpuestos * row("PorcentajeIVA").ToString().ToDecimal()).RoundSQL()
+
+ row("IVA") = IVA
+ row("Total") = (TotalCalculableImpuestos + IVA).RoundSQL
+
+ TmpDTRNCBonificacionDetalleSeleccionadas.Rows.Add(row.ItemArray)
+ Next
End If
-
- ListaNCBonificacion.Add(RemNC)
End If
- End If
- Next
+ Next
- 'Dim LimiteBonficaciones As Decimal = LblSaldoMaximoBonificacion.Text.Trim().ToDecimal()
+ Dim TerminarCiclo As Boolean = False
- ''VERIFICA EL LIMITE DE LOS USADOS
- 'If ListaNCBonificacion.Sum(Function(x) x.TotalRemNCAplicado) > LimiteBonficaciones Then
- ' Alert($"La suma de las remisiones de nota de crédito de tipo 'Bonificación' no debe superar el limite. Total RNC: {ListaNCBonificacion.Sum(Function(x) x.TotalRemNCAplicado):N2}. Total Usados: {LimiteUsados:N2}", TipoMensaje.MsgAdvertencia)
- ' ListaNCDesc.Clear()
- ' ListaNCBonificacion.Clear()
- ' Exit Sub
- 'End If
+ For Each Dr As DataRow In TmpDTRNCBonificacionDetalleSeleccionadas.FiltraParametros("", DistinctColumns:={"CveVenta"}).Rows
+ Dim RemNC As New Modelos.Factura(UsuarioActual, Dr("CveVenta").ToString().ToEntero(), UsuarioActual.CveEmpresa)
+
+ Dim TotalRNC As Decimal = 0
+ For Each GvRow As GridViewRow In GvDescNCBonDetalle.Rows
+ If GvRow.RowType = DataControlRowType.DataRow Then
+
+ If GvRow.FCCheckBox("ChkAplicar").Checked AndAlso GvRow.DataKey("CveVenta").ToEntero() = Dr("CveVenta").ToString().ToEntero() Then
+
+ Dim Cantidad As Decimal = GvRow.FCTextBox("TxtCantidadRNC").Text.ToDecimal()
+ Dim PU = GvRow.DataKey("PU").ToDecimal()
+ Dim PorcentajeIVA As Decimal = GvRow.DataKey("PorcentajeIVA").ToDecimal()
+
+ Dim TotalCalculableImpuestos As Decimal = (Cantidad * PU)
+ Dim ImporteIVA As Decimal = (TotalCalculableImpuestos * PorcentajeIVA).RoundSQL(2)
+
+ Dim TotalRNCDetalle As Decimal = (TotalCalculableImpuestos + ImporteIVA)
+
+ TotalRNC += TotalRNCDetalle
+
+ If RemNC.CveVentaRNCCargo <= 0 Then
+ RemNC.CveVentaRNCCargo = GvRow.DataKey("CveVenta").ToEntero()
+ End If
+
+ End If
+
+ End If
+ Next
+
+ RemNC.TotalRemNCAplicado = TotalRNC
+ TotalRemNCAplicado += RemNC.TotalRemNCAplicado
+
+ If RemNC.TotalRemNCAplicado <= 0 Then
+ Alert($"Debe asignar un importe en la siguiente remisión: {RemNC.SerieFolio}", TipoMensaje.MsgAdvertencia)
+ ListaNCBonificacion.Clear()
+ Exit Sub
+ End If
+
+ ListaNCBonificacion.Add(RemNC)
+
+ If TerminarCiclo Then
+ Exit For
+ End If
+ Next
+
+ Else
+ For Each GvRow As GridViewRow In GvDescNCBonificaciones.Rows
+ If GvRow.RowType = DataControlRowType.DataRow Then
+ If GvRow.FCCheckBox("ChkAplicar").Checked Then
+ Dim RemNC As New Modelos.Factura(UsuarioActual, GvRow.DataKey("CveVenta").ToEntero(), UsuarioActual.CveEmpresa)
+ RemNC.TotalRemNCAplicado = GvRow.FCTextBox("TxtImporte").Text.ToDecimal()
+ RemNC.CveVentaRNCCargo = GvRow.DataKey("CveVentaRNCCargo").ToEntero()
+ TotalRemNCAplicado += RemNC.TotalRemNCAplicado
+
+ If RemNC.TotalRemNCAplicado <= 0 Then
+ Alert($"Debe asignar un importe en la siguiente remisión: {RemNC.SerieFolio}", TipoMensaje.MsgAdvertencia)
+ ListaNCBonificacion.Clear()
+ Exit Sub
+ End If
+
+ ListaNCBonificacion.Add(RemNC)
+ End If
+ End If
+ Next
+ End If
ElseIf RblRNCTipoDesc.SelectedValue.Contiene("2") Then
@@ -31112,6 +31352,9 @@ Partial Class Ventas
DtVentasNC.Rows.Add(Drt)
DtVentasNC.AcceptChanges()
+ ObjFacturaProntoPago.DtVentasRelacionadas = New DataTable
+ ObjFacturaProntoPago.DtVentasRelacionadas.Columns.Add("CveVenta", GetType(Integer))
+
ObjFacturaProntoPago.DtVentasNC = DtVentasNC
Resp = ObjFacturaProntoPago.EmitirFactura(False, Transac:=SqlTransaccion, ObjContPaqTransac:=ObjConta)