From 485113f14dea34215e4ce5364ae025d23bf7272e Mon Sep 17 00:00:00 2001 From: Jonathan Alexis Perez Morales Date: Wed, 2 Oct 2019 19:32:51 -0700 Subject: [PATCH] Recepcion de usados --- App_Code/ClsVentas.vb | 86 +++++++++++++++++++++++++++++++++++++++++++ App_Code/Modelos.vb | 78 +++++++++++++++++++++++---------------- 2 files changed, 132 insertions(+), 32 deletions(-) diff --git a/App_Code/ClsVentas.vb b/App_Code/ClsVentas.vb index a5f4d0b01..03bcd2a49 100644 --- a/App_Code/ClsVentas.vb +++ b/App_Code/ClsVentas.vb @@ -3929,6 +3929,92 @@ Public Class ClsVentas Return retorno End Function #End Region + +#Region " U S A D O S " + + Public Function AddVentaUsado(CveVenta As Integer, CvePS As Integer, Cantidad As Decimal, PU As Decimal) As Boolean + Dim Retorno As Boolean = False + + DataAdapter("PA_Vta_VentasUsadosAdd", CommandType.StoredProcedure) + + With SqlAdapter.SelectCommand.Parameters + .Add("@CveVenta", SqlDbType.Int).Value = CveVenta + .Add("@CvePS", SqlDbType.Int).Value = CvePS + .Add("@Cantidad", SqlDbType.Float).Value = Cantidad + .Add("@PU", SqlDbType.Money).Value = PU + End With + + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As Exception + OnError("Ocurrió un error al relacionar las ventas con 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 + + DataAdapter("PA_Vta_VentasUsadosGet", CommandType.StoredProcedure) + + With SqlAdapter.SelectCommand.Parameters + .Add("@CveVenta", SqlDbType.Int).Value = CveVenta + .Add("@CveSubProyecto", SqlDbType.Int).Value = CveSubProyecto + .Add("@Fecha", SqlDbType.DateTime).Value = Fecha + .Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa + End With + + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As Exception + OnError("Ocurrió un error al obtener las ventas con usados.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + Return Retorno + End Function + Public Function GetVentasUsadosDetalle(CveVenta As Integer) As Boolean + Dim Retorno As Boolean = False + + DataAdapter("PA_Vta_VentasUsadosDetalleGet", 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 obtener las ventas con usados.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + Return Retorno + End Function + Public Function UpdateVentaUsadoRecibido(CveVenta As Integer, CvePS As Integer, Recibido As Boolean) As Boolean + Dim Retorno As Boolean = False + + DataAdapter("PA_Vta_VentasUsadosRecibidoUpdate", CommandType.StoredProcedure) + + With SqlAdapter.SelectCommand.Parameters + .Add("@CveVenta", SqlDbType.Int).Value = CveVenta + .Add("@CvePS", SqlDbType.Int).Value = CvePS + .Add("@Recibido", SqlDbType.Bit).Value = Recibido + End With + + Try + SqlAdapter.Fill(Data) + Retorno = True + Catch ex As Exception + OnError("Ocurrió un error al actualizar el recibo de los usados.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + Return Retorno + End Function + + +#End Region #Region "IDisposable Support" diff --git a/App_Code/Modelos.vb b/App_Code/Modelos.vb index f77aa9e8d..9d954513c 100644 --- a/App_Code/Modelos.vb +++ b/App_Code/Modelos.vb @@ -1230,7 +1230,7 @@ Namespace Modelos End If - If Not GuardarUsados(ObjVentas.IniciaTransacSQL, ObjVentas.CveVenta) Then + If Not GuardarUsados(ObjVentas.IniciaTransacSQL, ObjVentas.CveVenta, ObjVentas) Then ErrorList.Add("Error al guardar usados") End If @@ -1480,7 +1480,7 @@ Namespace Modelos 'inventarios GuardarVentaInventarios(factura, ObjInventario, ObjConta) - GuardaRecepcionUsados(factura, ObjInventario, ObjConta) + 'GuardaRecepcionUsados(factura, ObjInventario, ObjConta) If ErrorList.Count = 0 Then 'estimaciones @@ -1755,36 +1755,50 @@ Namespace Modelos DtVentasNC.Rows.Add(Dr) End If End Sub - Private Function GuardarUsados(SqlTransaccion As SqlClient.SqlTransaction, CveVenta As Integer) As Boolean - Dim Resultado As Boolean = True - - If ClienteEsDistribuidor Then - If UsuarioActual.Empresa.Funcionalidad(533).ToEntero > 0 Then - Dim CvePSPSA As Integer = UsuarioActual.Empresa.Funcionalidad(533).ToEntero - - Dim ObjAcum As New ClsAcumuladores(SqlTransaccion) - - - For Each drow As DataRow In DtDetalle.Rows - If drow("CveTamaño").ToString.ToEntero > 0 And (CvePSPSA <> drow("CvePS").ToString.ToEntero) Then - If ObjAcum.DistribuidorMovtosAdd(CveCliente, drow("Cantidad").ToString.ToEntero, drow("CveTamaño").ToString.ToEntero, 2, CveVenta, UsuarioActual.CveUsuario, - UsuarioActual.CveEmpresa, 0D, "") Then - Else - Resultado = False - Exit For - End If - Else - Resultado = True - End If - Next - Else - ErrorList.Add("El cliente es Distribuidor y no se tiene un producto o servicio asigando como PS Acumulador") - Resultado = False - End If - Else - Resultado = True - End If - + Private Function GuardarUsados(SqlTransaccion As SqlClient.SqlTransaction, CveVenta As Integer, ByRef ObjVentas As ClsVentas) As Boolean + Dim Resultado As Boolean = True + + 'If ClienteEsDistribuidor Then + If UsuarioActual.Empresa.Funcionalidad(533).ToEntero > 0 Then + Dim CvePSPSA As Integer = UsuarioActual.Empresa.Funcionalidad(533).ToEntero + + Dim ObjAcum As New ClsAcumuladores(SqlTransaccion) + + For Each drow As DataRow In DtDetalle.Rows + If drow("CveTamaño").ToString.ToEntero > 0 And (CvePSPSA <> drow("CvePS").ToString.ToEntero) Then + If ObjAcum.DistribuidorMovtosAdd(CveCliente, drow("Cantidad").ToString.ToEntero, drow("CveTamaño").ToString.ToEntero, 2, CveVenta, UsuarioActual.CveUsuario, + UsuarioActual.CveEmpresa, 0D, "") Then + Else + Resultado = False + Exit For + End If + Else + Resultado = True + End If + Next + + If TipoDocto.Contiene("Rem") Then + If DtRecepcionUsados IsNot Nothing Then + For Each drow As DataRow In DtRecepcionUsados.Rows + If Not ObjVentas.AddVentaUsado(CveVenta, drow("CvePS").ToString.ToEntero, drow("Cantidad").ToString.ToDecimal, drow("PU").ToString.ToDecimal) Then + Resultado = False + Exit For + End If + Next + Else + Resultado = False + End If + End If + + + Else + ErrorList.Add("El cliente es Distribuidor y no se tiene un producto o servicio asigando como PS Acumulador") + Resultado = False + End If + 'Else + ' Resultado = True + 'End If + Return Resultado End Function