440 lines
18 KiB
VB.net
440 lines
18 KiB
VB.net
Imports System.Data
|
|
Imports Extensiones
|
|
Partial Class Inventarios_ConsignacionesMaterial
|
|
Inherits ClsPaginas
|
|
|
|
#Region "P R O P I E D A D E S"
|
|
Public Property DTmp() As DataTable
|
|
Get
|
|
Return CType(ViewState("DTmp"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DTmp") = value
|
|
End Set
|
|
End Property
|
|
|
|
|
|
Public Property CveConcepto() As Integer
|
|
Get
|
|
Return CType(ViewState("CveConcepto"), Integer)
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveConcepto") = value
|
|
End Set
|
|
End Property
|
|
#End Region
|
|
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
If Not IsPostBack Then
|
|
|
|
CreaDTCons()
|
|
InicializarListas()
|
|
|
|
TxtFecha.Text = Now
|
|
End If
|
|
End Sub
|
|
Private Sub CreaDTCons()
|
|
DTmp = New DataTable
|
|
DTmp.Columns.Add("No", GetType(Integer))
|
|
DTmp.Columns.Add("Cantidad", GetType(Double))
|
|
DTmp.Columns.Add("CveUnidadMedida", GetType(Integer))
|
|
DTmp.Columns.Add("UnidadMedida", GetType(String))
|
|
DTmp.Columns.Add("CveAlmacen", GetType(Integer))
|
|
DTmp.Columns.Add("Almacen", GetType(String))
|
|
DTmp.Columns.Add("CvePS", GetType(Integer))
|
|
DTmp.Columns.Add("PU", GetType(Double))
|
|
DTmp.Columns.Add("PS", GetType(String))
|
|
DTmp.Columns.Add("Nuevo", GetType(Integer))
|
|
DTmp.Columns.Add("CveSeccionAlmacen", GetType(Integer))
|
|
|
|
End Sub
|
|
Private Sub AddDTmp(Cantidad As Integer, CveUnidadMedida As Integer, UnidadMedida As String, CvePS As Integer, PS As String, Almacen As String, CveAlmacen As Integer, CveSeccion As Integer)
|
|
Dim Row As DataRow = Nothing
|
|
Row = DTmp.NewRow()
|
|
Row("Cantidad") = Cantidad
|
|
Row("CveUnidadMedida") = CveUnidadMedida
|
|
Row("CveAlmacen") = CveAlmacen
|
|
Row("CveSeccionAlmacen") = If(CveSeccion = 0, -1, CveSeccion)
|
|
Row("Almacen") = If(CveAlmacen <> -1, Almacen, "Sin Sección")
|
|
Row("UnidadMedida") = UnidadMedida
|
|
Row("CvePS") = CvePS
|
|
Row("PS") = PS
|
|
Row("Nuevo") = 1
|
|
|
|
DTmp.Rows.Add(Row)
|
|
UPGV.Update()
|
|
|
|
End Sub
|
|
Private Sub InicializarListas()
|
|
Dim ObjPersonal As New ClsRH
|
|
Dim productos As New ClsProductosServicios
|
|
DdlAlmacen.DataSource = GlobalDTAlmacen(UsuarioActual.CveEmpresa)
|
|
DdlAlmacen.DataBind()
|
|
DdlAlmacen.Items.Insert(0, New ListItem("Seleccione Almacen.", "-1"))
|
|
CveConcepto = 7
|
|
'Llenar el dropdownlist de Secciones
|
|
DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa)
|
|
DdlClasificacion.DataBind()
|
|
|
|
ddlProducto.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa)
|
|
ddlProducto.DataBind()
|
|
ddlProducto.Items.Insert(0, New ListItem("Seleccione Producto.", "-1"))
|
|
|
|
If ObjPersonal.GetPersonal(-1, UsuarioActual.CveEmpresa) Then
|
|
DdlPersonal.DataSource = ObjPersonal.DtResultados
|
|
DdlPersonal.DataBind()
|
|
DdlPersonal.Items.Insert(0, New ListItem("Seleccione Personal.", "-1"))
|
|
End If
|
|
|
|
|
|
ObjPersonal.Dispose()
|
|
productos.Dispose()
|
|
End Sub
|
|
Protected Sub btnGuardar_Click(sender As Object, e As EventArgs) Handles btnGuardar.Click
|
|
If Not DdlPersonal.SelectedValue.ToEntero = -1 Then
|
|
|
|
|
|
If GvConsignacion.Rows.Count > 0 Then
|
|
|
|
Dim CveMovimiento As Integer
|
|
Dim CveMovimientoC As Integer
|
|
Dim Mov As New ClsInventarios
|
|
Mov.IniciaTransacSQL() 'Inicia la transacción
|
|
Dim CvePersonal As Integer = -1
|
|
Dim Mensaje As String = ""
|
|
|
|
|
|
CvePersonal = DdlPersonal.SelectedValue.ToEntero
|
|
For Each dr As DataRow In DTmp.FiltraParametros("", DistinctColumns:={"CveAlmacen"}).Rows
|
|
|
|
|
|
|
|
CveMovimientoC = Mov.AddMovimiento(dr("CveAlmacen").ToString.ToEntero, 6, 1, TxtFecha.Text, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, -1, CvePersonal)
|
|
|
|
If CveMovimientoC <= 0 Then
|
|
Alert("No se pudo almacenar el movimiento correctamente", TipoMensaje.MsgError)
|
|
Mov.RollBack() 'deshace lo insertado
|
|
Else
|
|
|
|
|
|
For Each gr As GridViewRow In GvConsignacion.Rows
|
|
If Not gr.FCTextBox("tbCantR").Text.ToString = "" Then
|
|
|
|
If Not Mov.AddMovimientoDetalle(CveMovimientoC, gr.FCTextBox("tbCantR").Text.ToString.ToDouble, DTmp.Rows(gr.RowIndex)("CveUnidadMedida").ToString.ToEntero, DTmp.Rows(gr.RowIndex)("CvePS").ToString.ToEntero,
|
|
DTmp.Rows(gr.RowIndex)("PU").ToString.ToDouble, DTmp.Rows(gr.RowIndex)("CveSeccionAlmacen").ToString.ToEntero) Then
|
|
Mensaje = "Error al guardar los movimientos"
|
|
Exit For
|
|
End If
|
|
End If
|
|
Next
|
|
|
|
|
|
CveMovimiento = Mov.AddMovimiento(dr("CveAlmacen").ToString.ToEntero, 3, 1, TxtFecha.Text, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, -1, CvePersonal)
|
|
|
|
If CveMovimiento <= 0 Then
|
|
Alert("No se pudo almacenar el movimiento correctamente", TipoMensaje.MsgError)
|
|
Mov.RollBack() 'deshace lo insertado
|
|
Else
|
|
|
|
For Each gr As GridViewRow In GvConsignacion.Rows
|
|
If Not gr.FCTextBox("tbCantR").Text.ToString = "" Then
|
|
If Not Mov.AddMovimientoDetalle(CveMovimiento, gr.FCTextBox("tbCantR").Text.ToString.ToDouble, DTmp.Rows(gr.RowIndex)("CveUnidadMedida").ToString.ToEntero, DTmp.Rows(gr.RowIndex)("CvePS").ToString.ToEntero,
|
|
DTmp.Rows(gr.RowIndex)("PU").ToString.ToDouble, DTmp.Rows(gr.RowIndex)("CveSeccionAlmacen").ToString.ToEntero) Then
|
|
Mensaje = "Error al guardar los movimientos"
|
|
Exit For
|
|
End If
|
|
End If
|
|
Next
|
|
|
|
End If
|
|
|
|
|
|
End If
|
|
Next
|
|
|
|
If Mensaje = "" Then
|
|
Mov.Commit() ' aplica los movimientos insertados
|
|
Alert("Movimientos Registrado", TipoMensaje.MsgInformacion)
|
|
Else
|
|
Mov.RollBack() 'deshace lo insertado
|
|
Alert(Mensaje, TipoMensaje.MsgError)
|
|
End If
|
|
|
|
If Mov.GetConsignaciones(UsuarioActual.CveEmpresa, DdlPersonal.SelectedValue.ToEntero) Then
|
|
GvConsignacion.DataSource = Mov.DtResultados
|
|
GvConsignacion.DataBind()
|
|
DTmp = Mov.DtResultados
|
|
|
|
End If
|
|
Mov.Dispose() 'elimino la instancia
|
|
|
|
End If
|
|
|
|
End If
|
|
End Sub
|
|
Protected Sub lbAdd_Click(sender As Object, e As EventArgs) Handles lbAdd.Click
|
|
|
|
Dim ObjInventario As New ClsInventarios
|
|
Dim Existencia As Double = ObjInventario.GetExistenciasPS(ddlProducto.SelectedValue.ToEntero, ddlUnidad.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero)
|
|
ObjInventario.GetConsignaciones(UsuarioActual.CveEmpresa, -1)
|
|
Dim DTmpC As DataTable = ObjInventario.DtResultados
|
|
Dim Total As Double = Existencia - If(DTmpC.FiltraParametros("CvePS=" & ddlProducto.SelectedValue).Rows.Count > 0, DTmpC.FiltraParametros("CvePS=" & ddlProducto.SelectedValue).SUM("Cantidad"), 0) - If(DTmp.FiltraParametros("Nuevo=1").Rows.Count > 0, DTmp.FiltraParametros("Nuevo=1").SUM("Cantidad"), 0)
|
|
|
|
If CveConcepto = 7 Then
|
|
|
|
If tbCant.Text >= Total Then
|
|
|
|
Alert("No hay existencia suficiente en el Inventario.", TipoMensaje.MsgInformacion)
|
|
ObjInventario.Dispose()
|
|
Return
|
|
|
|
End If
|
|
|
|
'ElseIf CveConcepto = 6 Then
|
|
' If Not DdlPersonal.SelectedValue.ToEntero = -1 Then
|
|
' If DTmp.FiltraParametros("CvePS=" & ddlProducto.SelectedValue).SUM("Cantidad") < tbCant.Text.ToDouble Then
|
|
' Alert("No hay suficiente material consignado.")
|
|
' ObjInventario.Dispose()
|
|
' Return
|
|
' End If
|
|
' Else
|
|
|
|
' Alert("Seleccione Personal.")
|
|
' Return
|
|
' End If
|
|
|
|
|
|
End If
|
|
AddDTmp(tbCant.Text.ToDouble, ddlUnidad.SelectedValue.ToEntero, ddlUnidad.SelectedItem.ToString, ddlProducto.SelectedValue, ddlProducto.SelectedItem.ToString, DdlAlmacen.SelectedItem.ToString, DdlAlmacen.SelectedValue.ToEntero, DdlSeccion.SelectedValue.ToEntero)
|
|
tbCant.Text = ""
|
|
GvConsignacion.DataSource = DTmp
|
|
GvConsignacion.DataBind()
|
|
ObjInventario.Dispose()
|
|
End Sub
|
|
Protected Sub DdlClasificacion_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlClasificacion.SelectedIndexChanged
|
|
ddlProducto.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=DdlClasificacion.SelectedValue.ToEntero)
|
|
ddlProducto.DataBind()
|
|
ddlProducto.Items.Insert(0, New ListItem("----", "-1"))
|
|
End Sub
|
|
Protected Sub ddlProducto_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlProducto.SelectedIndexChanged
|
|
|
|
Dim ObjProducto As New ClsProductosServicios
|
|
|
|
If ObjProducto.GetPSEquivalencias(ddlProducto.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then
|
|
|
|
ddlUnidad.DataSource = ObjProducto.DtResultados
|
|
ddlUnidad.DataBind()
|
|
|
|
End If
|
|
|
|
ObjProducto.Dispose()
|
|
UPGV.Update()
|
|
End Sub
|
|
|
|
Protected Sub DdlAlmacen_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlAlmacen.SelectedIndexChanged
|
|
DdlSeccion.DataSource = GlobalDTSeccionAlmacen(UsuarioActual.CveEmpresa)
|
|
DdlSeccion.DataBind()
|
|
DdlSeccion.Items.Insert(0, New ListItem("Seleccione Sección.", "-1"))
|
|
UPEncabezado.Update()
|
|
|
|
End Sub
|
|
|
|
Protected Sub DdlPersonal_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlPersonal.SelectedIndexChanged
|
|
Dim ObjInventario As New ClsInventarios
|
|
If ObjInventario.GetConsignaciones(UsuarioActual.CveEmpresa, DdlPersonal.SelectedValue) Then
|
|
GvConsignacion.DataSource = ObjInventario.DtResultados
|
|
DTmp = ObjInventario.DtResultados
|
|
|
|
GvConsignacion.DataBind()
|
|
End If
|
|
ObjInventario.Dispose()
|
|
UPGV.Update()
|
|
End Sub
|
|
|
|
Protected Sub btnGuardarMa_Click(sender As Object, e As EventArgs) Handles btnGuardarMa.Click
|
|
Dim Mov As New ClsInventarios
|
|
If Not DdlAlmacen.SelectedValue.ToEntero = -1 Then
|
|
If Not DdlPersonal.SelectedValue.ToEntero = -1 Then
|
|
|
|
If GvConsignacion.Rows.Count > 0 Then
|
|
|
|
Dim CveMovimiento As Integer
|
|
Dim Mensaje As String = ""
|
|
Mov.IniciaTransacSQL() 'Inicia la transacción
|
|
Dim CvePersonal As Integer = -1
|
|
|
|
CvePersonal = DdlPersonal.SelectedValue.ToEntero
|
|
For Each dr As DataRow In DTmp.FiltraParametros("", DistinctColumns:={"CveAlmacen"}).Rows
|
|
CveMovimiento = Mov.AddMovimiento(dr("CveAlmacen").ToString.ToEntero, 6, 1, TxtFecha.Text, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, -1, CvePersonal)
|
|
|
|
If CveMovimiento <= 0 Then
|
|
Alert("No se pudo almacenar el movimiento correctamente", TipoMensaje.MsgError)
|
|
Mov.RollBack() 'deshace lo insertado
|
|
Else
|
|
|
|
For Each gr As GridViewRow In GvConsignacion.Rows
|
|
If Not gr.FCTextBox("tbCantR").Text.ToString = "" Then
|
|
If Not Mov.AddMovimientoDetalle(CveMovimiento, gr.FCTextBox("tbCantR").Text.ToString.ToDouble, DTmp.Rows(gr.RowIndex)("CveUnidadMedida").ToString.ToEntero, DTmp.Rows(gr.RowIndex)("CvePS").ToString.ToEntero,
|
|
DTmp.Rows(gr.RowIndex)("PU").ToString.ToDouble, DTmp.Rows(gr.RowIndex)("CveSeccionAlmacen").ToString.ToEntero) Then
|
|
Mensaje = "Error al guardar los movimientos"
|
|
Exit For
|
|
End If
|
|
End If
|
|
Next
|
|
|
|
|
|
|
|
End If
|
|
|
|
Next
|
|
If Mensaje = "" Then
|
|
Mov.Commit() ' aplica los movimientos insertados
|
|
Alert("Movimientos Registrado", TipoMensaje.MsgInformacion)
|
|
Else
|
|
Mov.RollBack() 'deshace lo insertado
|
|
Alert(Mensaje, TipoMensaje.MsgError)
|
|
End If
|
|
' inicializarTablas()
|
|
If Mov.GetConsignaciones(UsuarioActual.CveEmpresa, DdlPersonal.SelectedValue.ToEntero) Then
|
|
GvConsignacion.DataSource = Mov.DtResultados
|
|
GvConsignacion.DataBind()
|
|
DTmp = Mov.DtResultados
|
|
|
|
End If
|
|
End If
|
|
Else
|
|
Alert("No hay registros por guardar.", TipoMensaje.MsgInformacion)
|
|
End If
|
|
Else
|
|
Alert("Seleccione un Almacén.", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
Mov.Dispose() 'elimino la instancia
|
|
UPGV.Update()
|
|
End Sub
|
|
|
|
Protected Sub cbEC_CheckedChanged(sender As Object, e As EventArgs) Handles cbEC.CheckedChanged
|
|
If Not DdlPersonal.SelectedValue.ToEntero = -1 Then
|
|
Dim ObjInventario As New ClsInventarios
|
|
If ObjInventario.GetConsignaciones(UsuarioActual.CveEmpresa, DdlPersonal.SelectedValue) Then
|
|
GvConsignacion.DataSource = ObjInventario.DtResultados
|
|
DTmp = ObjInventario.DtResultados
|
|
|
|
GvConsignacion.DataBind()
|
|
End If
|
|
ObjInventario.Dispose()
|
|
|
|
UPGV.Update()
|
|
End If
|
|
CveConcepto = 6
|
|
|
|
GvConsignacion.Columns(0).Visible = True
|
|
btnGuardar.Visible = True
|
|
btnGuardarMa.Visible = True
|
|
btnGuardarC.Visible = False
|
|
AddControls.Visible = False
|
|
ColR.Visible = True
|
|
UPEncabezado.Update()
|
|
End Sub
|
|
|
|
Protected Sub cbSC_CheckedChanged(sender As Object, e As EventArgs) Handles cbSC.CheckedChanged
|
|
CveConcepto = 7
|
|
btnGuardar.Visible = False
|
|
btnGuardarMa.Visible = False
|
|
btnGuardarC.Visible = True
|
|
GvConsignacion.Columns(0).Visible = False
|
|
|
|
UPGV.Update()
|
|
AddControls.Visible = True
|
|
ColR.Visible = False
|
|
UPEncabezado.Update()
|
|
End Sub
|
|
|
|
Protected Sub btnGuardarC_Click(sender As Object, e As EventArgs) Handles btnGuardarC.Click
|
|
Dim Mov As New ClsInventarios
|
|
|
|
|
|
If Not DdlPersonal.SelectedValue.ToEntero = -1 AndAlso DTmp.FiltraParametros("Nuevo=1").Rows.Count > 0 Then
|
|
|
|
|
|
If GvConsignacion.Rows.Count > 0 Then
|
|
|
|
Dim CveMovimiento As Integer
|
|
|
|
|
|
Dim CvePersonal As Integer = -1
|
|
|
|
Mov.IniciaTransacSQL() 'Inicia la transacción
|
|
CvePersonal = DdlPersonal.SelectedValue.ToEntero
|
|
For Each dr As DataRow In DTmp.FiltraParametros("Nuevo=1", DistinctColumns:={"CveAlmacen"}).Rows
|
|
|
|
|
|
|
|
CveMovimiento = Mov.AddMovimiento(dr("CveAlmacen").ToString.ToEntero, 7, 1, TxtFecha.Text, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, -1, CvePersonal)
|
|
|
|
If CveMovimiento <= 0 Then
|
|
Alert("No se pudo almacenar el movimiento correctamente", TipoMensaje.MsgError)
|
|
Mov.RollBack() 'deshace lo insertado
|
|
Else
|
|
|
|
Dim Mensaje As String = ""
|
|
|
|
For Each row As DataRow In DTmp.FiltraParametros("Nuevo=1").Rows
|
|
|
|
If Not Mov.AddMovimientoDetalle(CveMovimiento, row("Cantidad").ToString.ToDouble, row("CveUnidadMedida").ToString.ToEntero, row("CvePS").ToString.ToEntero, row("PU").ToString.ToDouble,
|
|
row("CveSeccionAlmacen").ToString.ToEntero) Then
|
|
Mensaje = "Error al guardar los movimientos"
|
|
Exit For
|
|
End If
|
|
|
|
Next
|
|
|
|
If Mensaje = "" Then
|
|
Mov.Commit() ' aplica los movimientos insertados
|
|
Alert("Movimientos Registrado", TipoMensaje.MsgInformacion)
|
|
Else
|
|
Mov.RollBack() 'deshace lo insertado
|
|
Alert(Mensaje, TipoMensaje.MsgError)
|
|
End If
|
|
|
|
End If
|
|
Next
|
|
|
|
|
|
|
|
If Mov.GetConsignaciones(UsuarioActual.CveEmpresa, DdlPersonal.SelectedValue.ToEntero) Then
|
|
GvConsignacion.DataSource = Mov.DtResultados
|
|
GvConsignacion.DataBind()
|
|
DTmp = Mov.DtResultados
|
|
|
|
End If
|
|
|
|
|
|
End If
|
|
Else
|
|
Alert("No hay registros por guardar.", TipoMensaje.MsgInformacion)
|
|
|
|
End If
|
|
Mov.Dispose() 'elimino la instancia
|
|
|
|
End Sub
|
|
|
|
Protected Sub GvConsignacion_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvConsignacion.RowDataBound
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
|
|
If e.Row.DBCampo("Nuevo") = 0 Then
|
|
e.Row.FCImageButton("imgD").Visible = False
|
|
e.Row.FCTextBox("tbCantR").Attributes.Add("onchange", String.Format("ValidarCantidad(this,{0})", e.Row.DBCampo("Cantidad")))
|
|
End If
|
|
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Protected Sub GvConsignacion_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) Handles GvConsignacion.RowDeleting
|
|
DTmp.Rows.RemoveAt(e.RowIndex)
|
|
GvConsignacion.DataSource = DTmp
|
|
GvConsignacion.DataBind()
|
|
|
|
End Sub
|
|
End Class
|
|
|