From 26f92ae443a70400fd909e3bfad9ec9c2b193898 Mon Sep 17 00:00:00 2001 From: rrene Date: Fri, 24 Jan 2025 06:05:23 -0700 Subject: [PATCH] -- mejoras para unificar los productos iguales en material utilizado --- OS/OrdenesServicios.aspx | 5 +- OS/OrdenesServicios.aspx.vb | 125 ++++++++++++++++++++++++++++++++++-- 2 files changed, 124 insertions(+), 6 deletions(-) diff --git a/OS/OrdenesServicios.aspx b/OS/OrdenesServicios.aspx index 2763ea92a..77831e2cd 100644 --- a/OS/OrdenesServicios.aspx +++ b/OS/OrdenesServicios.aspx @@ -16,6 +16,9 @@
  • Material Utilizado
  • +
  • + +
  • @@ -348,7 +351,7 @@ - + diff --git a/OS/OrdenesServicios.aspx.vb b/OS/OrdenesServicios.aspx.vb index 347d43d1e..a91e1ca02 100644 --- a/OS/OrdenesServicios.aspx.vb +++ b/OS/OrdenesServicios.aspx.vb @@ -6,6 +6,7 @@ Imports System.IO Imports System.Data Imports System.Data.SqlClient Imports APP_Code_CSharp +Imports MoreLinq.Extensions Partial Class OS_OrdenesServicios Inherits ClsPaginas @@ -578,8 +579,6 @@ Partial Class OS_OrdenesServicios 'GvPS.DataSource = TmpDT 'GvPS.DataBind() - - Dim tmpTipoEstatus As Integer = GlobalDTEstatusOrdenServicios(UsuarioActual.CveEmpresa).FiltroPrimeroValor("TipoEstatus", $" CveEstatusOrdenServicio = {DdlEstatusOS.SelectedValue}").ToEntero Select Case tmpTipoEstatus Case 1, 2, 3 @@ -732,6 +731,10 @@ Partial Class OS_OrdenesServicios If TipoEstatus.Contiene(1, 2, 3) Then LnkAccionesMaterialUtilizado.Visible = True End If + If TipoEstatus.Contiene(4) Then 'finalizada + BtnCancelarRemision.Visible = True + End If + Else Alert("La Orden de Servicio Solicitado no existe, por favor revise su búsqueda.", TipoMensaje.MsgAdvertencia) BtnGuardar.Enabled = False @@ -3530,7 +3533,7 @@ Partial Class OS_OrdenesServicios If PU > 0 Then CountDetalles = CountDetalles + 1 Else - Alert($"Prodcuto {CodigoPS} con precio unitario en cero.", TipoMensaje.MsgAdvertencia) + Alert($"Producto {CodigoPS} con precio unitario en cero.", TipoMensaje.MsgAdvertencia) PuEnCero = True End If End If @@ -3552,7 +3555,7 @@ Partial Class OS_OrdenesServicios Return Respuesta End If - If ObjVentas.GetVenta(CvePedido, UsuarioActual.CveEmpresa, VerificaAlmacen:=False) Then + If ObjVentas.GetVenta(CvePedido, UsuarioActual.CveEmpresa) Then Dim DbRowVenta As DataRow = ObjVentas.DtResultados.Copy().Rows(0) CveMoneda = DbRowVenta("CveMoneda").ToString.ToEntero CveSubProyectoPedido = DbRowVenta("CveSubProyecto").ToString().ToEntero() @@ -3585,6 +3588,14 @@ Partial Class OS_OrdenesServicios TmpDTMat.Columns.Add("Lote", GetType(String)) TmpDTMat.Columns.Add("FechaCaducidad", GetType(Date)) TmpDTMat.Columns.Add("CveVentaDetalle", GetType(Integer)) + 'unificar en un solo producto, y generar las salidas a esa relación + + + Respuesta.CveVenta = -1 + Respuesta.SerieFolio = "" + Respuesta.dtdetalle = New DataTable + Alert("Remision sin detalles.", TipoMensaje.MsgAdvertencia) + Return Respuesta For Each GvRow As GridViewRow In GvMU.Rows @@ -3594,7 +3605,6 @@ Partial Class OS_OrdenesServicios Dim Descuento As Decimal = GvRow.DataKey("Descuento").ToDecimal Dim Obs As String = GvRow.DataKey("Observaciones") - If CantidadRegistro > 0 Then If ObjFactura.AgregarPS(CvePS, CantidadRegistro, PU, Descuento, Obs, CveSubProyecto:=CveSubProyectoPedido, CveVentaDetallePadre:=GvRow.DataKey("CveVentaDetalle").ToEntero) Then Dim drp As DataRow = TmpDTMat.NewRow @@ -3635,6 +3645,38 @@ Partial Class OS_OrdenesServicios End Function + Private Function AgrupadoProductos(gridView As GridView) As DataTable + ' Filtrar y agrupar las filas por clave3 y clave5 + Dim groupedData = From row As GridViewRow In gridView.Rows.Cast(Of GridViewRow)() + Where row.RowType = DataControlRowType.DataRow + Group row By + CvePS = gridView.DataKeys(row.RowIndex)("CvePS").ToString(), + CveUM = gridView.DataKeys(row.RowIndex)("CveUM").ToString() + Into Group + Select New With { + .CvePS = CvePS, + .CveUM = CveUM, + .ValorAcumulado = Group.Sum(Function(r) Convert.ToDecimal(r.Cells(5).Text)) + } + + ' Crear un nuevo DataTable para almacenar los resultados agrupados + Dim resultTable As New DataTable() + resultTable.Columns.Add("CvePS") + resultTable.Columns.Add("CveUM") + resultTable.Columns.Add("Cantidad", GetType(Decimal)) + + For Each item In groupedData + Dim newRow As DataRow = resultTable.NewRow() + newRow("CvePS") = item.CvePS + newRow("CveUM") = item.CveUM + newRow("Cantidad") = item.ValorAcumulado + resultTable.Rows.Add(newRow) + Next + + Return resultTable + End Function + + Friend Class RespuestaFacturacion Public Property CveVenta As Integer = -1 Public Property SerieFolio As String = "-1" @@ -3786,4 +3828,77 @@ Partial Class OS_OrdenesServicios End Try End Sub + + Private Sub CancelarRemision(CveVenta As Integer, CveAlmacenDevolucion As Integer, CvePedido As Integer) + + Dim LigaRedirigir As String = "" + + Dim ObjFacturaCancelacion As New Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa, EsCancelacion:=True, VerificaAlmacen:=True) + Try + Dim resp As Modelos.Factura.MCancelacionVentaMensaje = Nothing + Dim strMensaje As New StringBuilder() + If ObjFacturaCancelacion IsNot Nothing AndAlso ObjFacturaCancelacion.CveVenta > 0 Then + + Dim ListaRemisionesCancelar As New List(Of Integer) + ObjFacturaCancelacion.CveAlmacenDevolucion = CveAlmacenDevolucion + Dim CancelacionPagos = Modelos.OpcionesCancelacionPagos.SinPagos + + 'PARA GENERAR LA DEVOLUCION DE ALMACEN SIN ESPERAR LA ACEPTACION DEL SAT + Dim GenerarDevolucionAnticipada As Boolean = True + Dim CveEstadoCancelacion As Integer = 1 + Dim objos As New ClsOS + Dim ObjVenta As New ClsVentas(objos.IniciaTransacSQL) + + resp = ObjFacturaCancelacion.CancelarFactura(1, ListaRemisionesCancelar, CveMotivoCancelacion:=1, Motivo:="Corrección de material utilizado", CveEstadoCancelacion:=CveEstadoCancelacion, ForzarDevolucion:=GenerarDevolucionAnticipada, CancelacionPagos:=CancelacionPagos, TransaccionCompartida:=objos.IniciaTransacSQL) + + Dim HuboError As Boolean = False + If Not resp.HuboError Then + + If resp.CveEstatus = 12 Then + Dim cveoo As Integer = GlobalDTEstatusOrdenServicios(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveEstatusOrdenServicio", $" TipoEstatus = 3").ToEntero + If objos.UpdateOrdenesServiciosEstatus(cveoo, UsuarioActual.CveUsuario, CveOS) Then + 'retornar el estatus de la OS, + If Not ObjVenta.UpdateVentasDevolucionAlmacen(0, CvePedido) Then + HuboError = True + End If + Else + HuboError = True + End If + Else + 'si tiene pagos + HuboError = True + End If + Else + HuboError = True + End If + strMensaje.Append(resp.Mensaje) + If Not HuboError Then + objos.Commit() + Alert(strMensaje.ToString(), resp.TipoMensaje) + Else + objos.RollBack() + Alert(strMensaje.ToString(), resp.TipoMensaje) + End If + + objos.Dispose() + ObjVenta.Dispose() + Else + Alert("Ocurrió un error al generar la cancelación", TipoMensaje.MsgError) + End If + + Catch ex As Exception + OnError("Ocurrió un error al cancelar", ex) + End Try + ObjFacturaCancelacion.Dispose() + UpEstatus.Update() + + If Not String.IsNullOrEmpty(LigaRedirigir) Then + Response.Redirect(LigaRedirigir) + End If + + End Sub + + Protected Sub BtnCancelarRemision_Click(sender As Object, e As EventArgs) + CancelarRemision(CveVenta, 1, CvePedido) + End Sub End Class