338 lines
13 KiB
VB.net
338 lines
13 KiB
VB.net
Option Strict On
|
|
Imports System.Data
|
|
Imports System.Collections.Generic
|
|
Imports System.Linq
|
|
Imports System.Web
|
|
Imports System.Web.UI.WebControls
|
|
Imports Extensiones
|
|
Partial Class Inventarios_KardexSeccionAlmacen
|
|
Inherits ClsPaginas
|
|
|
|
|
|
#Region "PROPIEDADES"
|
|
|
|
Private Property DtSeccionAlmacen As DataTable
|
|
Get
|
|
Return CType(ViewState("DtSeccionAlmacen"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DtSeccionAlmacen") = 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 CveSeccionAlmacenOrigen As Integer
|
|
Get
|
|
Return CType(ViewState("CveSeccionAlmacenOrigen"), Integer)
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveSeccionAlmacenOrigen") = value
|
|
End Set
|
|
End Property
|
|
Private Property SeccionAlmacenOrigen As String
|
|
Get
|
|
Return CType(ViewState("SeccionAlmacenOrigen"), String)
|
|
End Get
|
|
Set(value As String)
|
|
ViewState("SeccionAlmacenOrigen") = value
|
|
End Set
|
|
End Property
|
|
Private Property CveAlmacen As Integer
|
|
Get
|
|
Return CType(ViewState("CveAlmacen"), Integer)
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveAlmacen") = value
|
|
End Set
|
|
End Property
|
|
Private Property CveUM As Integer
|
|
Get
|
|
Return CType(ViewState("CveUM"), Integer)
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveUM") = value
|
|
End Set
|
|
End Property
|
|
Private Property CveSubProyecto As Integer
|
|
Get
|
|
Return CType(ViewState("CveSubProyecto"), Integer)
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveSubProyecto") = value
|
|
End Set
|
|
End Property
|
|
Private Property SerieLote As String
|
|
Get
|
|
Return CType(ViewState("SerieLote"), String)
|
|
End Get
|
|
Set(value As String)
|
|
ViewState("SerieLote") = value
|
|
End Set
|
|
End Property
|
|
|
|
|
|
#End Region
|
|
|
|
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
If Not IsPostBack Then
|
|
InicializaValores()
|
|
End If
|
|
End Sub
|
|
|
|
#Region "CARGAS"
|
|
|
|
Private Sub InicializaValores()
|
|
CantidadTotal = 0
|
|
SeccionAlmacenOrigen = ""
|
|
CvePS = 0
|
|
CveAlmacen = 0
|
|
CveSeccionAlmacenOrigen = 0
|
|
CveSubProyecto = 0
|
|
CveUM = 0
|
|
SerieLote = ""
|
|
|
|
CreaDtSeccionAlmacen()
|
|
CargaDdlAlmacen()
|
|
CargaPS()
|
|
End Sub
|
|
|
|
Private Sub CargaPS()
|
|
DdlPS.setEsWebService(UsuarioActual.Empresa.Funcionalidad(105) = "1")
|
|
|
|
If UsuarioActual.Empresa.Funcionalidad(105) = "1" Then
|
|
DdlPS.ddlWS.Attributes.Add("data-cveclasificacion", "-1")
|
|
DdlPS.SelectedText = "Seleccione"
|
|
DdlPS.SelectedValue = "-1"
|
|
Else
|
|
DdlPS.ddl.Items.Clear()
|
|
DdlPS.ddl.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa)
|
|
DdlPS.ddl.DataBind()
|
|
DdlPS.ddl.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub CargaDdlAlmacen()
|
|
DdlAlmacen.DataSource = GlobalDTAlmacen(UsuarioActual.CveEmpresa)
|
|
DdlAlmacen.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
DdlAlmacen.DataBind()
|
|
|
|
DdlSeccionAlmacen.DataSource = GlobalDTSeccionAlmacen(UsuarioActual.CveEmpresa)
|
|
DdlSeccionAlmacen.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
DdlSeccionAlmacen.DataBind()
|
|
|
|
DdlSeccionAlmacenDestino.DataSource = GlobalDTSeccionAlmacen(UsuarioActual.CveEmpresa)
|
|
DdlSeccionAlmacenDestino.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
DdlSeccionAlmacenDestino.DataBind()
|
|
End Sub
|
|
|
|
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs)
|
|
CargaDatos()
|
|
End Sub
|
|
|
|
Private Sub CargaDatos()
|
|
If Not DdlPS.SelectedValue.ToEntero > 0 Then
|
|
Alert("Tiene que seleccionar un producto/servicio.", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
If Not DdlAlmacen.SelectedValue.ToEntero > 0 Then
|
|
Alert("Tiene que seleccionar un alamacen.", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
Dim ObjInv As New ClsInventarios
|
|
If ObjInv.GetKardexSeccionAlmacen(DdlPS.SelectedValue.ToEntero, DdlAlmacen.SelectedValue.ToEntero, DdlSeccionAlmacen.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then
|
|
GvDatos.DataSource = ObjInv.DtResultados
|
|
End If
|
|
ObjInv.Dispose()
|
|
GvDatos.DataBind()
|
|
UpDatos.Update()
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
|
|
#Region "SECCION ALMACEN"
|
|
Private Sub CreaDtSeccionAlmacen()
|
|
DtSeccionAlmacen = New DataTable
|
|
DtSeccionAlmacen.Columns.Add("CantidadSeccionAlmacen", GetType(Decimal))
|
|
DtSeccionAlmacen.Columns.Add("CveSeccionAlmacenOrigen", GetType(Integer))
|
|
DtSeccionAlmacen.Columns.Add("CveSeccionAlmacenDestino", GetType(Integer))
|
|
DtSeccionAlmacen.Columns.Add("SeccionAlmacenOrigen", GetType(String))
|
|
DtSeccionAlmacen.Columns.Add("SeccionAlmacenDestino", GetType(String))
|
|
DtSeccionAlmacen.Columns.Add("Consec", GetType(Integer))
|
|
End Sub
|
|
|
|
Protected Sub LnkSeccionAlmacen_Click(sender As Object, e As EventArgs)
|
|
Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow)
|
|
DtSeccionAlmacen.Rows.Clear()
|
|
CantidadTotal = gvRow.DataKey("Existencia").ToDecimal
|
|
CveSeccionAlmacenOrigen = gvRow.DataKey("CveAlmacenSeccion").ToEntero
|
|
SeccionAlmacenOrigen = gvRow.DataKey("AlmacenSeccion").ToString
|
|
CvePS = gvRow.DataKey("CvePS").ToEntero
|
|
SerieLote = gvRow.DataKey("SerieLote").ToString
|
|
CveAlmacen = gvRow.DataKey("CveAlmacen").ToEntero
|
|
CveUM = gvRow.DataKey("CveUM").ToEntero
|
|
CveSubProyecto = gvRow.DataKey("CveSubProyecto").ToEntero
|
|
RegistraScript("$('#DModalSeccionAlmacen').modal()")
|
|
CargaSeccionAlmacen()
|
|
End Sub
|
|
|
|
Protected Sub LnkAddSeccionAlmacen_Click(sender As Object, e As EventArgs)
|
|
|
|
Dim ObjInv As New ClsInventarios
|
|
Dim CantidadDisponible As Decimal = 0
|
|
If ObjInv.GetMovimientosDetalleSeccionesAlmacen(CveSeccionAlmacenOrigen, CveAlmacen, CvePS, UsuarioActual.CveEmpresa) Then
|
|
If ObjInv.DtResultados.Rows.Count > 0 Then
|
|
CantidadDisponible = ObjInv.DtResultados.Rows(0)("CantidadRestante").ToString.ToDecimal
|
|
End If
|
|
End If
|
|
ObjInv.Dispose()
|
|
|
|
CantidadDisponible -= DtSeccionAlmacen.SUMD("CantidadSeccionAlmacen")
|
|
|
|
If TxtCantidadSeccion.Text.ToDecimal > CantidadDisponible Then
|
|
Alert($"No tiene cantidad de producto suficiente en esta seccion de almacen, su cantidad restante es: <b>{CantidadDisponible}</b>", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
Dim Row As DataRow = Nothing
|
|
DtSeccionAlmacen.AcceptChanges()
|
|
Row = DtSeccionAlmacen.NewRow
|
|
Row("CantidadSeccionAlmacen") = TxtCantidadSeccion.Text.ToDecimal
|
|
Row("CveSeccionAlmacenOrigen") = CveSeccionAlmacenOrigen
|
|
Row("SeccionAlmacenOrigen") = SeccionAlmacenOrigen
|
|
Row("CveSeccionAlmacenDestino") = DdlSeccionAlmacenDestino.SelectedValue.ToEntero
|
|
Row("SeccionAlmacenDestino") = DdlSeccionAlmacenDestino.SelectedItem.Text
|
|
Row("Consec") = DtSeccionAlmacen.Rows.Count + 1
|
|
DtSeccionAlmacen.Rows.Add(Row)
|
|
DtSeccionAlmacen.AcceptChanges()
|
|
CargaSeccionAlmacen()
|
|
End Sub
|
|
|
|
Protected Sub LnkEliminarSeccion_Click(sender As Object, e As EventArgs)
|
|
Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow)
|
|
Dim Index As Integer = 0
|
|
For Each Dr As DataRow In DtSeccionAlmacen.Rows
|
|
If Dr("Consec").ToString.ToEntero = gvRow.DataKey("Consec").ToEntero() Then
|
|
Exit For
|
|
End If
|
|
Index += 1
|
|
Next
|
|
DtSeccionAlmacen.Rows.RemoveAt(Index)
|
|
DtSeccionAlmacen.AcceptChanges()
|
|
CargaSeccionAlmacen()
|
|
End Sub
|
|
|
|
Private Sub CargaSeccionAlmacen()
|
|
Dim CantidadTotalSeccion As Decimal = DtSeccionAlmacen.SUMD("CantidadSeccionAlmacen")
|
|
GvSeccion.DataSource = DtSeccionAlmacen
|
|
GvSeccion.DataBind()
|
|
|
|
TxtCantidadSeccion.Text = ""
|
|
DdlSeccionAlmacenDestino.SelectedIndex = 0
|
|
Dim CantidadRestante As Decimal = CantidadTotal - CantidadTotalSeccion
|
|
If CantidadRestante = 0 Then
|
|
RVTxtCantidad.MaximumValue = "1"
|
|
TxtCantidadSeccion.Enabled = False
|
|
Else
|
|
RVTxtCantidad.MaximumValue = CantidadRestante.ToString
|
|
TxtCantidadSeccion.Enabled = True
|
|
End If
|
|
|
|
UpModalSeccionAlmacen.Update()
|
|
End Sub
|
|
|
|
Protected Sub BtnTraspasar_Click(sender As Object, e As EventArgs)
|
|
Dim ObjInv As New ClsInventarios
|
|
ObjInv.IniciaTransacSQL()
|
|
Dim TieneError As Boolean = False
|
|
Dim MensajeError As String = ""
|
|
|
|
'SALIDA
|
|
Dim CveMovimientoSalida As Integer = ObjInv.AddMovimiento(DdlAlmacen.SelectedValue.ToEntero, 3, 1, Now, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, CveSubProyecto, -1, CveAlmacenDestino:=CveAlmacen)
|
|
|
|
If CveMovimientoSalida <= 0 Then
|
|
TieneError = True
|
|
MensajeError = "Ocurrió un error al guardar el movimiento de salida. Por favor vuelva a intentar."
|
|
End If
|
|
|
|
Dim Cantidad As Decimal = DtSeccionAlmacen.SUMD("CantidadSeccionAlmacen")
|
|
|
|
If Not ObjInv.AddMovimientoDetalle(CveMovimientoSalida, Cantidad, CveUM, CvePS, 0, -1, SerieLote:=SerieLote) Then
|
|
MensajeError = "Ocurrió un error al guardar los detalles del movimiento de salida. Por favor vuelva a intentar."
|
|
TieneError = True
|
|
Else
|
|
If ObjInv.CveMovimientoDetalle > 0 AndAlso DtSeccionAlmacen.Rows.Count > 0 Then
|
|
For Each Dr2 As DataRow In DtSeccionAlmacen.Rows
|
|
If Not ObjInv.AddMovimientosDetalleSeccionesAlmacen(ObjInv.CveMovimientoDetalle, Dr2("CveSeccionAlmacenOrigen").ToString.ToEntero, -Dr2("CantidadSeccionAlmacen").ToString.ToDecimal) Then
|
|
TieneError = True
|
|
MensajeError = "Ocurrió un error al procesar las secciones de almacen. Por favor vuelva a intentar."
|
|
Exit For
|
|
End If
|
|
Next
|
|
End If
|
|
End If
|
|
|
|
'ENTRADA
|
|
If Not TieneError Then
|
|
Dim CveMovimientoEntrada As Integer = ObjInv.AddMovimiento(CveAlmacen, 2, 1, Now, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, CveSubProyecto, -1, CveMovimientoRelacionado:=CveMovimientoSalida)
|
|
|
|
If CveMovimientoEntrada <= 0 Then
|
|
MensajeError = "Ocurrió un error al guardar el movimiento de entrada correctamente. Por favor vuelva a intentar."
|
|
TieneError = True
|
|
Else
|
|
If ObjInv.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then
|
|
For Each Dr As DataRow In ObjInv.DtResultados.Rows
|
|
If Not ObjInv.AddMovimientoDetalle(CveMovimientoEntrada, Dr("Cantidad").ToString.ToDouble, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, Dr("PU").ToString.ToDecimal, Dr("CveAF").ToString.ToEntero, -1, Dr("SerieLote").ToString, Dr("Observaciones").ToString) Then
|
|
TieneError = True
|
|
MensajeError = "Ocurrió un error al guardar los movimientos de entrada"
|
|
Exit For
|
|
Else
|
|
If ObjInv.CveMovimientoDetalle > 0 AndAlso DtSeccionAlmacen.Rows.Count > 0 Then
|
|
For Each Dr2 As DataRow In DtSeccionAlmacen.Rows
|
|
If Not ObjInv.AddMovimientosDetalleSeccionesAlmacen(ObjInv.CveMovimientoDetalle, Dr2("CveSeccionAlmacenDestino").ToString.ToEntero, Dr2("CantidadSeccionAlmacen").ToString.ToDecimal) Then
|
|
TieneError = True
|
|
MensajeError = "Ocurrió un error al procesar las secciones de almacen. Por favor vuelva a intentar."
|
|
Exit For
|
|
End If
|
|
Next
|
|
End If
|
|
End If
|
|
Next
|
|
End If
|
|
End If
|
|
End If
|
|
|
|
If Not TieneError Then
|
|
ObjInv.Commit()
|
|
Alert("El traspaso se ha hecho correctamente")
|
|
CargaDatos()
|
|
RegistraScript("$('#DModalSeccionAlmacen').modal('hide')")
|
|
Else
|
|
ObjInv.RollBack()
|
|
Alert(MensajeError, TipoMensaje.MsgError)
|
|
End If
|
|
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
|
|
|
|
End Class
|