-- mejoras en manejo de folios de garantía

This commit is contained in:
2023-05-30 15:18:47 -07:00
parent e26427d897
commit f391b18dae

View File

@@ -1902,16 +1902,6 @@ Partial Class Compras_Compras
TxtSerie.Enabled = False
End If
If UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then 'cuando es emp acumuladora
divFolioGarantia.Visible = True
Using objAcum As New ClsAcumuladores
If objAcum.FoliosGarantiaGet(-1, UsuarioActual.Empresa.CveEmpresa, Estatus:=2, TipoFolio:="-1", Area:=-1, CveSubProyecto:=-1) Then
DdlFolioGarantia.DataSource = objAcum.DtResultados.FiltraParametros("", "FechaIng DESC")
DdlFolioGarantia.DataBind()
End If
End Using
End If
'PERMISO PARA MODIFICACIÓN DE FECHA AUN CON FACTURA
TxtFecha.Enabled = UsuarioActual.TienePermisoProceso(216)
ImgFecha.Enabled = UsuarioActual.TienePermisoProceso(216)
@@ -4102,7 +4092,6 @@ Partial Class Compras_Compras
Alert("Falta asignar Proyecto a la compra", TipoMensaje.MsgAdvertencia)
End If
If Not ValidaVinculacionNotaFactura() Then
Alert("Se requiere que la nota este aplciada a las facturas", TipoMensaje.MsgAdvertencia)
Exit Sub
@@ -4521,6 +4510,13 @@ Partial Class Compras_Compras
UM.Dispose()
PSS.Dispose()
If UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso DdlTipoCompra.SelectedValue = "12" Then 'cuando es garantía, debe de especificar la salida de almacen
If Not GvInv.HeaderRow.FCCheckBox("cbAll").Checked OrElse GvInv.HeaderRow.FCDropDownList("ddlAlmacen").SelectedValue.ToEntero <= 0 Then
Alert("No ha especificado la salida de almacen en la garantía.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
End If
'VALIDA IMPORTES
If Not ValidaTotalesGuardar() Then
Exit Sub
@@ -4542,9 +4538,9 @@ Partial Class Compras_Compras
Exit Sub
End If
If DdlFolioGarantia.Visible AndAlso DdlFolioGarantia.SelectedValue <> "-1" Then
If Not ValidaFolioGarantia() Then Exit Sub
End If
'If DdlFolioGarantia.Visible AndAlso DdlFolioGarantia.SelectedValue <> "-1" Then
' If Not ValidaFolioGarantia() Then Exit Sub
'End If
'------------------TERMINA VALIDACIONES------------------
@@ -5453,10 +5449,12 @@ Partial Class Compras_Compras
Dim ListAlmacenes = (From CveAlmacen In DtInv.AsEnumerable() Where CveAlmacen.Field(Of Integer)("CveAlmacen") > 0 Select CveAlmacen.Field(Of Integer)("CveAlmacen")).Distinct().ToList
Dim indice = 0
Dim ImporteConcepto As Decimal = 0
Dim tCveFolioGarantia As Integer = -1
Dim CveConceptoMovimiento As Integer = 2
'apoyo logistico/garantia
If UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") AndAlso DdlTipoCompra.SelectedValue = "12" Then
If UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") AndAlso DdlTipoCompra.SelectedValue = "12" Then 'garantía
CveConceptoMovimiento = 13
tCveFolioGarantia = DdlFolioGarantia.SelectedValue.ToEntero
End If
If (DdlTipoComprobante.SelectedValue = "Fac" AndAlso CveCompraRefacturacion <= 0) OrElse CveConceptoMovimiento = 13 Then
@@ -5469,7 +5467,7 @@ Partial Class Compras_Compras
Dim fecha As Date = TxtFecha.Text.ToDate
If Not UsuarioActual.Empresa.UsaAC Then fecha = Now
CveMovimientoInventario = ObjInventario.AddMovimiento(tCveAlmacen, CveConceptoMovimiento, 1, fecha, 0, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra, -1, -1, -1, TipoCambio:=If(DdlMoneda.SelectedValue.ToEntero = 1, -1, TipoCambioGuardar), Modulo:="Comp/G2")
CveMovimientoInventario = ObjInventario.AddMovimiento(tCveAlmacen, CveConceptoMovimiento, 1, fecha, 0, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompra, -1, -1, -1, TipoCambio:=If(DdlMoneda.SelectedValue.ToEntero = 1, -1, TipoCambioGuardar), CveFolioGarantia:=tCveFolioGarantia, Modulo:="Comp/G2")
If CveMovimientoInventario <= 0 Then
ErrorMovInv = True
@@ -13491,18 +13489,6 @@ Partial Class Compras_Compras
Dim IdPolizaAnterior = -1
Dim TotalRefact As Decimal = 0
'SI NO TIENE POLIZA NI PAGOS NO HACE NADA
'If ObjCompra.GetCompras(CveCompraRefacturacion, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then
' If ObjCompra.DtResultados IsNot Nothing AndAlso ObjCompra.DtResultados.Rows.Count = 1 Then
' Dim drc As DataRow = ObjCompra.DtResultados.Rows(0)
' TotalRefact = drc("Total").ToString.ToDecimal
' If drc("IdPoliza").ToString.ToEntero <= 0 AndAlso drc("Saldo").ToString.ToDecimal = drc("Total").ToString.ToDecimal AndAlso drc("CveMovimiento").ToString.ToEntero <= 0 Then
' Alert("La factura a refacturar no esta contabilizada ni tiene pagos ni movimientos de almacen. No se puede refacturar, debera eliminar la factura anterior y agregar esta factura de forma normal.", TipoMensaje.MsgAdvertencia)
' Return True
' End If
' End If
'End If
'GUARDA ADJUNTOS Y LIGA EN BITACORA (RELACION DE FACTURA NUEVA Y VIEJA)
ErrorBitacora = GuardaRefacturacionBitacora(ObjCompra, ObjEventos)
@@ -17223,6 +17209,9 @@ Partial Class Compras_Compras
If DrPS IsNot Nothing Then
Row("PSCodigo") = If(PSCodigo = "", DrPS("PSCodigo").ToString, PSCodigo)
Row("CveMetodoInventario") = DrPS("Inv_CveMetodoInventario").ToString.ToEntero
If DdlTipoCompra.SelectedValue = "12" AndAlso DrPS("AplicaSerie").ToString = "True" Then
Row("CveMetodoInventario") = "1"
End If
Else
Row("PSCodigo") = PSCodigo
Row("CveMetodoInventario") = 0
@@ -17269,8 +17258,6 @@ Partial Class Compras_Compras
End Try
Dim DecimalesPermitidos = 6
Row("CveConcepto") = TmpDT.Rows.Count + 1
@@ -17314,8 +17301,6 @@ Partial Class Compras_Compras
Row("IVAPorcentaje") = PorcentajeIVA
End If
Row("RetIVA") = Math.Round(RetIVA, DecimalesPermitidos)
Row("RetIVAPorcentaje") = PorcentajeRetIVA
Row("RetISR") = Math.Round(RetISR, DecimalesPermitidos)
@@ -19508,6 +19493,17 @@ Partial Class Compras_Compras
Protected Sub DdlTipoCompra_SelectedIndexChanged(sender As Object, e As EventArgs)
If DdlTipoCompra.SelectedValue.ToEntero.Contiene(9, 10, 12) Then 'Al seleccionar apoyo logístico se cargan los amancenes de devoculcion proveedor para dar entrada
If DdlTipoCompra.SelectedValue = "12" AndAlso UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso DdlTipoComprobante.SelectedValue.Contiene("NC", "DEV") Then 'cuando es emp acumuladora
divFolioGarantia.Visible = True
Using objAcum As New ClsAcumuladores
If objAcum.FoliosGarantiaGet(-1, UsuarioActual.Empresa.CveEmpresa, Estatus:=2, TipoFolio:="-1", Area:=-1, CveSubProyecto:=-1) Then
DdlFolioGarantia.DataSource = objAcum.DtResultados.FiltraParametros("", "FechaIng DESC")
DdlFolioGarantia.DataBind()
End If
End Using
End If
'cambia si hay ps con uso de serie
For Each dr As DataRow In TmpDT.Rows
dr("CveMetodoInventario") = 1
@@ -19538,6 +19534,8 @@ Partial Class Compras_Compras
Dim ExistenciasPSGarantia As New Dictionary(Of Integer, Decimal)
Dim PSFaltantes As New Dictionary(Of Integer, Decimal)
Dim DtGarantia As New DataTable
TxtDescripcion.Text = DdlFolioGarantia.SelectedItem.Text
UpParametros.Update()
'Agrupa los CvePS iguales y suma sus cantidades
For Each row In TmpDT.AsEnumerable()
@@ -19555,7 +19553,7 @@ Partial Class Compras_Compras
DtGarantia = ObjAcum.DtResultados
ExistenciasPSGarantia = DtGarantia.AsEnumerable().ToDictionary(Function(row) row.Field(Of Integer)("CvePS"), Function(row) row.Field(Of Decimal)("CantidadDisponible"))
Else
Alert($"Ocurrió un error al obtener la información de la garantía.</br> CveUsuario={UsuarioActual.CveUsuario}</br> CveFolioGarantia={DdlFolioGarantia.SelectedValue}", TipoMensaje.MsgError)
Alert($"Ocurrió un error al obtener la información de la garantía.</br> CveU={UsuarioActual.CveUsuario}</br> CveFG={DdlFolioGarantia.SelectedValue}", TipoMensaje.MsgError)
Return False
End If
End Using
@@ -19578,13 +19576,34 @@ Partial Class Compras_Compras
Select New With {.CvePS = Producto.Key, .NombrePS = row.Field(Of String)("PS"), .CantidadFaltante = Producto.Value}
If PSFaltantes.Count > 0 Then
Dim mensaje As String = "Los siguientes productos no tienen suficientes existencias en la garantía seleccionada:</br></br>"
Dim mensaje As String = "Los siguientes productos no fueron registrados en la garantía seleccionada:</br></br>"
For Each Producto In IEnumPSFaltantes
mensaje += $"Falta: &times;&hairsp;<b>{Producto.CantidadFaltante:0.##}</b>&emsp;{Producto.NombrePS}</br>"
Next
'eliminar los registros
Dim tImporteAjuste As Decimal = 0
Dim PSS = (From c In IEnumPSFaltantes Select c.CvePS).Distinct.ToList
For Each Producto In PSS
Dim drr As DataRow() = TmpDT.Select($"CvePS = {Producto}")
For Each drt As DataRow In drr
If TmpDT.Rows.Count > 1 Then 'valida que exista cuando menos un registro
tImporteAjuste += drt("Total").ToString.ToDecimal
TmpDT.Rows.Remove(drt)
End If
Next
TmpDT.AcceptChanges()
Next
If tImporteAjuste > 0 Then AjustaImporteUltimoConcepto(tImporteAjuste)
GvPS.DataSource = TmpDT
GvPS.DataBind()
CalculaTotales(True)
CargaGvInv()
If MsgExito Then Alert(mensaje, TipoMensaje.MsgAdvertencia) Else Alert(mensaje, TipoMensaje.MsgError)
Else
If MsgExito Then Alert("Todos los productos seleccionados están disponibles en el Folio de Garantía.")
If MsgExito Then Alert("Todos los productos seleccionados están registrados en el Folio de Garantía.")
Return True
End If
Else
@@ -20242,10 +20261,8 @@ Partial Class Compras_Compras
End If
End If
End Sub
Protected Sub BtnFolioGarantiaRestantes_Click(sender As Object, e As EventArgs)
Using ObjAcum As New ClsAcumuladores
@@ -20330,8 +20347,6 @@ Partial Class Compras_Compras
ErrorCompra = True
Exit For
End If
Next
End If
@@ -20342,36 +20357,20 @@ Partial Class Compras_Compras
Dim SBEliminacionCompra As New StringBuilder
SBEliminacionCompra.Append($"Serie-Folio: {TxtSerie.Text}-{TxtFolio.Text}, Proveedor: {HplProveedor.Text}, Descripción: {TxtDescripcion.Text}, SubTotal: {TxtSubTotal2.Text}, ")
If TxtIVA.Text.Trim.ToDecimal > 0 Then
SBEliminacionCompra.Append($"IVA: { TxtIVA.Text},")
End If
If TxtIVA.Text.Trim.ToDecimal > 0 Then SBEliminacionCompra.Append($"IVA: { TxtIVA.Text},")
If TxtRetISR.Text.Trim.ToDecimal > 0 Then SBEliminacionCompra.Append($"Ret. ISR: { TxtRetISR.Text}, ")
If TxtRetISR.Text.Trim.ToDecimal > 0 Then
SBEliminacionCompra.Append($"Ret. ISR: { TxtRetISR.Text}, ")
End If
If TxtRetIVA.Text.Trim.ToDecimal > 0 Then
SBEliminacionCompra.Append($"Ret. IVA: { TxtRetIVA.Text}, ")
End If
If TxtIEPS.Text.Trim.ToDecimal > 0 Then
SBEliminacionCompra.Append($"IEPS: { TxtIEPS.Text}, ")
End If
If TxtRetIVA.Text.Trim.ToDecimal > 0 Then SBEliminacionCompra.Append($"Ret. IVA: { TxtRetIVA.Text}, ")
If TxtIEPS.Text.Trim.ToDecimal > 0 Then SBEliminacionCompra.Append($"IEPS: { TxtIEPS.Text}, ")
SBEliminacionCompra.Append($"Total: {TxtTotal.Text}, ")
SBEliminacionCompra.Append($"Moneda: {DdlMoneda.SelectedItem.Text}, ")
If TxtOC.Text.Trim.Length > 0 Then
SBEliminacionCompra.Append($"OC: {TxtOC.Text }, ")
End If
If TxtOC.Text.Trim.Length > 0 Then SBEliminacionCompra.Append($"OC: {TxtOC.Text }, ")
SBEliminacionCompra.Append($"Fecha {TxtFecha.Text}, ")
SBEliminacionCompra.Append($"Capturó: {LblUsuarioCaptura.Text}, ")
@@ -20385,7 +20384,6 @@ Partial Class Compras_Compras
If Not ObjGral.AddHistorialBitacora(Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, CveCompra, Nothing, "", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1,
TxtModalEliminarCompraDescripcion.Text, "Compras", SBEliminacionCompra.ToString) Then
ErrorCompra = True
End If
If Not ErrorCompra Then