From 7314a278da976a87d0973cdd4c5e8f25f07ec53c Mon Sep 17 00:00:00 2001 From: rakcsle Date: Fri, 12 Jan 2024 15:58:46 -0700 Subject: [PATCH] =?UTF-8?q?SMS=20-=20Ajustes=202024.01.10=20guardar=20mate?= =?UTF-8?q?rial=20os=20tipo=20venta=20=20Consignaci=C3=B3n=20-=20=20Uso=20?= =?UTF-8?q?material?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App_Code/ClsOS.vb | 26 +++ OS/OrdenesServicios.aspx.vb | 315 ++++++++++++++++++++++-------------- 2 files changed, 224 insertions(+), 117 deletions(-) diff --git a/App_Code/ClsOS.vb b/App_Code/ClsOS.vb index 4aaabb0e2..950871f6f 100644 --- a/App_Code/ClsOS.vb +++ b/App_Code/ClsOS.vb @@ -1871,6 +1871,32 @@ Public Class ClsOS #End Region + Public Function AddOrdenesServicioMateriales(CveOS As Integer, CvePS As Integer, Cantidad As Decimal, Serie As String, Lote As String, FechaCaducidad As Date, CveUsuario As Integer) As Boolean + Dim Retorno As Boolean = False + + DataAdapter("PA_OS_OrdenesServicioMaterialesAdd") + + With SqlAdapter.SelectCommand.Parameters + .Add("@CveOS", SqlDbType.Int).Value = CveOS + .Add("@CvePS", SqlDbType.Int).Value = CvePS + .Add("@Cantidad", SqlDbType.Decimal).Value = Cantidad + .Add("@Serie", SqlDbType.VarChar).Value = Serie + .Add("@Lote", SqlDbType.VarChar).Value = Lote + .Add("@FechaCaducidad", SqlDbType.Date).Value = FechaCaducidad + .Add("@CveUsuario", SqlDbType.Int).Value = CveUsuario + End With + + Try + SqlAdapter.Fill(Data) + Retorno = True + + Catch ex As Exception + OnError("Ocurrió un error al guardar el material.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo) + End Try + + Return Retorno + End Function + 'Public Function GetCveCliente(CveVenta As Integer) As Boolean ' Dim Retorno As Boolean = False ' DataAdapter("PA_OS_ClienteGet") diff --git a/OS/OrdenesServicios.aspx.vb b/OS/OrdenesServicios.aspx.vb index 36b7a9574..b7536f248 100644 --- a/OS/OrdenesServicios.aspx.vb +++ b/OS/OrdenesServicios.aspx.vb @@ -8,6 +8,8 @@ Imports Telerik.Web.UI Imports System.Data.SqlClient Imports Stimulsoft.Report.StiOptions.Export Imports Modelos +Imports System.Runtime.InteropServices.ComTypes +Imports APP_Code_CSharp Partial Class OS_OrdenesServicios Inherits ClsPaginas @@ -670,7 +672,7 @@ Partial Class OS_OrdenesServicios ' End If 'End If - ElseIf TipoEstatus = 4 Then + ElseIf TipoEstatus = 4 AndAlso Not UsuarioActual.Empresa.Funcionalidad(578).ToEntero = 1 Then 'DisableAll() If SeFacturara = "True" Then HplFacturar.Visible = True @@ -2955,6 +2957,20 @@ Partial Class OS_OrdenesServicios LnkModalMaterialUtilizado.Visible = True DTSolicitudDev = New DataTable Dim Opcion As Integer = If(DdlTipoVenta.SelectedValue.Contiene("2", "3"), 2, 1) + + + Select Case DdlTipoVenta.SelectedValue.ToEntero + Case 2, 3 + Opcion = 2 + Exit Select + Case 5 + Opcion = 3 + Exit Select + Case Else + Opcion = 1 + Exit Select + End Select + Dim ObjOS As New ClsOS If ObjOS.GetOrdenesServicioDevolucionMaterial(CveOS, CveVenta, Opcion, UsuarioActual.CveEmpresa) Then DTSolicitudDev = ObjOS.DtResultados @@ -2996,176 +3012,241 @@ Partial Class OS_OrdenesServicios Dim CveVentaPedido As Integer = DTSolicitudDev.FiltroPrimeroValor("CveVenta").ToEntero Dim CveAlmacenDestino As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, 10).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto = {CveSubProyectoPedido}").ToEntero - If Not CveAlmacenDestino > 0 Then - Alert("No se encontró almacen de entrega por adelantado", TipoMensaje.MsgAdvertencia) - Exit Sub + If DdlTipoVenta.SelectedValue.ToEntero = 5 Then + Dim TotalSeleccionado As Decimal = 0 + + For Each GVRow As GridViewRow In GvMU.Rows + TotalSeleccionado = TotalSeleccionado + GVRow.FCTextBox("TxtUtilizado").Text.ToDecimal + Next + + If TotalSeleccionado = 0 Then + Alert("No se selecciono ningun material", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + Else + + If Not CveAlmacenDestino > 0 Then + Alert("No se encontró almacen de entrega por adelantado", TipoMensaje.MsgAdvertencia) + Exit Sub + End If + End If + + Dim ProcesoOK As Boolean = True Dim ObjV As New ClsVentas - Dim ClsOS As New ClsOS(ObjV.IniciaTransacSQL()) + Dim ObjOS As New ClsOS(ObjV.IniciaTransacSQL()) Dim ObjInventario As New ClsInventarios(ObjV.IniciaTransacSQL()) Dim ObjConta As New ClsContabilidad(ObjV.IniciaTransacSQL()) - Dim GenrarRemisionMovimientos As Boolean = False - If ProcesoOK Then - Dim AplicaDevolucion As Boolean = False - For Each GvRow As GridViewRow In GvMU.Rows - Dim CveVentaDetalle As Integer = GvRow.DataKey("CveVentaDetalle").ToEntero - Dim CantidadDev As Decimal = GvRow.DataKey("Cantidad").ToDecimal - GvRow.FCTextBox("TxtUtilizado").Text.ToDecimal - If CantidadDev > 0 Then - AplicaDevolucion = True - If Not ObjV.UpdateVentasDetalleCantidadDevolucion(CveVentaDetalle, CantidadDev) Then + + + If DdlTipoVenta.SelectedValue.ToEntero = 5 Then + + For Each GVRow As GridViewRow In GvMU.Rows + Dim CantidadRegistro As Decimal = GVRow.FCTextBox("TxtUtilizado").Text.ToDecimal + Dim CvePS As Integer = GVRow.DataKey("CvePS").ToEntero + + If CantidadRegistro > 0 Then + + Dim Serie As String = If(GVRow.DataKey("Serie") = "", "-1", GVRow.DataKey("Serie")) + Dim Lote As String = If(GVRow.DataKey("Lote") = "", "-1", GVRow.DataKey("Lote")) + Dim FechaCaducidad As DateTime = If(GVRow.DataKey("FechaCaducidad") = "", MinFecha, GVRow.DataKey("FechaCaducidad").ToDate) + + If Not ObjOS.AddOrdenesServicioMateriales(CveOS, CvePS, CantidadRegistro, Serie, Lote, FechaCaducidad, UsuarioActual.CveUsuario) Then + Alert("Ocurrió un error al guardar el material.", TipoMensaje.MsgAdvertencia) ProcesoOK = False - GenrarRemisionMovimientos = False - AplicaDevolucion = False Exit For End If - End If - If GvRow.FCTextBox("TxtUtilizado").Text.ToDecimal > 0 Then - GenrarRemisionMovimientos = True End If - Next - If AplicaDevolucion Then - If Not ObjV.UpdateVentasDevolucionAlmacen(1, CveVenta) Then + + If ProcesoOK Then + + Dim CveOSEstatusFinalizada As Integer = GlobalDTEstatusOrdenServicios(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveEstatusOrdenServicio", "TipoEstatus = 4").ToEntero + + If CveOSEstatusFinalizada > 0 Then + If Not ObjOS.UpdateOrdenesServiciosEstatus(CveOSEstatusFinalizada, UsuarioActual.CveUsuario, CveOS) Then + ProcesoOK = False + End If + Else + Alert("No se pudo obtener el estado para finalizar la orden de servicio.") ProcesoOK = False End If + + End If - End If - Dim Respuesta As New RespuestaFacturacion() - Dim DtVentaDetalle As New DataTable - Dim CveMovimientoSalida, CveMovimientoEntrada As Integer - Dim ImporteAlmacen As Decimal - Dim Fecha As DateTime = ClsPaginas.NowADS() - - If GenrarRemisionMovimientos AndAlso ProcesoOK Then - Respuesta = GeneraRemision(CveVentaPedido, ObjV.IniciaTransacSQL()) - - If Respuesta.CveVenta > 0 Then - If ObjV.GetVentaDetalle(Respuesta.CveVenta) Then - Dim dtClon As DataTable = ObjV.DtResultados.Copy - dtClon.DefaultView.Sort = "CveVentaDetalle ASC" - DtVentaDetalle = dtClon.DefaultView.ToTable() - End If - Else - ProcesoOK = False - End If - End If - - If GenrarRemisionMovimientos AndAlso ProcesoOK Then - - CveMovimientoSalida = ObjInventario.AddMovimiento(CveAlmacenActual, 8, CveMoneda, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, Respuesta.CveVenta, CveSubProyectoPedido, -1, CveOS:=CveOS, CveAlmacenDestino:=CveAlmacenDestino, Modulo:="OS/MatUtil") - Dim Folio As Integer = ObjInventario.Folio - - If CveMovimientoSalida > 0 Then - - Dim IndexMov1 As Integer = 0 + Else + If ProcesoOK Then + Dim AplicaDevolucion As Boolean = False For Each GvRow As GridViewRow In GvMU.Rows + Dim CveVentaDetalle As Integer = GvRow.DataKey("CveVentaDetalle").ToEntero + Dim CantidadDev As Decimal = GvRow.DataKey("Cantidad").ToDecimal - GvRow.FCTextBox("TxtUtilizado").Text.ToDecimal - Dim Cantidad As Decimal = GvRow.DataKey("Cantidad").ToDecimal - Dim CantidadRegistro As Decimal = GvRow.FCTextBox("TxtUtilizado").Text.ToDecimal - Dim CvePS As Integer = GvRow.DataKey("CvePS").ToEntero - Dim CveUM As Integer = GvRow.DataKey("CveUM").ToEntero - Dim PU As Decimal = GvRow.DataKey("PU").ToDecimal - - If CantidadRegistro > 0 Then - Dim CveVentaDetalle As Integer = GvRow.DataKey("CveVentaDetalle").ToEntero ' DtVentaDetalle.Rows(IndexMov1)("CveVentaDetalle").ToString.ToEntero - Dim CveMovimientoDetalle As Integer = GvRow.DataKey("CveMovimientoDetalle").ToEntero - - Dim Serie As String = GvRow.DataKey("Serie") - Dim Lote As String = GvRow.DataKey("Lote") - Dim FechaCaducidad As DateTime = GvRow.DataKey("FechaCaducidad").ToDate - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadRegistro, CveUM, CvePS, PU, CveVentaDetalle:=CveVentaDetalle, CveMovimientoDetalleEntrada:=CveMovimientoDetalle, Lote:=Lote, Serie:=Serie, FechaCaducidad:=FechaCaducidad) Then - Alert("Error al agregar detalle de movimiento.", TipoMensaje.MsgAdvertencia) + If CantidadDev > 0 Then + AplicaDevolucion = True + If Not ObjV.UpdateVentasDetalleCantidadDevolucion(CveVentaDetalle, CantidadDev) Then ProcesoOK = False + GenrarRemisionMovimientos = False + AplicaDevolucion = False Exit For End If End If - IndexMov1 = IndexMov1 + 1 + + If GvRow.FCTextBox("TxtUtilizado").Text.ToDecimal > 0 Then + GenrarRemisionMovimientos = True + End If + Next + If AplicaDevolucion Then + If Not ObjV.UpdateVentasDevolucionAlmacen(1, CveVenta) Then + ProcesoOK = False + End If + End If + End If + Dim Respuesta As New RespuestaFacturacion() + Dim DtVentaDetalle As New DataTable + Dim CveMovimientoSalida, CveMovimientoEntrada As Integer + Dim ImporteAlmacen As Decimal + Dim Fecha As DateTime = ClsPaginas.NowADS() - If ProcesoOK Then + If GenrarRemisionMovimientos AndAlso ProcesoOK Then + Respuesta = GeneraRemision(CveVentaPedido, ObjV.IniciaTransacSQL()) - CveMovimientoEntrada = ObjInventario.AddMovimiento(CveAlmacenDestino, 9, CveMoneda, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, Respuesta.CveVenta, CveSubProyectoPedido, -1, CveOS:=CveOS, CveMovimientoRelacionado:=CveMovimientoSalida, Modulo:="OS/MatUtil2") + If Respuesta.CveVenta > 0 Then + If ObjV.GetVentaDetalle(Respuesta.CveVenta) Then + Dim dtClon As DataTable = ObjV.DtResultados.Copy + dtClon.DefaultView.Sort = "CveVentaDetalle ASC" + DtVentaDetalle = dtClon.DefaultView.ToTable() + End If + Else + ProcesoOK = False + End If + End If - If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then - ImporteAlmacen = ObjInventario.DtResultados.SUM("Total") - Dim IndexMov2 As Integer = 0 - For Each dRow As DataRow In ObjInventario.DtResultados.Rows + If GenrarRemisionMovimientos AndAlso ProcesoOK Then - Dim Cantidad As Decimal = dRow("Cantidad").ToString.ToDecimal - Dim CvePS As Integer = dRow("CvePS").ToString.ToEntero - Dim CveUM As Integer = dRow("CveUM").ToString.ToEntero - Dim PU As Decimal = dRow("PU").ToString.ToDecimal - Dim CveVentaDetalle As Integer = dRow("CveVentaDetalle").ToString.ToEntero - Dim CveMovimientoDetalle As Integer = dRow("CveMovimientoDetalle").ToString.ToEntero + CveMovimientoSalida = ObjInventario.AddMovimiento(CveAlmacenActual, 8, CveMoneda, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, Respuesta.CveVenta, CveSubProyectoPedido, -1, CveOS:=CveOS, CveAlmacenDestino:=CveAlmacenDestino, Modulo:="OS/MatUtil") + Dim Folio As Integer = ObjInventario.Folio - Dim Lote As String = dRow("Lote").ToString - Dim Serie As String = dRow("Serie").ToString - Dim FechaCaducidad As DateTime = dRow("FechaCaducidad").ToString.ToDateTime + If CveMovimientoSalida > 0 Then - If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Cantidad, CveUM, CvePS, PU, CveVentaDetalle:=CveVentaDetalle, CveMovimientoDetalleEntrada:=CveMovimientoDetalle, Lote:=Lote, Serie:=Serie, FechaCaducidad:=FechaCaducidad) Then + Dim IndexMov1 As Integer = 0 + For Each GvRow As GridViewRow In GvMU.Rows + + Dim Cantidad As Decimal = GvRow.DataKey("Cantidad").ToDecimal + Dim CantidadRegistro As Decimal = GvRow.FCTextBox("TxtUtilizado").Text.ToDecimal + Dim CvePS As Integer = GvRow.DataKey("CvePS").ToEntero + Dim CveUM As Integer = GvRow.DataKey("CveUM").ToEntero + Dim PU As Decimal = GvRow.DataKey("PU").ToDecimal + + If CantidadRegistro > 0 Then + Dim CveVentaDetalle As Integer = GvRow.DataKey("CveVentaDetalle").ToEntero ' DtVentaDetalle.Rows(IndexMov1)("CveVentaDetalle").ToString.ToEntero + Dim CveMovimientoDetalle As Integer = GvRow.DataKey("CveMovimientoDetalle").ToEntero + + Dim Serie As String = GvRow.DataKey("Serie") + Dim Lote As String = GvRow.DataKey("Lote") + Dim FechaCaducidad As DateTime = GvRow.DataKey("FechaCaducidad").ToDate + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadRegistro, CveUM, CvePS, PU, CveVentaDetalle:=CveVentaDetalle, CveMovimientoDetalleEntrada:=CveMovimientoDetalle, Lote:=Lote, Serie:=Serie, FechaCaducidad:=FechaCaducidad) Then Alert("Error al agregar detalle de movimiento.", TipoMensaje.MsgAdvertencia) ProcesoOK = False Exit For End If - IndexMov2 = IndexMov2 + 1 - Next - If ProcesoOK Then - Dim ObjEventos As New ClsOIEventos(ObjInventario.IniciaTransacSQL) - Dim LigaVenta As String = String.Format("Venta {2} en Folio: {1}", CveMovimientoEntrada, Folio, "Material utilizado") + End If + IndexMov1 = IndexMov1 + 1 + Next - If Not ObjEventos.AddEventoBitacora(LigaVenta, "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveVenta:=Respuesta.CveVenta, CveOS:=CveOS) Then + If ProcesoOK Then + + CveMovimientoEntrada = ObjInventario.AddMovimiento(CveAlmacenDestino, 9, CveMoneda, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, Respuesta.CveVenta, CveSubProyectoPedido, -1, CveOS:=CveOS, CveMovimientoRelacionado:=CveMovimientoSalida, Modulo:="OS/MatUtil2") + + If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then + ImporteAlmacen = ObjInventario.DtResultados.SUM("Total") + Dim IndexMov2 As Integer = 0 + For Each dRow As DataRow In ObjInventario.DtResultados.Rows + + Dim Cantidad As Decimal = dRow("Cantidad").ToString.ToDecimal + Dim CvePS As Integer = dRow("CvePS").ToString.ToEntero + Dim CveUM As Integer = dRow("CveUM").ToString.ToEntero + Dim PU As Decimal = dRow("PU").ToString.ToDecimal + Dim CveVentaDetalle As Integer = dRow("CveVentaDetalle").ToString.ToEntero + Dim CveMovimientoDetalle As Integer = dRow("CveMovimientoDetalle").ToString.ToEntero + + Dim Lote As String = dRow("Lote").ToString + Dim Serie As String = dRow("Serie").ToString + Dim FechaCaducidad As DateTime = dRow("FechaCaducidad").ToString.ToDateTime + + If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Cantidad, CveUM, CvePS, PU, CveVentaDetalle:=CveVentaDetalle, CveMovimientoDetalleEntrada:=CveMovimientoDetalle, Lote:=Lote, Serie:=Serie, FechaCaducidad:=FechaCaducidad) Then + Alert("Error al agregar detalle de movimiento.", TipoMensaje.MsgAdvertencia) + ProcesoOK = False + Exit For + End If + IndexMov2 = IndexMov2 + 1 + Next + If ProcesoOK Then + Dim ObjEventos As New ClsOIEventos(ObjInventario.IniciaTransacSQL) + Dim LigaVenta As String = String.Format("Venta {2} en Folio: {1}", CveMovimientoEntrada, Folio, "Material utilizado") + + If Not ObjEventos.AddEventoBitacora(LigaVenta, "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveVenta:=Respuesta.CveVenta, CveOS:=CveOS) Then + ProcesoOK = False + End If + End If + Else + ProcesoOK = False + End If + End If + If ProcesoOK Then + If Not ObjOS.UpdateOrdenesServiciosFinaliza(CveOS, -1, -1, UsuarioActual.CveEmpresa) Then + ProcesoOK = False + End If + End If + If ProcesoOK Then + Dim Contabilizable As Boolean = False + Dim Concepto As String = "Material utilizado" + Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("OS-MatUtil", 53, 0, 0, 1, Fecha, Concepto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) + If CveMovimientoSalida > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImporteAlmacen, ImporteAlmacen, 68, "", Concepto, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=Contabilizable) Then ProcesoOK = False End If End If - Else - ProcesoOK = False - End If - End If - If ProcesoOK Then - If Not ClsOS.UpdateOrdenesServiciosFinaliza(CveOS, -1, -1, UsuarioActual.CveEmpresa) Then - ProcesoOK = False - End If - End If - If ProcesoOK Then - Dim Contabilizable As Boolean = False - Dim Concepto As String = "Material utilizado" - Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("OS-MatUtil", 53, 0, 0, 1, Fecha, Concepto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) - If CveMovimientoSalida > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImporteAlmacen, ImporteAlmacen, 68, "", Concepto, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=Contabilizable) Then - ProcesoOK = False + If CveMovimientoEntrada > 0 Then + If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteAlmacen, ImporteAlmacen, 68, "", Concepto, CveMovimientoAlmacen:=CveMovimientoEntrada, Contabilizable:=Contabilizable) Then + ProcesoOK = False + End If End If - End If - If CveMovimientoEntrada > 0 Then - If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ImporteAlmacen, ImporteAlmacen, 68, "", Concepto, CveMovimientoAlmacen:=CveMovimientoEntrada, Contabilizable:=Contabilizable) Then - ProcesoOK = False - End If - End If + End If + Else + ProcesoOK = False End If - Else - ProcesoOK = False End If End If + + If ProcesoOK Then + ObjV.Commit() - If GenrarRemisionMovimientos = False Then - Alert("El material sera recibido en almacén.") + If DdlTipoVenta.SelectedValue.ToEntero = 5 Then + Dim Liga As String = $" document.location.href=""/OS/OrdenesServicios.aspx?CveOS={CveOS}""; " + Alert("El material utilizado se guardó correctamente", TipoMensaje.MsgInformacion, Liga) Else - Alert("El material utilizado se guardó correctamente") + If GenrarRemisionMovimientos = False Then + Alert("El material sera recibido en almacén.") + Else + Alert("El material utilizado se guardó correctamente") + End If End If RegistraScript("$('#DivModalMaterialUtilizado').modal('hide');") Else ObjV.RollBack() - Alert("El material utilizado no se guardó correctamente", TipoMensaje.MsgAdvertencia) + Alert("Se presento un error al guardar el material", TipoMensaje.MsgAdvertencia) End If ObjV.Dispose()