EMD - Activar prespuesto en compras/oc Orden de Compra
This commit is contained in:
@@ -3201,13 +3201,14 @@ Public Class ClsContratos
|
|||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
|
||||||
Public Function GetPresupuestosResumen(CveEmpresa As Integer, CveSubProyecto As Integer) As Boolean
|
Public Function GetPresupuestosResumen(CveEmpresa As Integer, CveSubProyecto As Integer, Optional Opcion As Integer = 1) As Boolean
|
||||||
Dim Retorno As Boolean = False
|
Dim Retorno As Boolean = False
|
||||||
|
|
||||||
DataAdapter("PA_Con_PresupuestosResumenGet")
|
DataAdapter("PA_Con_PresupuestosResumenGet")
|
||||||
With SqlAdapter.SelectCommand.Parameters
|
With SqlAdapter.SelectCommand.Parameters
|
||||||
.Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa
|
.Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa
|
||||||
.Add("@CveSubProyecto", SqlDbType.Int).Value = CveSubProyecto
|
.Add("@CveSubProyecto", SqlDbType.Int).Value = CveSubProyecto
|
||||||
|
.Add("@Opcion", SqlDbType.Int).Value = Opcion
|
||||||
End With
|
End With
|
||||||
|
|
||||||
Try
|
Try
|
||||||
|
|||||||
206
OC/OC.aspx.vb
206
OC/OC.aspx.vb
@@ -2211,40 +2211,50 @@ Partial Class OC_OC
|
|||||||
Exit Sub
|
Exit Sub
|
||||||
End If
|
End If
|
||||||
|
|
||||||
If UsuarioActual.Empresa.Funcionalidad(532) = "1" Then
|
|
||||||
Dim ObjCon As New ClsContratos
|
|
||||||
Dim CvePresupuesto As Integer = 0
|
|
||||||
Dim Autorizado As Decimal = 0
|
|
||||||
Dim Ejercido As Decimal = 0
|
|
||||||
If ObjCon.GetPresupuestos(-1, "-1", DdlSubProyecto.SelectedValue.ToEntero, 2, -1, UsuarioActual.CveEmpresa) Then
|
|
||||||
If ObjCon.DtResultados.Rows.Count > 0 Then
|
|
||||||
CvePresupuesto = ObjCon.DtResultados.Rows(0)("CvePresupuesto").ToString.ToEntero
|
|
||||||
If CvePresupuesto > 0 Then
|
|
||||||
If ObjCon.GetPresupuestosDetalle(CvePresupuesto, -1, UsuarioActual.CveEmpresa) Then
|
|
||||||
If ObjCon.DtResultados.FiltraParametros($"CveClasificacion = {DdlClasificacion.SelectedValue.ToEntero} AND Importe > 0").Rows.Count > 0 Then
|
|
||||||
Autorizado = ObjCon.DtResultados.FiltraParametros($"CveClasificacion = {DdlClasificacion.SelectedValue.ToEntero} AND Importe > 0").Rows(0)("Importe").ToString.ToDecimal
|
|
||||||
End If
|
|
||||||
End If
|
|
||||||
If ObjCon.GetPresupuestosRep(CvePresupuesto, -1, 1, $"01/09/{NowADS().Year - 1}".ToDate, NowADS(), UsuarioActual.CveEmpresa, DdlProyecto.SelectedValue.ToEntero,
|
|
||||||
DdlSubProyecto.SelectedValue.ToEntero, UsuarioActual.CveUsuario, DdlClasificacion.SelectedValue.ToEntero) Then
|
|
||||||
If ObjCon.DtResultados.Rows.Count > 0 Then
|
|
||||||
Ejercido = ObjCon.DtResultados.Rows(0)("Ejercido").ToString.ToDecimal
|
|
||||||
End If
|
|
||||||
End If
|
|
||||||
End If
|
|
||||||
End If
|
|
||||||
End If
|
|
||||||
ObjCon.Dispose()
|
|
||||||
|
|
||||||
If CvePresupuesto > 0 And Autorizado > 0 Then
|
|
||||||
Dim Diferencia As Decimal = (Ejercido + If(txtPrecioUnitario.Text.ToDecimal > 0, (txtPrecioUnitario.Text.ToDecimal * TxtCant.Text.ToDecimal) - TxtDescuentoAdd.Text.ToDecimal, 0)) - Autorizado
|
Dim ValImporte As Decimal = (TxtCant.Text.ToDecimal * txtPrecioUnitario.Text.ToDecimal).RoundSQL(2)
|
||||||
If Diferencia > 0 Then
|
If Not ValidaPresupuesto(1, DdlSubProyecto.SelectedValue.ToEntero, DdlSubProyecto.SelectedItem.Text, DdlClasificacion.SelectedValue.ToEntero, DdlClasificacion.SelectedItem.Text, ValImporte) Then
|
||||||
Alert($"No hay presupuesto disponible en el subproyecto <b>{DdlSubProyecto.SelectedItem.Text}</b> y la clasificación <b>{DdlClasificacion.SelectedItem.Text}</b> se excede por <b>{Diferencia.FormatoNumero}</b>", TipoMensaje.MsgAdvertencia)
|
Exit Sub
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
End If
|
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
'If UsuarioActual.Empresa.Funcionalidad(532) = "1" Then
|
||||||
|
|
||||||
|
'Dim ObjCon As New ClsContratos
|
||||||
|
'Dim CvePresupuesto As Integer = 0
|
||||||
|
'Dim Autorizado As Decimal = 0
|
||||||
|
'Dim Ejercido As Decimal = 0
|
||||||
|
'If ObjCon.GetPresupuestos(-1, "-1", DdlSubProyecto.SelectedValue.ToEntero, 2, -1, UsuarioActual.CveEmpresa) Then
|
||||||
|
' If ObjCon.DtResultados.Rows.Count > 0 Then
|
||||||
|
' CvePresupuesto = ObjCon.DtResultados.Rows(0)("CvePresupuesto").ToString.ToEntero
|
||||||
|
' If CvePresupuesto > 0 Then
|
||||||
|
' If ObjCon.GetPresupuestosDetalle(CvePresupuesto, -1, UsuarioActual.CveEmpresa) Then
|
||||||
|
' If ObjCon.DtResultados.FiltraParametros($"CveClasificacion = {DdlClasificacion.SelectedValue.ToEntero} AND Importe > 0").Rows.Count > 0 Then
|
||||||
|
' Autorizado = ObjCon.DtResultados.FiltraParametros($"CveClasificacion = {DdlClasificacion.SelectedValue.ToEntero} AND Importe > 0").Rows(0)("Importe").ToString.ToDecimal
|
||||||
|
' End If
|
||||||
|
' End If
|
||||||
|
' If ObjCon.GetPresupuestosRep(CvePresupuesto, -1, 1, $"01/09/{NowADS().Year - 1}".ToDate, NowADS(), UsuarioActual.CveEmpresa, DdlProyecto.SelectedValue.ToEntero,
|
||||||
|
' DdlSubProyecto.SelectedValue.ToEntero, UsuarioActual.CveUsuario, DdlClasificacion.SelectedValue.ToEntero) Then
|
||||||
|
' If ObjCon.DtResultados.Rows.Count > 0 Then
|
||||||
|
' Ejercido = ObjCon.DtResultados.Rows(0)("Ejercido").ToString.ToDecimal
|
||||||
|
' End If
|
||||||
|
' End If
|
||||||
|
' End If
|
||||||
|
' End If
|
||||||
|
'End If
|
||||||
|
'ObjCon.Dispose()
|
||||||
|
|
||||||
|
'If CvePresupuesto > 0 And Autorizado > 0 Then
|
||||||
|
' Dim Diferencia As Decimal = (Ejercido + If(txtPrecioUnitario.Text.ToDecimal > 0, (txtPrecioUnitario.Text.ToDecimal * TxtCant.Text.ToDecimal) - TxtDescuentoAdd.Text.ToDecimal, 0)) - Autorizado
|
||||||
|
' If Diferencia > 0 Then
|
||||||
|
' Alert($"No hay presupuesto disponible en el subproyecto <b>{DdlSubProyecto.SelectedItem.Text}</b> y la clasificación <b>{DdlClasificacion.SelectedItem.Text}</b> se excede por <b>{Diferencia.FormatoNumero}</b>", TipoMensaje.MsgAdvertencia)
|
||||||
|
' Exit Sub
|
||||||
|
' End If
|
||||||
|
'End If
|
||||||
|
'End If
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Dim RetISR As Decimal = DrPS("RetISR").ToString.ToDecimal
|
Dim RetISR As Decimal = DrPS("RetISR").ToString.ToDecimal
|
||||||
Dim RetIVA As Decimal = DrPS("RetIVA").ToString.ToDecimal
|
Dim RetIVA As Decimal = DrPS("RetIVA").ToString.ToDecimal
|
||||||
@@ -2624,6 +2634,10 @@ Partial Class OC_OC
|
|||||||
'VALIDACIONES PARA GUARDAR
|
'VALIDACIONES PARA GUARDAR
|
||||||
If ValidaGuardar() Then Exit Sub
|
If ValidaGuardar() Then Exit Sub
|
||||||
|
|
||||||
|
If Not ValidaPresupuesto(2) Then
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
|
||||||
Dim MsgError As String = "Hubo un error al registrar"
|
Dim MsgError As String = "Hubo un error al registrar"
|
||||||
'VARIABLES
|
'VARIABLES
|
||||||
Dim CveProveedorSucursal As Integer = -1
|
Dim CveProveedorSucursal As Integer = -1
|
||||||
@@ -8952,6 +8966,136 @@ Partial Class OC_OC
|
|||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
|
||||||
|
#Region "PRESUPUESTOS"
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Valida si hay presupuesto, Se valida con base en CveSubProyecto, CveClasificacion y CveTipoGasto
|
||||||
|
''' </summary>
|
||||||
|
''' <param name="Opcion">Int 1 Indica que es una valiadcion al agregar el Producto o servicio 2 Indica validacion General antes de guardae .</param>
|
||||||
|
''' <param name="ValCveSubProyecto">Usado al validar Presupuesto cuando se agrega un producto o servicio</param>
|
||||||
|
''' <param name="ValSubProyecto">Usado al validar Presupuesto cuando se agrega un producto o servicio</param>
|
||||||
|
''' <param name="ValCveClasificacion">Usado al validar Presupuesto cuando se agrega un producto o servicio</param>
|
||||||
|
''' <param name="ValClasificacion">Usado al validar Presupuesto cuando se agrega un producto o servicio</param>
|
||||||
|
''' <param name="ValImporte">Usado al validar Presupuesto cuando se agrega un producto o servicio </param>
|
||||||
|
''' <returns>Verdadero si hay presupuesto, Falso si no hay presupuesto.</returns>
|
||||||
|
Public Function ValidaPresupuesto(Opcion As Integer, Optional ValCveSubProyecto As Integer = -1, Optional ValSubProyecto As String = "", Optional ValCveClasificacion As Integer = -1, Optional ValClasificacion As String = "",
|
||||||
|
Optional ValImporte As Decimal = 0) As Boolean
|
||||||
|
|
||||||
|
Dim respuesta As Boolean = False
|
||||||
|
|
||||||
|
If UsuarioActual.Empresa.Funcionalidad(532) = "1" Then
|
||||||
|
|
||||||
|
Dim ObjCon As New ClsContratos
|
||||||
|
Dim CvePresupuesto As Integer = 0
|
||||||
|
Dim Autorizado As Double = 0
|
||||||
|
Dim Ejercido As Double = 0
|
||||||
|
|
||||||
|
If ObjCon.GetPresupuestosResumen(UsuarioActual.CveEmpresa, -1, 2) Then
|
||||||
|
|
||||||
|
Dim FechaCompra As Date = TxtFecha.Text.ToDate
|
||||||
|
|
||||||
|
Dim resultadosFiltrados = From row In ObjCon.DtResultados.AsEnumerable()
|
||||||
|
Where FechaCompra >= row.Field(Of Date)("FechaInicio") AndAlso
|
||||||
|
FechaCompra <= row.Field(Of Date)("FechaFin")
|
||||||
|
Select row
|
||||||
|
|
||||||
|
|
||||||
|
If resultadosFiltrados.Count > 0 Then
|
||||||
|
|
||||||
|
Dim EnumAgrupado = (From row In DtDetalle.AsEnumerable()
|
||||||
|
Group row By
|
||||||
|
SubProyecto = row.Field(Of String)("SubProyecto"),
|
||||||
|
CveSubProyecto = row.Field(Of Integer)("CveSubProyecto"),
|
||||||
|
Clasificacion = row.Field(Of String)("Clasificacion"),
|
||||||
|
CveClasificacion = row.Field(Of Integer)("CveClasificacion")
|
||||||
|
Into Group
|
||||||
|
Select New With {
|
||||||
|
.SubProyecto = SubProyecto,
|
||||||
|
.CveSubProyecto = CveSubProyecto,
|
||||||
|
.Clasificacion = Clasificacion,
|
||||||
|
.CveClasificacion = CveClasificacion,
|
||||||
|
.TotalSum = Group.Sum(Function(r) r.Field(Of Decimal)("Total"))
|
||||||
|
}).ToList()
|
||||||
|
|
||||||
|
|
||||||
|
If Opcion = 1 Then
|
||||||
|
|
||||||
|
Dim saldoTotal As Decimal = (From row In resultadosFiltrados
|
||||||
|
Where row.Field(Of Integer)("CveSubProyecto") = ValCveSubProyecto AndAlso
|
||||||
|
row.Field(Of Integer)("CveClasificacion") = ValCveClasificacion
|
||||||
|
Select row.Field(Of Decimal)("Saldo")).Sum()
|
||||||
|
If saldoTotal > 0 Then
|
||||||
|
|
||||||
|
Dim TotalAcumuladoTabla As Decimal = (DtDetalle.SUM("Total", $" CveSubProyecto = {ValCveSubProyecto} AND CveClasificacion = {ValCveClasificacion} "))
|
||||||
|
Dim Diferencia As Decimal = saldoTotal - TotalAcumuladoTabla - ValImporte
|
||||||
|
|
||||||
|
If (Diferencia) < 0 Then
|
||||||
|
Alert($"No hay presupuesto disponible en el subproyecto <b>{ValSubProyecto}</b> con la clasificación <b>{ValClasificacion}</b>. Se excede por <b>{Diferencia.FormatoNumero}</b>", TipoMensaje.MsgAdvertencia)
|
||||||
|
respuesta = False
|
||||||
|
|
||||||
|
Else
|
||||||
|
respuesta = True
|
||||||
|
End If
|
||||||
|
|
||||||
|
Else
|
||||||
|
Alert($"No hay presupuesto disponible en el subproyecto <b>{ValSubProyecto}</b> con la clasificación <b>{ValClasificacion}</b>.", TipoMensaje.MsgAdvertencia)
|
||||||
|
respuesta = False
|
||||||
|
End If
|
||||||
|
|
||||||
|
Else
|
||||||
|
For Each item In EnumAgrupado
|
||||||
|
|
||||||
|
Dim saldoTotal As Decimal = (From row In resultadosFiltrados
|
||||||
|
Where row.Field(Of Integer)("CveSubProyecto") = item.CveSubProyecto AndAlso
|
||||||
|
row.Field(Of Integer)("CveClasificacion") = item.CveClasificacion
|
||||||
|
Select row.Field(Of Decimal)("Saldo")).Sum()
|
||||||
|
If saldoTotal > 0 Then
|
||||||
|
|
||||||
|
Dim Diferencia As Decimal = saldoTotal - item.TotalSum
|
||||||
|
|
||||||
|
If (Diferencia) < 0 Then
|
||||||
|
Alert($"No hay presupuesto disponible en el subproyecto <b>{item.SubProyecto}</b> con la clasificación <b>{item.Clasificacion}</b>. Se excede por <b>{Diferencia.FormatoNumero}</b>", TipoMensaje.MsgAdvertencia)
|
||||||
|
respuesta = False
|
||||||
|
Exit For
|
||||||
|
Else
|
||||||
|
respuesta = True
|
||||||
|
End If
|
||||||
|
|
||||||
|
Else
|
||||||
|
Alert($"No hay presupuesto disponible en el subproyecto <b>{item.SubProyecto}</b> con la clasificación <b>{item.Clasificacion}</b>.", TipoMensaje.MsgAdvertencia)
|
||||||
|
respuesta = False
|
||||||
|
Exit For
|
||||||
|
End If
|
||||||
|
|
||||||
|
Next
|
||||||
|
End If
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Else
|
||||||
|
Alert("No hay presupuestos.", TipoMensaje.MsgAdvertencia)
|
||||||
|
End If
|
||||||
|
Else
|
||||||
|
Alert("No hay presupuestos.", TipoMensaje.MsgAdvertencia)
|
||||||
|
End If
|
||||||
|
|
||||||
|
ObjCon.Dispose()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Else
|
||||||
|
respuesta = True
|
||||||
|
End If
|
||||||
|
|
||||||
|
|
||||||
|
Return respuesta
|
||||||
|
|
||||||
|
End Function
|
||||||
|
|
||||||
|
|
||||||
|
#End Region
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user