759 lines
35 KiB
VB.net
759 lines
35 KiB
VB.net
Imports System.Data
|
|
Imports ClosedXML.Excel.XLPredefinedFormat
|
|
Imports DocumentFormat.OpenXml.Math
|
|
Imports Extensiones
|
|
Imports Telerik.Web.UI.ComboBox.ComboBoxStyles
|
|
|
|
Partial Class Inventarios_TrasladoSolicitud
|
|
Inherits ClsPaginas
|
|
|
|
|
|
Private Property TempDT As DataTable
|
|
Get
|
|
Return CType(ViewState("TempDT"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("TempDT") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property CveTraspasoSolicitud As Integer
|
|
Get
|
|
If ViewState("CveTraspasoSolicitud") Is Nothing Then
|
|
ViewState("CveTraspasoSolicitud") = -1
|
|
End If
|
|
Return ViewState("CveTraspasoSolicitud").ToString.ToEntero
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveTraspasoSolicitud") = value
|
|
End Set
|
|
End Property
|
|
|
|
|
|
Private Property CveAlmacenOrigen As Integer
|
|
Get
|
|
If ViewState("CveAlmacenOrigen") Is Nothing Then
|
|
ViewState("CveAlmacenOrigen") = -1
|
|
End If
|
|
Return ViewState("CveAlmacenOrigen").ToString.ToEntero
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveAlmacenOrigen") = value
|
|
End Set
|
|
End Property
|
|
|
|
|
|
Private Property CveAlmacenDestino As Integer
|
|
Get
|
|
If ViewState("CveAlmacenDestino") Is Nothing Then
|
|
ViewState("CveAlmacenDestino") = -1
|
|
End If
|
|
Return ViewState("CveAlmacenDestino").ToString.ToEntero
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveAlmacenDestino") = value
|
|
End Set
|
|
End Property
|
|
|
|
|
|
Private Sub Inventarios_RepTrasladoSolicitud_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
If Not Page.IsPostBack Then
|
|
CargaCombos()
|
|
InicializaValores()
|
|
|
|
TxtFechaI.Text = NowADS().FirstDayOfMonth.ToShortDateString
|
|
TxtFechaF.Text = NowADS().ToShortDateString
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub InicializaValores()
|
|
CreaDTTemporal()
|
|
CargaAlmacenes()
|
|
CargaPS()
|
|
'CargaClientes()
|
|
|
|
' CargaUnidadMedida()
|
|
|
|
End Sub
|
|
|
|
|
|
'Private Sub CargaUnidadMedida()
|
|
' DdlUM.DataSource = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa)
|
|
' DdlUM.DataBind()
|
|
'End Sub
|
|
|
|
Private Sub CargaAlmacenes()
|
|
'Cargo los almacenes
|
|
DdlAlmacenOrigen.DataSource = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveEstatus:=1).FiltraParametros("CveTipoAlmacen = 1") 'GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen <> 9") 'Excluir almacenes de Apartado
|
|
'DdlAlmacenDestino.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen <> 9") 'Excluir almacenes de Apartado
|
|
DdlAlmacenOrigen.DataBind()
|
|
DdlAlmacenOrigen.Items.Insert(0, New ListItem("Seleccione Uno", "-1"))
|
|
'DdlAlmacenDestino.DataBind()
|
|
End Sub
|
|
|
|
|
|
|
|
Private Sub CargaPS()
|
|
DdlProductoServicio.setEsWebService(UsuarioActual.Empresa.Funcionalidad(105) = "1")
|
|
|
|
If UsuarioActual.Empresa.Funcionalidad(105) = "1" Then
|
|
DdlProductoServicio.ddlWS.Attributes.Add("data-cveclasificacion", "-1")
|
|
DdlProductoServicio.SelectedText = ""
|
|
DdlProductoServicio.SelectedValue = "-1"
|
|
Else
|
|
DdlProductoServicio.ddl.Items.Clear()
|
|
DdlProductoServicio.ddl.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=-1)
|
|
DdlProductoServicio.ddl.DataBind()
|
|
DdlProductoServicio.ddl.Items.Insert(0, New ListItem("Seleccione el Producto", "-1"))
|
|
End If
|
|
'DdlProductoServicio.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa)
|
|
'DdlProductoServicio.DataBind()
|
|
'DdlProductoServicio.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
End Sub
|
|
|
|
Private Sub CargaCombos()
|
|
DdlAlmacenOrigenFiltro.DataSource = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltraParametros("CveTipoAlmacen = 1") 'GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen <> 9")
|
|
DdlAlmacenOrigenFiltro.DataBind()
|
|
DdlAlmacenOrigenFiltro.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
|
|
DdlAlmacenDestinoFiltro.DataSource = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltraParametros("CveTipoAlmacen = 1") 'GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen <> 9")
|
|
DdlAlmacenDestinoFiltro.DataBind()
|
|
DdlAlmacenDestinoFiltro.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
|
|
'DdlContrato.DataSource = GlobalDTContratos(UsuarioActual.CveEmpresa)
|
|
'DdlContrato.DataBind()
|
|
'DdlContrato.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
|
|
'DdlSolicitante.DataSource = GlobalDTUsuarios(CveEmpresa:=UsuarioActual.CveEmpresa).FiltraParametros("", "Nombre")
|
|
'DdlSolicitante.DataBind()
|
|
'DdlSolicitante.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.RepTrasladoSolicitud(DdlAlmacenOrigenFiltro.SelectedValue.ToEntero, DdlAlmacenDestinoFiltro.SelectedValue.ToEntero, -1, TxtFechaI.Text.ToDate, TxtFechaF.Text.ToDate, -1, -1,
|
|
-1, UsuarioActual.CveEmpresa, CveUsuarioConsulta:=UsuarioActual.CveUsuario) Then
|
|
|
|
GvT.DataSource = ObjInv.DtResultados
|
|
End If
|
|
|
|
ObjInv.Dispose()
|
|
GvT.DataBind()
|
|
|
|
UPPMov.Update()
|
|
End Sub
|
|
|
|
|
|
|
|
Public Sub CreaDTTemporal()
|
|
TempDT = New DataTable
|
|
TempDT.Columns.Add("Cantidad", Type.GetType("System.Double"))
|
|
TempDT.Columns.Add("CvePS", Type.GetType("System.Int32"))
|
|
TempDT.Columns.Add("CodigoPS", Type.GetType("System.String"))
|
|
TempDT.Columns.Add("CveUM", Type.GetType("System.Int32"))
|
|
TempDT.Columns.Add("UnidadMedida", Type.GetType("System.String"))
|
|
TempDT.Columns.Add("Precio", Type.GetType("System.Double"))
|
|
TempDT.Columns.Add("Observaciones", Type.GetType("System.String"))
|
|
TempDT.Columns.Add("CveContratoDetalle", Type.GetType("System.Int32"))
|
|
'TempDT.Columns.Add("CveContratoDetalle", Type.GetType("System.Int32"))
|
|
'TempDT.Columns.Add("CveDireccionEnvio", Type.GetType("System.Int32"))
|
|
TempDT.Columns.Add("Serie", Type.GetType("System.String"))
|
|
TempDT.Columns.Add("Lote", Type.GetType("System.String"))
|
|
TempDT.Columns.Add("FechaCaducidad", Type.GetType("System.DateTime"))
|
|
TempDT.Columns.Add("Existencia", Type.GetType("System.Decimal"))
|
|
|
|
|
|
|
|
|
|
TempDT.Columns.Add()
|
|
End Sub
|
|
|
|
Private Sub BtnAgregarPS_Click(sender As Object, e As EventArgs) Handles BtnAgregarPS.Click
|
|
|
|
If Not DdlProductoServicio.SelectedValue.ToEntero > 0 Then
|
|
Alert("Tiene que seleccionar un producto.", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
If Not AddPSTemporal() Then
|
|
Exit Sub
|
|
End If
|
|
|
|
|
|
|
|
'If ObjInventario.GetExistenciasPS(DdlProductoServicio.SelectedValue.ToEntero, DdlUM.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, DdlAlmacenOrigen.SelectedValue.ToEntero, PendientePorSurtir:=1, Lote:=TxtLote.Text.ToString, FechaCaducidad:=TxtCaducidad.Text.ToString) >= TxtCantidad.Text.ToDouble Then
|
|
|
|
TxtCantidad.Text = ""
|
|
DdlProductoServicio.SelectedText = ""
|
|
DdlProductoServicio.SelectedValue = "-1"
|
|
'DdlUM.SelectedIndex = 0
|
|
'TxtCaducidad.Text = ""
|
|
'TxtSerie.Text = ""
|
|
'TxtLote.Text = ""
|
|
|
|
GvDatos.DataSource = TempDT
|
|
GvDatos.DataBind()
|
|
|
|
UpPS.Update()
|
|
|
|
|
|
End Sub
|
|
|
|
|
|
Private Function AddPSTemporal() As Boolean
|
|
|
|
|
|
'Dim CveUsuarioAutoriza As Integer = -1
|
|
Dim EstatusAlmacen As Integer = 2
|
|
'VERIFICA EXISTENCIAS
|
|
Dim ObjInventarios As New ClsInventarios
|
|
Dim Existencia As Decimal = 0
|
|
Dim TieneErrorExistencia As Boolean = False
|
|
Dim MensajeExistencia As New StringBuilder
|
|
MensajeExistencia.Append("No hay la existencia suficiente de los siguientes productos:<br/>")
|
|
'Dim CodigoPS As String = ""
|
|
Dim CveUnidadMedida As Integer = GlobalDTPS(UsuarioActual.CveEmpresa, DdlProductoServicio.SelectedValue.ToEntero).FiltroPrimeroValor("CveUnidadMedida").ToEntero
|
|
|
|
|
|
'CodigoPS = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=Row.DataKey("CvePS").ToEntero).FiltroPrimeroValor("PSCodigo", "")
|
|
Existencia = ObjInventarios.GetExistenciasPS(DdlProductoServicio.SelectedValue.ToEntero, CveUnidadMedida, UsuarioActual.CveEmpresa, DdlAlmacenOrigen.SelectedValue.ToEntero, FechaMovto:=NowADS.ToString("yyyy/MM/dd 23:59"))
|
|
|
|
If Existencia - (TempDT.SUM("Cantidad", $"CvePS = {DdlProductoServicio.SelectedValue.ToEntero} AND CveUM = {CveUnidadMedida}") + TxtCantidad.Text.Trim.ToDecimal) <= 0 Then
|
|
MensajeExistencia.AppendFormat("<br/> - <b>{0}.</b> Existencia: {1}", DdlProductoServicio.SelectedText, Existencia)
|
|
TieneErrorExistencia = True
|
|
End If
|
|
|
|
If TieneErrorExistencia Then
|
|
Alert(MensajeExistencia.ToString, TipoMensaje.MsgAdvertencia)
|
|
ObjInventarios.Dispose()
|
|
Return False
|
|
End If
|
|
ObjInventarios.Dispose()
|
|
|
|
|
|
Dim TieneError As Boolean = False
|
|
|
|
Dim Row As DataRow = TempDT.NewRow()
|
|
Dim Lote As String = "-1"
|
|
Dim FechaCaducidad As Date = MinFecha
|
|
Row("Cantidad") = TxtCantidad.Text.Trim.ToDecimal
|
|
Row("CvePS") = DdlProductoServicio.SelectedValue.ToEntero
|
|
Row("CodigoPS") = DdlProductoServicio.SelectedText
|
|
Row("Precio") = 0
|
|
Row("CveUM") = CveUnidadMedida
|
|
Row("Existencia") = Existencia
|
|
'Row("UnidadMedida") = DdlUM.SelectedItem.Text
|
|
Row("Observaciones") = ""
|
|
Row("Lote") = "-1"
|
|
Row("Serie") = "-1"
|
|
Row("FechaCaducidad") = MinFecha
|
|
|
|
|
|
|
|
TempDT.Rows.Add(Row)
|
|
|
|
|
|
Return True
|
|
End Function
|
|
|
|
|
|
#Region " GUARDAR "
|
|
Private Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click
|
|
|
|
Dim CveTraspasoSolicitud As Integer = -1
|
|
|
|
If DdlAlmacenOrigen.SelectedValue = DdlAlmacenDestino.SelectedValue Then
|
|
Alert("Los almacenes de origen y destino no pueden ser el mismo. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
If Not GvDatos.Rows.Count > 0 Then
|
|
Alert("No se ha seleccionado ningún Producto para trasladar.", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
'Dim CveUsuarioAutoriza As Integer = -1
|
|
Dim EstatusAlmacen As Integer = 2
|
|
'VERIFICA EXISTENCIAS
|
|
Dim ObjInventarios As New ClsInventarios
|
|
Dim Existencia As Decimal = 0
|
|
Dim TieneErrorExistencia As Boolean = False
|
|
Dim MensajeExistencia As New StringBuilder
|
|
MensajeExistencia.Append("No hay la existencia suficiente de los siguientes productos:<br/>")
|
|
Dim CodigoPS As String = ""
|
|
|
|
|
|
|
|
|
|
|
|
For Each row As GridViewRow In GvDatos.Rows
|
|
CodigoPS = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=row.DataKey("CvePS").ToEntero).FiltroPrimeroValor("PSCodigo", "")
|
|
Existencia = ObjInventarios.GetExistenciasPS(row.DataKey("CvePS").ToEntero, row.DataKey("CveUM").ToEntero, UsuarioActual.CveEmpresa, DdlAlmacenOrigen.SelectedValue.ToEntero, FechaMovto:=NowADS.ToString("yyyy/MM/dd 23:59"), Lote:=row.DataKey("Lote").ToString, FechaCaducidad:=row.DataKey("FechaCaducidad").ToString.ToDate)
|
|
If Existencia - TempDT.SUM("Cantidad", $"CvePS = {row.DataKey("CvePS").ToEntero} AND CveUM = {row.DataKey("CveUM").ToEntero}") < 0 Then
|
|
MensajeExistencia.AppendFormat("<br/> - <b>{0}.</b> Existencia: {1}", CodigoPS, Existencia)
|
|
TieneErrorExistencia = True
|
|
End If
|
|
Next
|
|
|
|
If TieneErrorExistencia Then
|
|
Alert(MensajeExistencia.ToString, TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
|
|
ObjInventarios.IniciaTransacSQL()
|
|
Dim TieneError As Boolean = False
|
|
|
|
'Dim CveContrato As Integer = 0
|
|
'Dim Guia As String = ""
|
|
'If TxtGuia.Text <> "" Then Guia = TxtGuia.Text Else Guia = ""
|
|
'If DdlContratos.SelectedValue.ToEntero > 0 Then CveContrato = DdlContratos.SelectedValue.ToEntero Else CveContrato = -1
|
|
|
|
Dim Estatus As Integer = -1
|
|
|
|
If UsuarioActual.Empresa.Funcionalidad(105) <> "" Then
|
|
Estatus = 1
|
|
Else
|
|
Estatus = 3
|
|
End If
|
|
|
|
Dim Folio As Integer = ObjInventarios.AddTrasladoSolicitud(TxtObservaciones.text, DdlAlmacenOrigen.SelectedValue.ToEntero, DdlAlmacenDestino.SelectedValue.ToEntero, Estatus, -1, NowADS, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, EstatusAlmacen:=EstatusAlmacen)
|
|
|
|
If Folio > 0 Then
|
|
CveTraspasoSolicitud = ObjInventarios.CveTraspasoSolicitud
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
|
|
If Not TieneError Then
|
|
For Each Row As GridViewRow In GvDatos.Rows
|
|
'Dim CveUM As Integer = Row.DataKey("CveUM").ToEntero
|
|
Dim CvePS As Integer = Row.DataKey("CvePS").ToEntero
|
|
Dim Cantidad As Integer = Row.DataKey("Cantidad").ToEntero
|
|
'Dim Precio As Decimal = Row.DataKey("Precio").ToDecimal
|
|
'Dim Observaciones As String = Row.DataKey("Observaciones")
|
|
'Dim CveContratoDetalle As Integer = Row.DataKey("CveContratoDetalle").ToEntero
|
|
'Dim Serie As String = Row.DataKey("Serie")
|
|
'Dim Lote As String = Row.DataKey("Lote")
|
|
'Dim FechaCaducidad As Date = Row.DataKey("FechaCaducidad").ToDate
|
|
|
|
If Not ObjInventarios.AddTrasladoSolicitudDetalle(CveTraspasoSolicitud, Cantidad, -1, CvePS, 0, "", -1, "-1", "-1", MinFecha) Then
|
|
TieneError = True
|
|
Exit For
|
|
End If
|
|
Next
|
|
End If
|
|
|
|
|
|
If TieneError = False Then
|
|
ObjInventarios.Commit()
|
|
Alert($"El Traspaso se guardó correctamente con el folio #: <b>{Folio}</b>.", TipoMensaje.MsgInformacion)
|
|
RegistraScript(String.Format("$('#{0}').modal('hide');", "DVModalSolicitudAdd"))
|
|
CargaDatos()
|
|
Else
|
|
ObjInventarios.RollBack()
|
|
Alert("Ocurrió un Error al guardar el traspaso.", TipoMensaje.MsgError)
|
|
End If
|
|
ObjInventarios.Dispose()
|
|
|
|
End Sub
|
|
#End Region
|
|
|
|
|
|
#Region " GV DATOS "
|
|
Private Sub GvDatos_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) Handles GvDatos.RowDeleting
|
|
EliminarRow(e.RowIndex)
|
|
End Sub
|
|
Private Sub EliminarRow(RowIndex As Integer)
|
|
TempDT.Rows(RowIndex).Delete()
|
|
TempDT.AcceptChanges()
|
|
GvDatos.DataSource = TempDT
|
|
GvDatos.DataBind()
|
|
UpPS.Update()
|
|
End Sub
|
|
|
|
|
|
#End Region
|
|
|
|
|
|
Protected Sub LnkAgregarSolicitud_Click(sender As Object, e As EventArgs)
|
|
GvSolicitudes.DataSource = Nothing
|
|
GvSolicitudes.DataBind()
|
|
UpModalSolicitudes.Update()
|
|
RegistraScript(String.Format("$('#{0}').modal();", "DVModalSolicitudAdd"))
|
|
End Sub
|
|
|
|
Protected Sub LnkMostrarTraspaso_Click(sender As Object, e As EventArgs)
|
|
|
|
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
|
|
CveTraspasoSolicitud = GvRow.DataKey("CveTraspasoSolicitud").ToEntero
|
|
CveAlmacenOrigen = GvRow.DataKey("CveAlmacenOrigen").ToEntero
|
|
CveAlmacenDestino = GvRow.DataKey("CveAlmacenDestino").ToEntero
|
|
Dim CveTrasladoEstatus As Integer = GvRow.DataKey("CveTrasladoEstatus").ToEntero
|
|
|
|
LblModalSolicitudFolio.Text = GvRow.DataKey("Folio")
|
|
LblModalSolicitudSolicitante.Text = GvRow.DataKey("Nombre")
|
|
LblModalSolicitudOrigen.Text = GvRow.DataKey("AlmacenOrigen")
|
|
LblModalSolicitudDestino.Text = GvRow.DataKey("AlmacenDestino")
|
|
|
|
' TraspasoEstatus,AlmacenOrigen,AlmacenDestino,Nombre
|
|
|
|
Dim ObjInventarios As New ClsInventarios
|
|
If ObjInventarios.AddTrasladoSolicitudGet(CveTraspasoSolicitud, UsuarioActual.CveEmpresa) Then
|
|
GvSolicitudes.DataSource = ObjInventarios.DtResultados
|
|
End If
|
|
ObjInventarios.Dispose()
|
|
GvSolicitudes.DataBind()
|
|
|
|
GvSolicitudes.Columns(0).Visible = If(CveTrasladoEstatus = 1, True, False)
|
|
GvSolicitudes.Columns(2).Visible = If(CveTrasladoEstatus = 1, True, False)
|
|
BtnAceptarSolicitud.Visible = If(CveTrasladoEstatus = 1, True, False)
|
|
BtnRechazarSolicitud.Visible = If(CveTrasladoEstatus = 1, True, False)
|
|
|
|
|
|
|
|
UpModalSolicitudes.Update()
|
|
RegistraScript(String.Format("$('#{0}').modal();", "DVModalSolicitud"))
|
|
|
|
End Sub
|
|
|
|
Protected Sub BtnAceptarSolicitud_Click(sender As Object, e As EventArgs)
|
|
|
|
|
|
Dim CveAlmacenTransictorio As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveEstatus:=1).FiltraParametros("CveTipoAlmacen = 3").FiltroPrimeroValor("CveAlmacen").ToEntero 'GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 3).FiltroPrimeroValor("CveAlmacen").ToEntero
|
|
|
|
If Not CveAlmacenTransictorio > 0 Then
|
|
Alert("No se encontro un almacen transitorio", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
Dim ErrorMovInv As Boolean = False
|
|
Dim ErrorExistencia As Boolean = False
|
|
|
|
Dim ObjInventario As New ClsInventarios
|
|
Dim ObjConta As New ClsContabilidad(ObjInventario.IniciaTransacSQL())
|
|
|
|
Dim TextoExistencia As StringBuilder = New StringBuilder
|
|
TextoExistencia.Append("Los siguiente productos no tienen existencia:<br/>")
|
|
|
|
For Each gvr As GridViewRow In GvSolicitudes.Rows
|
|
Dim Existencia As Decimal = 0
|
|
|
|
Dim MsgAdicional As String = ""
|
|
|
|
If ObjInventario.GetExistenciasProducto(gvr.DataKey("CvePS").ToEntero, gvr.DataKey("CveUM").ToEntero, UsuarioActual.CveEmpresa, CveAlmacenOrigen, FechaMovto:=NowADS.ToString("yyyy/MM/dd 23:59"), CveSeccionAlmacen:=-1, Serie:="-1", Lote:="-1", Caducidad:=MinFecha) Then
|
|
'si hay existencia en almacen costeado, lo tengo que sacar
|
|
' si tiene serie el producto, debe de
|
|
Existencia = ObjInventario.DtResultados.FiltroPrimeroValor("ExistenciaFinal", String.Format("CveAlmacen = {0}", CveAlmacenOrigen)).ToDecimal
|
|
Dim ExistenciaSinPendiente As Decimal = ObjInventario.DtResultados.FiltroPrimeroValor("Existencia", String.Format("CveAlmacen = {0}", CveAlmacenOrigen)).ToDecimal
|
|
Dim PendienteporSurtir As Decimal = ObjInventario.DtResultados.FiltroPrimeroValor("PendientePorSurtir", String.Format("CveAlmacen = {0}", CveAlmacenOrigen)).ToDecimal
|
|
|
|
' si la existencia es negativa y tiene serie ó lote, quiere decir que la consulta es específica, y si hay pendientes por surtir. puede generar negativos
|
|
' para asegurarnos que lo pendiente por surtir se pueda surtir con otras series, consultamos de nuevo, pero a nivel producto, para checar existencia
|
|
|
|
If ExistenciaSinPendiente > 0 AndAlso Existencia <= 0 AndAlso PendienteporSurtir > 0 Then
|
|
MsgAdicional = " Pendiente por surtir: " & PendienteporSurtir.FormatoNumero(0)
|
|
If ObjInventario.GetExistenciasProducto(gvr.DataKey("CvePS").ToEntero, gvr.DataKey("CveUM").ToEntero, UsuarioActual.CveEmpresa, CveAlmacenOrigen, FechaMovto:=NowADS.ToString("yyyy/MM/dd 23:59")) Then
|
|
'si hay existencia en almacen costeado, lo tengo que sacar
|
|
Existencia = ObjInventario.DtResultados.FiltroPrimeroValor("ExistenciaFinal", String.Format("CveAlmacen = {0}", CveAlmacenOrigen)).ToDecimal
|
|
'si la existencia del producto en general, supera a lo pendiente, entonces la serie si se puede sacar.
|
|
|
|
End If
|
|
End If
|
|
|
|
End If
|
|
Existencia -= gvr.FCTextBox("TxtCantidad").Text.ToDecimal()
|
|
|
|
If Existencia < 0 Then
|
|
ErrorExistencia = True
|
|
TextoExistencia.AppendFormat("-<b>#{0}</b> {1} {2} Existencia: <b>{3}</b>{4}<br/>", "", gvr.DataKey("CodigoPS"), "", (Existencia + gvr.FCTextBox("TxtCantidad").Text.ToDecimal()), MsgAdicional)
|
|
End If
|
|
Next
|
|
|
|
If ErrorExistencia Then
|
|
ObjInventario.Dispose()
|
|
Alert(TextoExistencia.ToString, TipoMensaje.MsgError)
|
|
RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')")
|
|
|
|
Exit Sub
|
|
End If
|
|
|
|
|
|
|
|
Dim DrAlmO, DrAlmD As DataRow
|
|
Dim CveSucursalOrigen, CveSucursalDestino As Integer
|
|
Dim TipoAlmacenOrigen, TipoAlmacenDestino As Integer
|
|
Dim CveSubProyectoOrigen, CveSubProyectoDestino As Integer
|
|
|
|
Dim CveAlmacenVirtualSalida As Integer = -1
|
|
Dim CveAlmacenVirtualEntrada As Integer = -1
|
|
|
|
DrAlmO = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=CveAlmacenOrigen).FiltroPrimero("")
|
|
DrAlmD = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=CveAlmacenDestino).FiltroPrimero("")
|
|
|
|
If DrAlmO IsNot Nothing AndAlso DrAlmD IsNot Nothing Then
|
|
CveSucursalOrigen = DrAlmO("CveSubProyecto").ToString.ToEntero
|
|
TipoAlmacenOrigen = DrAlmO("CveTipoAlmacen").ToString.ToEntero
|
|
CveSubProyectoOrigen = DrAlmO("CveSubProyecto").ToString.ToEntero
|
|
CveAlmacenVirtualSalida = DrAlmO("CveAlmacenVirtual").ToString.ToEntero
|
|
|
|
|
|
CveSucursalDestino = DrAlmD("CveSubProyecto").ToString.ToEntero
|
|
TipoAlmacenDestino = DrAlmD("CveTipoAlmacen").ToString.ToEntero
|
|
CveSubProyectoDestino = DrAlmD("CveSubProyecto").ToString.ToEntero
|
|
CveAlmacenVirtualEntrada = DrAlmD("CveAlmacenVirtual").ToString.ToEntero
|
|
|
|
End If
|
|
|
|
|
|
|
|
' val Existencia
|
|
|
|
Dim CveMovimientoSalida As Integer = -1
|
|
Dim CveMovimientoEntrada As Integer = -1
|
|
Dim TipoMovimientoSalida As Integer = 26
|
|
|
|
Dim FolioSalida As Integer = 0
|
|
Dim FolioEntrada As Integer = 0
|
|
|
|
Dim TextoError As String = ""
|
|
Dim CveConceptoEntrada As Integer = 9
|
|
|
|
|
|
'AGREGAMOS LA SALIDA DEL ALMACEN ORIGEN
|
|
CveMovimientoSalida = ObjInventario.AddMovimiento(CveAlmacenOrigen, TipoMovimientoSalida, 1, NowADS, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1,
|
|
Observaciones:="", Recibio:="-1",
|
|
CveAlmacenDestino:=CveAlmacenDestino, GastoIndirecto:=-1,
|
|
ResponsableCarga:="", ResponsableRecibio:="",
|
|
Modulo:="STA/G1", CveFolioGarantia:=-1)
|
|
|
|
|
|
|
|
FolioSalida = ObjInventario.Folio
|
|
'Folio = ObjInventario.Folio
|
|
If CveMovimientoSalida <= 0 Then
|
|
TextoError = "Ocurrió un error al generar el movimiento de salida"
|
|
ErrorMovInv = True
|
|
Else
|
|
Dim Cont As Integer = 0
|
|
|
|
|
|
For Each gvr As GridViewRow In GvSolicitudes.Rows
|
|
|
|
Dim Cantidad As Decimal = gvr.FCTextBox("TxtCantidad").Text.ToDecimal
|
|
If gvr.FCCheckBox("Chk").Checked AndAlso Cantidad > 0 Then
|
|
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, Cantidad, gvr.DataKey("CveUM").ToEntero, gvr.DataKey("CvePS").ToEntero, 0, CveAF:=-1, CveSeccionAlmacen:=-1, Serie:="-1", Lote:="-1", FechaCaducidad:=MinFecha, Observaciones:="") Then
|
|
ErrorMovInv = True
|
|
TextoError = "Ocurrió un error al guardar los movimientos de salida"
|
|
Exit For
|
|
End If
|
|
Cont += 1
|
|
End If
|
|
Next
|
|
|
|
'For Each Dr As DataRow In DtMovimientos.RowsF
|
|
|
|
'Next
|
|
End If
|
|
|
|
'ENTRADA
|
|
CveMovimientoEntrada = ObjInventario.AddMovimiento(CveAlmacenTransictorio, CveConceptoEntrada, 1, NowADS, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, -1, -1,
|
|
Observaciones:="", Recibio:="",
|
|
CveAlmacenDestino:=CveAlmacenDestino, CveMovimientoRelacionado:=CveMovimientoSalida, Modulo:="STA/G2", CveFolioGarantia:=-1)
|
|
FolioEntrada = ObjInventario.Folio
|
|
If CveMovimientoEntrada <= 0 Then
|
|
TextoError = "Ocurrió un error al generar el movimiento de entrada"
|
|
ErrorMovInv = True
|
|
Else
|
|
If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then
|
|
Dim Cont As Integer = 0
|
|
Dim dttSalida As DataTable = ObjInventario.DtResultados
|
|
|
|
Dim tCveClasificacion As Integer = ObjInventario.DtResultados.MAX("CveClasificacion").ToEntero
|
|
|
|
For Each Dr As DataRow In ObjInventario.DtResultados.Rows
|
|
Dim CostoEntrada As Decimal = If(TipoAlmacenDestino = 26, 0, Dr("PU").ToString.ToDecimal())
|
|
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Dr("Cantidad").ToString.ToDecimal, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, CostoEntrada, CveAF:=-1,
|
|
CveSeccionAlmacen:=-1, Serie:="-1", Lote:="-1", FechaCaducidad:=MinFecha, CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString.ToEntero, Observaciones:="") Then
|
|
ErrorMovInv = True
|
|
TextoError = "Ocurrió un error al guardar los movimientos de entrada"
|
|
Exit For
|
|
End If
|
|
Cont += 1
|
|
Next
|
|
|
|
Dim Concepto As String = ""
|
|
If Concepto = "" Then Concepto = "Traspaso"
|
|
|
|
'AGREGAMOS PREPOLIZAS TRASPASO DIRECTO:
|
|
If Not ErrorMovInv Then
|
|
Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Inventario/TraspasoAlmacen", 53, 0, 0, 1, NowADS, Concepto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
|
|
|
|
Dim importe As Decimal = dttSalida.SUMD("Total").RoundSQL
|
|
Dim Contabilizable As Boolean = False
|
|
If UsuarioActual.Empresa.Funcionalidad(267) = "1" Then Contabilizable = True 'cuando es citrícola
|
|
If TipoAlmacenOrigen = 26 AndAlso TipoAlmacenDestino <> 26 Then Contabilizable = True
|
|
|
|
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importe, importe, 68, "", "", CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=Contabilizable) Then
|
|
ErrorMovInv = True
|
|
End If
|
|
|
|
'si el tipo de almacen de entrada es Almacen sin costo, se registra al costo, la salida.
|
|
If TipoAlmacenOrigen <> 26 AndAlso TipoAlmacenDestino = 26 Then
|
|
|
|
|
|
|
|
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importe, importe, 69, "", "", CveClasificacion:=tCveClasificacion, CveSubProyecto:=CveSubProyectoOrigen, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=Contabilizable) Then
|
|
ErrorMovInv = True
|
|
End If
|
|
Contabilizable = False
|
|
importe = 0
|
|
End If
|
|
|
|
If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importe, importe, 68, "", "", CveMovimientoAlmacen:=CveMovimientoEntrada, Contabilizable:=Contabilizable) Then
|
|
ErrorMovInv = True
|
|
End If
|
|
|
|
If Not ErrorMovInv Then
|
|
If ObjConta.ValidacionesPrePoliza(CvePrePoliza, UsuarioActual) Then
|
|
If ObjConta.ValorPolizaDescuadre > 0 Then
|
|
'MsgError = ObjMov.MensajePolizaDescuadre
|
|
ErrorMovInv = True
|
|
'GuardaLogAD($"Bancos/Transferencias | Error:{ObjMov.MensajePolizaDescuadre} Diferencia:{ObjMov.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas")
|
|
End If
|
|
Else
|
|
ErrorMovInv = True
|
|
End If
|
|
End If
|
|
End If
|
|
End If
|
|
End If
|
|
|
|
|
|
If Not ErrorMovInv Then
|
|
If ObjInventario.UpdateTraspasoSolicitudMovimiento(CveTraspasoSolicitud, CveMovimientoSalida) Then
|
|
If Not ObjInventario.UpdateTraspasoSolicitudEstatus(CveTraspasoSolicitud, 2) Then
|
|
ErrorMovInv = True
|
|
End If
|
|
Else
|
|
ErrorMovInv = True
|
|
End If
|
|
End If
|
|
|
|
Dim MensajeAlert As New StringBuilder
|
|
If Not ErrorMovInv Then
|
|
ObjInventario.Commit()
|
|
MensajeAlert.Append("Se realizó con éxito el traspaso.")
|
|
MensajeAlert.AppendFormat("<br/> Folio de Salida: <b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={1}"" target=""_blank"">{0}</a></b>", FolioSalida, CveMovimientoSalida)
|
|
MensajeAlert.AppendFormat("<br/><a target='_blank' class='Texto' href='/Compras/PopUpVerFactura.aspx?P={0}'> Imprimir Salida </a>", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoSalida)))
|
|
|
|
MensajeAlert.AppendFormat("<br/> Folio de Transitorio: <b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={1}"" target=""_blank"">{0}</a></b>", FolioEntrada, CveMovimientoEntrada)
|
|
MensajeAlert.AppendFormat("<br/><a target='_blank' class='Texto' href='/Compras/PopUpVerFactura.aspx?P={0}'> Imprimir Transitorio </a>", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoEntrada)))
|
|
|
|
|
|
Alert(MensajeAlert.ToString, TipoMensaje.MsgInformacion, "")
|
|
RegistraScript(String.Format("$('#{0}').modal('hide');", "DVModalSolicitud"))
|
|
Else
|
|
ObjInventario.RollBack()
|
|
Alert(TextoError, TipoMensaje.MsgError)
|
|
End If
|
|
|
|
ObjInventario.Dispose()
|
|
|
|
If Not ErrorMovInv Then
|
|
CargaDatos()
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Protected Sub BtnRechazarSolicitud_Click(sender As Object, e As EventArgs)
|
|
Dim ErrorMovInv As Boolean = False
|
|
|
|
Dim ObjInventarios As New ClsInventarios
|
|
If Not ObjInventarios.UpdateTraspasoSolicitudEstatus(CveTraspasoSolicitud, 3) Then
|
|
ErrorMovInv = True
|
|
End If
|
|
ObjInventarios.Dispose()
|
|
|
|
If Not ErrorMovInv Then
|
|
RegistraScript(String.Format("$('#{0}').modal('hide');", "DVModalSolicitud"))
|
|
Alert("Se rechazo correctamente la solicitud de traspaso.", TipoMensaje.MsgInformacion)
|
|
CargaDatos()
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Protected Sub GvSolicitudes_RowDataBound(sender As Object, e As GridViewRowEventArgs)
|
|
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
Dim Cantidad As Decimal = e.Row.DataKey("Cantidad").ToDecimal
|
|
e.Row.FCCheckBox("chk").Attributes.Add("onclick", $"validaCantidadSolicitud({Cantidad},'{e.Row.FCTextBox("TxtCantidad").ClientID}','{e.Row.FCCheckBox("Chk").ClientID}',1);")
|
|
e.Row.FCTextBox("TxtCantidad").Attributes.Add("onkeyup", $"validaCantidadSolicitud({Cantidad},'{e.Row.FCTextBox("TxtCantidad").ClientID}','{e.Row.FCCheckBox("Chk").ClientID}',2);")
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Protected Sub GvT_RowDataBound(sender As Object, e As GridViewRowEventArgs)
|
|
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
|
|
Dim PermisoOrigen As Boolean = If(e.Row.DataKey("PermisoOrigen").ToEntero = 1, True, False)
|
|
Dim PermisoDestino As Boolean = If(e.Row.DataKey("PermisoDestino").ToEntero = 1, True, False)
|
|
|
|
Dim CveMovimientoAlmacen As Integer = e.Row.DataKey("CveMovimientoAlmacen").ToEntero
|
|
Dim FolioMovimiento As Integer = e.Row.DataKey("FolioMovimiento").ToEntero
|
|
Dim CveAlmacenDestino As Integer = e.Row.DataKey("CveAlmacenDestino").ToEntero
|
|
Dim CveMovimientoTransitorio As Integer = e.Row.DataKey("CveMovimientoTransitorio").ToEntero
|
|
Dim CveAlmacenTransitorio As Integer = e.Row.DataKey("CveAlmacenTransitorio").ToEntero
|
|
|
|
Dim CveMomientoEntrada As Integer = e.Row.DataKey("CveAlmacenTransitorio").ToEntero ' Este es el movmiento de recepcion de traspaso
|
|
|
|
e.Row.FCLinkButton("LnkMostrarTraspaso").Visible = True
|
|
|
|
If e.Row.DataKey("CveTrasladoEstatus").ToEntero = 1 Then
|
|
e.Row.FCLinkButton("LnkMostrarTraspaso").CssClass = "btn btn-circle btn-sm blue"
|
|
e.Row.FCLabel("LblTraspasoEstatus").CssClass = "label label-sm label-info"
|
|
e.Row.FCLinkButton("LnkMostrarTraspaso").Visible = PermisoOrigen
|
|
Else
|
|
If e.Row.DataKey("CveTrasladoEstatus").ToEntero = 2 Then
|
|
e.Row.FCLabel("LblTraspasoEstatus").CssClass = "label label-sm label-success"
|
|
e.Row.FCLinkButton("LnkMostrarTraspaso").CssClass = "btn btn-circle btn-sm green"
|
|
e.Row.FCLinkButton("LnkMostrarTraspaso").Text = "<i class='fa fa-info'></i>"
|
|
|
|
If CveMovimientoAlmacen > 0 AndAlso PermisoDestino AndAlso e.Row.DataKey("CveMovimientoRelacionado") = "" Then
|
|
e.Row.FCHyperLink("HypRecibeTraspaso").Visible = True
|
|
e.Row.FCHyperLink("HypRecibeTraspaso").NavigateUrl = $"~/Inventarios/TraspasoAlmacen.aspx?CveAlmacenTransitorioR={CveAlmacenTransitorio}&FolioR={FolioMovimiento}&CveAlmacenDestinoR={CveAlmacenDestino}"
|
|
End If
|
|
|
|
If e.Row.DataKey("CveMovimientoRelacionado") <> "" Then
|
|
e.Row.FCLabel("LblTraspasoEstatus").Text = "Recibido"
|
|
End If
|
|
|
|
Else
|
|
e.Row.FCLabel("LblTraspasoEstatus").CssClass = "label label-sm label-danger"
|
|
e.Row.FCLinkButton("LnkMostrarTraspaso").CssClass = "btn btn-circle btn-sm red"
|
|
End If
|
|
End If
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Protected Sub DdlAlmacenOrigen_SelectedIndexChanged(sender As Object, e As EventArgs)
|
|
|
|
DdlAlmacenDestino.ClearSelection()
|
|
DdlAlmacenDestino.SelectedValue = Nothing
|
|
DdlAlmacenDestino.Items.Clear()
|
|
|
|
DdlAlmacenDestino.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros($"CveTipoAlmacen = 1 AND CveAlmacen <> {DdlAlmacenOrigen.SelectedValue}")
|
|
DdlAlmacenDestino.DataBind()
|
|
DdlAlmacenDestino.Items.Insert(0, New ListItem("Seleccione Uno", "-1"))
|
|
UpPS.Update()
|
|
End Sub
|
|
End Class
|