353 lines
18 KiB
VB.net
353 lines
18 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()
|
|
|
|
DdlAlmacenExcel.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
|
|
DdlAlmacenExcel.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
|
|
|
|
Protected Sub BtnDescargar_Click(sender As Object, e As EventArgs) Handles LbDescargarExcel.Click, BtnDescargar.Click
|
|
Dim Directorio As String = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\Formatos\FormatoAjusteSecCad.xlsx"
|
|
Dim Archivo As New IO.FileInfo(Directorio)
|
|
If Archivo.Exists Then
|
|
Response.Clear()
|
|
Response.ClearHeaders()
|
|
Response.ClearContent()
|
|
Response.AddHeader("Content-Disposition", "attachment; filename=" + Archivo.Name)
|
|
Response.AddHeader("Content-Length", Archivo.Length.ToString())
|
|
Response.ContentType = "text/plain"
|
|
Response.Flush()
|
|
Response.TransmitFile(Archivo.FullName)
|
|
Response.End()
|
|
End If
|
|
End Sub
|
|
|
|
Protected Sub BtnCargaExcel_Click(sender As Object, e As EventArgs) Handles BtnCargaExcel.Click
|
|
If TxtExcel.getfiles().Archivos.Count > 0 Then
|
|
Dim file As Archivo = TxtExcel.getfiles().Archivos(0)
|
|
Dim Directorio As String = AppDomain.CurrentDomain.BaseDirectory & file.patch
|
|
Dim Tipo As String = If(file.Extencion.Contiene("xlsx", "xlsx", "xlsm", "xlsb"), "EXCEL", "")
|
|
If Tipo = "EXCEL" Then
|
|
Dim CveAlmacen As Integer = DdlAlmacenExcel.SelectedValue.ToEntero()
|
|
Dim CveSubProyecto As Integer = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", $"CveAlmacen={CveAlmacen}")
|
|
|
|
CargarArchivo(Directorio, file.filename, CveAlmacen, CveSubProyecto)
|
|
Else
|
|
Alert("El archivo no es de tipo excel", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
|
|
Else
|
|
Alert("No existe el archivo. Favor de subir un archivo excel a la plataforma.", TipoMensaje.MsgError)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub CargarArchivo(Ruta As String, FileName As String, CveAlmacen As Integer, CveSubProyecto As Integer)
|
|
Dim DtExcel As DataTable = ReadExcelFile(Ruta + FileName, True)
|
|
|
|
Dim ErrorArchivo = False
|
|
If Not ErrorArchivo AndAlso DtExcel IsNot Nothing Then
|
|
If Not DtExcel.Columns(0).ColumnName = "Cantidad" Then
|
|
Alert("El nombre de la primera columna debe ser 'Código'.Favor de corregirlo", TipoMensaje.MsgError)
|
|
Exit Sub
|
|
End If
|
|
If Not DtExcel.Columns(1).ColumnName = "Código" Then
|
|
Alert("El nombre de la segunda columna debe ser 'Código'.Favor de corregirlo", TipoMensaje.MsgError)
|
|
Exit Sub
|
|
End If
|
|
If Not DtExcel.Columns(2).ColumnName = "Producto/Servicio" Then
|
|
Alert("El nombre de la tercera columna debe ser 'Producto/Servicio'. Favor de corregirlo", TipoMensaje.MsgError)
|
|
Exit Sub
|
|
End If
|
|
If Not DtExcel.Columns(3).ColumnName = "SeccionAlmacen" Then
|
|
Alert("El nombre de la cuarta columna debe ser 'SeccionAlmacen'. Favor de corregirlo", TipoMensaje.MsgError)
|
|
Exit Sub
|
|
End If
|
|
If Not DtExcel.Columns(4).ColumnName = "Serie" Then
|
|
Alert("El nombre de la quinta columna debe ser 'Serie'. Favor de corregirlo", TipoMensaje.MsgError)
|
|
Exit Sub
|
|
End If
|
|
If Not DtExcel.Columns(5).ColumnName = "Lote" Then
|
|
Alert("El nombre de la sexta columna debe ser 'Lote'. Favor de corregirlo", TipoMensaje.MsgError)
|
|
Exit Sub
|
|
End If
|
|
If Not DtExcel.Columns(6).ColumnName = "FechaCaducidad" Then
|
|
Alert("El nombre de la séptima columna debe ser 'FechaCaducidad'. Favor de corregirlo", TipoMensaje.MsgError)
|
|
Exit Sub
|
|
End If
|
|
|
|
DtExcel.TableName = "Datos"
|
|
|
|
If Not ErrorArchivo Then
|
|
Dim ErrorMovInv As Boolean = False
|
|
|
|
Dim RowNoEncontrados As New StringBuilder()
|
|
Dim NumAgregados As Integer = 0
|
|
|
|
Dim ObjInventario As New ClsInventarios()
|
|
Dim ObjPS As New ClsProductosServicios(ObjInventario.IniciaTransacSQL())
|
|
|
|
Try
|
|
Dim DtExistenciasSecciones As DataTable = Nothing
|
|
If ObjInventario.GetMovimientosDetalleSeccionesAlmacen(DdlAlmacen.SelectedValue.ToEntero, DdlClasificaciones.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then
|
|
DtExistenciasSecciones = ObjInventario.DtResultados.Copy()
|
|
End If
|
|
|
|
'SALIDA ALMACÉN
|
|
Dim CveMovimientoSalida = ObjInventario.AddMovimiento(CveAlmacen, 3, 1, Now, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:="", TipoCambio:=-1,
|
|
MovimientoFijo:=False, Modulo:="ASA/SA")
|
|
|
|
'ENTRADA ALMACÉN
|
|
Dim CveMovimientoEntrada = ObjInventario.AddMovimiento(CveAlmacen, 2, 1, Now, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:="", TipoCambio:=-1,
|
|
MovimientoFijo:=False, Modulo:="ASA/EA")
|
|
|
|
Dim dtSecciones As DataTable = GlobalDTSeccionAlmacen(UsuarioActual.CveEmpresa, CveAlmacen)
|
|
dtSecciones.CaseSensitive = False
|
|
|
|
For Each RowExcel As DataRow In DtExcel.Rows
|
|
|
|
Dim Codigo As String = RowExcel("Código").ToString.Trim()
|
|
Dim PS As String = RowExcel("Producto/Servicio").ToString().Trim()
|
|
|
|
Dim DrPS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, Codigo:=Codigo).FiltroPrimero($"PS='{PS}'")
|
|
|
|
If DrPS IsNot Nothing Then
|
|
If Not ErrorMovInv Then
|
|
|
|
Dim CantidadEntrada As Decimal = RowExcel("Cantidad").ToString().ToDecimal()
|
|
|
|
Dim CvePS As Integer = DrPS("CvePS").ToString().ToEntero()
|
|
Dim CveUM As Integer = DrPS("CveUM").ToString().ToEntero()
|
|
|
|
Dim SeccionAlmacen As String = RowExcel("SeccionAlmacen").ToString.Trim
|
|
Dim CveSeccionAlmacen As Integer = dtSecciones.FiltroPrimeroValor("CveSeccion", $"SeccionAlmacen='{SeccionAlmacen}'")
|
|
|
|
Dim Serie As String = RowExcel("Serie").ToString()
|
|
Dim Lote As String = RowExcel("Lote").ToString()
|
|
Dim FechaCaducidad As Date = IfNull(RowExcel("FechaCaducidad"), MinFecha).ToString.ToDate
|
|
|
|
Dim RowExistencia As DataRow = DtExistenciasSecciones.FiltroPrimero($"CvePS={CvePS}")
|
|
|
|
If RowExistencia IsNot Nothing Then
|
|
Dim CveSeccionAlmacenSalida As Integer = RowExistencia("CveSeccionAlmacen").ToString().ToEntero()
|
|
Dim CantidadSalida As Decimal = RowExistencia("Existencia").ToString().ToDecimal()
|
|
Dim SerieSalida As String = RowExistencia("Serie").ToString()
|
|
Dim LoteSalida As String = RowExistencia("Lote").ToString()
|
|
Dim FechaCaducidadSalida As Date = IfNull(RowExistencia("FechaCaducidad"), MinFecha).ToString.ToDate
|
|
Dim PUSalida As Decimal = RowExistencia("PU").ToString()
|
|
|
|
'GENERA LA SALIDA DE LOS PRODUCTOS QUE VIENEN EN EL EXCEL
|
|
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadSalida, CveUM, CvePS, PUSalida, CveSeccionAlmacen:=CveSeccionAlmacenSalida, Serie:=SerieSalida, Lote:=LoteSalida, FechaCaducidad:=FechaCaducidadSalida, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then
|
|
ErrorMovInv = True
|
|
Exit For
|
|
End If
|
|
|
|
Dim CveMovimientoDetalleSalida As Integer = ObjInventario.CveMovimientoDetalle
|
|
|
|
ErrorMovInv = CveMovimientoDetalleSalida <= 0
|
|
|
|
'GENERA LA ENTRADA DE LOS PRODUCTOS QUE SE DIERON ENTRADA
|
|
If Not ErrorMovInv Then
|
|
If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa, CveMovimientoDetalle:=CveMovimientoDetalleSalida) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then
|
|
Dim RowEntrada As DataRow = ObjInventario.DtResultados.Rows(0)
|
|
|
|
Dim CvePSEntrada = RowEntrada("CvePS").ToString().ToEntero()
|
|
Dim PUEntrada As Decimal = RowEntrada("PUOriginal").ToString().ToDecimal()
|
|
Dim CveUMEntrada As Integer = RowEntrada("CveUM").ToString().ToEntero()
|
|
|
|
Dim CostoIndirecto As Decimal = RowEntrada("CostoIndirecto").ToString().ToDecimal()
|
|
|
|
'ACTUALIZAMOS EL PS, PARA QUE TENGA EL APLICA SECCION
|
|
ErrorMovInv = Not ObjPS.UpdateAplicaSeccionAlmacen(CvePS, UsuarioActual.CveEmpresa, True)
|
|
|
|
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, CantidadEntrada, CveUMEntrada, CvePSEntrada, PUEntrada, -1, CostoIndirecto:=CostoIndirecto, CveSeccionAlmacen:=CveSeccionAlmacen, Serie:=Serie, Lote:=Lote, FechaCaducidad:=FechaCaducidad, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then
|
|
ErrorMovInv = True
|
|
Exit For
|
|
End If
|
|
|
|
Else
|
|
ErrorMovInv = True
|
|
End If
|
|
End If
|
|
Else
|
|
ErrorMovInv = True
|
|
RowNoEncontrados.AppendFormat("{0},", Codigo)
|
|
End If
|
|
|
|
End If
|
|
Else
|
|
ErrorMovInv = True
|
|
RowNoEncontrados.AppendFormat("{0},", Codigo)
|
|
End If
|
|
|
|
Next
|
|
dtSecciones.Dispose()
|
|
|
|
Catch ex As Exception
|
|
ErrorMovInv = True
|
|
OnError("Ocurrió un error al agregar el inventario", ex)
|
|
End Try
|
|
|
|
If ErrorMovInv Then
|
|
ObjInventario.RollBack()
|
|
|
|
Dim SbError As New StringBuilder()
|
|
SbError.Append("Ocurrió un error al guardar")
|
|
If RowNoEncontrados.Length > 0 Then
|
|
SbError.Append("Los siguientes códigos no fueron encontrados en el sistema.<br/>")
|
|
SbError.Append(RowNoEncontrados.ToString())
|
|
End If
|
|
|
|
Alert(SbError.ToString(), TipoMensaje.MsgError)
|
|
Else
|
|
ObjInventario.Commit()
|
|
Alert("Se realizó el ajuste de los productos correctamente.")
|
|
End If
|
|
|
|
ObjInventario.Dispose()
|
|
ObjPS.Dispose()
|
|
|
|
End If
|
|
Else
|
|
Alert("Ocurrió un error al cargar el excel.", TipoMensaje.MsgError)
|
|
End If
|
|
End Sub
|
|
|
|
End Class |