diff --git a/Ventas/PV.aspx.vb b/Ventas/PV.aspx.vb index dee07e6c9..ec8e13550 100644 --- a/Ventas/PV.aspx.vb +++ b/Ventas/PV.aspx.vb @@ -1789,7 +1789,7 @@ Partial Class PV 'Cargo de nueva cuenta el detalle de Ventas (Conceptos) If Not OcurrioError Then Dim index As Integer = 0 - For Each Row As DataRow In TmpDT.Rows + For Each Row As DataRow In TmpDT.FiltraParametros("EliminarDB = False").Rows Dim CveVentaDetalle As Integer = Row("CveVentaDetalle").ToString.ToEntero() If CveVentaDetalle > 0 Then If Not ObjVentas.UpdateVentaDetalleRemision(Row("CveVentaDetalle").ToString.ToEntero, Row("CvePS").ToString.ToEntero, Row("Cantidad").ToString.ToDecimal, Row("PU").ToString.ToDecimal(), Row("ImporteIEPS").ToString.ToDecimal(), Row("Obs").ToString, UsuarioActual.CveUsuario) Then @@ -1847,19 +1847,45 @@ Partial Class PV End If 'RECARGA LOS DATOS - If ObjVentas.GetVentaDetalle(CveVenta) Then - TmpDT = ObjVentas.DtResultados.Copy() - ObjFactura.DtDetalle = TmpDT - Else + ObjFactura.Dispose() + ObjFactura = Nothing + ObjFactura = New Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa) + + If ObjFactura Is Nothing Then OcurrioError = True + Else + TmpDT = ObjFactura.DtDetalle + TmpDT.Columns.Add("EntregaDirecta", GetType(Integer)) + TmpDT.Columns.Add("CveMovimientoDetallePedido", GetType(Integer)) + + Dim NumRowsPS As Integer = 0 + Dim CantidadPS As Decimal = 0 + For Each GvRow As GridViewRow In GvPS.Rows + If GvRow.RowType = DataControlRowType.DataRow Then + NumRowsPS += 1 + CantidadPS += GvRow.DataKey("Cantidad").ToDecimal() + End If + Next + + 'VALIDA NUMERO DE REGISTROS + If TmpDT.Rows.Count <> NumRowsPS Then + OcurrioError = True + End If + + 'VALIDA CANTIDAD DE REGISTROS + If TmpDT.SUM("Cantidad") <> CantidadPS Then + OcurrioError = True + End If + End If + 'GUARDA USADOS - If Not ObjVentas.EliminarUsados(CveVenta) Then + If Not OcurrioError AndAlso Not ObjVentas.EliminarUsados(CveVenta) Then OcurrioError = True End If - If TmpDTRecepcionUsados IsNot Nothing Then + If Not OcurrioError AndAlso 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 @@ -1869,11 +1895,11 @@ Partial Class PV End If 'GUARDAR AJUSTES' - If Not ObjAcum.EliminarGarantiasDetalle(CveVenta) Then + If Not OcurrioError AndAlso Not ObjAcum.EliminarGarantiasDetalle(CveVenta) Then OcurrioError = True End If - If TmpDTAjustes IsNot Nothing AndAlso TmpDTAjustes.Rows.Count > 0 Then + If Not OcurrioError AndAlso 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, @@ -1884,11 +1910,11 @@ Partial Class PV End If 'GUARDAR POLIZA VIRTUAL - If Not ObjAcum.EliminarPolizaVirtual(CveVenta) Then + If Not OcurrioError AndAlso Not ObjAcum.EliminarPolizaVirtual(CveVenta) Then OcurrioError = True End If - If TmpDTPolizaVirtual IsNot Nothing Then + If Not OcurrioError AndAlso 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), @@ -2758,13 +2784,18 @@ Partial Class PV #Region "GVPS" Protected Sub GvPS_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvPS.RowDeleting - Dim DbRow As DataRow = Nothing DbRow = TmpDT.Rows(e.RowIndex) - EliminarUsados(DbRow("Consec").ToString().ToEntero()) + Me.CveVentaDetalle = DbRow("CveVentaDetalle").ToString().ToEntero() - TmpDT.Rows.Remove(DbRow) + If Me.CveVentaDetalle <= 0 Then + EliminarUsados(DbRow("Consec").ToString().ToEntero()) + TmpDT.Rows.Remove(DbRow) + Else + EliminarUsados() + DbRow("EliminarDB") = True + End If GvPS.DataSource = TmpDT.FiltraParametros("EliminarDB = False") DtInv = TmpDT.Copy.FiltraParametros("CveTipoPS = 2") @@ -2774,6 +2805,9 @@ Partial Class PV Alert("Eliminado Correctamente.", TipoMensaje.MsgInformacion) + Me.CveVentaDetalle = -1 + + UpContado.Update() End Sub Protected Sub GvPS_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvPS.RowDataBound