1141 lines
51 KiB
VB.net
1141 lines
51 KiB
VB.net
Option Strict On
|
|
Option Explicit On
|
|
|
|
Imports System.Data
|
|
Imports Extensiones
|
|
Imports Microsoft.Reporting.WebForms
|
|
|
|
Partial Class Inventarios_TrasladoSolicitud
|
|
Inherits ClsPaginas
|
|
|
|
#Region "Propiedades"
|
|
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
|
|
Return CType(ViewState("CveTraspasoSolicitud"), Integer)
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveTraspasoSolicitud") = value
|
|
End Set
|
|
End Property
|
|
|
|
'CveDireccionEnvio del Traslado
|
|
Private Property CveDireccionEnvio As Integer
|
|
Get
|
|
Return CType(ViewState("CveDireccionEnvio"), Integer)
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveDireccionEnvio") = value
|
|
End Set
|
|
End Property
|
|
Private Property CveUsuarioSolicita As Integer
|
|
Get
|
|
If ViewState("CveUsuarioSolicita") Is Nothing Then
|
|
Return -1
|
|
Else
|
|
Return CType(ViewState("CveUsuarioSolicita"), Integer)
|
|
End If
|
|
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveUsuarioSolicita") = 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()
|
|
|
|
'CARGAMOS SOLICITUD YA EXISTENTE.
|
|
If Request("CveTraspasoSolicitud").ToEntero > 0 Then
|
|
CveTraspasoSolicitud = Request("CveTraspasoSolicitud").ToEntero
|
|
CargaDatos()
|
|
End If
|
|
|
|
End If
|
|
End Sub
|
|
|
|
|
|
|
|
#Region " INICIALIZA VALORES "
|
|
Private Sub InicializaValores()
|
|
CveTraspasoSolicitud = -1
|
|
CveDireccionEnvio = -1
|
|
DivFolio.Visible = False
|
|
|
|
TxtFecha.Text = Now.ToShortDateString
|
|
CreaDTTemporal()
|
|
CargaAlmacenes()
|
|
CargaPS()
|
|
CargaClientes()
|
|
DdlContratos.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
CargaUnidadMedida()
|
|
CargaPaqueterias()
|
|
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()
|
|
End Sub
|
|
Private Sub CargaPaqueterias()
|
|
DdlPaqueteria.DataSource = GlobalDTPaqueterias(UsuarioActual.CveEmpresa)
|
|
DdlPaqueteria.DataBind()
|
|
DdlPaqueteria.Items.Insert(0, New ListItem("-", "-1"))
|
|
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).FiltraParametros("CveTipoAlmacen <> 9") 'Excluir almacenes de Apartado
|
|
DdlAlmacenDestino.DataSource = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltraParametros("CveTipoAlmacen <> 9") 'Excluir almacenes de Apartado
|
|
DdlAlmacenOrigen.DataBind()
|
|
DdlAlmacenDestino.DataBind()
|
|
End Sub
|
|
|
|
Private Sub CargaClientes()
|
|
DdlClientes.DataSource = GlobalDTCliente(UsuarioActual.CveEmpresa)
|
|
DdlClientes.DataBind()
|
|
DdlClientes.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
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
|
|
#End Region
|
|
|
|
|
|
#Region " CARGA DATOS "
|
|
Private Sub CargaDatos()
|
|
Dim ObjInventarios As New ClsInventarios
|
|
Dim ObjClientes As New ClsClientes
|
|
|
|
If ObjInventarios.AddTrasladoSolicitudGet(CveTraspasoSolicitud, UsuarioActual.CveEmpresa) Then
|
|
If ObjInventarios.DtResultados.Rows.Count > 0 Then
|
|
|
|
GvDatos.Columns(4).Visible = False
|
|
GvDatos.Columns(5).Visible = True
|
|
DivFolio.Visible = True
|
|
LbFolio.Text = ObjInventarios.DtResultados.Rows(0)("FolioTraspaso").ToString
|
|
TxtObservaciones.Text = ObjInventarios.DtResultados.Rows(0)("ObservacionesTraspaso").ToString
|
|
|
|
TempDT = ObjInventarios.DtResultados
|
|
GvDatos.DataSource = ObjInventarios.DtResultados
|
|
GvDatos.DataBind()
|
|
|
|
If ObjInventarios.DtResultados.Rows(0)("CveContrato").ToString.ToEntero > 0 Then
|
|
RowContrato.Visible = True
|
|
ChkDesdeContrato.Checked = True
|
|
GvDatos.Columns(3).Visible = True
|
|
Else
|
|
GvDatos.Columns(3).Visible = False
|
|
End If
|
|
|
|
DdlAlmacenOrigen.SelectedValue = ObjInventarios.DtResultados.Rows(0)("CveAlmacenOrigen").ToString
|
|
DdlAlmacenDestino.SelectedValue = ObjInventarios.DtResultados.Rows(0)("CveAlmacenDestino").ToString
|
|
DdlPaqueteria.SelectedValue = ObjInventarios.DtResultados.Rows(0)("CvePaqueteria").ToString
|
|
TxtFecha.Text = ObjInventarios.DtResultados.Rows(0)("Fecha").ToString
|
|
LblUsuario.Text = ObjInventarios.DtResultados.Rows(0)("Usuario").ToString
|
|
HplContrato.Text = ObjInventarios.DtResultados.Rows(0)("DescripcionContrato").ToString
|
|
HplContrato.NavigateUrl = $"/Contratos/Contrato.aspx?CveContrato={ObjInventarios.DtResultados.Rows(0)("CveContrato").ToString.ToEntero}"
|
|
|
|
CveUsuarioSolicita = ObjInventarios.DtResultados.Rows(0)("CveUsuario").ToString.ToEntero
|
|
|
|
'25/04/2018
|
|
CveDireccionEnvio = ObjInventarios.DtResultados.Rows(0)("CveDireccionEnvio").ToString.ToEntero
|
|
If CveDireccionEnvio > 0 And ObjClientes.DireccionEnvioGet(CveDireccionEnvio, -1, -1) Then
|
|
LblDireccionEnvio.Text = ObjClientes.DtResultados.FiltraParametros(String.Format("Estatus = 1")).Rows(0)("SucursalClienteVentaDireccion").ToString
|
|
Else
|
|
Dim CveCliente As Integer = GlobalDTContratos().FiltroPrimeroValor("CveCliente", $"CveContrato = {ObjInventarios.DtResultados.Rows(0)("CveContrato").ToString.ToEntero}").ToEntero
|
|
Dim DtCliente As DataTable = GlobalDTCliente(UsuarioActual.CveEmpresa).FiltraParametros($"CveCliente = {CveCliente}")
|
|
If DtCliente.Rows.Count > 0 Then
|
|
LblDireccionEnvio.Text = String.Format("{0},{1}, {2}", DtCliente.FiltroPrimeroValor("Direccion"), DtCliente.FiltroPrimeroValor("Colonia"), DtCliente.FiltroPrimeroValor("Ciudad"), DtCliente.FiltroPrimeroValor("Contacto"))
|
|
End If
|
|
End If
|
|
|
|
If ObjInventarios.DtResultados.Rows(0)("CveTrasladoEstatus").ToString.Contiene("1", "3") And Not ObjInventarios.DtResultados.Rows(0)("CveMovimientoAlmacen").ToString.ToEntero > 0 Then
|
|
LBCancelarTraslado.Visible = True
|
|
End If
|
|
|
|
If ObjInventarios.DtResultados.Rows(0)("CveTrasladoEstatus").ToString = "2" Then
|
|
DivCancelado.Visible = True
|
|
End If
|
|
|
|
If ObjInventarios.DtResultados.Rows(0)("CveMovimientoAlmacen").ToString.ToEntero > 0 Then
|
|
RowMovimiento.Visible = True
|
|
HLMovimiento.Text = ObjInventarios.DtResultados.Rows(0)("FolioAlmacen").ToString
|
|
HLMovimiento.NavigateUrl = $"/Inventarios/EntradasSalidas.aspx?CveMovimiento={ObjInventarios.DtResultados.Rows(0)("CveMovimientoAlmacen").ToString.ToEntero}"
|
|
Else
|
|
RowMovimiento.Visible = False
|
|
End If
|
|
|
|
If ObjInventarios.DtResultados.Rows(0)("Guia").ToString <> "" Then
|
|
TrGuia.Visible = True
|
|
TxtGuia.Text = ObjInventarios.DtResultados.Rows(0)("Guia").ToString
|
|
Else
|
|
TrGuia.Visible = False
|
|
End If
|
|
BtnEliminar.Visible = True
|
|
BtnGuardar.Enabled = False
|
|
TxtObservaciones.Enabled = False
|
|
TxtFecha.Enabled = False
|
|
DdlPaqueteria.Enabled = False
|
|
ChkDesdeContrato.Enabled = False
|
|
DdlAlmacenDestino.Enabled = False
|
|
DdlAlmacenOrigen.Enabled = False
|
|
TxtGuia.Enabled = False
|
|
HLDesdeContrato.Enabled = False
|
|
LbAgregarPS.Enabled = False
|
|
DivInfo.Visible = True
|
|
LbImprimir.Visible = True
|
|
ImgExcel.Visible = True
|
|
|
|
LbAgregarPS.Visible = False
|
|
HLDesdeContrato.Visible = False
|
|
|
|
|
|
Dim EstatusAlmacen As Integer = ObjInventarios.DtResultados.Rows(0)("EstatusAlmacen").ToString().ToEntero
|
|
Dim CveUsuarioAutoriza As Integer = ObjInventarios.DtResultados.Rows(0)("CveUsuarioAutorizaDestino").ToString().ToEntero
|
|
|
|
If EstatusAlmacen > 0 Then
|
|
|
|
|
|
If UsuarioActual.CveUsuario = CveUsuarioAutoriza Then
|
|
|
|
If EstatusAlmacen = 1 Then
|
|
|
|
|
|
DivAutoriza.Visible = True
|
|
DVAutorizarBotones.Visible = True
|
|
DVAutorizaInformacion.Visible = False
|
|
|
|
ElseIf EstatusAlmacen.Contiene(2, 3) Then
|
|
DivAutoriza.Visible = True
|
|
|
|
DVAutorizarBotones.Visible = False
|
|
DVAutorizaInformacion.Visible = True
|
|
|
|
LblEstatusAutorizo.Text = If(EstatusAlmacen = 2, "Aceptado", "Rechazado")
|
|
LblUsaurioAutorizo.Text = ObjInventarios.DtResultados.Rows(0)("NombreAutoriza").ToString()
|
|
LblFechaAutoriza.Text = ObjInventarios.DtResultados.Rows(0)("FechaAutorizacion").ToString().ToDate().ToString("dd/MM/yyyy")
|
|
Else
|
|
|
|
End If
|
|
|
|
ElseIf EstatusAlmacen.Contiene(2, 3) Then
|
|
|
|
DivAutoriza.Visible = True
|
|
|
|
DVAutorizarBotones.Visible = False
|
|
DVAutorizaInformacion.Visible = True
|
|
|
|
LblEstatusAutorizo.Text = If(EstatusAlmacen = 2, "Aceptado", "Rechazado")
|
|
LblUsaurioAutorizo.Text = ObjInventarios.DtResultados.Rows(0)("NombreAutoriza").ToString()
|
|
LblFechaAutoriza.Text = ObjInventarios.DtResultados.Rows(0)("FechaAutorizacion").ToString().ToDate().ToString("dd/MM/yyyy")
|
|
GvDatos.Columns(6).Visible = False ' se oculta la columna de eliminar
|
|
|
|
End If
|
|
|
|
|
|
Else
|
|
DivAutoriza.Visible = False
|
|
End If
|
|
|
|
|
|
|
|
Else
|
|
Alert("Ocurrió un error al obtener los datos del traspaso.", TipoMensaje.MsgError)
|
|
End If
|
|
|
|
UpAutorizaciones.Update()
|
|
|
|
End If
|
|
ObjInventarios.Dispose()
|
|
ObjClientes.Dispose()
|
|
MostarSerieColumn()
|
|
End Sub
|
|
#End Region
|
|
|
|
|
|
#Region " AGREGAR "
|
|
Private Sub BtnAgregarModal_Click(sender As Object, e As EventArgs) Handles LbAgregarPS.Click
|
|
|
|
If ChkDesdeContrato.Checked Then
|
|
GvDatos.Columns(3).Visible = False
|
|
ChkDesdeContrato.Checked = False
|
|
TempDT.Rows.Clear()
|
|
GvDatos.DataSource = TempDT
|
|
GvDatos.DataBind()
|
|
UpDatos.Update()
|
|
End If
|
|
|
|
TxtCantidad.Text = ""
|
|
DdlUM.SelectedIndex = 0
|
|
LbContratos.Text = ""
|
|
DdlProductoServicio.SelectedText = ""
|
|
DdlProductoServicio.SelectedValue = "-1"
|
|
UpPS.Update()
|
|
UpDatos.Update()
|
|
RegistraScript(String.Format("$('#{0}').modal();", "ModalPS"))
|
|
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
|
|
|
|
TxtCantidad.Text = ""
|
|
DdlProductoServicio.SelectedText = ""
|
|
DdlProductoServicio.SelectedValue = "-1"
|
|
DdlUM.SelectedIndex = 0
|
|
|
|
GvDatos.DataSource = TempDT
|
|
GvDatos.DataBind()
|
|
|
|
If ChkSeguirAgregando.Checked Then
|
|
TxtCantidad.Focus()
|
|
Else
|
|
RegistraScript("$('#ModalPS').hide();", "EscondeAgregar")
|
|
End If
|
|
|
|
UpPS.Update()
|
|
UpDatos.Update()
|
|
|
|
End Sub
|
|
Private Function AddPSTemporal() As Boolean
|
|
Dim Row As DataRow = TempDT.NewRow()
|
|
Row("Cantidad") = TxtCantidad.Text.Trim.ToDouble
|
|
Row("CvePS") = DdlProductoServicio.SelectedValue.ToEntero
|
|
Row("CodigoPS") = DdlProductoServicio.SelectedText
|
|
Row("Precio") = 0
|
|
Row("CveUM") = DdlUM.SelectedValue.ToEntero
|
|
Row("UnidadMedida") = DdlUM.SelectedItem.Text
|
|
Row("Observaciones") = ""
|
|
|
|
If Div4.Visible Then
|
|
Row("Serie") = TxtSerie.Text
|
|
GvDatos.Columns(5).Visible = True
|
|
Else
|
|
Row("Serie") = "-1"
|
|
End If
|
|
|
|
Dim ObjInventarios As New ClsInventarios
|
|
Dim Existencia As Double = ObjInventarios.GetExistenciasPS(DdlProductoServicio.SelectedValue.ToEntero, DdlUM.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, DdlAlmacenOrigen.SelectedValue.ToEntero, FechaMovto:=TxtFecha.Text.ToDate.ToString("yyyy/MM/dd 23:59"))
|
|
ObjInventarios.Dispose()
|
|
|
|
If Existencia - TxtCantidad.Text.Trim.ToDouble - TempDT.SUM("Cantidad", $"CvePS = {DdlProductoServicio.SelectedValue.ToEntero} AND CveUM = {DdlUM.SelectedValue.ToEntero}") < 0 Then
|
|
If Existencia = 0 Then
|
|
Alert("No hay existencia del producto", TipoMensaje.MsgAdvertencia)
|
|
Else
|
|
Alert($"No hay existencia suficiente del producto. Solo hay en existencia: {Existencia}", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
Return False
|
|
End If
|
|
|
|
TempDT.Rows.Add(Row)
|
|
|
|
|
|
Return True
|
|
End Function
|
|
#End Region
|
|
|
|
#Region " AGREGAR DESDE CONTRATO "
|
|
Private Sub ChkDesdeContrato_CheckedChanged(sender As Object, e As EventArgs) Handles ChkDesdeContrato.CheckedChanged
|
|
|
|
If ChkDesdeContrato.Checked Then
|
|
GvDatos.Columns(3).Visible = True
|
|
DdlContratos.SelectedIndex = 0
|
|
DdlClientes.SelectedIndex = 0
|
|
|
|
DdlDireccionEnvio.Items.Clear()
|
|
DivContratoDireccionEnvio.Visible = False
|
|
|
|
CargaExcel.Visible = False
|
|
GvContratos.DataBind()
|
|
UpContrato.Update()
|
|
RegistraScript(String.Format("$('#{0}').modal().show();", "ModalContrato"))
|
|
Else
|
|
LbContratos.Text = ""
|
|
End If
|
|
|
|
TempDT.Rows.Clear()
|
|
GvDatos.DataSource = TempDT
|
|
GvDatos.DataBind()
|
|
UpDatos.Update()
|
|
|
|
End Sub
|
|
Private Sub HLDesdeContrato_Click(sender As Object, e As EventArgs) Handles HLDesdeContrato.Click
|
|
DdlContratos.SelectedIndex = 0
|
|
DdlClientes.SelectedIndex = 0
|
|
DdlDireccionEnvio.Items.Clear()
|
|
DivContratoDireccionEnvio.Visible = False
|
|
UpContrato.Update()
|
|
RegistraScript(String.Format("$('#{0}').modal();", "ModalContrato"))
|
|
End Sub
|
|
Private Sub DdlClientes_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlClientes.SelectedIndexChanged
|
|
DdlContratos.Items.Clear()
|
|
|
|
Dim ObjContratos As New ClsContratos
|
|
If ObjContratos.GetContratosEstatus(UsuarioActual.CveEmpresa) Then
|
|
Dim CveEstatusVigente = ObjContratos.DtResultados.FiltroPrimeroValor("CveContratoEstatus", "TipoEstatus = 1", Orderby:="CveContratoEstatus").ToEntero
|
|
|
|
DdlContratos.DataSource = GlobalDTContratos().FiltraParametros($"CveEmpresa = {UsuarioActual.CveEmpresa} AND CveCliente = {DdlClientes.SelectedValue.ToEntero} AND CveContratosEstatus = {CveEstatusVigente}")
|
|
|
|
'If ObjContratos.GetContratos(-1, UsuarioActual.CveEmpresa, DdlClientes.SelectedValue.ToEntero, CveEstatusVigente) Then
|
|
' DdlContratos.DataSource = ObjContratos.DtResultados
|
|
'End If
|
|
|
|
End If
|
|
ObjContratos.Dispose()
|
|
|
|
DdlContratos.DataBind()
|
|
DdlContratos.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
GvContratos.DataBind()
|
|
|
|
Dim ObjClientes As New ClsClientes
|
|
|
|
DdlDireccionEnvio.Items.Clear()
|
|
If DdlClientes.SelectedValue <> "-1" And ObjClientes.DireccionEnvioGet(-1, DdlClientes.SelectedValue.ToEntero, -1) And ObjClientes.DtResultados.Rows.Count > 0 Then
|
|
DivContratoDireccionEnvio.Visible = True
|
|
DdlDireccionEnvio.DataSource = ObjClientes.DtResultados.FiltraParametros(String.Format("Estatus = 1"))
|
|
DdlDireccionEnvio.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
DdlDireccionEnvio.DataBind()
|
|
Else
|
|
DivContratoDireccionEnvio.Visible = False
|
|
End If
|
|
ObjClientes.Dispose()
|
|
|
|
UpContrato.Update()
|
|
End Sub
|
|
Private Sub DdlContratos_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlContratos.SelectedIndexChanged
|
|
Dim ObjContratos As New ClsContratos
|
|
If ObjContratos.GetContratosDetalle(DdlContratos.SelectedValue.ToEntero) Then
|
|
GvContratos.DataSource = ObjContratos.DtResultados
|
|
GvContratos.DataBind()
|
|
If ObjContratos.DtResultados.Rows.Count > 0 Then
|
|
CargaExcel.Visible = True
|
|
Else
|
|
CargaExcel.Visible = False
|
|
End If
|
|
End If
|
|
ObjContratos.Dispose()
|
|
UpContrato.Update()
|
|
End Sub
|
|
Private Sub BtnAgregarContrato_Click(sender As Object, e As EventArgs) Handles BtnAgregarContrato.Click
|
|
|
|
TempDT.Rows.Clear()
|
|
|
|
Dim ObjInventarios As New ClsInventarios
|
|
Dim Existencia = 0.0
|
|
Dim TieneErrorExistencia = 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 GvContratos.Rows
|
|
If row.FCTextBox("TxtCantContrato").Text.Trim.ToDouble > 0 Then
|
|
Dim RowTemp As DataRow = TempDT.NewRow()
|
|
RowTemp("Cantidad") = row.FCTextBox("TxtCantContrato").Text.Trim.ToDouble
|
|
RowTemp("CvePS") = row.DataKey("CvePS").ToEntero
|
|
RowTemp("CodigoPS") = row.DataKey("CodigoPS")
|
|
RowTemp("Precio") = row.DataKey("PU")
|
|
RowTemp("CveUM") = row.DataKey("CveUM").ToEntero
|
|
RowTemp("UnidadMedida") = row.DataKey("UM")
|
|
RowTemp("Observaciones") = ""
|
|
'RowTemp("CveDireccionEnvio") = DdlDireccionEnvio.SelectedValue
|
|
'RowTemp("DireccionEnvio") = IIf(DdlDireccionEnvio.SelectedValue = "-1", "", DdlDireccionEnvio.SelectedItem)
|
|
RowTemp("CveContratoDetalle") = row.DataKey("CveContratoDetalle")
|
|
CodigoPS = RowTemp("CodigoPS").ToString
|
|
|
|
|
|
Existencia = ObjInventarios.GetExistenciasPS(row.DataKey("CvePS").ToEntero, row.DataKey("CveUM").ToEntero, UsuarioActual.CveEmpresa, DdlAlmacenOrigen.SelectedValue.ToEntero, FechaMovto:=TxtFecha.Text.ToDate.ToString("yyyy/MM/dd 23:59"))
|
|
If Existencia - row.FCTextBox("TxtCantContrato").Text.Trim.ToDouble - 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
|
|
Continue For
|
|
End If
|
|
|
|
TempDT.Rows.Add(RowTemp)
|
|
End If
|
|
Next
|
|
|
|
If TieneErrorExistencia Then
|
|
Alert(MensajeExistencia.ToString, TipoMensaje.MsgAdvertencia)
|
|
ObjInventarios.Dispose()
|
|
Exit Sub
|
|
Else
|
|
CveDireccionEnvio = DdlDireccionEnvio.SelectedValue.ToEntero
|
|
End If
|
|
|
|
ObjInventarios.Dispose()
|
|
GvDatos.DataSource = TempDT
|
|
GvDatos.DataBind()
|
|
CargaTextoContrato()
|
|
RegistraScript(String.Format("$('#{0}').modal().hide();", "ModalContrato"))
|
|
|
|
UpDatos.Update()
|
|
|
|
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()
|
|
UpDatos.Update()
|
|
End Sub
|
|
|
|
|
|
#End Region
|
|
|
|
|
|
#Region " GUARDAR "
|
|
Private Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click
|
|
|
|
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 = 0.0
|
|
Dim TieneErrorExistencia = False
|
|
Dim MensajeExistencia As New StringBuilder
|
|
MensajeExistencia.Append("No hay la existencia suficiente de los siguientes productos:<br/>")
|
|
Dim CodigoPS As String = ""
|
|
|
|
|
|
If ObjInventarios.GetAlmacenes(-1, -1, UsuarioActual.CveEmpresa, -1) Then
|
|
|
|
If ObjInventarios.DtResultados.Rows.Count > 0 Then
|
|
|
|
CveUsuarioAutoriza = If(ObjInventarios.DtResultados.FiltraParametros($"CveAlmacen = {DdlAlmacenDestino.SelectedValue}")(0)("CveUsuarioAutoriza").ToString.ToEntero > 0, ObjInventarios.DtResultados.FiltraParametros($"CveAlmacen = {DdlAlmacenDestino.SelectedValue}")(0)("CveUsuarioAutoriza").ToString.ToEntero, -1)
|
|
If CveUsuarioAutoriza > 0 Then
|
|
EstatusAlmacen = 1
|
|
End If
|
|
|
|
Else
|
|
CveUsuarioAutoriza = -1
|
|
End If
|
|
End If
|
|
|
|
|
|
|
|
|
|
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:=TxtFecha.Text.ToDate.ToString("yyyy/MM/dd 23:59"))
|
|
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 = 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 = ObjInventarios.AddTrasladoSolicitud(TxtObservaciones.Text.Trim, DdlAlmacenOrigen.SelectedValue.ToEntero, DdlAlmacenDestino.SelectedValue.ToEntero, Estatus, -1, TxtFecha.Text.ToDate, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveContrato:=CveContrato, Guia:=Guia, CvePaqueteria:=DdlPaqueteria.SelectedValue.ToEntero, CveDireccionEnvio:=CveDireccionEnvio, 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 Double = Row.DataKey("Precio").ToEntero
|
|
Dim Observaciones As String = Row.DataKey("Observaciones")
|
|
Dim CveContratoDetalle As Integer = Row.DataKey("CveContratoDetalle").ToEntero
|
|
Dim Serie As String = Row.DataKey("Serie")
|
|
|
|
If Not ObjInventarios.AddTrasladoSolicitudDetalle(CveTraspasoSolicitud, Cantidad, CveUM, CvePS, Precio, Observaciones, CveContratoDetalle, Serie) 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, $"document.location.href=""/Inventarios/TrasladoSolicitud.aspx?CveTraspasoSolicitud={CveTraspasoSolicitud}""")
|
|
|
|
If CveUsuarioAutoriza > 0 Then
|
|
MandaCorreoAutorizacion(Folio, CveTraspasoSolicitud, CveUsuarioAutoriza)
|
|
End If
|
|
|
|
Else
|
|
ObjInventarios.RollBack()
|
|
Alert("Ocurrió un Error al guardar el traspaso.", TipoMensaje.MsgError)
|
|
End If
|
|
ObjInventarios.Dispose()
|
|
|
|
End Sub
|
|
#End Region
|
|
|
|
|
|
#Region " ELIMINAR - CANCELAR "
|
|
Private Sub BtnEliminar_Click(sender As Object, e As EventArgs) Handles BtnEliminar.Click
|
|
Dim ObjInventarios As New ClsInventarios
|
|
If ObjInventarios.RemoveTrasladoSolicitud(CveTraspasoSolicitud, UsuarioActual.CveEmpresa) Then
|
|
Alert("Se eliminó correctamente el Traspaso.", TipoMensaje.MsgInformacion, "document.location.href=""/Inventarios/TrasladoSolicitud.aspx""")
|
|
End If
|
|
ObjInventarios.Dispose()
|
|
End Sub
|
|
Protected Sub LBCancelarTraslado_Click(sender As Object, e As EventArgs)
|
|
Dim ObjInventarios As New ClsInventarios
|
|
|
|
If ObjInventarios.UpdateTraspasoSolicitudEstatus(CveTraspasoSolicitud, 2) Then
|
|
LBCancelarTraslado.Visible = False
|
|
Alert("Se canceló correctamente la solicitud de traslado.", TipoMensaje.MsgInformacion)
|
|
End If
|
|
|
|
ObjInventarios.Dispose()
|
|
End Sub
|
|
#End Region
|
|
|
|
|
|
#Region " IMPRESION "
|
|
Protected Sub ImgImprimir_Click(sender As Object, e As EventArgs) Handles LbImprimir.Click
|
|
GenerarPDF()
|
|
End Sub
|
|
Protected Sub ImgExcel_Click(sender As Object, e As EventArgs) Handles ImgExcel.Click
|
|
GenerarPDF("Excel")
|
|
End Sub
|
|
Private Sub GenerarPDF(Optional Formato As String = "PDF")
|
|
|
|
|
|
Dim ObjInventarios As New ClsInventarios
|
|
Dim ObjClientes As New ClsClientes
|
|
|
|
|
|
Dim CveTraspasoSolicitud As Integer = Request("CveTraspasoSolicitud").ToEntero
|
|
If ObjInventarios.AddTrasladoSolicitudGet(CveTraspasoSolicitud, UsuarioActual.CveEmpresa) Then
|
|
If ObjInventarios.DtResultados.Rows.Count > 0 Then
|
|
Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta))
|
|
Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa)
|
|
Dim dt As DataTable = ObjInventarios.DtResultados
|
|
|
|
Dim DTCliente As New DataTable
|
|
Dim CveCliente As Integer = 0
|
|
Dim CveDireccionEnvio As Integer = 0
|
|
Dim ClienteNombre = "", EnvioContacto = "", EnvioDireccion = "", EnvioColonia = "", EnvioCiudad = "", EnvioEstado = "", ClientePais = "", EnvioCP = "", Contrato = "",
|
|
Paqueteria = "", NumContrato = ""
|
|
|
|
|
|
|
|
Dim CveContrato As Integer = ObjInventarios.DtResultados.FiltroPrimeroValor("CveContrato").ToString.ToEntero
|
|
If CveContrato > 0 Then
|
|
Contrato = GlobalDTContratos().FiltroPrimeroValor("DescripcionContrato", $"CveContrato={CveContrato} AND CveEmpresa = {UsuarioActual.CveEmpresa}")
|
|
NumContrato = GlobalDTContratos().FiltroPrimeroValor("NumeroContrato", $"CveContrato={CveContrato} AND CveEmpresa = {UsuarioActual.CveEmpresa}")
|
|
CveCliente = GlobalDTContratos().FiltroPrimeroValor("CveCliente", $"CveContrato = {CveContrato}").ToEntero
|
|
CveDireccionEnvio = GlobalDTContratos().FiltroPrimeroValor("CveDireccionEnvio", $"CveContrato = {CveContrato}").ToEntero
|
|
|
|
|
|
If CveCliente > 0 Then
|
|
|
|
DTCliente = GlobalDTCliente(UsuarioActual.CveEmpresa).FiltraParametros($"CveCliente = {CveCliente}")
|
|
|
|
'Si el traslado tiene cvedireccionenvio trae sus datos
|
|
If Me.CveDireccionEnvio > 0 And ObjClientes.DireccionEnvioGet(Me.CveDireccionEnvio, DdlClientes.SelectedValue.ToEntero, -1) And ObjClientes.DtResultados.Rows.Count > 0 Then
|
|
|
|
ClienteNombre = DTCliente.FiltroPrimeroValor("Nombre")
|
|
'ClientePais = DTCliente.FiltroPrimeroValor("PAIS")
|
|
EnvioContacto = ObjClientes.DtResultados.Rows(0)("EnvioContacto").ToString '??
|
|
|
|
EnvioDireccion = ObjClientes.DtResultados.Rows(0)("EnvioDireccion").ToString
|
|
EnvioColonia = ObjClientes.DtResultados.Rows(0)("EnvioColonia").ToString
|
|
EnvioCiudad = ObjClientes.DtResultados.Rows(0)("EnvioCiudad").ToString
|
|
EnvioCP = ObjClientes.DtResultados.Rows(0)("EnvioCP").ToString
|
|
EnvioEstado = ObjClientes.DtResultados.Rows(0)("EnvioEstado").ToString
|
|
Else
|
|
'25/04/2018 - Si el trasladosolicitud no tiene cvedireccion envio asignada, va por la el cliente
|
|
Dim ObjVentas As New ClsClientes
|
|
If ObjVentas.DireccionEnvioGet(CveDireccionEnvio, -1, -1) Then
|
|
If ObjVentas.DtResultados.Rows.Count > 0 Then
|
|
ClienteNombre = DTCliente.FiltroPrimeroValor("Nombre")
|
|
ClientePais = DTCliente.FiltroPrimeroValor("PAIS")
|
|
EnvioContacto = ObjVentas.DtResultados.Rows(0)("EnvioContacto").ToString
|
|
EnvioDireccion = ObjVentas.DtResultados.Rows(0)("EnvioDireccion").ToString
|
|
EnvioColonia = ObjVentas.DtResultados.Rows(0)("EnvioColonia").ToString
|
|
EnvioCiudad = ObjVentas.DtResultados.Rows(0)("EnvioCiudad").ToString
|
|
EnvioCP = ObjVentas.DtResultados.Rows(0)("EnvioCP").ToString
|
|
EnvioEstado = ObjVentas.DtResultados.Rows(0)("EnvioEstado").ToString
|
|
Else
|
|
ClienteNombre = DTCliente.FiltroPrimeroValor("Nombre")
|
|
EnvioContacto = DTCliente.FiltroPrimeroValor("Contacto")
|
|
EnvioDireccion = DTCliente.FiltroPrimeroValor("Direccion")
|
|
EnvioColonia = DTCliente.FiltroPrimeroValor("Colonia")
|
|
EnvioCiudad = DTCliente.FiltroPrimeroValor("Ciudad")
|
|
EnvioEstado = DTCliente.FiltroPrimeroValor("Estado")
|
|
ClientePais = DTCliente.FiltroPrimeroValor("PAIS")
|
|
EnvioCP = DTCliente.FiltroPrimeroValor("CP")
|
|
End If
|
|
End If
|
|
ObjVentas.Dispose()
|
|
End If
|
|
End If
|
|
End If
|
|
|
|
|
|
Dim params As New List(Of ReportParameter)
|
|
params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa))
|
|
params.Add(New ReportParameter("FechaImpresion", Now.ToShortDateString))
|
|
params.Add(New ReportParameter("Fecha", TxtFecha.Text.Substring(0, 10)))
|
|
params.Add(New ReportParameter("AlmacenOrigen", DdlAlmacenOrigen.SelectedItem.Text))
|
|
params.Add(New ReportParameter("AlmacenDestino", DdlAlmacenDestino.SelectedItem.Text))
|
|
params.Add(New ReportParameter("Guia", TxtGuia.Text))
|
|
params.Add(New ReportParameter("UsuarioSolicito", LblUsuario.Text))
|
|
params.Add(New ReportParameter("Folio", LbFolio.Text))
|
|
params.Add(New ReportParameter("Observaciones", TxtObservaciones.Text))
|
|
params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Usuario))
|
|
'NUEVOS
|
|
params.Add(New ReportParameter("ClienteNombre", ClienteNombre))
|
|
params.Add(New ReportParameter("EnvioContacto", EnvioContacto))
|
|
params.Add(New ReportParameter("EnvioDireccion", EnvioDireccion))
|
|
params.Add(New ReportParameter("EnvioColonia", EnvioColonia))
|
|
params.Add(New ReportParameter("EnvioCiudad", EnvioCiudad))
|
|
params.Add(New ReportParameter("EnvioEstado", EnvioEstado))
|
|
params.Add(New ReportParameter("ClientePais", ClientePais))
|
|
params.Add(New ReportParameter("EnvioCP", EnvioCP))
|
|
params.Add(New ReportParameter("Contrato", Contrato))
|
|
params.Add(New ReportParameter("Paqueteria", DdlPaqueteria.SelectedItem.Text))
|
|
params.Add(New ReportParameter("NumeroContrato", NumContrato))
|
|
params.Add(New ReportParameter("FechaEnvio", TxtFecha.Text.Substring(0, 10)))
|
|
params.Add(New ReportParameter("TieneSerie", GvDatos.Columns(5).Visible.ToString()))
|
|
|
|
Dim RutaFormato As String = String.Format("Empresas\{0}\Formatos\RepTrasladoSolicitud.rdlc", UsuarioActual.CveEmpresa)
|
|
Dim RutaFormatoDefault As String = String.Format("Empresas\Grales\Formatos\RepTrasladoSolicitud.rdlc")
|
|
|
|
Dim Archivo As New System.IO.FileInfo(RutaFormato)
|
|
|
|
|
|
If Imagen.Exists Then
|
|
params.Add(New ReportParameter("LogoPath", logouri))
|
|
Else
|
|
params.Add(New ReportParameter("LogoPath", ""))
|
|
End If
|
|
|
|
If UsuarioActual.CveEmpresa = 72 Or UsuarioActual.CveEmpresa = 1 Then
|
|
ImprimirPDF(String.Format("Empresas\{0}\Formatos\RepTrasladoSolicitud.rdlc", UsuarioActual.CveEmpresa), dt, params, String.Format("Solicitud de Traslado - {0}", Now.ToDateTime.ToShortDateString), Formato:=Formato)
|
|
Else
|
|
ImprimirPDF(RutaFormatoDefault, dt, params, String.Format("Solicitud de Traslado - {0}", Now.ToDateTime.ToShortDateString), Formato:=Formato)
|
|
End If
|
|
|
|
Else
|
|
Alert("Ocurrió un error al obtener los datos del traspaso.", TipoMensaje.MsgError)
|
|
End If
|
|
|
|
End If
|
|
ObjInventarios.Dispose()
|
|
ObjClientes.Dispose()
|
|
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
|
|
#Region "Carga Excel"
|
|
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 = ModExtensiones.DirectorioBaseEmpresas & file.patch
|
|
Dim Tipo As String = If(file.Extencion.Contiene("xlsx", "xlsx", "xlsm", "xlsb"), "EXCEL", "CSV")
|
|
CargarArchivo(Directorio, file.filename, Tipo)
|
|
Else
|
|
Alert("No existe el archivo.Favor de subir un archivo csv o excel a la plataforma", TipoMensaje.MsgError)
|
|
End If
|
|
End Sub
|
|
|
|
|
|
Private Sub CargarArchivo(Ruta As String, FileName As String, Tipo As String)
|
|
Dim dt As New DataTable
|
|
Dim Conexion As Odbc.OdbcConnection = Nothing
|
|
Dim ErrorArchivo = False
|
|
Dim ErrorExcel = False
|
|
Dim strConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + Ruta + FileName + ";Extended Properties=Excel 8.0;"
|
|
Dim objDbFactory As Common.DbProviderFactory = Common.DbProviderFactories.GetFactory("System.Data.OleDb")
|
|
Dim objDbAdapter As Common.DbDataAdapter = objDbFactory.CreateDataAdapter()
|
|
Dim objDbConnection As Common.DbConnection = objDbFactory.CreateConnection()
|
|
objDbConnection.ConnectionString = strConnString
|
|
objDbConnection.Open()
|
|
Dim objSheetNames As DataTable = objDbConnection.GetSchema("Tables")
|
|
Dim HojaExcel As String = objSheetNames.FiltroPrimeroValor("TABLE_NAME")
|
|
Try
|
|
Select Case Tipo
|
|
Case "CSV"
|
|
Conexion = New Odbc.OdbcConnection("Driver={Microsoft Access Text Driver (*.txt, *.csv)};Dbq=" + Ruta + ";Extensions=asc,csv,tab,txt;")
|
|
Conexion.Open()
|
|
Dim cmd = Conexion.CreateCommand()
|
|
cmd.CommandType = CommandType.Text
|
|
cmd.CommandText = $"SELECT * FROM [{FileName}]"
|
|
Dim DataAdapter = New Odbc.OdbcDataAdapter(cmd)
|
|
DataAdapter.Fill(dt)
|
|
Case "EXCEL"
|
|
Conexion = New Odbc.OdbcConnection("Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + Ruta + FileName + ";")
|
|
Conexion.Open()
|
|
Dim cmd = Conexion.CreateCommand()
|
|
cmd.CommandType = CommandType.Text
|
|
cmd.CommandText = $"SELECT * FROM [{HojaExcel}]"
|
|
Dim DataAdapter = New Odbc.OdbcDataAdapter(cmd)
|
|
DataAdapter.Fill(dt)
|
|
Case Else
|
|
Alert("El archivo no tiene el formato correcto", TipoMensaje.MsgError)
|
|
Exit Sub
|
|
End Select
|
|
Catch ex As Exception
|
|
ErrorArchivo = True
|
|
OnError("Ocurrio un error al leer el archivo <br/>" & ex.Message, ex)
|
|
End Try
|
|
Conexion.Close()
|
|
|
|
|
|
Dim DTContratosTemporal As New DataTable
|
|
Dim ObjContratos As New ClsContratos
|
|
If ObjContratos.GetContratosDetalle(DdlContratos.SelectedValue.ToEntero) Then
|
|
DTContratosTemporal = ObjContratos.DtResultados
|
|
End If
|
|
ObjContratos.Dispose()
|
|
|
|
If DTContratosTemporal IsNot Nothing Then
|
|
If Not ErrorArchivo Then
|
|
For Each Row As DataRow In dt.FiltraParametros("Cantidad > 0").Rows
|
|
Dim Cantidad As String = Row("Cantidad").ToString
|
|
Dim Codigo As String = Row("Codigo").ToString.Trim
|
|
Dim Observaciones As String = Row("Observaciones").ToString
|
|
Dim CodigoPS As String = ""
|
|
Dim CodigoContrato As String = ""
|
|
|
|
CodigoPS = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimeroValor("PSCodigo", $"Codigo = '{Codigo}'")
|
|
|
|
CodigoContrato = DTContratosTemporal.FiltroPrimeroValor("Codigo", $"Codigo = '{Codigo}'").ToString
|
|
|
|
If CodigoContrato <> "" Then
|
|
Dim RowTemp As DataRow = TempDT.NewRow()
|
|
RowTemp("Cantidad") = Cantidad
|
|
RowTemp("CvePS") = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CvePS", $"Codigo = '{Codigo}'").ToString.ToEntero
|
|
RowTemp("CodigoPS") = CodigoPS
|
|
RowTemp("Observaciones") = Observaciones
|
|
|
|
Dim ObjInventarios As New ClsInventarios
|
|
Dim Existencia As Double = ObjInventarios.GetExistenciasPS(RowTemp("CvePS").ToString.ToEntero, RowTemp("CveUM").ToString.ToEntero, UsuarioActual.CveEmpresa, DdlAlmacenOrigen.SelectedValue.ToEntero, FechaMovto:=TxtFecha.Text.ToDate.ToString("yyyy/MM/dd 23:59"))
|
|
ObjInventarios.Dispose()
|
|
|
|
If Existencia - RowTemp("Cantidad").ToString.ToDouble - TempDT.SUM("Cantidad", $"CvePS = {RowTemp("CvePS").ToString.ToEntero} AND CveUM = {RowTemp("CveUM").ToString.ToEntero}") < 0 Then
|
|
If Existencia = 0 Then
|
|
Alert($"No hay existencia del producto: {CodigoPS}", TipoMensaje.MsgAdvertencia)
|
|
Else
|
|
Alert($"No hay existencia suficiente del producto: {CodigoPS}, Solo hay en existencia: {Existencia}", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
End If
|
|
TempDT.Rows.Add(RowTemp)
|
|
Else
|
|
Alert($"El Código: ""<b>{CodigoPS}</b>"", no se encuentra en el contrato.", TipoMensaje.MsgAdvertencia)
|
|
Exit For
|
|
End If
|
|
|
|
Next
|
|
|
|
GvDatos.DataSource = TempDT
|
|
GvDatos.DataBind()
|
|
CargaTextoContrato()
|
|
UpDatos.Update()
|
|
RegistraScript(String.Format("$('#{0}').modal().hide();", "ModalContrato"))
|
|
|
|
End If
|
|
Else
|
|
Alert($"Ha ocurrido un error al cargar el contrato.", TipoMensaje.MsgError)
|
|
|
|
End If
|
|
|
|
|
|
End Sub
|
|
|
|
|
|
Public Sub CargaTextoContrato()
|
|
If DdlContratos.SelectedValue.ToEntero > 0 Then
|
|
LbContratos.Text = DdlContratos.SelectedItem.Text
|
|
Else
|
|
LbContratos.Text = ""
|
|
End If
|
|
UpDatos.Update()
|
|
End Sub
|
|
|
|
Private Sub LbContratos_Click(sender As Object, e As EventArgs) Handles LbContratos.Click
|
|
RegistraScript(String.Format("$('#{0}').modal().show();", "ModalContrato"))
|
|
End Sub
|
|
|
|
Protected Sub BtnDescargar_Click(sender As Object, e As EventArgs) Handles BtnDescargar.Click
|
|
Dim Directorio As String = ""
|
|
Directorio = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\SolicitudTraslado.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
|
|
|
|
|
|
#End Region
|
|
|
|
|
|
Protected Sub DdlProductoServicio_selectedindexchange(sender As Object, e As EventArgs)
|
|
If DdlProductoServicio.SelectedValue.ToEntero > 0 Then
|
|
Dim drPS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlProductoServicio.SelectedValue.ToEntero).FiltroPrimero("")
|
|
DdlUM.Items.Clear()
|
|
If UsuarioActual.Empresa.UsaInventarios Then
|
|
DdlUM.DataSource = GlobalDTProductosServiciosEquivalencias(DdlProductoServicio.SelectedValue.ToEntero, -1, UsuarioActual.CveEmpresa)
|
|
Else
|
|
DdlUM.DataSource = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa)
|
|
End If
|
|
DdlUM.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
DdlUM.SelectedValue = "-1"
|
|
DdlUM.DataBind()
|
|
DdlUM.SelectedValueExist(drPS("CveUnidadMedida").ToString)
|
|
Dim AplicaSerie As Boolean = drPS("AplicaSerie").ToString = "True"
|
|
Div4.Visible = AplicaSerie
|
|
End If
|
|
UpPS.Update()
|
|
UpDatos.Update()
|
|
End Sub
|
|
|
|
|
|
Protected Sub LnkAceptarTraslado_Click(sender As Object, e As EventArgs)
|
|
|
|
Dim ObjInven As New ClsInventarios
|
|
If ObjInven.UpdateTrasladoAutorizar(CveTraspasoSolicitud, UsuarioActual.CveEmpresa, 2, UsuarioActual.CveUsuario, Now) Then
|
|
Alert("Autorizado correctamente.")
|
|
End If
|
|
ObjInven.Dispose()
|
|
|
|
CargaDatos()
|
|
|
|
End Sub
|
|
|
|
Protected Sub LnkRechazarTraslado_Click(sender As Object, e As EventArgs)
|
|
|
|
TxtMotivoRechazo.Text = ""
|
|
UpModalRechazo.Update()
|
|
RegistraScript("$('#ModalRechazarTraslado').modal();")
|
|
|
|
End Sub
|
|
|
|
|
|
Protected Sub BtnModalRechazo_Click(sender As Object, e As EventArgs)
|
|
RechazarTraslado()
|
|
End Sub
|
|
|
|
Private Sub RechazarTraslado()
|
|
|
|
Dim ErrorProceso As Boolean = False
|
|
|
|
If TxtMotivoRechazo.Text.Trim.Length.ToEntero = 0 Then
|
|
Alert("El motivo de rechazo es necesario", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
|
|
|
|
Dim ObjInven As New ClsInventarios
|
|
|
|
If ObjInven.UpdateTrasladoAutorizar(CveTraspasoSolicitud, UsuarioActual.CveEmpresa, 3, UsuarioActual.CveUsuario, Now) Then
|
|
Alert("Rechazado correctamente.")
|
|
ErrorProceso = False
|
|
Else
|
|
ErrorProceso = True
|
|
End If
|
|
|
|
ObjInven.Dispose()
|
|
|
|
If Not ErrorProceso Then
|
|
MandaCorreoRechazo(LbFolio.Text.ToEntero, CveTraspasoSolicitud, CveUsuarioSolicita, TxtMotivoRechazo.Text)
|
|
CargaDatos()
|
|
RegistraScript("$('#ModalRechazarTraslado').modal('hide');")
|
|
|
|
|
|
|
|
End If
|
|
|
|
End Sub
|
|
|
|
|
|
Private Sub MandaCorreoRechazo(Folio As Integer, CveTraspasoSolicitud As Integer, CveUsuarioSolicita As Integer, MotivoRechazo As String)
|
|
|
|
Dim SB As New StringBuilder
|
|
|
|
Dim CorreoDestino As String = GlobalDTUsuarios(CveUsuarioSolicita)(0)("Correo").ToString.Trim
|
|
|
|
|
|
If CorreoDestino.Length > 0 Then
|
|
|
|
|
|
SB.AppendLine($"<p>Se ha rechazado la solicitud de traspaso con folio {Folio}, el traspaso fue rechazado por el usuario {UsuarioActual.Nombre }, el traspaso fue rechazado por el motivo: {MotivoRechazo} </p>")
|
|
|
|
|
|
|
|
SB.AppendLine("<br>")
|
|
SB.AppendLine("<table border = '0'>")
|
|
SB.AppendLine("<tr style='color:white;background-color:#808080;' ><th>Cantidad</th> <th>U.M.</th> <th>Producto</th> <th>Observaciones</th> </tr>")
|
|
|
|
For Each GvRow As GridViewRow In GvDatos.Rows
|
|
|
|
If GvRow.RowType = DataControlRowType.DataRow Then
|
|
SB.AppendLine($"<tr style='background-color:#F2F2F0;'> <td>{GvRow.DataKey("Cantidad")}</td> <td>{GvRow.DataKey("UnidadMedida")}</td> <td>{GvRow.DataKey("CodigoPS")}</td> <td>{GvRow.DataKey("Observaciones")}</td> </tr>")
|
|
End If
|
|
|
|
Next
|
|
SB.AppendLine("</table>")
|
|
SB.AppendLine("<br>")
|
|
|
|
SB.AppendLine($"<strong> <a href='{Request.Url.GetLeftPart(UriPartial.Authority)}/Inventarios/TrasladoSolicitud.aspx?CveTraspasoSolicitud={CveTraspasoSolicitud}'>Ir a solicitud de traspaso folio {Folio}</a></strong>")
|
|
|
|
|
|
|
|
Dim MandaCorre As New ClsSisMail
|
|
MandaCorre.SendMail(ClsPaginas.EmpresaNotificaciones, CorreoDestino, $"Rechazo de Autorización de traspaso #{Folio}", SB.ToString, Displayname:="SIG Notificaciones: Rechazo de Traspaso")
|
|
|
|
End If
|
|
|
|
End Sub
|
|
|
|
|
|
Private Sub MandaCorreoAutorizacion(Folio As Integer, CveTraspasoSolicitud As Integer, CveUsuarioAutoriza As Integer)
|
|
|
|
Dim SB As New StringBuilder
|
|
|
|
Dim CorreoDestino As String = GlobalDTUsuarios(CveUsuarioAutoriza)(0)("Correo").ToString.Trim
|
|
|
|
|
|
If CorreoDestino.Length > 0 Then
|
|
|
|
|
|
|
|
SB.AppendLine($"<p>Se ha registrado una solicitud de traspaso de {DdlAlmacenOrigen.SelectedItem.Text} a {DdlAlmacenDestino.SelectedItem.Text}, con los siguientes productos.</p>")
|
|
|
|
|
|
|
|
SB.AppendLine("<br>")
|
|
SB.AppendLine("<table border = '0'>")
|
|
SB.AppendLine("<tr style='color:white;background-color:#808080;' ><th>Cantidad</th> <th>U.M.</th> <th>Producto</th> <th>Observaciones</th> </tr>")
|
|
|
|
For Each GvRow As GridViewRow In GvDatos.Rows
|
|
|
|
If GvRow.RowType = DataControlRowType.DataRow Then
|
|
SB.AppendLine($"<tr style='background-color:#F2F2F0;'> <td>{GvRow.DataKey("Cantidad")}</td> <td>{GvRow.DataKey("UnidadMedida")}</td> <td>{GvRow.DataKey("CodigoPS")}</td> <td>{GvRow.DataKey("Observaciones")}</td> </tr>")
|
|
End If
|
|
|
|
Next
|
|
SB.AppendLine("</table>")
|
|
SB.AppendLine("<br>")
|
|
SB.AppendLine($"<strong> <a href='{Request.Url.GetLeftPart(UriPartial.Authority)}/Inventarios/TrasladoSolicitud.aspx?CveTraspasoSolicitud={CveTraspasoSolicitud}'>Ir a solicitud de traspaso para autorización</a></strong>")
|
|
|
|
|
|
|
|
Dim MandaCorre As New ClsSisMail
|
|
MandaCorre.SendMail(ClsPaginas.EmpresaNotificaciones, CorreoDestino, $"Solicitud de Autorización de traspaso #{Folio}", SB.ToString, Displayname:="SIG Notificaciones: Solicitud de Traspaso")
|
|
|
|
End If
|
|
|
|
End Sub
|
|
|
|
Public Sub MostarSerieColumn()
|
|
Dim Mostrar As Boolean = False
|
|
For Each row As GridViewRow In GvDatos.Rows
|
|
Dim Serie As String = row.DataKey("Serie").ToString
|
|
If Serie IsNot "-1" And Serie IsNot "" Then
|
|
Mostrar = True
|
|
Exit For
|
|
End If
|
|
Next
|
|
GvDatos.Columns(5).Visible = Mostrar
|
|
End Sub
|
|
|
|
End Class
|
|
|