diff --git a/App_Code/ClsAcumuladores.vb b/App_Code/ClsAcumuladores.vb index 2d74b5f69..e451e5b44 100644 --- a/App_Code/ClsAcumuladores.vb +++ b/App_Code/ClsAcumuladores.vb @@ -797,6 +797,21 @@ Public Class ClsAcumuladores Return Retorno End Function + Public Function EliminarGarantiasDetalle(CveVenta As Integer) As Boolean + Dim Retorno As Boolean = False + SqlDataAdapter("PA_Acum_GarantiasDetallePolizaRemove") + With SqlAdapter.SelectCommand.Parameters + .Add("@CveVenta", SqlDbType.Int).Value = CveVenta + End With + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As SqlException + OnError("Ocurrió un error a eliminar de garantia.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + Return Retorno + End Function + #End Region @@ -863,6 +878,21 @@ Public Class ClsAcumuladores End Try Return Retorno End Function + + Public Function EliminarPolizaVirtual(CveVenta As Integer) As Boolean + Dim Retorno As Boolean = False + SqlDataAdapter("PA_Vta_PolizaVirtualRemove") + With SqlAdapter.SelectCommand.Parameters + .Add("@CveVenta", SqlDbType.Int).Value = CveVenta + End With + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As SqlException + OnError("Ocurrió un al eliminar poliza virtual. ", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + Return Retorno + End Function #End Region Public Function DistribuidorMovtosAdd(CveCliente As Integer, Cantidad As Integer, CveTamaño As Integer, CveConcepto As Integer, CveVenta As Integer, CveUsuario As Integer, diff --git a/App_Code/ClsVentas.vb b/App_Code/ClsVentas.vb index a9e28e571..5d07b8c90 100644 --- a/App_Code/ClsVentas.vb +++ b/App_Code/ClsVentas.vb @@ -4496,6 +4496,25 @@ Public Class ClsVentas Return Retorno End Function + + Public Function EliminarUsados(CveVenta As Integer) As Boolean + Dim Retorno As Boolean = False + + DataAdapter("PA_Vta_VentasUsadosRemove", CommandType.StoredProcedure) + + With SqlAdapter.SelectCommand.Parameters + .Add("@CveVenta", SqlDbType.Int).Value = CveVenta + End With + + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As Exception + OnError("Ocurrió un error al eliminar los usados.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + Return Retorno + End Function Public Function GetVentasUsados(CveVenta As Integer, CveSubProyecto As Integer, Fecha As DateTime, CveEmpresa As Integer) As Boolean Dim Retorno As Boolean = False diff --git a/Ventas/PV.aspx.vb b/Ventas/PV.aspx.vb index a19c6152c..3355cd25b 100644 --- a/Ventas/PV.aspx.vb +++ b/Ventas/PV.aspx.vb @@ -1276,6 +1276,7 @@ Partial Class PV TmpDT.Columns.Add("EntregaDirecta", GetType(Integer)) TmpDT.Columns.Add("CveMovimientoDetallePedido", GetType(Integer)) TmpDT.Columns.Add("ConsecPSPadre", GetType(Integer)) + GvPS.DataSource = TmpDT GvPS.DataBind() @@ -1656,8 +1657,8 @@ Partial Class PV 'SI EL DETALLE NO TIENE MOVIMIENTOS DE INVENTARIO ES VISIBLE Dim CantidadFacturadaRemision = 0.0 For Each Gvr As GridViewRow In GvPS.Rows - Gvr.FCLinkButton("imgE").Visible = Not Gvr.DataKey("CantidadFacturadaRem").ToString.ToDouble > 0 AndAlso Gvr.DataKey("EsCargo") = "True" - Gvr.FCLinkButton("imgD").Visible = Not Gvr.DataKey("CantidadInventario").ToString.ToDouble > 0 AndAlso Gvr.DataKey("EsCargo") = "True" + Gvr.FCLinkButton("imgE").Visible = Not Gvr.DataKey("CantidadFacturadaRem").ToString.ToDouble > 0 AndAlso Gvr.DataKey("EsCargo") = "False" + Gvr.FCLinkButton("imgD").Visible = Not Gvr.DataKey("CantidadInventario").ToString.ToDouble > 0 AndAlso Gvr.DataKey("EsCargo") = "False" CantidadFacturadaRemision += Gvr.DataKey("CantidadFacturadaRem").ToString.ToDouble Next @@ -1694,6 +1695,8 @@ Partial Class PV Dim ObjConta As New ClsContabilidad(ObjVentas.IniciaTransacSQL()) Dim ObjBancos As New ClsBancos(ObjVentas.IniciaTransacSQL()) Dim ObjCGame As New ClsCGame(ObjVentas.IniciaTransacSQL()) + Dim ObjAcum As New ClsAcumuladores(ObjVentas.IniciaTransacSQL()) + Dim ObjAC As ClsContPAQi = Nothing Dim Moneda As Integer = DdlMoneda.SelectedValue.ToEntero @@ -1701,8 +1704,8 @@ Partial Class PV Try 'CONVERTIR REMISION - TIPO MONEDA -DOLARES A PESOS If DdlMoneda.SelectedValue.ToEntero <> 2 AndAlso ChkConvertirDolares.Checked Then - - For Each Row As DataRow In TmpDT.Rows + Dim TmpDTTotales As DataTable = TmpDT.FiltraParametros("EliminarDB = False") + For Each Row As DataRow In TmpDTTotales.Rows Row("PU") = Math.Round(Row("PU").ToString.ToDecimal / TxtTipoCambioDlls.Text.Trim.ToDecimal, 6) Row("Total") = Math.Round(Row("Cantidad").ToString.ToDecimal * Row("PU").ToString.ToDecimal, NumeroDecimales) Row("TotalImporte") = Math.Round(Row("Cantidad").ToString.ToDecimal * Row("PU").ToString.ToDecimal, NumeroDecimales) @@ -1721,13 +1724,13 @@ Partial Class PV End If Next - TxtSubTotal.Text = TmpDT.SUM("Total").ToDecimal.FormatoNumero - LblDescuentos.Text = TmpDT.SUM("Descuento").ToDecimal.FormatoNumero + TxtSubTotal.Text = TmpDTTotales.SUM("Total").ToDecimal.FormatoNumero + LblDescuentos.Text = TmpDTTotales.SUM("Descuento").ToDecimal.FormatoNumero LblAmortizacion.Text = Math.Round(LblAmortizacion.Text.Trim.ToDecimal / TxtTipoCambioDlls.Text.Trim.ToDecimal, NumeroDecimales).FormatoNumero - TxtIVA.Text = TmpDT.SUM("ImporteIVA").ToDecimal.FormatoNumero - TxtRetIVA.Text = TmpDT.SUM("ImporteRetIVA").ToDecimal.FormatoNumero - TxtRetISR.Text = TmpDT.SUM("ImporteRetISR").ToDecimal.FormatoNumero - TxtIEPS.Text = TmpDT.SUM("ImporteIEPS").ToDecimal.FormatoNumero + TxtIVA.Text = TmpDTTotales.SUM("ImporteIVA").ToDecimal.FormatoNumero + TxtRetIVA.Text = TmpDTTotales.SUM("ImporteRetIVA").ToDecimal.FormatoNumero + TxtRetISR.Text = TmpDTTotales.SUM("ImporteRetISR").ToDecimal.FormatoNumero + TxtIEPS.Text = TmpDTTotales.SUM("ImporteIEPS").ToDecimal.FormatoNumero TxtTotal.Text = (TxtSubTotal.Text.ToDecimal - LblDescuentos.Text.ToDecimal - LblAmortizacion.Text.ToDecimal + TxtIVA.Text.ToDecimal + TxtIEPS.Text.ToDecimal - TxtRetIVA.Text.ToDecimal - TxtRetISR.Text.ToDecimal - ImpuestosLocales).ToDecimal.FormatoNumero TipoCambio = TxtTipoCambioDlls.Text.Trim.ToDecimal @@ -1736,9 +1739,10 @@ Partial Class PV 'CONVERTIR REMISION - TIPO MONEDA -PESO A DOLARES If DdlMoneda.SelectedValue.ToEntero <> 1 AndAlso ChkConvertirDoctoPesos.Checked Then + Dim TmpDTTotales As DataTable = TmpDT.FiltraParametros("EliminarDB = False") Dim Importe As Decimal Dim TCC As Decimal = TxtTipoCambio.Text.Trim.ToDecimal - For Each Row As DataRow In TmpDT.Rows + For Each Row As DataRow In TmpDTTotales.Rows Row("PU") = Math.Round(Row("PU").ToString.ToDecimal * TCC, 6) Row("Total") = Math.Round(Row("Cantidad").ToString.ToDecimal * Row("PU").ToString.ToDecimal, NumeroDecimales) Row("TotalImporte") = Math.Round(Row("Cantidad").ToString.ToDecimal * Row("PU").ToString.ToDecimal, NumeroDecimales) @@ -1758,13 +1762,13 @@ Partial Class PV End If Next - TxtSubTotal.Text = TmpDT.SUM("Total").ToDecimal.FormatoNumero - LblDescuentos.Text = TmpDT.SUM("Descuento").ToDecimal.FormatoNumero + TxtSubTotal.Text = TmpDTTotales.SUM("Total").ToDecimal.FormatoNumero + LblDescuentos.Text = TmpDTTotales.SUM("Descuento").ToDecimal.FormatoNumero LblAmortizacion.Text = Math.Round(LblAmortizacion.Text.Trim.ToDecimal * TxtTipoCambio.Text.Trim.ToDecimal, NumeroDecimales).FormatoNumero - TxtIVA.Text = TmpDT.SUM("ImporteIVA").ToDecimal.FormatoNumero - TxtRetIVA.Text = TmpDT.SUM("ImporteRetIVA").ToDecimal.FormatoNumero - TxtRetISR.Text = TmpDT.SUM("ImporteRetISR").ToDecimal.FormatoNumero - TxtIEPS.Text = TmpDT.SUM("ImporteIEPS").ToDecimal.FormatoNumero + TxtIVA.Text = TmpDTTotales.SUM("ImporteIVA").ToDecimal.FormatoNumero + TxtRetIVA.Text = TmpDTTotales.SUM("ImporteRetIVA").ToDecimal.FormatoNumero + TxtRetISR.Text = TmpDTTotales.SUM("ImporteRetISR").ToDecimal.FormatoNumero + TxtIEPS.Text = TmpDTTotales.SUM("ImporteIEPS").ToDecimal.FormatoNumero TxtTotal.Text = (TxtSubTotal.Text.ToDecimal - LblDescuentos.Text.ToDecimal - LblAmortizacion.Text.ToDecimal + TxtIVA.Text.ToDecimal + TxtIEPS.Text.ToDecimal - TxtRetIVA.Text.ToDecimal - TxtRetISR.Text.ToDecimal - ImpuestosLocales).ToDecimal.FormatoNumero @@ -1802,32 +1806,99 @@ Partial Class PV Exit For Else TmpDT.Rows(index)("CveVentaDetalle") = ObjVentas.CveVentaDetalle + + If TmpDTRecepcionUsados IsNot Nothing Then + If TmpDTRecepcionUsados.Select($"CvePS={Row("CvePS").ToString.ToEntero}").Length > 0 Then + Dim rowInv As DataRow = TmpDTRecepcionUsados.Select($"CvePS={Row("CvePS").ToString.ToEntero}")(0) + rowInv("CveVentaDetalle") = ObjVentas.CveVentaDetalle + End If + End If + + If TmpDTAjustes IsNot Nothing AndAlso TmpDTAjustes.Rows.Count > 0 Then + If TmpDTAjustes.Select($"ConsecutivoVenta={Row("Consec").ToString.ToEntero}").Length > 0 Then + Dim DrAju As DataRow = TmpDTAjustes.Select($"ConsecutivoVenta={Row("Consec").ToString.ToEntero}")(0) + DrAju("CveVentaDetalle") = ObjVentas.CveVentaDetalle + End If + End If + + If TmpDTPolizaVirtual IsNot Nothing Then + If TmpDTPolizaVirtual.Select($"CvePS={Row("CvePS").ToString.ToEntero}").Length > 0 Then + Dim RowPoliza As DataRow = TmpDTPolizaVirtual.Select($"CvePS={Row("CvePS").ToString.ToEntero}")(0) + RowPoliza("CveVentaDetalle") = ObjVentas.CveVentaDetalle + End If + End If + End If End If index = index + 1 Next End If - ObjFactura.DtDetalle = TmpDT 'ELIMINA LOS DETALLES If Not OcurrioError Then - Dim DtEliminados As New DataTable - If ObjVentas.GetVentaDetalle(CveVenta) Then - DtEliminados = ObjVentas.DtResultados.FiltraParametros("", "", {"CveVentaDetalle"}) - For Each Dr1 As DataRow In DtEliminados.Rows - If TmpDT.FiltraParametros($"CveVentaDetalle = {Dr1("CveVentaDetalle")}").Rows.Count = 0 Then - If Not ObjVentas.RemoveVentasDetalle(CveVenta, Dr1("CveVentaDetalle").ToString.ToEntero) Then - OcurrioError = True - End If - End If - Next - Else - OcurrioError = True - End If + Dim DtEliminados As DataTable = TmpDT.FiltraParametros("EliminarDB = True AND CveVentaDetalle > 0", "", {"CveVentaDetalle"}) + + For Each Dr1 As DataRow In DtEliminados.Rows + If Not ObjVentas.RemoveVentasDetalle(CveVenta, Dr1("CveVentaDetalle").ToString.ToEntero) Then + OcurrioError = True + End If + Next End If - 'OcurrioError = ProcesoPrepolizas(ObjConta, ObjFactura, -1, TmpDT, ObjAC, 1, ObjBancos, ObjVentas) + 'RECARGA LOS DATOS + If ObjVentas.GetVentaDetalle(CveVenta) Then + TmpDT = ObjVentas.DtResultados.Copy() + ObjFactura.DtDetalle = TmpDT + Else + OcurrioError = True + End If + + 'GUARDA USADOS + If Not ObjVentas.EliminarUsados(CveVenta) Then + OcurrioError = True + End If + + If TmpDTRecepcionUsados IsNot Nothing Then + For Each drow As DataRow In TmpDTRecepcionUsados.Rows + If Not ObjVentas.AddVentaUsado(CveVenta, drow("CvePS").ToString.ToEntero, drow("Cantidad").ToString.ToDecimal, drow("PU").ToString.ToDecimal, drow("CveBCIUsado").ToString.ToEntero, drow("CveModeloAuto").ToString.ToEntero) Then + OcurrioError = True + Exit For + End If + Next + End If + + 'GUARDAR AJUSTES' + If Not ObjAcum.EliminarGarantiasDetalle(CveVenta) Then + OcurrioError = True + End If + + If TmpDTAjustes IsNot Nothing AndAlso TmpDTAjustes.Rows.Count > 0 Then + For Each Dr As DataRow In TmpDTAjustes.Rows + If Not ObjAcum.AddGarantiasDetalle(Dr("CveVentaDetalle").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, Dr("CveFolioGarantia").ToString.ToEntero, Dr("CveTipoUso").ToString.ToEntero, + Dr("CodigoEnsamble").ToString, Dr("CodigoLinea").ToString, Dr("CodigoInspeccion").ToString, Dr("CveTipoDefecto").ToString.ToEntero, + Dr("NumPoliza").ToString, Dr("Importe").ToString.ToDouble, Dr("Consecutivo").ToString, Dr("FechaAjuste").ToString.ToDateTime()) Then + ErrorList.Add("Ocurrió un error al agregar la garantia detalle.") + End If + Next + End If + + 'GUARDAR POLIZA VIRTUAL + If Not ObjAcum.EliminarPolizaVirtual(CveVenta) Then + OcurrioError = True + End If + + If TmpDTPolizaVirtual IsNot Nothing Then + For Each drow As DataRow In TmpDTPolizaVirtual.Rows + If ObjAcum.AddPolizaVirtual(CveVenta, drow("CveVentaDetalle").ToString().ToEntero(), drow("CvePS").ToString.ToEntero, drow("Cantidad").ToString.ToDecimal, drow("PU").ToString.ToDecimal, drow("Descuento").ToString.ToDecimal, + drow("Total").ToString.ToDecimal, drow("TipoServicio").ToString.ToEntero, drow("TipoPoliza").ToString.ToEntero, drow("CveModeloAuto").ToString.ToEntero, drow("AnioVehiculo").ToString.ToEntero, CBool(drow("TieneUsado").ToString), + drow("FechaUsado").ToString().ToDateTime, drow("CvePSUsado").ToString.ToEntero, drow("CveBCIUsado").ToString.ToEntero) Then + Else + OcurrioError = True + Exit For + End If + Next + End If 'Actualizo impuestos locales If Not OcurrioError Then @@ -2695,7 +2766,7 @@ Partial Class PV TmpDT.Rows.Remove(DbRow) - GvPS.DataSource = TmpDT + GvPS.DataSource = TmpDT.FiltraParametros("EliminarDB = False") DtInv = TmpDT.Copy.FiltraParametros("CveTipoPS = 2") GvPS.DataBind() CargaGVInv(DtInv) @@ -2751,7 +2822,7 @@ Partial Class PV TmpDT = resultados.CopyToDataTable CalculaTotalesVenta() - GvPS.DataSource = TmpDT + GvPS.DataSource = TmpDT.FiltraParametros("EliminarDB = False") GvPS.DataBind() UpPS.Update() @@ -2857,7 +2928,7 @@ Partial Class PV GvInv.Columns(5).Visible = DtTemporal.MAX("Lote", "Lote <> ''") <> "" GvInv.Columns(6).Visible = DtTemporal.MAX("Lote", "Lote <> ''") <> "" - GvInv.DataSource = DtTemporal + GvInv.DataSource = DtTemporal.FiltraParametros("EliminarDB = False") GvInv.DataBind() UpINV.Update() @@ -3806,6 +3877,9 @@ Partial Class PV TmpDT.Columns.Add("PUOriginal", GetType(Decimal)) TmpDT.Columns.Add("ConsecPSPadre", GetType(Integer)) + TmpDT.Columns.Add("EliminarDB", GetType(Boolean)) + TmpDT.Columns("EliminarDB").DefaultValue = False + End Sub Private Sub CreaDTmpC() @@ -3878,7 +3952,7 @@ Partial Class PV Row("TiempoEntrega") = TiempoEntrega TmpDT.Rows.Add(Row) - GvPS.DataSource = TmpDT + GvPS.DataSource = TmpDT.FiltraParametros("EliminarDB = False") GvPS.DataBind() DtInv = TmpDT.Copy.FiltraParametros("CveTipoPS = 2") @@ -3999,7 +4073,7 @@ Partial Class PV Optional CveContratoDetalle As Integer = 0, Optional CveVentaDetalle As Integer = 0, Optional CveMovimientoDetallePedido As Integer = 0, Optional CveOrdenCompraDetalle As Integer = 0, Optional CveVentaDetalleRemision As Integer = 0, Optional CveVentaDetalleCotizacion As Integer = 0, Optional CuentaPredial As String = "", Optional RegeneraIEPS As Boolean = True, Optional CveVentaDetallePedido2 As Integer = 0, Optional EsCargo As Boolean = False, - Optional ConsecPSPadre As Integer = -1) As Integer + Optional ConsecPSPadre As Integer = -1, Optional EliminarDB As Boolean = False) As Integer Dim Retorno As Integer = -1 If Not CvePS > 0 Then @@ -4170,6 +4244,8 @@ Partial Class PV Row("ConsecPSPadre") = ConsecPSPadre End If + Row("EliminarDB") = EliminarDB + If UsuarioActual.CveEmpresa = 119 Then If Not RemisionesLista.Count > 0 Then 'SI VIENE DE REMISION NO SE CONSIDERA @@ -4477,8 +4553,8 @@ Partial Class PV Else If Me.CveVentaDetalle > 0 Then For Each Gvr As GridViewRow In GvPS.Rows - Gvr.FCLinkButton("imgE").Visible = Not Gvr.DataKey("CantidadFacturadaRem").ToString.ToDouble > 0 AndAlso Gvr.DataKey("EsCargo") = "True" - Gvr.FCLinkButton("imgD").Visible = Not Gvr.DataKey("CantidadInventario").ToString.ToDouble > 0 AndAlso Gvr.DataKey("EsCargo") = "True" + Gvr.FCLinkButton("imgE").Visible = Not Gvr.DataKey("CantidadFacturadaRem").ToString.ToDouble > 0 AndAlso Gvr.DataKey("EsCargo") = "False" + Gvr.FCLinkButton("imgD").Visible = Not Gvr.DataKey("CantidadInventario").ToString.ToDouble > 0 AndAlso Gvr.DataKey("EsCargo") = "False" Next End If UpVenta.Update() @@ -4530,7 +4606,12 @@ Partial Class PV If ListaPSCargo.Count > 0 Then CalculaRecepcionUsados(GvRecepcionUsados, CvePS, ListaPSCargo) End If - + ElseIf CveVentaDetalle > 0 AndAlso Not EsCargo Then + EliminarUsados() + Dim ListaPSCargo = CalculaUsados(Consec, LimpiarUsados:=False) + If ListaPSCargo.Count > 0 Then + CalculaRecepcionUsados(GvRecepcionUsados, CvePS, ListaPSCargo) + End If End If Return True @@ -4662,6 +4743,7 @@ Partial Class PV #Region "CALCULA TOTALES" Private Sub CalculaTotalesVenta(Optional RecalculaImpuestosLocales As Boolean = True) + Dim TmpDT = Me.TmpDT.FiltraParametros("EliminarDB = False", Orderby:="Consec") Dim TotalSubTotal As Decimal = TmpDT.SUM("TotalImporte").ToDecimal Dim TotalDescuentos As Decimal = TmpDT.SUM("Descuento").ToDecimal @@ -4715,9 +4797,7 @@ Partial Class PV 'JJMQ 20160506: Se agrego para la validacion de pago de contado. 'CVImporteContado.ValueToCompare = Total.ToString - Dim view As DataView = New DataView(TmpDT) - view.Sort = "Consec" - GvPS.DataSource = view + GvPS.DataSource = TmpDT GvPS.DataBind() 'RECARGA GV INVENTARIO @@ -6325,7 +6405,7 @@ Partial Class PV Dim Total As Decimal = ((Cantidad * PU) - Descuento).RoundSQL(2) Dim TipoServicio As Integer = DdlTipoServicio.SelectedValue.ToEntero() - Dim FechaUsado As DateTime = TxtFechaAjuste.Text.ToDateTime() + Dim FechaUsado As DateTime = If(TxtFechaAjuste.Text.ToDateTime() < MinFecha, Now, TxtFechaAjuste.Text.ToDateTime()) Dim CveModeloAuto As Integer = DdlModeloAuto.SelectedValue.ToEntero() Dim AnioVehiculo As Integer = TxtAnioVehiculo.Text.ToEntero() Dim TipoPoliza As Integer = 1 'VENTA @@ -6376,6 +6456,7 @@ Partial Class PV Return Retorno End Function #End Region + #Region "U S A D O S" Private Sub CreaDTmpDTRecepcionUsados() @@ -6388,6 +6469,8 @@ Partial Class PV TmpDTRecepcionUsados.Columns.Add("PU", GetType(Double)) TmpDTRecepcionUsados.Columns.Add("CveBCIUsado", GetType(Integer)) TmpDTRecepcionUsados.Columns.Add("CveModeloAuto", GetType(Integer)) + TmpDTRecepcionUsados.Columns.Add("EliminarDB", GetType(Boolean)) + TmpDTRecepcionUsados.Columns("EliminarDB").DefaultValue = False End Sub @@ -6453,7 +6536,7 @@ Partial Class PV ' Exit Sub 'End If - For Each Dr As DataRow In TmpDT.FiltraParametros($"EsCargo = True AND CvePS IN ({StrCargos})").Rows + For Each Dr As DataRow In TmpDT.FiltraParametros($"EsCargo = True AND EliminarDB = False AND CvePS IN ({StrCargos})").Rows Dim TotalAnterior As Decimal = Dr("Cantidad").ToString.ToDecimal * Dr("PU").ToString.ToDecimal Dim PUActual As Decimal = (TotalAnterior - TotalCargos) / Dr("Cantidad").ToString.ToDecimal @@ -6485,7 +6568,7 @@ Partial Class PV Next TmpDT.AcceptChanges() If TotalCargos > 0 Then ' cuando se entrega más valor de usados, que los cargos hechos, se descuenta sobre el PU del producto de venta - For Each Dr As DataRow In TmpDT.FiltraParametros($"EsCargo = False AND CvePS={CvePS}").Rows + For Each Dr As DataRow In TmpDT.FiltraParametros($"EsCargo = False AND EliminarDB = False AND CvePS={CvePS}").Rows Dim PUAnterior As Decimal = Dr("Cantidad").ToString.ToDecimal * Dr("PU").ToString.ToDecimal Dim PUActual As Decimal = PUAnterior - (TotalCargos / Dr("Cantidad").ToString.ToDecimal) @@ -6522,8 +6605,8 @@ Partial Class PV CalculaTotalesVenta() End Sub - Private Function CalculaUsados(Consec As Integer) As List(Of Integer) - If Modalidad = "U" Then + Private Function CalculaUsados(Consec As Integer, Optional LimpiarUsados As Boolean = True) As List(Of Integer) + If Modalidad = "U" AndAlso LimpiarUsados Then EliminarUsados(Consec) End If @@ -6556,6 +6639,8 @@ Partial Class PV DTPSTemp.Columns.Add("CveSubProyecto", GetType(Integer)) DTPSTemp.Columns.Add("SubProyecto", GetType(String)) DTPSTemp.Columns.Add("ConsecPSPadre", GetType(Integer)) + DTPSTemp.Columns.Add("EliminarDB", GetType(Boolean)) + DTPSTemp.Columns("EliminarDB").DefaultValue = False Dim ObjProductosServicios As New ClsProductosServicios() For Each DrowPartidas As DataRow In TmpDT.Select($"Consec = {Consec}") @@ -6628,7 +6713,7 @@ Partial Class PV Dim Concec = AgregarProductoServicio(drowPsTamaños("Cantidad").ToString.ToEntero, drowPsTamaños("CveUnidadMedida").ToString.ToEntero, drowPsTamaños("UnidadMedida").ToString, drowPsTamaños("CveClasificacion").ToString.ToEntero, drowPsTamaños("Clasificacion").ToString, drowPsTamaños("CvePS").ToString.ToEntero, drowPsTamaños("PS").ToString, "", drowPsTamaños("PU").ToString.ToDecimal, 0, -1, "", drowPsTamaños("CveSubProyecto").ToString.ToEntero, - drowPsTamaños("SubProyecto").ToString, EsCargo:=True, ConsecPSPadre:=drowPsTamaños("ConsecPSPadre").ToString.ToEntero) + drowPsTamaños("SubProyecto").ToString, EsCargo:=True, ConsecPSPadre:=drowPsTamaños("ConsecPSPadre").ToString.ToEntero, EliminarDB:=CBool(drowPsTamaños("EliminarDB").ToString())) If Consec > 0 Then ListaPScargo.Add(drowPsTamaños("CvePS").ToString.ToEntero) End If @@ -6655,6 +6740,25 @@ Partial Class PV Next Next + TmpDT.AcceptChanges() + TmpDTRecepcionUsados.AcceptChanges() + End Sub + Private Sub EliminarUsados() + + 'ELIMINAR EL USADO EXTRAS + For Each drow As DataRow In TmpDT.Select("EsCargo = True") + drow("EliminarDB") = True + Next + + 'ELIMINAR LOS USADOS QUE SE MANDAN A RECEPCION + For Each drow As DataRow In TmpDT.Select("EsCargo = True") + For Each RowRecepcionUsados As DataRow In TmpDTRecepcionUsados.Rows + If (RowRecepcionUsados("CvePSRelacionado").ToString() = drow("CvePS").ToString()) Then + RowRecepcionUsados.Delete() + End If + Next + Next + TmpDT.AcceptChanges() TmpDTRecepcionUsados.AcceptChanges() End Sub