145 lines
6.4 KiB
VB.net
145 lines
6.4 KiB
VB.net
|
|
Imports System.Data
|
|
Imports Extensiones
|
|
|
|
Partial Class Inventarios_AjustesSeccionAlmacen
|
|
Inherits ClsPaginas
|
|
|
|
Private Sub Inventarios_AjustesSeccionAlmacen_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
If Not Page.IsPostBack Then
|
|
CargaCombos()
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub CargaCombos()
|
|
DdlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
|
|
DdlAlmacen.DataBind()
|
|
|
|
DdlClasificaciones.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa)
|
|
DdlClasificaciones.DataBind()
|
|
DdlClasificaciones.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
End Sub
|
|
|
|
Private Sub BtnConsultar_Click(sender As Object, e As EventArgs) Handles BtnConsultar.Click
|
|
CargaDatos()
|
|
End Sub
|
|
|
|
Private Sub CargaDatos()
|
|
Dim ObjInv As New ClsInventarios
|
|
|
|
If ObjInv.GetMovimientosDetalleSeccionesAlmacen(DdlAlmacen.SelectedValue.ToEntero, DdlClasificaciones.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then
|
|
GvD.DataSource = ObjInv.DtResultados
|
|
End If
|
|
|
|
ObjInv.Dispose()
|
|
GvD.DataBind()
|
|
UppD.Update()
|
|
End Sub
|
|
|
|
Private Sub GvD_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvD.RowDataBound
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
|
|
e.Row.FCDropDownList("DDlS").DataSource = GlobalDTSeccionAlmacen(UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero)
|
|
e.Row.FCDropDownList("DDlS").DataBind()
|
|
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub BtnCambiarSeccion_Click(sender As Object, e As EventArgs) Handles BtnCambiarSeccion.Click
|
|
Dim ObjInventario As New ClsInventarios
|
|
Dim ObjPS As New ClsProductosServicios(ObjInventario.IniciaTransacSQL)
|
|
Dim Dtt As DataTable = Nothing
|
|
Dim CveMovimientoEntrada As Integer = 0
|
|
Dim Folio = 0
|
|
Dim ErrorMovInv As Boolean = False
|
|
Dim TextoError = ""
|
|
Dim CveAlmacen As Integer = DdlAlmacen.SelectedValue.ToEntero
|
|
|
|
|
|
|
|
Dim Fecha As Date = DateTime.Now
|
|
'AGREGAMOS LA ENTRADA
|
|
Dim CveMovimientoSalida As Integer = ObjInventario.AddMovimiento(CveAlmacen, 3, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1,
|
|
Observaciones:="", Modulo:="ASA/G1")
|
|
Folio = ObjInventario.Folio
|
|
|
|
If CveMovimientoSalida <= 0 Then
|
|
TextoError = "No se pudo generar el movimiento de salida correctamente"
|
|
ErrorMovInv = True
|
|
Else
|
|
|
|
Dim CveMovimientoDetalleEntrada As Integer = 0
|
|
Dim Cont As Integer = 0
|
|
For Each gvr As GridViewRow In GvD.Rows
|
|
|
|
'que este seleccionado y que tenga diferente seccion
|
|
If gvr.FCCheckBox("Chk").Checked AndAlso gvr.FCDropDownList("DDlS").SelectedValue.ToEntero <> gvr.DataKey("CveSeccionAlmacen").ToEntero Then
|
|
|
|
If gvr.DataKey("CveSeccionAlmacen").ToEntero > 0 Then
|
|
ObjPS.UpdateAplicaSeccionAlmacen(gvr.DataKey("CvePS").ToEntero, UsuarioActual.CveEmpresa, True)
|
|
End If
|
|
|
|
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, gvr.DataKey("Existencia").ToDecimal, gvr.DataKey("CveUM").ToEntero, gvr.DataKey("CvePS").ToEntero, 0, -1, CveSeccionAlmacen:=gvr.DataKey("CveSeccionAlmacen").ToEntero, Serie:=gvr.DataKey("Serie"), Lote:=gvr.DataKey("Lote"), FechaCaducidad:=gvr.DataKey("FechaCaducidad").ToDate) Then
|
|
ErrorMovInv = True
|
|
TextoError = "Ocurrió un error al guardar los movimientos de salida"
|
|
Exit For
|
|
End If
|
|
|
|
End If
|
|
|
|
Next
|
|
|
|
If Not ErrorMovInv Then
|
|
|
|
If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then
|
|
|
|
Dim resultado As DataTable = ObjInventario.DtResultados
|
|
CveMovimientoEntrada = ObjInventario.AddMovimiento(CveAlmacen, 2, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:="", CveMovimientoRelacionado:=CveMovimientoSalida, Modulo:="ASA/G1")
|
|
Dim ind As Integer = 0
|
|
|
|
For Each Row As DataRow In resultado.Rows
|
|
Dim CvePS = Row("CvePS").ToString().ToEntero()
|
|
Dim Cantidad As Decimal = Row("Cantidad").ToString().ToDecimal()
|
|
Dim PU As Decimal = Row("PUOriginal").ToString().ToDecimal()
|
|
Dim CveUM As Integer = Row("CveUM").ToString().ToEntero()
|
|
Dim CveSeccionAlmacen As Integer = GvD.Rows(ind).FCDropDownList("DDlS").SelectedValue.ToEntero ' IfNull(Row("CveSeccionAlmacen"), "-1").ToString().ToEntero()
|
|
Dim CostoIndirecto As Decimal = Row("CostoIndirecto").ToString().ToDecimal()
|
|
Dim Serie As String = Row("Serie").ToString()
|
|
Dim Lote As String = Row("Lote").ToString()
|
|
Dim FechaCaducidad As Date = IfNull(Row("FechaCaducidad"), MinFecha).ToString.ToDate
|
|
|
|
'actualizamos el PS, para que tenga el aplica seccion
|
|
|
|
ObjPS.UpdateAplicaSeccionAlmacen(Row("CvePS").ToString().ToEntero(), UsuarioActual.CveEmpresa, True)
|
|
|
|
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Cantidad, CveUM, CvePS, PU, -1, CostoIndirecto:=CostoIndirecto, CveSeccionAlmacen:=CveSeccionAlmacen, Lote:=Lote, Serie:=Serie, FechaCaducidad:=FechaCaducidad, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then
|
|
ErrorMovInv = True
|
|
Exit For
|
|
End If
|
|
ind += 1
|
|
Next
|
|
resultado.Dispose()
|
|
|
|
Else
|
|
TextoError = "No se pudo registrar el movimiento"
|
|
ErrorMovInv = True
|
|
End If
|
|
|
|
End If
|
|
|
|
End If
|
|
|
|
|
|
If Not ErrorMovInv Then
|
|
ObjInventario.Commit()
|
|
cargadatos
|
|
Alert("El Movimiento quede registrado correctamente", TipoMensaje.MsgInformacion)
|
|
Else
|
|
ObjInventario.RollBack()
|
|
Alert("Ocurrio un error al registrar el movimiento", TipoMensaje.MsgError)
|
|
End If
|
|
|
|
ObjInventario.Dispose()
|
|
End Sub
|
|
End Class
|