Files
SIG/Inventarios/ResguardoMaterial.aspx.vb
Antonio Gonzalez 2bb4d34483 -
2020-06-09 13:39:20 -07:00

993 lines
42 KiB
VB.net

Option Explicit On
Option Strict On
Imports System.Data
Imports Extensiones
Imports Microsoft.Reporting.WebForms
Partial Class Inventarios_ResguardoMaterial
Inherits ClsPaginas
#Region "Propiedades"
Public Property DtMovimientos() As DataTable
Get
Return CType(ViewState("DtMovimientos"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtMovimientos") = value
End Set
End Property
Public Property DtMovimientosLiberacion() As DataTable
Get
Return CType(ViewState("DtMovimientosLiberacion"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtMovimientosLiberacion") = value
End Set
End Property
Public Property CveAlmacenLiberación() As Integer
Get
Return ViewState("CveAlmacenLiberación").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveAlmacenLiberación") = value
End Set
End Property
Public Property CvePersonalLiberacion() As Integer
Get
Return ViewState("CvePersonalLiberacion").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CvePersonalLiberacion") = value
End Set
End Property
Public Property CveClienteLiberacion() As Integer
Get
Return ViewState("CveClienteLiberacion").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveClienteLiberacion") = value
End Set
End Property
Public Property CveProveedorLiberacion() As Integer
Get
Return ViewState("CveProveedorLiberacion").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveProveedorLiberacion") = value
End Set
End Property
Public Property FechaLiberacion As String
Get
Return ViewState("FechaLiberacion").ToString
End Get
Set(value As String)
ViewState("FechaLiberacion") = value
End Set
End Property
Public Property EsSurtidoUniforme As Boolean
Get
If ViewState("EsSurtidoUniforme") Is Nothing Then
Return False
Else
Return Boolean.Parse(ViewState("EsSurtidoUniforme").ToString)
End If
End Get
Set(value As Boolean)
ViewState("EsSurtidoUniforme") = value
End Set
End Property
Private Property CantidadTotal As Decimal
Get
Return CType(ViewState("CantidadTotal"), Decimal)
End Get
Set(value As Decimal)
ViewState("CantidadTotal") = value
End Set
End Property
Private Property CvePS As Integer
Get
Return CType(ViewState("CvePS"), Integer)
End Get
Set(value As Integer)
ViewState("CvePS") = value
End Set
End Property
Private Property TipoSeccionAlmacen As Integer
Get
Return CType(ViewState("TipoSeccionAlmacen"), Integer)
End Get
Set(value As Integer)
ViewState("TipoSeccionAlmacen") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
If Not Request.QueryString("EsSurtidoUniforme") Is Nothing Then
EsSurtidoUniforme = If(Request.QueryString("EsSurtidoUniforme").ToString = "1", True, False)
End If
InicializaValores()
If Not Request.QueryString("CvePersonal") Is Nothing Then
Try
Dim CvePersonal As Integer = Request.QueryString("CvePersonal").ToString.ToEntero
OcultarControles(CvePersonal)
Catch ex As Exception
End Try
End If
End If
End Sub
Private Sub OcultarControles(CvePersonal As Integer)
DdlPersonal.ddl.SelectedValueExist(CvePersonal)
DdlPersonal.Enabled = False
DVTipo.Visible = False
End Sub
#Region " INICIALIZA VALORES "
Private Sub InicializaValores()
CreaDT()
CargaCombos()
TxtFecha.Text = Now.ToShortDateString
TxtFechaLiberacion.Text = Now.ToShortDateString
GvM.Columns(6).Visible = UsuarioActual.Empresa.Funcionalidad(563) = "1"
GvMLiberacion.Columns(7).Visible = UsuarioActual.Empresa.Funcionalidad(563) = "1"
GvM.DataBind()
CantidadTotal = 0
CvePS = 0
TipoSeccionAlmacen = 0
End Sub
Protected Sub CreaDT()
Dim dt As New DataTable
Dim column As DataColumn = New DataColumn("No")
column.DataType = Type.GetType("System.Int32")
With column
.AutoIncrement = True
.AutoIncrementSeed = 1
.AutoIncrementStep = 1
End With
dt.Columns.Add(column)
dt.Columns.Add("CveMovimiento", Type.GetType("System.Int32"))
dt.Columns.Add("CveMovimientoDetalle", Type.GetType("System.Int32"))
dt.Columns.Add("Cantidad", Type.GetType("System.Double"))
dt.Columns.Add("CveUM", Type.GetType("System.Int32"))
dt.Columns.Add("UnidadMedida")
dt.Columns.Add("CvePS", Type.GetType("System.Int32"))
dt.Columns.Add("PS")
dt.Columns.Add("Estatus")
dt.Columns.Add("Codigo")
dt.Columns.Add("Serie")
dt.Columns.Add("Observaciones")
dt.Columns.Add("CvePersonal", Type.GetType("System.Int32"))
dt.Columns.Add("Checado", Type.GetType("System.Boolean"))
dt.Columns.Add("CveSeccionAlmacen", Type.GetType("System.Int32"))
dt.Columns.Add("SeccionAlmacen")
DtMovimientos = dt
CargaGvM()
End Sub
Private Sub CargaCombos()
DdlPersonal.setEsWebService(True)
DdlPersonal.Attributes.Add("data-metodo", "getpersonal")
DdlPersonal.SelectedValue = "-1"
DdlPersonal.SelectedText = "Seleccione"
DdlPersonalLiberacion.setEsWebService(True)
DdlPersonalLiberacion.Attributes.Add("data-metodo", "getpersonal")
DdlPersonalLiberacion.SelectedValue = "-1"
DdlPersonalLiberacion.SelectedText = "Seleccione"
DdlCliente.setEsWebService(True)
DdlCliente.Attributes.Add("data-metodo", "getcliente")
DdlCliente.SelectedValue = "-1"
DdlCliente.SelectedText = "Seleccione"
DdlClienteLiberacion.setEsWebService(True)
DdlClienteLiberacion.Attributes.Add("data-metodo", "getcliente")
DdlClienteLiberacion.SelectedValue = "-1"
DdlClienteLiberacion.SelectedText = "Seleccione"
DdlProveedor.setEsWebService(True)
DdlProveedor.Attributes.Add("data-metodo", "getproveedores")
DdlProveedor.SelectedValue = "-1"
DdlProveedor.SelectedText = "Seleccione"
DdlProveedorLiberacion.setEsWebService(True)
DdlProveedorLiberacion.Attributes.Add("data-metodo", "getproveedores")
DdlProveedorLiberacion.SelectedValue = "-1"
DdlProveedorLiberacion.SelectedText = "Seleccione"
If isWhitFamily() Then
DdlClasificacion.DataSource = GlobalDTSubFamilias(UsuarioActual.CveEmpresa).FiltraParametros("", Orderby:="Clasificacion")
Else
DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros(" Codigo = '' OR Codigo IS NULL ", Orderby:="Clasificacion")
End If
DdlClasificacion.DataBind()
If EsSurtidoUniforme Then
'RESGUARDO
DdlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen IN (19)") 'GlobalDTAlmacen(UsuarioActual.CveEmpresa)
DdlAlmacen.DataBind()
DdlAlmacen.Items.Insert(0, New ListItem("Seleccione", "-1"))
'Almacen Destino
DdlAlmacenDestino.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 20)
DdlAlmacenDestino.DataBind()
DdlAlmacenDestino.Items.Insert(0, New ListItem("Seleccione", "-1"))
'LIBERACION
DdlAlmacenLiberacion.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 20)
DdlAlmacenLiberacion.DataBind()
DdlAlmacenLiberacion.Items.Insert(0, New ListItem("Seleccione", "-1"))
''Almacen Destino
Else
'RESGUARDO
DdlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1) '.FiltraParametros("CveTipoAlmacen IN (1,2)") 'GlobalDTAlmacen(UsuarioActual.CveEmpresa)
DdlAlmacen.DataBind()
DdlAlmacen.Items.Insert(0, New ListItem("Seleccione", "-1"))
'Almacen Destino
DdlAlmacenDestino.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 8)
DdlAlmacenDestino.DataBind()
DdlAlmacenDestino.Items.Insert(0, New ListItem("Seleccione", "-1"))
'LIBERACION
DdlAlmacenLiberacion.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 8)
DdlAlmacenLiberacion.DataBind()
DdlAlmacenLiberacion.Items.Insert(0, New ListItem("Seleccione", "-1"))
End If
''Almacen Destino
DdlAlmacenDestinoLiberacion.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1) '.FiltraParametros("CveTipoAlmacen IN (1,2)")
DdlAlmacenDestinoLiberacion.DataBind()
DdlAlmacenDestinoLiberacion.Items.Insert(0, New ListItem("Seleccione", "-1"))
DdlSeccionAlmacen.DataSource = GlobalDTSeccionAlmacen(UsuarioActual.CveEmpresa, -1)
DdlSeccionAlmacen.DataBind()
CargaPS()
End Sub
Private Sub CargaPS()
DdlProducto2.setEsWebService(UsuarioActual.Empresa.Funcionalidad(105) = "1")
If DdlProducto2.UsaWebService Then
'DdlProducto2.ddlWS.Attributes.Add("data-pagina", "Inventarios")
'DdlProducto2.ddlWS.Attributes.Add("data-cveclasificacion", DdlClasificacion.SelectedValue.ToString)
End If
If Not DdlProducto2.UsaWebService AndAlso CType(DdlProducto2.DataSource, DataTable) Is Nothing Then
DdlProducto2.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa)
DdlProducto2.DataBind()
End If
VerificaProducto()
End Sub
Private Function isWhitFamily() As Boolean
Return (UsuarioActual.CveEmpresa = 66)
End Function
#End Region
#Region " RESGUARDO "
#Region " FUNCIONALIDAD 105 - CLASIFICACION PS"
Protected Sub DdlClasificacion_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DdlClasificacion.SelectedIndexChanged
CargaProductosPorClasificacion()
End Sub
Protected Sub DdlProducto_ValueChanged(sender As Object, e As EventArgs) Handles DdlProducto2.selectedindexchange
VerificaProducto()
End Sub
Private Sub CargaProductosPorClasificacion()
If UsuarioActual.Empresa.Funcionalidad(105) = "" Then
'Dim filtro As String = ""
'If Not (DdlClasificacion.SelectedValue = "-1") Then
' If isWhitFamily() Then
' 'filtro = String.Format("CveSubFamilia={0}", DdlClasificacion.SelectedValue)
' Else
' filtro = String.Format("CveClasificacion={0}", DdlClasificacion.SelectedValue)
' End If
'End If
DdlProducto2.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=DdlClasificacion.SelectedValue.ToEntero).FiltraParametros("", "PSCodigo")
DdlProducto2.DataBind()
DdlProducto2.ddl.Items.Insert(0, New ListItem("----", "-1"))
Else
'If isWhitFamily() Then
' 'DdlProducto2.ddlWS.Attributes.Add("data-idSubFamilia", DdlClasificacion.SelectedValue)
'Else
DdlProducto2.ddlWS.Attributes.Add("data-cveclasificacion", DdlClasificacion.SelectedValue)
'End If
End If
End Sub
Private Sub VerificaProducto()
If DdlProducto2.SelectedValue.ToEntero > 0 Then
If GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlProducto2.SelectedValue.ToEntero).FiltraParametros("Inv_CveMetodoInventario = 5", "PS").Rows.Count > 0 Then
ThSerie.Visible = True
TrSerie.Visible = True
TxtnSerie.Visible = True
ThSeccion.Visible = True
TrSeccion.Visible = True
GvM.Columns(4).Visible = True
Else
TxtnSerie.Visible = False
End If
End If
'If (1.Contiene("3", "7", "8", "11")) Then
' Dim objinv As New ClsInventarios
' If objinv.GetExistenciasPS(DdlProducto2.SelectedValue.ToEntero, -1, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero, FechaMovto:=DateTime.Today.AddDays(1).ToString("yyyy/MM/dd HH:mm")) Then
' DdlUnidad.DataSource = objinv.DtResultados.FiltraParametros("", "UnidadMedida", {"CveUnidadMedida", "UnidadMedida"})
' If objinv.DtResultados.Rows.Count = 0 Then
' Alert("No hay existencias de este producto", TipoMensaje.MsgAdvertencia)
' End If
' End If
' objinv.Dispose()
'Else
' DdlUnidad.DataSource = GlobalDTProductosServiciosEquivalencias(DdlProducto2.SelectedValue.ToEntero, -1)
'End If
DdlUnidad.Items.Clear()
DdlUnidad.DataSource = GlobalDTProductosServiciosEquivalencias(DdlProducto2.SelectedValue.ToEntero, -1, UsuarioActual.CveEmpresa)
DdlUnidad.DataBind()
UPDatos.Update()
End Sub
#End Region
#Region " EXISTENCIAS "
Private Function GetExistencias(CvePS As Integer, CveUnidadMedida As Integer, CveEmpresa As Integer, CveAlmacen As Integer, Optional Serie As String = "-1") As Double
Dim Inv As New ClsInventarios
Dim Existencia As Double = Inv.GetExistenciasPS(CvePS, CveUnidadMedida, CveEmpresa, CveAlmacen, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), Serie:=Serie)
Inv.Dispose()
Return Existencia
End Function
#End Region
#Region " AGREGAR "
Protected Sub btnAgregar_Click(sender As Object, e As EventArgs) Handles LbAgregar.Click
AgregaProducto()
LimpiarAgregar()
End Sub
Protected Sub AgregaProducto()
Dim PSSelected As Integer = DdlProducto2.SelectedValue.ToEntero
If DdlAlmacen.SelectedValue.ToEntero <= 0 Then Alert("Seleccione un almacen", TipoMensaje.MsgInformacion) : Exit Sub
If PSSelected > 0 Then
If TxtnSerie.Visible Then
If TxtnSerie.Text = "" Then
Alert("Serie-Lote es necesario", TipoMensaje.MsgAdvertencia)
Return
End If
End If
Dim Valido As Boolean = True
Dim cantidadd As Double = txtCantidad.Text.ToDouble
Dim Existencia As Double = GetExistencias(PSSelected, DdlUnidad.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero, If(TxtnSerie.Visible, TxtnSerie.Text, "-1").ToString)
If Existencia - txtCantidad.Text.ToDouble < 0 Then
If Existencia <= 0 Then
Alert("No hay existencia del producto", TipoMensaje.MsgAdvertencia)
Else
Alert(String.Format("Solo hay en existencia: {0}", Existencia), TipoMensaje.MsgAdvertencia)
If Not UsuarioActual.TienePermisoProceso(114) Then
cantidadd = Existencia
End If
End If
Valido = False
'Valido = If(UsuarioActual.TienePermisoProceso(114), True, False)
End If
If Valido Then
Dim CveClasificacion As Integer
Dim dr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=PSSelected).FiltroPrimero("", "PS")
If dr IsNot Nothing Then CveClasificacion = dr("CveClasificacion").ToString.ToEntero
Dim registro As DataRow = DtMovimientos.NewRow
registro.Item("Cantidad") = cantidadd
registro.Item("CveUM") = DdlUnidad.SelectedValue.ToEntero
registro.Item("UnidadMedida") = DdlUnidad.SelectedItem.Text
registro.Item("CvePS") = PSSelected
registro.Item("PS") = DdlProducto2.SelectedText
registro.Item("Estatus") = ""
registro.Item("Serie") = TxtnSerie.Text
registro.Item("SeccionAlmacen") = If(DdlSeccionAlmacen.SelectedValue.ToEntero > 0, DdlSeccionAlmacen.SelectedItem.Text, "")
registro.Item("CveSeccionAlmacen") = If(DdlSeccionAlmacen.SelectedValue.ToEntero > 0, DdlSeccionAlmacen.SelectedValue.ToEntero, -1)
registro.Item("Observaciones") = TxtObservacionesdetalle.Text
DtMovimientos.Rows.Add(registro)
CargaGvM()
UPDatos.Update()
txtCantidad.Text = ""
txtCantidad.Focus()
End If
End If
End Sub
Private Sub LimpiarAgregar()
DdlClasificacion.SelectedValue = "-1"
txtCantidad.Text = ""
TxtObservacionesdetalle.Text = ""
End Sub
#End Region
#Region " GvM "
Private Sub CargaGvM()
ThSerie.Visible = False
TrSerie.Visible = False
TxtnSerie.Visible = False
GvM.Columns(5).Visible = False
GvM.Columns(4).Visible = False
Dim Contador As Integer = 0
Dim UltimoRenglon As Integer = DtMovimientos.Rows.Count - 1
Dim MostrarSerie As Boolean = False
Dim MostrarSeccion As Boolean = False
While Contador <= UltimoRenglon And (Not MostrarSerie And Not MostrarSeccion)
Dim Dr As DataRow = DtMovimientos.Rows(Contador)
MostrarSerie = If(Not MostrarSerie, Dr("Serie").ToString <> "", True)
MostrarSeccion = If(Not MostrarSerie, Dr("SeccionAlmacen").ToString <> "", True)
Contador += 1
End While
ThSerie.Visible = MostrarSerie
TrSerie.Visible = MostrarSerie
GvM.Columns(5).Visible = MostrarSerie
GvM.Columns(4).Visible = MostrarSeccion
'For Each Dr As DataRow In DtMovimientos.Rows
' If Dr("Serie").ToString <> "" Then
' ThSerie.Visible = True
' TrSerie.Visible = True
' GvM.Columns(5).Visible = True
' Exit For
' End If
' If Dr("SeccionAlmacen").ToString <> "" Then
' GvM.Columns(4).Visible = True
' End If
'Next
GvM.DataSource = DtMovimientos
GvM.DataBind()
End Sub
Private Sub GvM_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) Handles GvM.RowDeleting
Dim DbRow As DataRow = Nothing
DbRow = DtMovimientos.Rows(e.RowIndex)
DtMovimientos.Rows.Remove(DbRow)
GvM.EditIndex = -1
CargaGvM()
UPDatos.Update()
End Sub
Protected Sub GvM_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
'If DtSeccionAlmacen.FiltraParametros($"IndexSeccionAlmacen = {e.Row.RowIndex}").SUMD("CantidadSeccionAlmacen") > 0 Then
' e.Row.FCLinkButton("lnkRemove").Visible = False
' e.Row.FCLinkButton("lnkRemove").ToolTip = "Cuenta con sección almacen"
'End If
End If
End Sub
#End Region
#Region " NUEVO "
Protected Sub BtnNuevo_Click(sender As Object, e As EventArgs)
LimpiarMovimiento()
End Sub
Private Sub LimpiarMovimiento()
DtMovimientos.Clear()
CargaGvM()
BtnGuardarResguardo.Visible = True
DdlAlmacen.SelectedValueExist("-1")
DdlAlmacenDestino.SelectedValueExist("-1")
TxtObservaciones.Text = ""
TxtFecha.Text = Now.ToShortDateString
DdlPersonal.SelectedValue = "-1"
DdlPersonal.SelectedText = "Seleccione"
LimpiarAgregar()
UPDatos.Update()
UpGenerales.Update()
End Sub
#End Region
#End Region
#Region " LIBERACION "
#Region " GV DATOS LIBERACION "
Protected Sub GvMLiberacion_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.FCLabel("LblCantidad").Text = e.Row.FCLabel("LblCantidad").Text.FormatoNumero(2)
End If
End Sub
Protected Sub GvMLiberacion_RowCreated(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim Index = e.Row.RowIndex
e.Row.FCTextBox("TxtCantidad").Attributes.Add("onKeyUp", String.Format("ValidarCantidad({0});", Index))
End If
End Sub
#End Region
#Region " CARGA RESGUARDOS PARA LIBERACION "
Protected Sub BtnVerificarExistencias_Click(sender As Object, e As EventArgs)
If Not DdlProveedorLiberacion.SelectedValue.ToEntero > 0 AndAlso DdlTipo.SelectedValue.ToEntero = 3 Then
Alert("Tiene que seleccionar un proveedor.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If Not DdlPersonalLiberacion.SelectedValue.ToEntero > 0 AndAlso DdlTipo.SelectedValue.ToEntero = 1 Then
Alert("Tiene que seleccionar un personal.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If Not DdlClienteLiberacion.SelectedValue.ToEntero > 0 AndAlso DdlTipo.SelectedValue.ToEntero = 2 Then
Alert("Tiene que seleccionar un cliente.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
CargaResguardos()
End Sub
Private Sub CargaResguardos()
Dim ObjInventario As New ClsInventarios()
Dim Existencias As Double = 0
If ObjInventario.GetMovimientosDetallePorPersonal(DdlPersonalLiberacion.SelectedValue.ToEntero, DdlAlmacenLiberacion.SelectedValue.ToEntero, DdlClienteLiberacion.SelectedValue.ToEntero, DdlProveedorLiberacion.SelectedValue.ToEntero) Then
DtMovimientosLiberacion = ObjInventario.DtResultados
DtMovimientosLiberacion.Columns("No").AutoIncrement = True
DtMovimientosLiberacion.Columns("No").AutoIncrementSeed = DtMovimientosLiberacion.Rows.Count + 1
DtMovimientosLiberacion.Columns("No").AutoIncrementStep = 1
Dim keys(1) As DataColumn
keys(0) = DtMovimientosLiberacion.Columns("No")
DtMovimientosLiberacion.PrimaryKey = keys
CargaGvMLiberacion()
If DdlPersonalLiberacion.SelectedValue.ToEntero <> -1 Then
LblTipo.InnerText = "Personal/Responsable:"
LbTipoLiberacion.Text = DdlPersonalLiberacion.SelectedText
End If
If DdlProveedorLiberacion.SelectedValue.ToEntero <> -1 Then
LblTipo.InnerText = "Proveedor:"
LbTipoLiberacion.Text = DdlProveedorLiberacion.SelectedText
End If
If DdlClienteLiberacion.SelectedValue.ToEntero <> -1 Then
LblTipo.InnerText = "Cliente:"
LbTipoLiberacion.Text = DdlClienteLiberacion.SelectedText
End If
CvePersonalLiberacion = DdlPersonalLiberacion.SelectedValue.ToEntero
CveClienteLiberacion = DdlClienteLiberacion.SelectedValue.ToEntero
CveProveedorLiberacion = DdlProveedorLiberacion.SelectedValue.ToEntero
LbAlmacenLiberacion.Text = DdlAlmacenLiberacion.SelectedItem.Text
CveAlmacenLiberación = DdlAlmacenLiberacion.SelectedValue.ToEntero
LbFechaLiberacion.Text = TxtFechaLiberacion.Text
FechaLiberacion = TxtFechaLiberacion.Text
BtnGuardarLiberacion.Visible = True
UpGeneralesLibreacion.Update()
Else
Alert("Ocurrió un error al cargar los resguardos del personal. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
ObjInventario.Dispose()
End Sub
Private Sub CargaGvMLiberacion()
GvM.Columns(5).Visible = False
For Each Dr As DataRow In DtMovimientosLiberacion.Rows
If Dr("Serie").ToString <> "" Then
GvM.Columns(5).Visible = True
Exit For
End If
Next
GvMLiberacion.DataSource = DtMovimientosLiberacion
GvMLiberacion.DataBind()
UpGridLiberacion.Update()
End Sub
#End Region
#Region " LIMPIAR LIBERACION "
Private Sub LimpiarLiberacion()
LbTipoLiberacion.Text = ""
LblTipo.InnerText = ""
CvePersonalLiberacion = -1
CveClienteLiberacion = -1
CveProveedorLiberacion = -1
LbAlmacenLiberacion.Text = ""
CveAlmacenLiberación = -1
LbFechaLiberacion.Text = ""
FechaLiberacion = ""
BtnGuardarLiberacion.Visible = False
DdlAlmacenDestinoLiberacion.SelectedValue = "-1"
TxtObservacionesLiberacion.Text = ""
DtMovimientosLiberacion.Clear()
CargaGvMLiberacion()
UpGeneralesLibreacion.Update()
End Sub
#End Region
#End Region
#Region " GUARDAR "
Protected Sub BtnGuardarResguardo_Click(sender As Object, e As EventArgs) Handles BtnGuardarResguardo.Click
If Not GvM.Rows.Count > 0 Then
Alert("No hay ningun registro para generar el movimiento. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If Not DdlProveedor.SelectedValue.ToEntero > 0 And DivProveedor.Visible Then
Alert("Tiene que seleccionar un proveedor.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
'VALIDA LA EXISTENCIA DEL ALMACEN
Dim ObjInventario As New ClsInventarios
Dim ErrorExistencia = False
Dim TextoExistencia As StringBuilder = New StringBuilder
Dim Existencia As Double
TextoExistencia.Append("Los siguiente productos se ajustaron por falta de exitencia:<br/>")
For Each dr As DataRow In DtMovimientos.Rows
Existencia = ObjInventario.GetExistenciasPS(dr("CvePS").ToString.ToEntero, dr("CveUM").ToString.ToEntero, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero, FechaMovto:=TxtFecha.Text.ToDate.ToString("yyyy/MM/dd 23:59"), Serie:=If(dr("Serie").ToString = "", "-1", dr("Serie").ToString))
Existencia -= DtMovimientos.SUM("Cantidad", $"CvePS = {dr("CvePS").ToString.ToEntero} AND CveUM = {dr("CveUM").ToString.ToEntero} {If(dr("Serie").ToString <> "-1", $" AND Serie = '{dr("Serie").ToString}'", "")}")
If Existencia < 0 Then
ErrorExistencia = True
dr("Cantidad") = Existencia
TextoExistencia.AppendFormat("- #{0} {1}<br/>", dr("No").ToString, dr("PS").ToString)
End If
Next
ObjInventario.Dispose()
If ErrorExistencia Then
Alert(TextoExistencia.ToString, TipoMensaje.MsgError)
End If
Guardar(23)
End Sub
Protected Sub BtnGuardarLiberacion_Click(sender As Object, e As EventArgs)
If Not DdlProveedorLiberacion.SelectedValue.ToEntero > 0 And DivProveedorLiberacion2.Visible Then
Alert("Tiene que seleccionar un proveedor.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If Not GvMLiberacion.Rows.Count > 0 Then
Alert("No hay ningun registro para generar el movimiento. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim TieneError = True
Dim TotalCantidad As Decimal = 0
For Each Gvr As GridViewRow In GvMLiberacion.Rows
If Gvr.FCTextBox("TxtCantidad").Text.ToDecimal > 0 Then
TieneError = False
Exit For
Else
TotalCantidad += Gvr.FCTextBox("TxtCantidad").Text.ToDecimal
End If
Next
If TieneError Then
Alert("Se debe seleccionar por lo menos una cantidad de los resguardos para generar la liberación. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Guardar(24)
End Sub
Private Sub Guardar(Concepto As Integer)
Dim ObjInventario As New ClsInventarios
Dim ObjEventos As New ClsOIEventos(ObjInventario.IniciaTransacSQL()) 'Inicia la transacción
Dim TieneError = False
Dim MensajeError As String = ""
Dim ImporteConcepto = 0.0
Dim CveMovimientoSalida = 0
Dim FolioSalida = 0
Dim CveMovimientoEntrada = 0
Dim FolioEntrada = 0
'Para Campos Nuevos AF y OC
Dim SubProyecto = -1
Dim ActivoFijo = -1
Dim CveProveedor = -1
Dim CveCliente = -1
Dim CvePersonal = -1
If RbTipoCliente.Checked Then CveCliente = DdlCliente.SelectedValue.ToEntero
If RbTipoProveedor.Checked Then CveProveedor = DdlProveedor.SelectedValue.ToEntero
If RbTipoPersonal.Checked Then CvePersonal = DdlPersonal.SelectedValue.ToEntero
Dim Fecha = If(Concepto = 23, TxtFecha.Text.ToDate, FechaLiberacion.ToDate)
Select Case (Concepto)
Case 23 ' Resguardo
'SALIDA ORIGEN
CveMovimientoSalida = ObjInventario.AddMovimiento(DdlAlmacen.SelectedValue.ToEntero, 24, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, SubProyecto, ActivoFijo, Observaciones:=TxtObservaciones.Text, CvePersonal:=CvePersonal, CveAlmacenDestino:=DdlAlmacenDestino.SelectedValue.ToEntero, CveCliente:=CveCliente, CveProveedor:=CveProveedor)
FolioSalida = ObjInventario.Folio
If CveMovimientoSalida <= 0 Then
TieneError = True
MensajeError = "Ocurrió un error al guardar el movimiento de salida. Por favor vuelva a intentar."
Exit Select
End If
Dim Cont As Integer = 0
For Each Dr As DataRow In DtMovimientos.Rows
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, Dr("Cantidad").ToString.ToDouble, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, 0,
-1, CveSeccionAlmacen:=Dr("CveSeccionAlmacen").ToString.ToEntero, Serie:=Dr("Serie").ToString, Observaciones:=Dr("Observaciones").ToString) Then
MensajeError = "Ocurrió un error al guardar los detalles del movimiento de salida. Por favor vuelva a intentar."
TieneError = True
Exit For
End If
Cont += 1
Next
Cont = 0
If Not TieneError Then
CveMovimientoEntrada = ObjInventario.AddMovimiento(DdlAlmacenDestino.SelectedValue.ToEntero, 2, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, SubProyecto, ActivoFijo, Observaciones:=TxtObservaciones.Text, CvePersonal:=CvePersonal, CveMovimientoRelacionado:=CveMovimientoSalida, CveCliente:=CveCliente, CveProveedor:=CveProveedor)
FolioEntrada = ObjInventario.Folio
If CveMovimientoEntrada <= 0 Then
MensajeError = "Ocurrió un error al guardar el movimiento de entrada correctamente. Por favor vuelva a intentar."
TieneError = True
Else
If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then
For Each Dr As DataRow In ObjInventario.DtResultados.Rows
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Dr("Cantidad").ToString.ToDouble, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero,
Dr("PU").ToString.ToDecimal, Dr("CveAF").ToString.ToEntero, CveSeccionAlmacen:=Dr("CveSeccionAlmacen").ToString.ToEntero,
Serie:=Dr("Serie").ToString, Observaciones:=Dr("Observaciones").ToString) Then
TieneError = True
MensajeError = "Ocurrió un error al guardar los movimientos de entrada"
Exit For
End If
Cont += 1
Next
End If
End If
End If
Case 24 'LIBERACION
'SALIDA ORIGEN - RESGUARDO
CveMovimientoSalida = ObjInventario.AddMovimiento(CveAlmacenLiberación, 3, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, SubProyecto, ActivoFijo, Observaciones:=TxtObservacionesLiberacion.Text, CvePersonal:=CvePersonalLiberacion, CveAlmacenDestino:=DdlAlmacenDestinoLiberacion.SelectedValue.ToEntero, CveProveedor:=CveProveedorLiberacion, CveCliente:=CveClienteLiberacion, MovimientoFijo:=True)
FolioSalida = ObjInventario.Folio
If CveMovimientoSalida <= 0 Then
TieneError = True
MensajeError = "Ocurrió un error al guardar el movimiento de salida. Por favor vuelva a intentar."
Exit Select
End If
Dim Cont As Integer = 0
For Each Gvr As GridViewRow In GvMLiberacion.Rows
If Gvr.FCTextBox("TxtCantidad").Text.ToDouble > 0 Then
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, Gvr.FCTextBox("TxtCantidad").Text.ToDouble, Gvr.DataKey("CveUM").ToString.ToEntero, Gvr.DataKey("CvePS").ToString.ToEntero, Gvr.DataKey("PU").ToString.ToDecimal, -1, -1, Gvr.DataKey("Serie").ToString, Gvr.DataKey("Observaciones").ToString) Then
MensajeError = "Ocurrió un error al guardar los detalles del movimiento de salida. Por favor vuelva a intentar."
TieneError = True
Exit For
End If
End If
Cont += 1
Next
If Not TieneError Then
CveMovimientoEntrada = ObjInventario.AddMovimiento(DdlAlmacenDestinoLiberacion.SelectedValue.ToEntero, 23, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, SubProyecto, ActivoFijo, Observaciones:=TxtObservacionesLiberacion.Text, CvePersonal:=CvePersonalLiberacion, CveMovimientoRelacionado:=CveMovimientoSalida, CveProveedor:=CveProveedorLiberacion, CveCliente:=CveClienteLiberacion, MovimientoFijo:=True)
FolioEntrada = ObjInventario.Folio
If CveMovimientoEntrada <= 0 Then
MensajeError = "Ocurrió un error al guardar el movimiento de entrada correctamente. Por favor vuelva a intentar."
TieneError = True
Else
If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then
Cont = 0
For Each Dr As DataRow In ObjInventario.DtResultados.Rows
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Dr("Cantidad").ToString.ToDouble, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, Dr("PU").ToString.ToDecimal, Dr("CveAF").ToString.ToEntero, -1, Dr("Serie").ToString, Dr("Observaciones").ToString) Then
TieneError = True
MensajeError = "Ocurrió un error al guardar los movimientos de entrada"
Exit For
End If
Cont += 1
Next
End If
End If
End If
End Select
If Not TieneError Then
TieneError = Not AgregarAgenda(ObjEventos, FolioEntrada, FolioSalida)
End If
If Not TieneError Then
Dim Msg As New StringBuilder
If Concepto = 23 Then
Msg.AppendFormat("<br/>Resguardo con Folio: <b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}"" target=""_blank"">{1}</a></b>", CveMovimientoSalida, FolioSalida)
Msg.AppendFormat("<br/><a class=""Texto"" target='_blank' href=""/Compras/PopUpVerFactura.aspx?P={0}"">Imprimir Resguardo</a> ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoSalida)))
Msg.AppendFormat("<br/><br/><br/>El Movimiento de control se registro con el Folio: <b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}"" target=""_blank"">{1}</a></b>", CveMovimientoEntrada, FolioEntrada)
Else
Msg.AppendFormat("<br/>Liberación de Resguardo con Folio: <b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}"" target=""_blank"">{1}</a></b>", CveMovimientoEntrada, FolioEntrada)
Msg.AppendFormat("<br/><a class=""Texto"" target='_blank' href=""/Compras/PopUpVerFactura.aspx?P={0}"">Imprimir liberación de Resguardo</a> ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoEntrada)))
Msg.AppendFormat("<br/><br/><br/>El Movimiento de control se registro con el Folio: <b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}"" target=""_blank"">{1}</a></b>", CveMovimientoSalida, FolioSalida)
End If
Alert(Msg.ToString, TipoMensaje.MsgInformacion)
'Limpia Valores cuando inserta de campos especiales
If UsuarioActual.CveEmpresa = 66 Then
DdlSubProyecto.SelectedValueExist("-1")
End If
ObjInventario.Commit()
If Concepto = 23 Then
LimpiarMovimiento()
Else
LimpiarLiberacion()
End If
UPDatos.Update()
Else
Alert(MensajeError, TipoMensaje.MsgError)
ObjInventario.RollBack()
End If
ObjInventario.Dispose()
ObjEventos.Dispose()
End Sub
Private Function AgregarAgenda(ByRef ObjEventos As ClsOIEventos, FolioEntrada As Integer, FolioSalida As Integer) As Boolean
Dim TieneError As Boolean = False
Dim RecurrenciaTipo = 0, Frecuencia = -1, DiasSemana = "-1", Dias = -1, Mes = -1, RecurrenciaFin = "-1", CveAgendaTipo = 4, Prioridad = 3, CveTipoEvento = 2, Importe = -1
Dim Asunto As String = $"Vencimiento de Resguardo de Material. FolioEntrada:{FolioEntrada}, FolioSalida:{FolioSalida}"
Dim Descripcion As String = TxtObservaciones.Text.Trim()
Dim Fecha As DateTime = TxtFechaVigencia.Text.Trim().ToDateTime()
Dim FechaI As DateTime = Fecha
Dim FechaF As DateTime = Fecha.AddHours(22)
If Fecha > MinFecha Then
TieneError = Not ObjEventos.AddEventoAgenda(CveAgendaTipo, Asunto, Descripcion, Prioridad, FechaI, FechaF, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa,
RecurrenciaTipo:=RecurrenciaTipo, Frecuencia:=Frecuencia, DiasSemana:=DiasSemana, Dia:=Dias, Mes:=Mes, RecurrenciaFin:=RecurrenciaFin, CveTipoEvento:=CveTipoEvento, Importe:=Importe)
End If
Return Not TieneError
End Function
#End Region
#Region "TIPOS"
Protected Sub RbTipo_CheckedChanged(sender As Object, e As EventArgs)
DivCliente.Visible = False
DivPersonal.Visible = False
DivProveedor.Visible = False
If RbTipoCliente.Checked Then
DivCliente.Visible = True
'DdlPersonal.Attributes.Add("data-metodo", "getcliente")
End If
If RbTipoPersonal.Checked Then
DivPersonal.Visible = True
'DdlPersonal.Attributes.Add("data-metodo", "getpersonal")
End If
If RbTipoProveedor.Checked Then
DivProveedor.Visible = True
'DdlPersonal.Attributes.Add("data-metodo", "getproveedores")
End If
UpGenerales.Update()
End Sub
Protected Sub DdlTipo_SelectedIndexChanged(sender As Object, e As EventArgs)
'DdlPersonalLiberacion.ddl.SelectedIndex = 0
'DdlProveedorLiberacion.SelectedValue = "-1"
'DdlProveedorLiberacion.SelectedText = "Seleccione"
'DdlClienteLiberacion.SelectedValue = "0"
DivPersonalLiberacion.Visible = False
DivPersonalLiberacion2.Visible = False
DivClienteLiberacion.Visible = False
DivClienteLiberacion2.Visible = False
DivProveedorLiberacion.Visible = False
DivProveedorLiberacion2.Visible = False
If DdlTipo.SelectedValue.ToEntero = 1 Then
DivPersonalLiberacion.Visible = True
DivPersonalLiberacion2.Visible = True
End If
If DdlTipo.SelectedValue.ToEntero = 2 Then
DivClienteLiberacion.Visible = True
DivClienteLiberacion2.Visible = True
End If
If DdlTipo.SelectedValue.ToEntero = 3 Then
DivProveedorLiberacion.Visible = True
DivProveedorLiberacion2.Visible = True
End If
UpFiltraLiberacion.Update()
End Sub
#End Region
Private Sub ImgExcel_Click(sender As Object, e As EventArgs) Handles ImgExcel.Click
Imprime("Excel")
End Sub
Private Sub Imprime(Formato As String)
If DtMovimientosLiberacion IsNot Nothing Then
Dim params As New List(Of ReportParameter)
ImprimirPDF("Empresas/Grales/Formatos/ResguardoMaterial.rdlc", DtMovimientosLiberacion, params, String.Format("RepResguardoMaterial-{0}", Now.ToDateTime.ToShortDateString), Formato)
Else
Alert("No hay datos consultados", TipoMensaje.MsgAdvertencia)
End If
End Sub
End Class