Files
SIG/Inventarios/EntregaAlmacen.aspx.vb

4072 lines
218 KiB
VB.net

Option Strict On
Option Explicit On
Imports System.Data
Imports System.Data.Entity.Core.Common.CommandTrees
Imports System.IO
Imports Extensiones
Imports Microsoft.Reporting.WebForms
Imports Stimulsoft.Base.Indicator
Partial Class Inventarios_EntregaAlmacen
Inherits ClsPaginas
#Region "PROPIEDADES"
Private Property CveVentaAD As Integer
Get
Return CType(ViewState("CveVentaAD"), Integer)
End Get
Set(value As Integer)
ViewState("CveVentaAD") = value
End Set
End Property
Private Property DtDatos As DataTable
Get
Return CType(ViewState("DtDatos"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtDatos") = value
End Set
End Property
Private Property DtDatosDetalle As DataTable
Get
Return CType(ViewState("DtDatosDetalle"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtDatosDetalle") = value
End Set
End Property
Private Property DtDatosSugerencias As DataTable
Get
Return CType(ViewState("DtDatosSugerencias"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtDatosSugerencias") = value
End Set
End Property
Private Property DtDatosDetalleLote As DataTable
Get
Return CType(ViewState("DtDatosDetalleLote"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtDatosDetalleLote") = value
End Set
End Property
Private Property PSSerie As String
Get
Return CType(ViewState("PSSerie"), String)
End Get
Set(value As String)
ViewState("PSSerie") = value
End Set
End Property
Private Property CveConsecSerie As Integer
Get
Return CType(ViewState("CveConsecSerie"), Integer)
End Get
Set(value As Integer)
ViewState("CveConsecSerie") = value
End Set
End Property
Private Property CvePSSerie As Integer
Get
Return CType(ViewState("CvePSSerie"), Integer)
End Get
Set(value As Integer)
ViewState("CvePSSerie") = value
End Set
End Property
Private Property CveUMSerie As Integer
Get
Return CType(ViewState("CveUMSerie"), Integer)
End Get
Set(value As Integer)
ViewState("CveUMSerie") = value
End Set
End Property
Private Property EsInterno As Boolean
Get
Return CBool(If(ViewState("EsInterno") Is Nothing, 0, ViewState("EsInterno")))
End Get
Set(value As Boolean)
ViewState("EsInterno") = value
End Set
End Property
Private Property CveMetodoInventario As Integer
Get
Return CType(ViewState("CveMetodoInventario"), Integer)
End Get
Set(value As Integer)
ViewState("CveMetodoInventario") = value
End Set
End Property
Private Property CveVentaSurtir As Integer
Get
Return CType(ViewState("CveVentaSurtir"), Integer)
End Get
Set(value As Integer)
ViewState("CveVentaSurtir") = value
End Set
End Property
Private Property TipoEstatus As Integer
Get
Return CType(ViewState("TipoEstatus"), Integer)
End Get
Set(value As Integer)
ViewState("TipoEstatus") = value
End Set
End Property
Private Property CveContrato As Integer
Get
Return CType(ViewState("CveContrato"), Integer)
End Get
Set(value As Integer)
ViewState("CveContrato") = value
End Set
End Property
Private Property CveAlmacenTraspasoOrigen As Integer
Get
Return CType(ViewState("CveAlmacenTraspasoOrigen"), Integer)
End Get
Set(value As Integer)
ViewState("CveAlmacenTraspasoOrigen") = value
End Set
End Property
Private Property CveAlmacenTraspasoDestino As Integer
Get
Return CType(ViewState("CveAlmacenTraspasoDestino"), Integer)
End Get
Set(value As Integer)
ViewState("CveAlmacenTraspasoDestino") = value
End Set
End Property
Private Property TipoMovimiento As Integer
Get
Return CType(ViewState("TipoMovimiento"), Integer)
End Get
Set(value As Integer)
ViewState("TipoMovimiento") = value
End Set
End Property
Private Property TipoDocto As String
Get
Return CType(ViewState("TipoDocto"), String)
End Get
Set(value As String)
ViewState("TipoDocto") = value
End Set
End Property
Private Property DtExistencias As DataTable
Get
Return CType(ViewState("DtExistencias"), DataTable)
End Get
Set(value As DataTable)
ViewState("DtExistencias") = value
End Set
End Property
Private Property RowIndexCantidadEspecial As Integer
Get
Return CType(ViewState("RowIndexCantidadEspecial"), Integer)
End Get
Set(value As Integer)
ViewState("RowIndexCantidadEspecial") = value
End Set
End Property
Private Property CantidadEspecialTemp As Decimal
Get
Return CType(ViewState("CantidadEspecialTemp"), Decimal)
End Get
Set(value As Decimal)
ViewState("CantidadEspecialTemp") = value
End Set
End Property
Private Property EsDevolucionVenta As Integer
Get
Return CType(ViewState("EsDevolucionVenta"), Integer)
End Get
Set(value As Integer)
ViewState("EsDevolucionVenta") = value
End Set
End Property
Private Property CveVendedor As Integer
Get
Return CType(ViewState("CveVendedor"), Integer)
End Get
Set(value As Integer)
ViewState("CveVendedor") = value
End Set
End Property
Private Property CveSubProyecto As Integer
Get
Return CType(ViewState("CveSubProyecto"), Integer)
End Get
Set(value As Integer)
ViewState("CveSubProyecto") = value
End Set
End Property
Private Property CveOP As Integer
Get
Return CType(ViewState("CveOP"), Integer)
End Get
Set(value As Integer)
ViewState("CveOP") = value
End Set
End Property
Private Property CveCliente As Integer
Get
Return CType(ViewState("CveCliente"), Integer)
End Get
Set(value As Integer)
ViewState("CveCliente") = value
End Set
End Property
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 CveMovimiento As Integer
Get
Return CType(ViewState("CveMovimiento"), Integer)
End Get
Set(value As Integer)
ViewState("CveMovimiento") = value
End Set
End Property
Private Property CveTraspasoSurtir As Integer
Get
Return CType(ViewState("CveTraspasoSurtir"), Integer)
End Get
Set(value As Integer)
ViewState("CveTraspasoSurtir") = value
End Set
End Property
Private Property TipoEntrega As Integer
Get
Return CType(ViewState("TipoEntrega"), Integer)
End Get
Set(value As Integer)
ViewState("TipoEntrega") = value
End Set
End Property
Private Property EsDevolucionDirecta As Boolean
Get
Return CBool(If(ViewState("EsDevolucionDirecta") Is Nothing, 0, ViewState("EsDevolucionDirecta")))
End Get
Set(value As Boolean)
ViewState("EsDevolucionDirecta") = value
End Set
End Property
Private Property FormaPaqueteria As Integer
Get
Return CType(ViewState("FormaPaqueteria"), Integer)
End Get
Set(value As Integer)
ViewState("FormaPaqueteria") = value
End Set
End Property
Private Property ValidaLoteCaducidad As Boolean
Get
Return CType(ViewState("ValidaLoteCaducidad"), Boolean)
End Get
Set(value As Boolean)
ViewState("ValidaLoteCaducidad") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
InicializaValores()
CargaParametrosAD()
If UsuarioActual.CveEmpresa.Contiene(1, 72, 80, 146, 119) Then DdlAlmacen.AutoPostBack = True
If UsuarioActual.Empresa.Funcionalidad(281).ToEntero() = 1 Then
TxtFecha.Enabled = False
ImgFecha.Visible = False
End If
End If
End Sub
#Region " INICIALIZA VALORES "
Private Sub InicializaValores()
TipoEstatus = -1
CveVendedor = -1
CveCliente = -1
CveSubProyecto = -1
DtDatosSugerencias = New DataTable
Dim StrAlmacenes As String = "CveTipoAlmacen IN (1,2)"
If (UsuarioActual.Empresa.Funcionalidad(105) = "1" Or UsuarioActual.Empresa.Funcionalidad(141) = "1") Then
DdlClientes.setEsWebService(True)
DdlClientes.Attributes.Add("data-metodo", "getcliente")
DdlClientes.SelectedText = "Todos"
DdlClientes.SelectedValue = "-1"
Else
DdlClientes.setEsWebService(False)
DdlClientes.ddl.DataSource = GlobalDTCliente(UsuarioActual.CveEmpresa)
DdlClientes.ddl.DataBind()
DdlClientes.ddl.Items.Insert(0, New ListItem("Todos", "-1"))
End If
If UsuarioActual.CveSubProyecto = 8804 Then
StrAlmacenes = "CveTipoAlmacen IN (1,2,12)"
End If
DdlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros(StrAlmacenes) 'GlobalDTAlmacen(UsuarioActual.CveEmpresa)
DdlAlmacen.Items.Insert(0, New ListItem(" Seleccione ", "-1"))
DdlAlmacen.SelectedValue = "-1"
DdlAlmacen.DataBind()
DdlAlmacen.SelectedValueExist(UsuarioActual.CveAlmacen)
DdlAlmacenTransitorio.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 3)
DdlAlmacenTransitorio.DataBind()
DdlAlmacenTransitorio.Items.Insert(0, New ListItem("Seleccione", "-1"))
DdlFolio.Items.Insert(0, New ListItem("Seleccione", "-1"))
TxtFechaPendientes.Text = Now.ToShortDateString
'TxtFechaCaducidad.Text = Now.ToShortDateString
TxtFecha.Text = Now.ToShortDateString
RVFecha.MaximumValue = MaxFecha.ToShortDateString
If UsuarioActual.CveEmpresa.Contiene(119) Then RVFecha.MinimumValue = Now.ToShortDateString : CEFecha.StartDate = Now Else RVFecha.MinimumValue = MinFecha.ToShortDateString
If Not UsuarioActual.TienePermisoProceso(190) Then
'CARGA SOLO LAS SUCURSALES DE LOS ALMCENES QUE TIENE ASIGNADO EL USUARIO
Dim ObjInventarios As New ClsInventarios
If ObjInventarios.GetSucursalesAlmacenUsuario(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then
DdlSubProyectos.DataSource = ObjInventarios.DtResultados
End If
ObjInventarios.Dispose()
Else
DdlSubProyectos.DataSource = GlobalDTSubProyectos(-1, CveEmpresa:=UsuarioActual.CveEmpresa)
End If
DdlSubProyectos.DataBind()
DdlSubProyectos.SelectedValueExist(UsuarioActual.CveSubProyecto.ToString())
If UsuarioActual.TienePermisoProceso(152) Then DdlSubProyectos.Enabled = False
If UsuarioActual.Empresa.Funcionalidad(280) = "1" Then PnlEntrega.Visible = True
CreaDtDetalle()
CreaDtDetalleLote()
CargaPendientes()
LimpiaCampos()
End Sub
#End Region
#Region " CARGA PARAMETROS - EXCLUSIVO USO AD "
Private Sub CargaParametrosAD()
CveVentaAD = -1
If UsuarioActual.CveUsuario <> 100 Then
Exit Sub
End If
If Not IsNothing(Request("CveVenta")) AndAlso IsNumeric(Request("CveVenta")) Then
CveVentaAD = Request("CveVenta").ToEntero()
CargaVentaPorSurtir(Request("CveVenta").ToEntero())
LbSurtida.Visible = True
LbSurtida.Text = "SOLO MODO VISUAL"
BtnGuardar.Visible = False
End If
End Sub
#End Region
#Region " CARGA PENDIENTES POR SURTIR "
Protected Sub DdlCliente_SelectedIndexChanged(sender As Object, e As EventArgs)
CargaFolios()
End Sub
Private Sub CargaFolios()
Dim ObjInventarios As New ClsInventarios
DdlFolio.Items.Clear()
If DdlClientes.SelectedValue.ToEntero() > 0 Then
If ObjInventarios.VentasPendientesAlmacenGet(DdlClientes.SelectedValue.ToEntero(), MinFecha, DdlSubProyectos.SelectedValue.ToEntero(), UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario) Then
DdlFolio.DataSource = ObjInventarios.DtResultados
Else
Alert("Ocurrió un error al obtener las Compras pendientes de recibir del proveedor. Por favor vuelva a intentar", TipoMensaje.MsgError)
End If
End If
ObjInventarios.Dispose()
DdlFolio.DataBind()
DdlFolio.Items.Insert(0, New ListItem("Seleccione", "-1"))
UpFiltros.Update()
End Sub
Protected Sub TimmerRefresh_Tick(sender As Object, e As EventArgs)
CargaPendientes()
End Sub
Protected Sub BtnConsultarPendientes_Click(sender As Object, e As EventArgs)
CargaPendientes()
End Sub
Private Sub CargaPendientes()
DivTipoCambioAdvertencia.Visible = False
Dim ObjInventarios As New ClsInventarios
Dim DtPendientes As New DataTable
If ObjInventarios.VentasPendientesAlmacenGet(-1, TxtFechaPendientes.Text.ToDate, DdlSubProyectos.SelectedValue.ToEntero(), UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario) Then
If UsuarioActual.TienePermisoProceso(266) AndAlso UsuarioActual.TienePermisoProceso(267) Then
DtPendientes = ObjInventarios.DtResultados.FiltraParametros("TipoDocto IN ('Ing','Dev','Rem','Traspaso','Ped','PDev','DPe','Ant')")
ElseIf UsuarioActual.TienePermisoProceso(266) AndAlso Not UsuarioActual.TienePermisoProceso(267) Then
DtPendientes = ObjInventarios.DtResultados.FiltraParametros("TipoDocto IN ('Ing','Dev','Rem','Traspaso','Ant')")
ElseIf UsuarioActual.TienePermisoProceso(267) AndAlso Not UsuarioActual.TienePermisoProceso(266) Then
DtPendientes = ObjInventarios.DtResultados.FiltraParametros("TipoDocto IN ('Ped','PDev','DPe')")
Else
DtPendientes = ObjInventarios.DtResultados
End If
Else
DtPendientes = Nothing
Alert("Ocurrió un error al obtener las Compras pendientes de recibir del proveedor. Por favor vuelva a intentar", TipoMensaje.MsgError)
End If
If UsuarioActual.Empresa.Funcionalidad(540) = "1" Then
BtnGuardar.Enabled = False
Dim FI As Date = Now.AddDays(-1)
Dim FF As Date = Now.AddDays(-7)
If ObjInventarios.RepNotasSinAlmacen(1, -1, FI, FF, "-1", -1, UsuarioActual.Empresa.CveEmpresa) Then
If ObjInventarios.DtResultados IsNot Nothing AndAlso ObjInventarios.DtResultados.Rows.Count > 1 Then
BtnGuardar.Enabled = False
Alert("No se podrá realizar entrega de mercancía si no se les da salida a los documentos pendientes. Para más información ver el Reporte de notas sin entrada en la sección Ventas.", TipoMensaje.MsgAdvertencia)
Else
BtnGuardar.Enabled = True
End If
End If
End If
ObjInventarios.Dispose()
If DtPendientes IsNot Nothing Then
GVPendientes.DataSource = DtPendientes
End If
LtActualizado.Text = String.Format("Actualizado: {0}", Now.ToString("H:mm"))
GVPendientes.DataBind()
UpPendientes.Update()
If DtPendientes IsNot Nothing Then DtPendientes.Dispose()
End Sub
Protected Sub GVPendientes_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GVPendientes.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.FCLinkButton("BtnSurtir").CommandArgument = If(e.Row.DBCampo("TipoEntrega") = "1", e.Row.DBCampo("CveVenta"), e.Row.DBCampo("CveTraspasoSolicitud"))
Select Case e.Row.DBCampo("TipoEntrega").ToString().ToEntero()
Case 1
If UsuarioActual.TienePermisoProceso(201) Then
Dim Css = "Texto"
Dim Liga = $"/Ventas/Ventas.aspx?&CveVenta={e.Row.DBCampo("CveVenta")}"
e.Row.FCLabel("LblFolio").Text = "<a class=" + "" + Css + "" + " href=" + "" + Liga + "" + ">" + e.Row.FCLabel("LblFolio").Text + "</a>"
End If
If UsuarioActual.CveEmpresa.Contiene(72, 80) Then
GVPendientes.Columns(4).Visible = True
e.Row.FCHyperLink("HplDownPDF").Visible = True
e.Row.FCHyperLink("HplDownPDF").NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=VTA&CVEVENTA={0}", e.Row.DBCampo("CveVenta"))))
End If
If e.Row.DBCampo("TipoDocto").ToString().Contiene({"Rem", "Ing", "Ped", "PeC", "Ant"}) And e.Row.DBCampo("EsDevolucionVenta").ToString().ToEntero() = 0 Then
e.Row.FCLinkButton("BtnSurtir").CssClass = "btn btn-primary btn-sm"
e.Row.FCLinkButton("BtnSurtir").Text = " Surtir <i class='fa fa-arrow-right' ></i>"
Else
e.Row.FCLinkButton("BtnSurtir").CssClass = "btn yellow-gold btn-sm"
e.Row.FCLinkButton("BtnSurtir").Text = "<i class='fa fa-arrow-left' > Recibir</i>"
End If
Case 2
Dim Css = "Texto"
Dim Liga = $"/Inventarios/TrasladoSolicitud.aspx?&CveTraspasoSolicitud={e.Row.DBCampo("CveTraspasoSolicitud")}"
e.Row.FCLabel("LblFolio").Text = "<a class=" + "" + Css + "" + " href=" + "" + Liga + "" + ">" + e.Row.FCLabel("LblFolio").Text + "</a>"
e.Row.FCLinkButton("BtnSurtir").CssClass = "btn btn-primary btn-sm"
e.Row.FCLinkButton("BtnSurtir").Text = " Traspasar <i class='fa fa-arrow-right' ></i>"
End Select
UpPendientes.Update()
End If
End Sub
#End Region
#Region " CARGA VENTA POR SURTIR "
Protected Sub BtnSurtir_Click(sender As Object, e As EventArgs)
Dim Boton = CType(sender, LinkButton)
CveVentaAD = -1
If Boton.CommandArgument.ToEntero() > 0 Then
TimmerRefresh.Enabled = False
DivTransitorio1.Visible = False
ChkTransitorio.Checked = False
TxtResponsable.Text = ""
DivTransitorio2.Visible = False
Select Case CType(Boton.NamingContainer, GridViewRow).DataKey("TipoEntrega").ToEntero()
Case 1 ' VENTA
CargaVentaPorSurtir(CType(sender, LinkButton).CommandArgument.ToEntero())
Case 2 ' TRASPASO
DivTransitorio1.Visible = True
CargaTraspasoPorSurtir(CType(Boton.NamingContainer, GridViewRow).DataKey("CveTraspasoSolicitud").ToEntero())
End Select
End If
End Sub
Protected Sub BtnBuscar_Click(sender As Object, e As EventArgs)
CveVentaAD = -2
CargaVentaPorSurtir(DdlFolio.SelectedValue.ToEntero())
End Sub
Private Sub CargaVentaPorSurtir(CveVenta As Integer, Optional CveAlmacen As Integer = -1)
LbSurtida.Visible = False
CveContrato = -1
CveSubProyecto = -1
CveOP = -1
DtDatos = Nothing
TipoEntrega = 1
BtnGuardar.Visible = True
Dim StrAlmacenes As String = "CveTipoAlmacen IN (1,2,26)"
If UsuarioActual.CveSubProyecto = 8804 Then
StrAlmacenes = "CveTipoAlmacen IN (1,2,12)"
End If
Dim ObjInventario As New ClsInventarios
If ObjInventario.EntregaAlmacenGet(CveVenta, CveAlmacen) Then
If ObjInventario.DtResultados IsNot Nothing AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then
DtDatos = ObjInventario.DtResultados
If Not DtDatos.Columns.Contains("Consec") Then DtDatos.Columns.Add("Consec", GetType(Integer))
If Not DtDatos.Columns.Contains("CantidadGV") Then DtDatos.Columns.Add("CantidadGV", GetType(Double))
If Not DtDatos.Columns.Contains("CantidadTraspaso") Then DtDatos.Columns.Add("CantidadTraspaso", GetType(Double))
Dim Index = 1
For Each Dr As DataRow In DtDatos.Rows
Dr("Consec") = Index
Index += 1
Next
DtDatosDetalle = Nothing
CreaDtDetalle()
DtDatosDetalleLote = Nothing
CreaDtDetalleLote()
If DtDatos.Rows(0) IsNot Nothing Then
Dim drE As DataRow = DtDatos.Rows(0)
EsDevolucionVenta = drE("EsDevolucionVenta").ToString().ToEntero()
TipoDocto = DtDatos.Rows(0)("TipoDocto").ToString()
TipoMovimiento = If(TipoDocto.Contiene({"Rem", "Ing", "Ped", "PeC", "Ant"}) And (EsDevolucionVenta = 0 Or CveVentaAD > 0), 1, 2)
LbCliente.Text = DtDatos.Rows(0)("Nombre").ToString()
HLFolio.Text = drE("SerieFolio").ToString()
If UsuarioActual.TienePermisoProceso(201) Then
HLFolio.NavigateUrl = $"/Ventas/Ventas.aspx?CveVenta={CveVenta}"
End If
'filtra los Almacenes de domicilio
If DtDatos.Rows(0)("ServicioDomicilio").ToString() = "True" Then
StrAlmacenes = String.Format("{0} AND Almacen like '%Domicilio%' ", StrAlmacenes)
Else
StrAlmacenes = String.Format("{0} AND NOT (Almacen like '%Domicilio%') ", StrAlmacenes)
End If
trObsGral.Visible = drE("Observaciones").ToString() <> ""
LbObservaciones.Text = DtDatos.Rows(0)("Observaciones").ToString()
trObsAlmacen.Visible = drE("ObservacionesAlmacen").ToString() <> ""
LbObservacionesAlmacen.Text = drE("ObservacionesAlmacen").ToString()
CveVentaSurtir = CveVenta
CveAlmacenTraspasoDestino = drE(If(EsDevolucionVenta = 1 And TipoDocto <> "Rem", "CveAlmacenTraspasoOrigen", "CveAlmacenTraspasoDestino")).ToString().ToEntero()
CveAlmacenTraspasoOrigen = drE(If(EsDevolucionVenta = 1 And TipoDocto <> "Rem", "CveAlmacenTraspasoDestino", "CveAlmacenTraspasoOrigen")).ToString().ToEntero()
CveContrato = drE("CveContrato").ToString().ToEntero()
CveVendedor = drE("CveVendedor").ToString().ToEntero()
CveCliente = drE("CveCliente").ToString().ToEntero()
ClienteEntregaPersonal(CveCliente)
CveSubProyecto = drE("CveSubProyecto").ToString().ToEntero()
EsInterno = CBool(DtDatos.Rows(0)("EsInterno").ToString())
CveDireccionEnvio = drE("CveDireccionEnvio").ToString.ToEntero
If CveDireccionEnvio > 0 Then
trDireccionEnvio.Visible = True
'carga la dirección de envío
Dim ObjClientes As New ClsClientes
If ObjClientes.DireccionEnvioGet(CveDireccionEnvio, CveCliente, -1) Then
Dim drenvio As DataRow = ObjClientes.DtResultados.FiltroPrimero("")
LblDirEnvio.Text = drenvio("SucursalClienteVentaDireccion").ToString
End If
ObjClientes.Dispose()
Else
trDireccionEnvio.Visible = False
End If
If DtDatos.SUM("CantidadS") <= 0 Then
GvDatos.CssClass = "table table-striped table-hover Widthall ScrollAD gvInventario gvEscondeColumna"
Else
GvDatos.CssClass = "table table-striped table-hover Widthall ScrollAD gvInventario"
End If
If CveAlmacenTraspasoDestino > 0 And Not (TipoMovimiento = 2 And TipoDocto = "Rem") Then
DivTipoCambioAdvertencia.Visible = True
LtTipoCambioAdvertencia.Text = $"Los productos seran Trasladados al Almacen: <b>{GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Almacen", $"CveAlmacen = {CveAlmacenTraspasoDestino}")}</b>"
Else
DivTipoCambioAdvertencia.Visible = False
End If
'DEVOLUCION REMISION
If TipoMovimiento = 2 And TipoDocto = "Rem" And Not CveAlmacenTraspasoDestino > 0 Then
Alert("La remisión que se intenta devolver presenta inconsistencias. Comuniquese con servicio tecnico SIG.", TipoMensaje.MsgError)
BtnGuardar.Visible = False
End If
If CveAlmacen <= 0 Then
DdlAlmacen.Items.Clear()
If CveAlmacenTraspasoOrigen > 0 Then 'Not (EsDevolucionVenta = 1 And DtDatos.Rows(0)("TipoDocto").ToString() = "Rem" And UsuarioActual.Empresa.Funcionalidad(145) = "1") - ESTO ES PARA CUANDO SEA REMISION DE ENTREGA POR ADELANTADO FUNCIONA LA DEVOLUCION
DdlAlmacen.Items.Clear()
DdlAlmacen.Items.Insert(0, New ListItem(GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Almacen", $"CveAlmacen = {CveAlmacenTraspasoOrigen}"), CveAlmacenTraspasoOrigen.ToString()))
Else
'[IPP] PARCHE - Debe hacerse permiso proceso - 17Enero2018
Dim RestriccionAlmacenSubProyecto = If(UsuarioActual.CveEmpresa.Contiene(72, 80), $" AND CveSubProyecto = {CveSubProyecto}", "")
DdlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros($"{StrAlmacenes} {RestriccionAlmacenSubProyecto}")
End If
DdlAlmacen.Items.Insert(0, New ListItem(" Seleccione ", "-1"))
DdlAlmacen.SelectedValue = "-1"
DdlAlmacen.DataBind()
DdlAlmacen.SelectedValueExist(UsuarioActual.CveAlmacen)
If CveAlmacenTraspasoOrigen > 0 Then
DdlAlmacen.SelectedValueExist(CveAlmacenTraspasoOrigen)
End If
End If
If UsuarioActual.CveEmpresa = 119 Then
Dim CveSubProyectoAlmacen As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=CveAlmacen).FiltroPrimeroValor("CveSubProyecto", "").ToEntero
If CveSubProyectoAlmacen.ToString.Contiene(UsuarioActual.Empresa.Funcionalidad(347)) Then
ValidaLoteCaducidad = True
Else
ValidaLoteCaducidad = False
End If
End If
If Not DtDatos.Columns.Contains("Serie") Then DtDatos.Columns.Add("Serie", GetType(String))
If Not DtDatos.Columns.Contains("Lote") Then DtDatos.Columns.Add("Lote", GetType(String))
If Not DtDatos.Columns.Contains("CveSeccion") Then DtDatos.Columns.Add("CveSeccion", GetType(Integer))
If Not DtDatos.Columns.Contains("FechaCaducidad") Then DtDatos.Columns.Add("FechaCaducidad", GetType(Date))
If Not DtDatos.Columns.Contains("Seleccionado") Then DtDatos.Columns.Add("Seleccionado", GetType(Boolean))
If Not DtDatos.Columns.Contains("CantidadSeleccionada") Then DtDatos.Columns.Add("CantidadSeleccionada", GetType(Double))
If UsuarioActual.Empresa.Funcionalidad(280) = "1" Then
FormaPaqueteria = DtDatos.Rows(0)("FormaPaqueteria").ToString().ToEntero()
Dim FormaPaq As Integer = FormaPaqueteria
RbSinEntrega.Checked = False
RbEntregaInterna.Checked = False
RbEntregaExterna.Checked = False
Select Case FormaPaq
Case 1
RbSinEntrega.Checked = True
LnkPaqueteriaDetalle.Visible = False
Case 2
RbEntregaInterna.Checked = True
'LnkPaqueteriaDetalle.Visible = True
DdlEstatus.SelectedValue = "5"
Case 3
RbEntregaExterna.Checked = True
LnkPaqueteriaDetalle.Visible = True
End Select
End If
'TxtFecha.Text = If(EsDevolucionVenta = 1, Now.ToShortDateString, DtDatos.Rows(0)("Fecha").ToString())
End If
If UsuarioActual.Empresa.Funcionalidad(132) = "1" Then
DivCodigoSeriePS.Visible = True
Else
DivCodigoSeriePS.Visible = False
End If
If TipoMovimiento = 2 Then ' cuando es cancelación
Dim Filtro As String '= If(ObjInventario.DtResultados.Rows(0)("TipoDocto").ToString().Contiene({"Ing", "Dev", "Ped"}), "CveConcepto = 3", "CveConcepto = 9")
Select Case ObjInventario.DtResultados.Rows(0)("TipoDocto").ToString()
Case "Ing", "Ped"
Filtro = "CveConcepto IN (3,40)"
Case "Dev"
'cuand es devolucionventa=1, es cancelación de la devolución
If EsDevolucionVenta = 1 Then Filtro = "CveConcepto = 18" Else Filtro = "CveConcepto IN (3,40)"
Case "DPe"
Filtro = "CveConcepto = 9"
Case Else
Filtro = "CveConcepto = 9"
End Select
If ObjInventario.GetInv_Mov(ObjInventario.DtResultados.Rows(0)("CveVentaPadre").ToString().ToEntero(), UsuarioActual.CveEmpresa) Then
DtExistencias = ObjInventario.DtResultados.FiltraParametros($"CvePS Is Not NULL AND {Filtro}")
If Not DtExistencias.Rows.Count > 0 Then
Alert("La Venta original de la Devolución no tiene salida de Almacén.", TipoMensaje.MsgAdvertencia)
End If
If TipoDocto.Contiene("Ing") AndAlso TipoMovimiento = 2 Then
Dim DtMov As DataTable = DtExistencias.FiltraParametros("CveConcepto = 40", "", {"CveAlmacen"})
If DtMov.Rows.Count > 0 AndAlso CveAlmacen <= 0 Then
Dim CveAlmacenDev As Integer = DtMov.Rows(0)("CveAlmacen").ToString().ToEntero()
DdlAlmacen.Items.Clear()
DdlAlmacen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros($"CveAlmacen = {CveAlmacenDev}")
DdlAlmacen.DataBind()
DdlAlmacen.SelectedValueExist(CveAlmacenDev)
EsDevolucionDirecta = True
End If
End If
Else
Alert("Ocurrió un error al cargar los datos de devolución. Por favor vuelva a intentar.", TipoMensaje.MsgError)
End If
End If
If UsuarioActual.Empresa.FacturaProduccion Then
CargaDocumentos(CveVenta)
End If
Else
Alert("No se encontraron productos pendientes por surtir. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
End If
Else
DtDatos = Nothing
End If
ObjInventario.Dispose()
UpGenerales.Update()
If CveAlmacen <= 0 Then CargaGvDatos()
End Sub
Private Sub CargaTraspasoPorSurtir(CveTraspaso As Integer)
LbSurtida.Visible = False
CveContrato = -1
CveSubProyecto = -1
DtDatos = Nothing
TipoEntrega = 2
Dim ObjInventario As New ClsInventarios
If ObjInventario.EntregaAlmacenTraspasosGet(CveTraspaso) Then
If ObjInventario.DtResultados IsNot Nothing AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then
CveTraspasoSurtir = CveTraspaso
TipoMovimiento = 1
DtDatos = ObjInventario.DtResultados
DtDatos.Columns.Add("Consec", GetType(Integer))
DtDatos.Columns.Add("CantidadGV", GetType(Double))
DtDatos.Columns.Add("CantidadTraspaso", GetType(Double))
LbCliente.Text = DtDatos.Rows(0)("Nombre").ToString()
HLFolio.Text = DtDatos.Rows(0)("SerieFolio").ToString()
If UsuarioActual.TienePermisoProceso(201) Then
HLFolio.NavigateUrl = $"/Inventarios/TrasladoSolicitud.aspx?CveTraspasoSolicitud={CveTraspasoSurtir}"
End If
LbObservaciones.Text = DtDatos.Rows(0)("Observaciones").ToString()
Dim Index = 1
For Each Dr As DataRow In DtDatos.Rows
Dr("Consec") = Index
Index += 1
Next
DtDatosDetalle = Nothing
CreaDtDetalle()
DtDatosDetalleLote = Nothing
CreaDtDetalleLote()
CveAlmacenTraspasoDestino = DtDatos.Rows(0)("CveAlmacenDestino").ToString().ToEntero()
CveAlmacenTraspasoOrigen = DtDatos.Rows(0)("CveAlmacenOrigen").ToString().ToEntero()
CveSubProyecto = DtDatos.Rows(0)("CveSubProyecto").ToString().ToEntero()
EsInterno = CBool(DtDatos.Rows(0)("EsInterno").ToString())
CveOP = DtDatos.Rows(0)("CveOP").ToString().ToEntero()
CveVentaSurtir = -1
If DtDatos.SUM("CantidadS") <= 0 Then
GvDatos.CssClass = "table table-striped table-hover Widthall ScrollAD gvInventario gvEscondeColumna"
Else
GvDatos.CssClass = "table table-striped table-hover Widthall ScrollAD gvInventario"
End If
If CveAlmacenTraspasoDestino > 0 Then
DivTipoCambioAdvertencia.Visible = True
LtTipoCambioAdvertencia.Text = $"Los productos seran Trasladados al Almacen: <b>{GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Almacen", $"CveAlmacen = {CveAlmacenTraspasoDestino}")}</b>"
Else
DivTipoCambioAdvertencia.Visible = False
End If
'If DtDatos.Rows.Cast(Of DataRow).Any(Function(Row) Row("CveTamaño").ToString().ToEntero() > 0) Then
'End If
DdlAlmacen.Items.Clear()
If CveAlmacenTraspasoOrigen > 0 Then
DdlAlmacen.Items.Insert(0, New ListItem(GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Almacen", $"CveAlmacen = {CveAlmacenTraspasoOrigen}"), CveAlmacenTraspasoOrigen.ToString()))
End If
DdlAlmacen.Items.Insert(0, New ListItem(" Seleccione ", "-1"))
DdlAlmacen.SelectedValue = "-1"
DdlAlmacen.DataBind()
DdlAlmacen.SelectedValueExist(UsuarioActual.CveAlmacen)
If CveAlmacenTraspasoOrigen > 0 Then
DdlAlmacen.SelectedValueExist(CveAlmacenTraspasoOrigen)
End If
If Not DtDatos.Columns.Contains("CveSeccion") Then
DtDatos.Columns.Add("CveSeccion", GetType(Integer))
End If
If Not DtDatos.Columns.Contains("Lote") Then
DtDatos.Columns.Add("Lote", GetType(String))
End If
If Not DtDatos.Columns.Contains("FechaCaducidad") Then
DtDatos.Columns.Add("FechaCaducidad", GetType(Date))
End If
If Not DtDatos.Columns.Contains("Seleccionado") Then
DtDatos.Columns.Add("Seleccionado", GetType(Boolean))
End If
If Not DtDatos.Columns.Contains("CantidadSeleccionada") Then
DtDatos.Columns.Add("CantidadSeleccionada", GetType(Double))
End If
If UsuarioActual.Empresa.Funcionalidad(132) = "1" Then
DivCodigoSeriePS.Visible = True
Else
DivCodigoSeriePS.Visible = False
End If
Else
Alert("No se encontraron productos pendientes por surtir. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
End If
Else
DtDatos = Nothing
End If
ObjInventario.Dispose()
UpGenerales.Update()
CargaGvDatos()
End Sub
Private Sub CargaGvDatos(Optional CveAlmacen As Integer = -1)
If DtDatos IsNot Nothing Then
Dim AplicaSeccion, AplicaLote, AplicaCaducidad, AplicaSerie As Boolean
If DtDatos IsNot Nothing AndAlso DtDatos.Rows.Count > 0 Then
AplicaSerie = CBool(DtDatos.MAX("AplicaSerie"))
AplicaSeccion = CBool(DtDatos.MAX("AplicaSeccion"))
AplicaLote = CBool(DtDatos.MAX("AplicaLote"))
AplicaCaducidad = CBool(DtDatos.MAX("AplicaCaducidad"))
End If
If AplicaSeccion Then GvDatos.Columns(7).Visible = True
If AplicaLote Then GvDatos.Columns(8).Visible = True
If AplicaCaducidad Then GvDatos.Columns(9).Visible = True
If Not String.IsNullOrWhiteSpace(UsuarioActual.Empresa.Funcionalidad(147)) Then GvDatos.Columns(9).HeaderText = UsuarioActual.Empresa.Funcionalidad(147)
'GvDatos.Columns(9).HeaderText = If(UsuarioActual.Empresa.Funcionalidad(147) <> "", UsuarioActual.Empresa.Funcionalidad(147), "")
'SugerirFecha()
If DdlAlmacen.SelectedValue.ToEntero > 0 And CveVentaSurtir > 0 Then
CargaVentaPorSurtir(CveVentaSurtir, CveAlmacen:=DdlAlmacen.SelectedValue.ToEntero)
' SugiereLoteCaducidad(DdlAlmacen.SelectedValue.ToEntero)
End If
End If
GvDatos.DataSource = DtDatos
GvDatos.DataBind()
UpDatos.Update()
UpVenta.Update()
'CARGA LO PRECARGADO CON SERIE
Dim Contador = 0
For Each Gvr As GridViewRow In GvDatos.Rows
If Gvr.DataKey("CvePS").ToEntero() = CvePSSerie AndAlso DtDatosDetalle IsNot Nothing Then
Contador = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Gvr.DataKey("Consec"))).Rows.Count
Gvr.FCCheckBox("cbInv").Enabled = False
Gvr.FCCheckBox("cbInv").Checked = True
Gvr.FCTextBox("TbCantidadF").Text = Contador.ToString()
End If
Next
End Sub
Protected Sub GvDatos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDatos.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
'código temporal
Dim AplicaSerie As Boolean = CBool(e.Row.DBCampo("AplicaSerie"))
If AplicaSerie Then
e.Row.FCButton("BtnSerie").Visible = True
e.Row.FCButton("BtnSerie").Text = "Serie"
e.Row.FCButton("BtnSerie").CommandArgument = String.Format("{0}°{1}°{2}°{3}°{4}°{5}", e.Row.DBCampo("CvePS"), e.Row.DBCampo("CveUM"), e.Row.DBCampo("PS"), e.Row.DBCampo("CantidadF"), e.Row.DBCampo("Consec"), e.Row.DBCampo("Inv_CveMetodoInventario"))
e.Row.FCTextBox("TbCantidadF").Enabled = False
e.Row.FCCheckBox("cbInv").Enabled = False
If e.Row.DBCampo("Consec") <> "" AndAlso DtDatosDetalle IsNot Nothing Then
Dim Contador = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", e.Row.DBCampo("Consec"))).Rows.Count
e.Row.FCTextBox("TbCantidadF").Text = Contador.ToString()
Else
e.Row.FCTextBox("TbCantidadF").Text = "0"
End If
If TipoDocto = "DPe" Then
CveConsecSerie = e.Row.DBCampo("Consec").ToString().ToEntero()
PSSerie = e.Row.DBCampo("PS").ToString()
CvePSSerie = e.Row.DBCampo("CvePS").ToEntero()
CveUMSerie = e.Row.DBCampo("CveUM").ToEntero()
LbCantidad.Text = e.Row.DBCampo("CantidadF")
LbCantidad2.Text = e.Row.DBCampo("CantidadF")
AgregaSerie(e.Row.DBCampo("ObservacionesDetalle"), 3)
End If
If TipoDocto = "Ing" AndAlso e.Row.DBCampo("ObservacionesDetalle").Length > 8 AndAlso DdlAlmacen.SelectedValue.ToEntero > 0 AndAlso UsuarioActual.CveRol = 1 Then
Dim Str = e.Row.DBCampo("ObservacionesDetalle").Replace(",", " ").Replace(".", " ").Replace(vbTab, " ").Replace(vbLf, " ").Split(" "c)
CveConsecSerie = e.Row.DBCampo("Consec").ToString().ToEntero()
PSSerie = e.Row.DBCampo("PS").ToString()
CvePSSerie = e.Row.DBCampo("CvePS").ToEntero()
CveUMSerie = e.Row.DBCampo("CveUM").ToEntero()
LbCantidad.Text = e.Row.DBCampo("CantidadF")
LbCantidad2.Text = e.Row.DBCampo("CantidadF")
For Each st As String In Str
If Not st.Contiene("", "/") Then
AgregaSerie(st, 3)
End If
Next
End If
Else
e.Row.FCButton("BtnSerie").Visible = False
e.Row.FCTextBox("TbCantidadF").Enabled = True
e.Row.FCTextBox("TbCantidadF").Attributes.Add("onblur", String.Format("ValidarCantidad(this, {0})", e.Row.DBCampo("CantidadF")))
End If
If CBool(e.Row.DBCampo("AplicaSeccion")) Then
e.Row.FCDropDownList("DdlSeccionAlmacen").Visible = True
If DdlAlmacen.SelectedValue.ToEntero() > 0 Then
CargaSeccionesAlmacen(e.Row.FCDropDownList("DdlSeccionAlmacen"), DdlAlmacen.SelectedValue.ToEntero(), e.Row.DBCampo("CvePS").ToEntero(), UsuarioActual.CveEmpresa, True)
'Dim dtt As DataTable = GlobalDTInvPSSeccionesAlmacen(UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero(), e.Row.DBCampo("CvePS").ToEntero())
'e.Row.FCDropDownList("DdlSeccionAlmacen").DataSource = dtt
'e.Row.FCDropDownList("DdlSeccionAlmacen").DataBind()
'If dtt.Rows.Count > 1 Then
' e.Row.FCDropDownList("DdlSeccionAlmacen").Items.Insert(0, New ListItem("Seleccione", "-1"))
'End If
'dtt.Dispose()
End If
Else
e.Row.FCDropDownList("DdlSeccionAlmacen").Visible = False
End If
If (ValidaLoteCaducidad) OrElse (UsuarioActual.CveEmpresa <> 119) Then
If CBool(e.Row.DBCampo("AplicaCaducidad")) Then
e.Row.FCTextBox("TxtCaducidad").Visible = True
e.Row.FCLinkButton("LnkCaducidad").Visible = True
e.Row.FCTextBox("TxtCaducidad").ReadOnly = True
CType(e.Row.FindControl("RFVCaducidad"), RequiredFieldValidator).Enabled = False
'si aplica caducidad y viene vacía (posible por venta anterior), que se active su registro
If e.Row.FCTextBox("TxtCaducidad").Text = "" OrElse e.Row.FCTextBox("TxtCaducidad").Text.ToDate <= MinFecha Then
e.Row.FCTextBox("TxtCaducidad").ReadOnly = False
CType(e.Row.FindControl("RFVCaducidad"), RequiredFieldValidator).Enabled = True
e.Row.FCTextBox("TxtCaducidad").Enabled = True
End If
Else
e.Row.FCTextBox("TxtCaducidad").Visible = False
e.Row.FCLinkButton("LnkCaducidad").Visible = False
e.Row.FCTextBox("TxtCaducidad").Enabled = True
End If
If CBool(e.Row.DBCampo("AplicaLote")) Then
e.Row.FCTextBox("TxtLote").Visible = True
'si aplica caducidad y viene vacía (posible por venta anterior), que se active su registro
If e.Row.FCTextBox("TxtLote").Text = "" Then
e.Row.FCTextBox("TxtLote").ReadOnly = False
e.Row.FCTextBox("TxtLote").Enabled = True
Else
e.Row.FCTextBox("TxtLote").ReadOnly = True
End If
Else
e.Row.FCTextBox("TxtLote").Visible = False
End If
End If
e.Row.FCButton("BtnDividir").Attributes.Add("onclick", String.Format("Dividir('{0}');", e.Row.FCTextBox("TxtDividir").ClientID))
e.Row.FCButton("BtnDividir").CommandArgument = e.Row.RowIndex.ToString()
e.Row.FCTextBox("TxtDividir").Attributes.Add("onkeyup", String.Format("LimitaCantidad({0},this,'{1}');", e.Row.DBCampo("CantidadF"), e.Row.FCButton("BtnDividir").ClientID))
'FUNCIONALIDAD PISTOLA DE CODIGOS
If UsuarioActual.Empresa.Funcionalidad(132) = "1" And e.Row.DBCampo("CodigoBarras").Trim <> "" Then
e.Row.FCTextBox("TbCantidadF").Text = "0"
'NO BLOQUEA PARA ROL AD
If UsuarioActual.CveRol = 1 Then
If AplicaSerie Then
e.Row.FCTextBox("TbCantidadF").Enabled = False
Else
e.Row.FCTextBox("TbCantidadF").Text = e.Row.DBCampo("CantidadF").ToDecimal.ToString("#,##0.######")
End If
End If
If Not UsuarioActual.CveRol = 1 Then
e.Row.FCTextBox("TbCantidadF").Enabled = False
End If
End If
'SI ES TRASPASO OBLIGATORIO SURTIR TODO
If TipoEntrega = 2 Then
e.Row.FCCheckBox("cbInv").Enabled = False
End If
End If
End Sub
Private Sub CargaDocumentos(tCveVenta As Integer)
If tCveVenta > 0 Then
Dim objInv As New ClsEdocumentacion
If objInv.DocumentacionElectronicaGet(-1, -1, -1, UsuarioActual.CveEmpresa, -1, tCveVenta) Then
GvDocs.DataSource = objInv.DtResultados.FiltraParametros("Adjunto <> ''")
End If
objInv.Dispose()
GvDocs.DataBind()
End If
End Sub
#End Region
#Region " AGREGAR "
Protected Sub BtnSerie_Click(sender As Object, e As EventArgs)
Dim Argumentos = CType(sender, Button).CommandArgument.Split("°"c)
LbProducto.Text = Argumentos(2)
LbCantidad.Text = Argumentos(3)
LbProducto2.Text = Argumentos(2)
LbCantidad2.Text = Argumentos(3)
CvePSSerie = Argumentos(0).ToEntero()
CveUMSerie = Argumentos(1).ToEntero()
PSSerie = Argumentos(2).ToString()
CveConsecSerie = Argumentos(4).ToEntero()
CveMetodoInventario = Argumentos(5).ToEntero()
If CveMetodoInventario = 6 Then
RegistraScript("$('#DivLote').modal('show')")
CargaLote()
UpLoteBatch.Update()
Else
RegistraScript("$('#DivSerie').modal('show')")
CargaSerie()
UpSerie.Update()
End If
End Sub
#Region " AGREGA POR SERIE/LOTE "
Private Sub CreaDtDetalle()
If DtDatosDetalle Is Nothing Then
DtDatosDetalle = New DataTable
DtDatosDetalle.Columns.Add("CveVentaDetalle", GetType(Integer))
DtDatosDetalle.Columns.Add("Consec", GetType(Integer))
DtDatosDetalle.Columns.Add("ConsecId", GetType(Integer))
DtDatosDetalle.Columns.Add("CvePS", GetType(Integer))
DtDatosDetalle.Columns.Add("PS", GetType(String))
DtDatosDetalle.Columns.Add("CveUM", GetType(Integer))
DtDatosDetalle.Columns.Add("Serie", GetType(String))
DtDatosDetalle.Columns.Add("Lote", GetType(String))
DtDatosDetalle.Columns.Add("FechaCaducidad", GetType(Date))
DtDatosDetalle.Columns.Add("FueTraspaso", GetType(Integer))
End If
End Sub
Private Sub CargaSerie(Optional CerrarCompletado As Boolean = False)
RegistraScript("$('#DivSerie').modal('show')", "show")
Dim AplicaCaducidad = False
If GlobalDTPS(UsuarioActual.CveEmpresa, ).FiltraParametros("").Rows(0) IsNot Nothing Then
AplicaCaducidad = If(GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePSSerie).FiltraParametros("").Rows(0)("AplicaCaducidad").ToString() = "True", True, False)
End If
GvSerie.Columns(1).HeaderText = UsuarioActual.Empresa.Funcionalidad(147)
If AplicaCaducidad Then
GvSerie.Columns(1).Visible = True
TdCaducidad1.Visible = True
TdCaducidad2.Visible = True
Else
GvSerie.Columns(1).Visible = False
TdCaducidad1.Visible = False
TdCaducidad2.Visible = False
End If
GvSerie.DataSource = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", CveConsecSerie), "Consec DESC")
GvSerie.DataBind()
'SERIE LOTE RECOMENDADO
Dim DtSerie As New DataTable
If TipoMovimiento = 1 Then
Dim ObjInventarios As New ClsInventarios
If ObjInventarios.SerieRecomendadoGet(CvePSSerie, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero(), CveSubProyecto:=CveSubProyecto, CveCliente:=CveCliente, CveVendedor:=CveVendedor) Then
DtSerie = ObjInventarios.DtResultados
End If
ObjInventarios.Dispose()
Else
DtSerie = DtExistencias.FiltraParametros("Serie <> ''")
End If
'SERIE LOTE RECOMENDADO - QUITA YA COMPLETADOS EN EL CLIENTE
If DtSerie.Rows.Count > 0 Then
'CALCULA YA COMPLETADOS
Dim DrsRemove As New List(Of DataRow)
DtSerie.Columns.Add("CantidadSeleccionada", GetType(Integer))
For Each dr As DataRow In DtSerie.Rows
dr("CantidadSeleccionada") = DtDatosDetalle.FiltraParametros(String.Format("Consec = {0} AND Serie = '{1}'", CveConsecSerie, dr("Serie").ToString().Replace("'", "''"))).Rows.Count
If dr("CantidadSeleccionada").ToString().ToDecimal = dr("Existencia").ToString().ToDecimal Then
DrsRemove.Add(dr)
End If
Next
'ELIMINA YA COMPLETADOS EN PAGINA
For Each dr As DataRow In DrsRemove
DtSerie.Rows.Remove(dr)
Next
If DtSerie.Rows.Count > 0 Then
Dim Mensaje As New StringBuilder
Mensaje.AppendFormat("Serie Recomendado: <b>{0}</b>", DtSerie.Rows(0)("Serie"))
If AplicaCaducidad Then Mensaje.AppendFormat(", Caducicdad: <b>{0}</b>", DtSerie.Rows(0)("FechaCaducidad").ToString().ToDate.ToShortDateString)
LbSerieRecomendado.Text = Mensaje.ToString() 'String.Format("Serie / Lote Recomendado: <b>{0}</b>, Caducicdad: <b>{1}</b>", ObjInventarios.DtResultados.Rows(0)("SerieLote"), ObjInventarios.DtResultados.Rows(0)("FechaCaducidad").ToString().ToDate.ToShortDateString)
Else
LbSerieRecomendado.Text = "No se encontro ningun Serie/Lote."
End If
Else
LbSerieRecomendado.Text = "No se encontro ningun Serie/Lote."
End If
'SI TIENE SALIDA POR SERIE LOTE, BLOQUEAMOS CHECK Y TXTCANTIDAD
Dim Contador = 0
For Each Gvr As GridViewRow In GvDatos.Rows
If Gvr.DataKey("AplicaSerie") = "True" Then
Contador = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Gvr.DataKey("Consec"))).Rows.Count
Gvr.FCCheckBox("cbInv").Enabled = False
Gvr.FCCheckBox("cbInv").Checked = True
Gvr.FCTextBox("TbCantidadF").Text = Contador.ToString()
End If
Next
UpDatos.Update()
'VALIDA QUE SIGA AGREGANDO
If DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", CveConsecSerie)).Rows.Count = LbCantidad.Text.ToEntero() Then
BtnAgregarPS.Enabled = False
If CerrarCompletado Then
RegistraScript("$('#DivSerie').modal('hide')", "hide")
End If
UpSerie.Update()
Exit Sub
Else
BtnAgregarPS.Enabled = True
UpSerie.Update()
End If
End Sub
Protected Sub BtnAgregarPS_Click(sender As Object, e As EventArgs)
If TxtSerie.Text.Trim.Length >= 2 AndAlso TxtSerie.Text.Trim.StartsWith("*") AndAlso TxtSerie.Text.Trim.EndsWith("*") Then
Dim ArraySeries() As String = Nothing
Dim Series As String = Nothing
Series = TxtSerie.Text.Trim
Series = Series.Remove(0, 1)
Series = Series.Remove(Series.Length - 1, 1)
ArraySeries = Series.Trim.Split(","c)
For i As Integer = 0 To ArraySeries.Length - 1
If ArraySeries(i).Trim.Length > 1 Then AgregaSerie(ArraySeries(i).Trim, 1)
Next
Else
AgregaSerie(TxtSerie.Text.Trim, 1)
End If
End Sub
Private Sub AgregaSerie(Serie As String, Tipo As Integer)
If Serie.Trim = "" Then
Alert("El campo Serie es obligatorio. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If DtDatosDetalle.FiltraParametros($"CvePS = {CvePSSerie} AND Serie = '{Serie}'").Rows.Count > 0 Then
Alert("La Serie indicada ya esta registrada. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
RegistraScript("playsonidito('142608__autistic-lucario__error.wav')", "Error1")
TxtSerie.Text = ""
Exit Sub
End If
Dim AplicaCaducidad As Boolean = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CvePS:=CvePSSerie).FiltroPrimeroValor("AplicaCaducidad", "") = "True"
'If GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CvePS:=CvePSSerie).FiltraParametros("").Rows(0) IsNot Nothing Then
' AplicaCaducidad = If(GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePSSerie).FiltraParametros("").Rows(0)("AplicaCaducidad").ToString() = "True", True, False)
'End If
'Valida Existencia
If TipoMovimiento = 1 Then
Dim ObjInventarios As New ClsInventarios
Dim Existencia = ObjInventarios.GetExistenciasPS(CvePSSerie, CveUMSerie, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero(), FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), Serie:=Serie, CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), ExcluyeApartados:=If(TipoEntrega = 2, 1, -1))
If Existencia < 1 Then
Alert($"No hay existencia suficiente del producto <b>""{PSSerie}""</b> con la Serie definida <b>""{Serie}""</b>. Por favor rectifique y vuelva a intentar", TipoMensaje.MsgAdvertencia, If(Tipo = 2, "window.setTimeout(Focus,200);", ""))
RegistraScript("playsonidito('142608__autistic-lucario__error.wav')", "Error2")
ObjInventarios.Dispose()
Exit Sub
End If
ObjInventarios.Dispose()
Else
If DtExistencias IsNot Nothing Then
Dim Existencia = DtExistencias.SUM("Cantidad", $"CvePS = {CvePSSerie} AND CveUM = {CveUMSerie} AND Serie = '{Serie}'")
If Existencia < 1 Then
Alert($"No hay existencia suficiente del producto <b>""{PSSerie}""</b> con la Serie definida <b>""{Serie}""</b>. Por favor rectifique y vuelva a intentar", TipoMensaje.MsgAdvertencia, If(Tipo = 2, "window.setTimeout(Focus,200);", ""))
RegistraScript("playsonidito('142608__autistic-lucario__error.wav')", "Error3")
Exit Sub
End If
End If
End If
Dim Row = DtDatosDetalle.NewRow
Row("ConsecId") = CveConsecSerie
Row("Consec") = DtDatosDetalle.Rows.Count + 1
Row("PS") = PSSerie
Row("CvePS") = CvePSSerie
Row("CveUM") = CveUMSerie
Row("Serie") = Serie
Row("FechaCaducidad") = If(AplicaCaducidad, TxtFechaCaducidad.Text, MinFecha.ToShortDateString)
DtDatosDetalle.Rows.Add(Row)
RegistraScript("playsonidito('beep-07.wav')", "Sonidito")
If Tipo = 1 Then
TxtSerie.Text = ""
TxtFechaCaducidad.Text = ""
End If
If Tipo < 3 Then
CargaSerie(True)
End If
End Sub
Protected Sub GvSerie_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvSerie.RowDeleting
Dim keySerie As String = e.Keys("Serie").ToString()
Try
For Each dr As DataRow In DtDatosDetalle.Rows
If dr("Serie").ToString() = keySerie Then
dr.Delete()
End If
Next
Catch ex As Exception
End Try
DtDatosDetalle.AcceptChanges()
CargaSerie()
End Sub
#End Region
#Region " AGREGA CON LOTE BATCH "
Private Sub CreaDtDetalleLote()
If DtDatosDetalleLote Is Nothing Then
DtDatosDetalleLote = New DataTable
DtDatosDetalleLote.Columns.Add("CveVentaDetalle", GetType(Integer))
DtDatosDetalleLote.Columns.Add("Consec", GetType(Integer))
DtDatosDetalleLote.Columns.Add("ConsecId", GetType(Integer))
DtDatosDetalleLote.Columns.Add("Cantidad", GetType(Double))
DtDatosDetalleLote.Columns.Add("CvePS", GetType(Integer))
DtDatosDetalleLote.Columns.Add("PS", GetType(String))
DtDatosDetalleLote.Columns.Add("CveUM", GetType(Integer))
DtDatosDetalleLote.Columns.Add("Lote", GetType(String))
DtDatosDetalleLote.Columns.Add("FechaCaducidad", GetType(String))
DtDatosDetalleLote.Columns.Add("FueTraspaso", GetType(Integer))
End If
End Sub
Private Sub CargaLote(Optional CerrarCompletado As Boolean = False)
RegistraScript("$('#DivLote').modal('show')")
GvLote.Columns(2).HeaderText = UsuarioActual.Empresa.Funcionalidad(147)
GvLote.DataSource = DtDatosDetalleLote.FiltraParametros(String.Format("ConsecId = {0}", CveConsecSerie), "Consec DESC")
GvLote.DataBind()
'VALIDA QUE SIGA AGREGANDO
If DtDatosDetalleLote.SUM("Cantidad", String.Format("ConsecId = {0}", CveConsecSerie)) = LbCantidad2.Text.ToDecimal Then
BtnLote.Enabled = False
If CerrarCompletado Then
RegistraScript("$('#DivLote').modal('hide')", "hide")
End If
Else
BtnLote.Enabled = True
End If
'LOTE RECOMENDADO
Dim DtLotes As New DataTable
If TipoMovimiento = 1 Then
Dim ObjInventarios As New ClsInventarios
If ObjInventarios.LoteRecomendadoGet(CvePSSerie, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero()) Then
DtLotes = ObjInventarios.DtResultados
End If
ObjInventarios.Dispose()
Else
DtLotes = DtExistencias.FiltraParametros("Lote <> ''")
End If
Dim DrsRemove As New List(Of DataRow)
If DtLotes.Rows.Count > 0 Then
'CALCULA YA COMPLETADOS
DtLotes.Columns.Add("CantidadSeleccionada", GetType(Integer))
For Each dr As DataRow In DtLotes.Rows
dr("CantidadSeleccionada") = DtDatosDetalleLote.SUM("Cantidad", String.Format("Consec = {0} AND Lote = '{1}'", CveConsecSerie, dr("Lote")))
If dr("CantidadSeleccionada").ToString().ToDecimal = dr("Existencia").ToString().ToDecimal Then
DrsRemove.Add(dr)
End If
Next
'ELIMINA YA COMPLETADOS EN PAGINA
For Each dr As DataRow In DrsRemove
DtLotes.Rows.Remove(dr)
Next
If DtLotes.Rows.Count > 0 Then
Dim Mensaje As New StringBuilder
Mensaje.AppendFormat("Recomendado: Existencia: <b>{0}</b> Lote: <b>{1}</b> Fecha Caducidad: <b>{2}</b> ", DtLotes.Rows(0)("Existencia").ToString().FormatoNumero, DtLotes.Rows(0)("Lote"), DtLotes.Rows(0)("FechaCaducidad").ToString().ToDate.ToShortDateString)
LbLoteRecomendado.Text = Mensaje.ToString()
Else
LbLoteRecomendado.Text = "No se encontro ningún Lote recomendado."
End If
Else
LbLoteRecomendado.Text = "No se encontro ningún Lote recomendado."
End If
'SI TIENE SALIDA POR LOTE, BLOQUEAMOS CHECK Y TXTCANTIDAD
Dim Contador As Decimal = 0
For Each Gvr As GridViewRow In GvDatos.Rows
If Gvr.DataKey("CvePS").ToEntero() = CvePSSerie Then
Contador = DtDatosDetalleLote.SUM("Cantidad", String.Format("ConsecId = {0}", Gvr.DataKey("Consec"))).ToDecimal
Gvr.FCCheckBox("cbInv").Enabled = False
Gvr.FCCheckBox("cbInv").Checked = True
Gvr.FCTextBox("TbCantidadF").Text = Contador.ToString().FormatoNumero
End If
Next
RVCantidadLote.MaximumValue = (If((LbCantidad2.Text.ToDecimal - Contador) = 0, 0.02, LbCantidad2.Text.ToDecimal - Contador)).ToString().FormatoNumero
TxtCantidadLote.Text = "1"
TxtLote.Text = ""
TxtBatch.Text = ""
TxtLote.Focus()
UpLoteBatch.Update()
UpDatos.Update()
End Sub
Protected Sub BtnAgregarPS2_Click(sender As Object, e As EventArgs)
AgregaLote(TxtLote.Text.Trim, TxtBatch.Text.Trim, 1)
End Sub
Private Sub AgregaLote(Lote As String, Batch As String, Tipo As Integer)
If Lote = "" Then
Alert("El campo Lote es obligatorio. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
'VALIDACION DE SERIES DUPLICADAS
Dim MensajeAlert As New StringBuilder
Dim DtDuplicado As New DataTable
Dim DtSeriesNuevas As New DataTable
DtSeriesNuevas.Columns.Add("Serie", GetType(String))
DtDuplicado = DtDatosDetalleLote.FiltraParametros($"ConsecId = {CveConsecSerie} AND Lote = '{Lote}' AND Batch = '{Batch}'")
If DtDuplicado IsNot Nothing AndAlso DtDuplicado.Rows.Count > 0 Then
Alert($"<br/> El numero de Lote <b>""{Lote}""</b> y Batch = '{Batch}' proporcionado ya se encuentra ingresado.", TipoMensaje.MsgAdvertencia)
RegistraScript("playsonidito('142608__autistic-lucario__error.wav')")
Exit Sub
End If
Dim Row = DtDatosDetalleLote.NewRow
Dim CantidadLote = TxtCantidadLote.Text.ToDecimal
Dim MensajeSinExistencias As New StringBuilder
Dim ObjInventarios As New ClsInventarios
'VERIFICA EXISTENCIAS
If TipoMovimiento = 1 Then
Dim Existencia = ObjInventarios.GetExistenciasPS(CvePSSerie, CveUMSerie, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero(), FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), Lote:=Lote, ExcluyeApartados:=If(TipoEntrega = 2, 1, -1))
If Existencia < CantidadLote Then
Alert($"No hay existencia suficiente del producto <b>""{PSSerie}""</b> con el lote definido <b>""{Lote}""</b> y el batch <b>""{Batch}""</b>. Por favor rectifique y vuelva a intentar", TipoMensaje.MsgAdvertencia)
RegistraScript("playsonidito('142608__autistic-lucario__error.wav')")
ObjInventarios.Dispose()
Exit Sub
End If
Else
If DtExistencias IsNot Nothing Then
Dim Existencia = DtExistencias.SUM("Cantidad", $"CvePS = {CvePSSerie} AND CveUM = {CveUMSerie} AND Lote = '{Lote}' AND Batch = '{Batch}'")
If Existencia < CantidadLote Then
Alert($"No hay existencia suficiente del producto <b>""{PSSerie}""</b> con el lote definido <b>""{Lote}""</b> y el batch <b>""{Batch}""</b>. Por favor rectifique y vuelva a intentar", TipoMensaje.MsgAdvertencia)
RegistraScript("playsonidito('142608__autistic-lucario__error.wav')")
ObjInventarios.Dispose()
Exit Sub
End If
End If
End If
Dim FechaCaducidad = ""
If ObjInventarios.LoteRecomendadoGet(CvePSSerie, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero()) AndAlso ObjInventarios.DtResultados.Rows.Count > 0 Then
FechaCaducidad = ObjInventarios.DtResultados.Rows(0)("FechaCaducidad").ToString().ToDate.ToShortDateString
End If
Row("ConsecId") = CveConsecSerie
Row("Consec") = DtDatosDetalle.Rows.Count + 1
Row("Cantidad") = CantidadLote
Row("CvePS") = CvePSSerie
Row("PS") = PSSerie
Row("CveUM") = CveUMSerie
Row("Lote") = Lote
Row("Batch") = Batch
Row("FechaCaducidad") = FechaCaducidad
DtDatosDetalleLote.Rows.Add(Row)
ObjInventarios.Dispose()
If Tipo = 1 Then
TxtCantidadLote.Text = "1"
TxtLote.Text = ""
TxtBatch.Text = ""
End If
CargaLote(True)
End Sub
Protected Sub GvLote_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvLote.RowDeleting
Dim keyLote As String = e.Keys("Lote").ToString()
Try
For Each dr As DataRow In DtDatosDetalleLote.Rows
If dr("Lote").ToString() = keyLote Then
dr.Delete()
End If
Next
Catch ex As Exception
End Try
DtDatosDetalleLote.AcceptChanges()
CargaLote()
End Sub
#End Region
#Region " AGREGA CON TXT | CODIGO - SERIE "
Protected Sub BtnCodigoPS_Click(sender As Object, e As EventArgs)
If TxtCodigoPS.Text = "" Then
Exit Sub
End If
TdSeriePS.Visible = False
Dim Existe = False
Dim PSTemp = ""
For Each Gvr As GridViewRow In GvDatos.Rows
If Gvr.DataKey("CodigoBarras") = TxtCodigoPS.Text.Trim Then
Dim TxtCantidad = GvDatos.Rows(Gvr.RowIndex).FCTextBox("TbCantidadF")
If Gvr.DataKey("CantidadF").ToDecimal - TxtCantidad.Text.ToDecimal - 1 >= 0 Then
''VALIDA EXISTENCIA
If Not TipoDocto.Contiene("Dev") Then
If TipoMovimiento = 1 Then
Dim ObjInventario As New ClsInventarios
Dim Existencia = ObjInventario.GetExistenciasPS(Gvr.DataKey("CvePS").ToString().ToEntero(), Gvr.DataKey("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero(), FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), ExcluyeApartados:=If(TipoEntrega = 2, 1, -1))
ObjInventario.Dispose()
If Not Existencia >= TxtCantidad.Text.ToDecimal + 1 Then
TxtCodigoPS.Text = ""
Alert($"No hay existencias suficientes del producto: <br/><b>""{Gvr.DataKey("Codigo")}-{Gvr.DataKey("PS")}""</b>. <br/>Solo hay disponibles <b>{Existencia.FormatoNumero}</b> en Almacen. Por favor Verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);")
RegistraScript("playsonidito('142608__autistic-lucario__error.wav')")
Exit Sub
End If
Else
If DtExistencias IsNot Nothing Then
Dim Existencia = DtExistencias.SUM("Cantidad", $"CvePS = {Gvr.DataKey("CvePS")} AND CveUM = {Gvr.DataKey("CveUM").ToString().ToEntero()}")
If Not Existencia >= TxtCantidad.Text.ToDecimal + 1 Then
TxtCodigoPS.Text = ""
Alert($"No hay existencias suficientes del producto: <br/><b>""{Gvr.DataKey("Codigo")}-{Gvr.DataKey("PS")}""</b>. <br/>Solo hay disponibles <b>{Existencia.FormatoNumero}</b> en Almacen. Por favor Verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);")
RegistraScript("playsonidito('142608__autistic-lucario__error.wav')")
Exit Sub
End If
End If
End If
End If
If Gvr.DataKey("AplicaSerieLote") = "True" Then
TdSeriePS.Visible = True
TxtSeriePS.Focus()
CveConsecSerie = Gvr.DataKey("Consec").ToString().ToEntero()
PSSerie = Gvr.DataKey("PS").ToString()
CvePSSerie = Gvr.DataKey("CvePS").ToEntero()
CveUMSerie = Gvr.DataKey("CveUM").ToEntero()
Exit Sub
End If
Dim CantidadEspecial = Gvr.DataKey("CveClasificacion").ToString().ToEntero().Contiene(17601, 17881) OrElse Gvr.DataKey("CvePS").ToString().ToEntero().Contiene(343032, 343033)
If CantidadEspecial Then
RegistraScript("CantidadEspecial();window.setTimeout(FocusCantidadEspecial,200);")
LtlProductoCantidad.Text = $"{Gvr.DataKey("Codigo")}"
RowIndexCantidadEspecial = Gvr.RowIndex
CantidadEspecialTemp = Gvr.DataKey("CantidadF").ToDecimal
TxtCodigoPS.Text = ""
Exit Sub
Else
TxtCantidad.Text = (TxtCantidad.Text.ToDecimal + 1).ToString().FormatoNumero
TxtCodigoPS.Text = ""
UpDatos.Update()
Exit Sub
End If
VerificaVentaSurtida()
Exit Sub
End If
Existe = True
PSTemp = Gvr.DataKey("PS").ToString()
'Alert($"Ya se ha cargado la totalidad del Producto ""<b>{Gvr.DataKey("PS").ToString()}</b>"" con el Codigo ""<b>{TxtCodigoPS.Text}</b>"".", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);")
'VerificaVentaSurtida()
'Exit Sub
End If
Next
VerificaVentaSurtida()
If Existe Then
Alert($"Ya se ha cargado la totalidad del Producto ""<b>{PSTemp}</b>"" con el Codigo ""<b>{TxtCodigoPS.Text}</b>"".", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);")
Else
Alert($"No se ha encontrado un producto para surtir con el Codigo ""<b>{TxtCodigoPS.Text}</b>"". ", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);")
End If
RegistraScript("playsonidito('142608__autistic-lucario__error.wav')")
TxtCodigoPS.Text = ""
End Sub
Private Sub VerificaVentaSurtida()
Dim Surtida = True
For Each Gvr As GridViewRow In GvDatos.Rows
If Gvr.DataKey("CantidadF").ToDecimal <> Gvr.FCTextBox("TbCantidadF").Text.ToDecimal Then
Surtida = False
Exit Sub
End If
Next
If Surtida Then
LbSurtida.Visible = True
End If
End Sub
Protected Sub BtnSeriePS_Click(sender As Object, e As EventArgs)
AgregaSerie(TxtSeriePS.Text.Trim, 2)
TdSeriePS.Visible = False
TxtSeriePS.Text = ""
TxtCodigoPS.Text = ""
TxtCodigoPS.Focus()
VerificaVentaSurtida()
End Sub
Protected Sub BtnGuardarCantidadEspecial_Click(sender As Object, e As EventArgs)
AgregaCantidadEspecial()
End Sub
Private Sub AgregaCantidadEspecial()
Dim TxtCantidad = GvDatos.Rows(RowIndexCantidadEspecial).FCTextBox("TbCantidadF")
If CantidadEspecialTemp - TxtCantidadEspecialDiv.Text.ToDecimal - TxtCantidad.Text.ToDecimal >= 0 Then
TxtCantidad.Text = (TxtCantidad.Text.ToDecimal + TxtCantidadEspecialDiv.Text.ToDecimal).ToString().FormatoNumero
'RegistraScript("$('#ModalCantidad').modal('hide');")
RegistraScript("$('#DivCantidadEspecial').hide(200);")
UpDatos.Update()
TxtCodigoPS.Focus()
Else
Alert("La cantidad excede la pendiente por surtir. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);")
RegistraScript("playsonidito('142608__autistic-lucario__error.wav')")
End If
TxtCantidadEspecialDiv.Text = "1"
End Sub
#End Region
#End Region
#Region " GUARDAR "
Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs)
Select Case TipoEntrega
Case 1
GuardaVenta()
Case 2
GuardaTraspaso()
End Select
End Sub
Private Sub GuardaVenta()
'' INICIA: VALIDACIONES
'Valida el estatus de la Venta, si es = 5 O DevolucionVenta = 2, NO SE SURTE!
Dim ObjVentaInv As New ClsInventarios
If ObjVentaInv.GetEstatusVentaPorSurtir(CveVentaSurtir) Then
TipoEstatus = ObjVentaInv.TipoEstatus
EsDevolucionVenta = ObjVentaInv.EsDevolucionVenta
End If
ObjVentaInv.Dispose()
If TipoEstatus = 5 Or EsDevolucionVenta.Contiene(2, 3) Then
Alert("No se puede surtir esta venta, verifique que no esté cancelada o ya registrado su movimiento en almacen", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim ValidaSeccion As Boolean = False : Dim ValidaCaducidad As Boolean = False : Dim ValidaLote As Boolean = False
'VALIDA CANTIDAD DE SALIDA
Dim Cantidad As Decimal = 0.0D
For Each Gvr As GridViewRow In GvDatos.Rows
If CBool(Gvr.DataKey("AplicaSeccion")) AndAlso Gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero() <= 0 Then
ValidaSeccion = True
End If
If CBool(Gvr.DataKey("AplicaCaducidad")) AndAlso Gvr.FCTextBox("TxtCaducidad").Text.Trim = "" Then
ValidaCaducidad = True
End If
If CBool(Gvr.DataKey("AplicaLote")) AndAlso Gvr.FCTextBox("TxtLote").Text.Trim = "" Then
ValidaLote = True
End If
If Gvr.FCCheckBox("cbInv").Checked AndAlso Gvr.FCTextBox("TbCantidadF").Text.ToDecimal > 0 Then
Cantidad = Gvr.FCTextBox("TbCantidadF").Text.ToDecimal
Exit For
End If
Next
If (Not ValidaLoteCaducidad) OrElse (UsuarioActual.CveEmpresa <> 119) Then
ValidaSeccion = False
ValidaCaducidad = False
ValidaLote = False
End If
If ValidaSeccion Then
Alert("La sección de almacen no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If ValidaCaducidad Then
Alert("La caducidad no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If ValidaLote Then
Alert("El lote de almacen no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If Not Cantidad > 0 Then
Alert("No se detecto ningun movimiento por hacer. Por favor verifique e intente nuevamente.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
'PROCESO , si tiene proceso "176" no lo valida
If Not UsuarioActual.TienePermisoProceso(176) Then
For Each Gvr As GridViewRow In GvDatos.Rows
If Gvr.DataKey("CantidadF").ToDecimal <> Gvr.FCTextBox("TbCantidadF").Text.ToDecimal Then
Alert("En la factura no se han especificado todos los productos a entregar, favor de especificarlos para poder dar salida.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Next
End If
If EsDevolucionVenta = 1 Or TipoDocto.Contiene({"Ped"}) Then
If Not (EsDevolucionVenta = 1 And TipoDocto.Contiene("Rem")) Then ' condicion si hay una devolucion de remision, no verifique la totalidad surtido
For Each Gvr As GridViewRow In GvDatos.Rows
If Not Gvr.FCCheckBox("cbInv").Checked Or (Gvr.FCCheckBox("cbInv").Checked AndAlso Gvr.FCTextBox("TbCantidadF").Text.ToDecimal <> Gvr.DataKey("CantidadC").ToString().ToDecimal) Then
Alert("Es necesario surtir todos los productos. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
RegistraScript("playsonidito('142608__autistic-lucario__error.wav')")
Exit Sub
End If
Next
End If
End If
Dim EsInterno As Integer = -1
If TipoDocto = "Ped" Then
EsInterno = If(Me.EsInterno, 1, 0)
End If
Dim ObjInventario As New ClsInventarios
Dim ObjConta As New ClsContabilidad(ObjInventario.IniciaTransacSQL())
Dim ObjVentas As New ClsVentas(ObjInventario.IniciaTransacSQL())
Dim ObjEventos As New ClsOIEventos(ObjInventario.IniciaTransacSQL())
Dim ObjAcumuladores As New ClsAcumuladores(ObjInventario.IniciaTransacSQL())
Dim ObjGeneral As New ClsGenerales(ObjInventario.IniciaTransacSQL())
Dim CveMovimiento As Integer
Dim Folio As Integer
Dim ErrorMovInv As Boolean
Dim DtDetalle As New DataTable
Dim DtDetalleLote As New DataTable
Dim TextoError As New StringBuilder
Dim CveMovimientoGarantia As Integer = -1
Dim FolioGarantia As Integer = -1
Dim CveMovimientoVirtual As Integer = -1
Dim FolioVirtual As Integer = -1
'PASA DATOS DEL GV A DATATABLE PARA MANEJOR CON FOR EACH
Dim Index = 0
For Each gvr As GridViewRow In GvDatos.Rows
If gvr.FCCheckBox("cbInv").Checked AndAlso gvr.FCTextBox("TbCantidadF").Text.ToDecimal > 0 Then
DtDatos.Rows(Index)("CantidadGV") = gvr.FCTextBox("TbCantidadF").Text.ToDecimal
DtDatos.Rows(Index)("CveSeccion") = gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero()
DtDatos.Rows(Index)("FechaCaducidad") = gvr.FCTextBox("TxtCaducidad").Text.ToDate
DtDatos.Rows(Index)("Lote") = gvr.FCTextBox("TxtLote").Text
End If
Index += 1
Next
'VALIDA SI HUBO CAMBIOS EN LA EXISTENCIA
Dim DtDatosVenta As New DataTable
If ObjInventario.EntregaAlmacenGet(CveVentaSurtir) Then
DtDatosVenta = ObjInventario.DtResultados
End If
Dim CantidadGV As Decimal = GvDatos.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.DataKey("CantidadF").ToDecimal)
If CantidadGV <> DtDatosVenta.SUMD("CantidadF") Then
ObjInventario.RollBack()
ObjInventario.Dispose()
ObjConta.Dispose()
ObjVentas.Dispose()
ObjEventos.Dispose()
CargaVentaPorSurtir(CveVentaSurtir)
CargaPendientes()
Alert("Ha sido cambiada la informacion de existencias de la venta actual, se han recargado la información.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If Not ObjVentas.UpdateVentasDevolucionAlmacen(3, CveVentaSurtir) Then
ObjInventario.RollBack()
ObjInventario.Dispose()
ObjConta.Dispose()
ObjVentas.Dispose()
ObjEventos.Dispose()
Exit Sub
End If
Dim DtTraspasos As New DataTable
DtTraspasos.Columns.Add("CveAlmacen", GetType(Integer))
DtTraspasos.Columns.Add("Almacen", GetType(String))
DtTraspasos.Columns.Add("CveMovimientoSalida", GetType(Integer))
DtTraspasos.Columns.Add("FolioSalida", GetType(Integer))
DtTraspasos.Columns.Add("CveMovimientoEntrada", GetType(Integer))
DtTraspasos.Columns.Add("FolioEntrada", GetType(Integer))
DtTraspasos.Columns.Add("CveTipoAlmacen", GetType(Integer))
DtTraspasos.Columns.Add("CveConceptoMovimientoSalida", GetType(Integer))
Dim CveMovimientoSalida = -1, FolioSalida = -1, CveMovimientoEntrada = -1, CveMovimientoEntradaApartado = -1, FolioEntrada = -1, CveMovimientoSalidaDevRem = -1, FolioMovimientoSalidaDevRem = -1, CveMovimientoEntradaDevRem = -1, FolioMovimientoEntradaDevRem = -1
Dim DtDevSinCosto As New DataTable
DtDevSinCosto.Columns.Add("CveAlmacen", GetType(Integer))
DtDevSinCosto.Columns.Add("Almacen", GetType(String))
DtDevSinCosto.Columns.Add("CveMovimientoEntrada", GetType(Integer))
DtDevSinCosto.Columns.Add("FolioEntrada", GetType(Integer))
DtDevSinCosto.Columns.Add("CveTipoAlmacen", GetType(Integer))
DtDevSinCosto.Columns.Add("CveConceptoMovimientoSalida", GetType(Integer))
Try
'VALIDA EXISTENCIA 2
If TipoMovimiento = 1 Then
Dim StrXML As New StringBuilder
StrXML.Append("<conceptos>")
Dim FechaCaducidad As Date
Dim Lote As String = ""
For Each Dr As DataRow In DtDatos.Rows
FechaCaducidad = If(CBool(Dr("AplicaCaducidad")) AndAlso Dr("FechaCaducidad").ToString() <> "", Dr("FechaCaducidad").ToString().ToDate, MinFecha)
Lote = If(CBool(Dr("AplicaLote")), Dr("Lote").ToString().Trim, "-1")
If Not ValidaLoteCaducidad Then
FechaCaducidad = MinFecha
Lote = "-1"
End If
If Dr("CantidadGV").ToString().ToDecimal > 0 Then
If CBool(Dr("AplicaSerie")) Then
DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Dr("Consec")))
For Each Dr1 As DataRow In DtDetalle.Rows
StrXML.AppendFormat("<concepto CvePS=""{0}"" CveUM=""{1}"" Cantidad= ""{2}"" CveSeccionAlmacen=""{3}"" Serie=""{4}"" Lote=""{5}"" FechaCaducidad=""{6}""></concepto>", Dr1("CvePS"), Dr1("CveUM"), 1, IfNull(Dr("CveSeccion"), -1), Dr1("Serie"), Lote, FechaCaducidad.ToString("yyyy/MM/dd"))
Next
Else
StrXML.AppendFormat("<concepto CvePS=""{0}"" CveUM=""{1}"" Cantidad= ""{2}"" CveSeccionAlmacen=""{3}"" Serie=""{4}"" Lote=""{5}"" FechaCaducidad=""{6}""></concepto>", Dr("CvePS"), Dr("CveUM"), Dr("CantidadGV"), IfNull(Dr("CveSeccion"), -1), "-1", Lote, FechaCaducidad.ToString("yyyy/MM/dd"))
End If
End If
Next
StrXML.Append("</conceptos>")
Dim TieneErrorExistencia = False
If ObjInventario.GetExistenciasPSXML(StrXML.ToString(), DdlAlmacen.SelectedValue.ToEntero(), TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveSubProyecto, CveVendedor, If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), If(TipoEntrega = 2, 1, -1), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then
If ObjInventario.DtResultados.Rows.Count > 0 Then
TieneErrorExistencia = True
For Each Dr As DataRow In ObjInventario.DtResultados.Rows
TextoError.AppendFormat("<b> - {0}</b> Existencia: {1:#,##0.##} <br/>", Dr("CodigoPS"), Dr("Existencia"))
Next
End If
Else
TieneErrorExistencia = True
End If
If TieneErrorExistencia Then
ObjInventario.RollBack()
ObjInventario.Dispose()
ObjConta.Dispose()
ObjVentas.Dispose()
ObjEventos.Dispose()
If TextoError.Length > 0 Then
Alert($" Lo(s) siguiente(s) Productos <b>no tienen</b> existencia suficiente:<br/><br/>{TextoError}", TipoMensaje.MsgAdvertencia)
End If
RegistraScript("playsonidito('142608__autistic-lucario__error.wav')")
Exit Sub
End If
End If
'' TERMINA: VALIDACIONES
Dim CantidadPendienteSinCosto As Decimal = 0
Dim CantidadSaldoSinCosto As Decimal = 0
Dim CantidadSalidaSinCosto As Decimal = 0
'' COMIENZA: SIN COSTO
If TipoDocto.Contiene("Ing", "Rem") AndAlso UsuarioActual.Empresa.Funcionalidad(587) = "1" AndAlso TipoMovimiento = 1 Then
Dim CveConceptoSalidaSinCosto As Integer = If(TipoDocto.Contiene("Rem"), 8, 40)
For Each Dr As DataRow In DtDatos.Rows
If Dr("CantidadGV").ToString().ToDecimal > 0 Then
If CBool(Dr("AplicaSerie")) Then
DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Dr("Consec")))
For Each Dr1 As DataRow In DtDetalle.Rows
If ObjInventario.GetExistenciasProducto(Dr1("CvePS").ToString().ToEntero(), Dr1("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, -1, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), Serie:=Dr1("Serie").ToString(), CveTipoAlmacen:=26, CveSubProyecto:=CveSubProyecto, Caducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then
For Each Dr2 As DataRow In ObjInventario.DtResultados.FiltraParametros("CveAlmacen > 0 AND ExistenciaFinal > 0").Rows
'BUSCA SI EXISTE YA UN TRASPASO DEL ALMACEN DE APARTADO
CveMovimientoSalida = DtTraspasos.FiltroPrimeroValor("CveMovimientoSalida", $"CveAlmacen = {Dr2("CveAlmacen")}").ToEntero()
If Not CveMovimientoSalida > 0 Then
CveMovimientoSalida = ObjInventario.AddMovimiento(Dr2("CveAlmacen").ToString().ToEntero(), CveConceptoSalidaSinCosto, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1,
Observaciones:=TxtObservaciones.Text.Trim, Guia:=TxtGuia.Text, CveContrato:=CveContrato, Modulo:="RE/GSC1")
FolioSalida = ObjInventario.Folio
If Not CveMovimientoSalida > 0 Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
Dim DrMovto = DtTraspasos.NewRow
DrMovto("Almacen") = Dr2("Almacen").ToString().ToEntero()
DrMovto("CveAlmacen") = Dr2("CveAlmacen").ToString().ToEntero()
DrMovto("CveMovimientoSalida") = CveMovimientoSalida
DrMovto("FolioSalida") = FolioSalida
DrMovto("CveTipoAlmacen") = 26
DrMovto("CveConceptoMovimientoSalida") = CveConceptoSalidaSinCosto
DtTraspasos.Rows.Add(DrMovto)
End If
CantidadPendienteSinCosto = 1
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadPendienteSinCosto, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, Serie:=Dr1("Serie").ToString(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un Error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("FueTraspaso") = 1
DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("CveVentaDetalle") = Dr("CveVentaDetalle")
Dr("CantidadTraspaso") = Dr("CantidadTraspaso").ToString().ToDecimal + CantidadPendienteSinCosto
Exit For
Next
End If
If ErrorMovInv Then Exit For
Next
Else
If ObjInventario.GetExistenciasProducto(Dr("CvePS").ToString().ToEntero(), Dr("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, -1, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveTipoAlmacen:=26, CveSubProyecto:=CveSubProyecto, Caducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then
CantidadSaldoSinCosto = Dr("CantidadGV").ToString().ToDecimal
For Each Dr1 As DataRow In ObjInventario.DtResultados.FiltraParametros("CveAlmacen > 0 AND ExistenciaFinal > 0").Rows
'BUSCA SI EXISTE YA UN TRASPASO DEL ALMACEN DE APARTADO
CveMovimientoSalida = DtTraspasos.FiltroPrimeroValor("CveMovimientoSalida", $"CveAlmacen = {Dr1("CveAlmacen")}").ToEntero()
If Not CveMovimientoSalida > 0 Then
CveMovimientoSalida = ObjInventario.AddMovimiento(Dr1("CveAlmacen").ToString().ToEntero(), CveConceptoSalidaSinCosto, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1,
Observaciones:=TxtObservaciones.Text.Trim, Guia:=TxtGuia.Text, CveContrato:=CveContrato, Modulo:="RE/GSC3")
FolioSalida = ObjInventario.Folio
If Not CveMovimientoSalida > 0 Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
Dim DrMovto = DtTraspasos.NewRow
DrMovto("Almacen") = Dr1("Almacen").ToString().ToEntero()
DrMovto("CveAlmacen") = Dr1("CveAlmacen").ToString().ToEntero()
DrMovto("CveMovimientoSalida") = CveMovimientoSalida
DrMovto("FolioSalida") = FolioSalida
DrMovto("CveTipoAlmacen") = 26
DrMovto("CveConceptoMovimientoSalida") = CveConceptoSalidaSinCosto
DtTraspasos.Rows.Add(DrMovto)
End If
CantidadPendienteSinCosto = If(Dr1("ExistenciaFinal").ToString().ToDecimal > CantidadSaldoSinCosto, CantidadSaldoSinCosto, Dr1("ExistenciaFinal").ToString().ToDecimal)
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadPendienteSinCosto.ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0,
Serie:=Dr("Serie").ToString(),
CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(),
FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha),
Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"),
CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
CantidadSaldoSinCosto -= CantidadPendienteSinCosto
Dr("CantidadTraspaso") = Dr("CantidadTraspaso").ToString().ToDecimal + CantidadPendienteSinCosto
If CantidadSaldoSinCosto <= 0 Then Exit For
Next
If ErrorMovInv Then Exit For
Else
ErrorMovInv = True
End If
End If
CantidadSalidaSinCosto += Dr("CantidadTraspaso").ToString().ToDecimal()
If ErrorMovInv Then Exit For
End If
Next
'ENTRADA POR TRASPASO A ENTREGA POR ADELANTADO
If TipoDocto = "Rem" AndAlso Not ErrorMovInv Then
For Each Dr1 As DataRow In DtTraspasos.Select("CveTipoAlmacen = 26")
CveMovimientoSalida = Dr1("CveMovimientoSalida").ToString().ToEntero()
Dim CveAlmacenExA As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveTipoAlmacen:=10).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto={CveSubProyecto}").ToEntero()
CveMovimientoEntradaApartado = ObjInventario.AddMovimiento(CveAlmacenExA, 9, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1,
Observaciones:=TxtObservaciones.Text.Trim, CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), CveMovimientoRelacionado:=CveMovimientoSalida,
Guia:=TxtGuia.Text, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=CveCliente, Modulo:="RE/G4")
FolioEntrada = ObjInventario.Folio
If Not CveMovimientoEntradaApartado > 0 Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
Dr1("CveMovimientoEntrada") = CveMovimientoEntradaApartado
Dr1("FolioEntrada") = FolioEntrada
If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then
Dim CveSeccionAlmacen As Integer = -1
For Each Dr As DataRow In ObjInventario.DtResultados.Rows
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntradaApartado, Dr("Cantidad").ToString().ToDouble, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3) Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
Next
End If
If ErrorMovInv Then Exit For
Next
End If
End If
If Not ErrorMovInv Then
For Each DrMovto As DataRow In DtTraspasos.FiltraParametros("CveConceptoMovimientoSalida = 40").Rows
ErrorMovInv = Not GenerarPrePoliza(ObjInventario, ObjVentas, ObjConta, DrMovto("CveMovimientoSalida").ToString().ToEntero(), TextoError)
If ErrorMovInv Then
Exit For
End If
Next
End If
''TERMINA: SIN COSTO
'' COMIENZA: APARTADOS
Dim CantidadPendiente As Decimal = 0
Dim CantidadSaldo As Decimal = 0
If Not ErrorMovInv AndAlso CveVendedor > 0 AndAlso (UsuarioActual.Empresa.Funcionalidad(146) = "1" Or CveCliente > 0) Then 'no debe considerar cuando es pedido de contrato
If TipoMovimiento = 1 Then ' SI ES DEVOLUCION NO APLICA APARTADO
' SALIDA POR TRASPASO DE LOS ALMACENES DE APARTADO
For Each Dr As DataRow In DtDatos.Rows
If Dr("CantidadGV").ToString().ToDecimal > 0 Then
If CBool(Dr("AplicaSerie")) Then
DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Dr("Consec")))
For Each Dr1 As DataRow In DtDetalle.Rows
If ObjInventario.GetExistenciasProducto(Dr1("CvePS").ToString().ToEntero(), Dr1("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, -1, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), Serie:=Dr1("Serie").ToString(), CveTipoAlmacen:=9, CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), ExcluyeApartados:=-1, Caducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-1) Then
Dim CveSeccionAlmacen As Integer = 0
For Each Dr2 As DataRow In ObjInventario.DtResultados.FiltraParametros("CveAlmacen > 0 AND ExistenciaFinal > 0").Rows
'BUSCA SI EXISTE YA UN TRASPASO DEL ALMACEN DE APARTADO
CveMovimientoSalida = DtTraspasos.FiltroPrimeroValor("CveMovimientoSalida", $"CveAlmacen = {Dr2("CveAlmacen")}").ToEntero()
If Not CveMovimientoSalida > 0 Then
CveMovimientoSalida = ObjInventario.AddMovimiento(Dr2("CveAlmacen").ToString().ToEntero(), 8, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1,
Observaciones:=TxtObservaciones.Text.Trim, Guia:=TxtGuia.Text, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente),
CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), Modulo:="RE/G1")
FolioSalida = ObjInventario.Folio
If Not CveMovimientoSalida > 0 Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
Dim DrMovto = DtTraspasos.NewRow
DrMovto("Almacen") = Dr2("Almacen").ToString().ToEntero()
DrMovto("CveAlmacen") = Dr2("CveAlmacen").ToString().ToEntero()
DrMovto("CveMovimientoSalida") = CveMovimientoSalida
DrMovto("FolioSalida") = FolioSalida
DrMovto("CveTipoAlmacen") = 9
DrMovto("CveConceptoMovimientoSalida") = 8
DtTraspasos.Rows.Add(DrMovto)
End If
CantidadPendiente = 1
'If CBool(Dr("AplicaSeccion")) Then
' CveSeccionAlmacen = GlobalDTInvPSSeccionesAlmacen(UsuarioActual.CveEmpresa, Dr2("CveAlmacen").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero()).FiltroPrimeroValor("CveSeccionAlmacen").ToEntero()
' Dim a As String = String.Format("CveAlmacen={0}-CvePS:{1}-CveseccionAlmacen={2}", Dr2("CveAlmacen"), Dr("CvePS"), CveSeccionAlmacen)
'Else
' CveSeccionAlmacen = -1
'End If
CveSeccionAlmacen = -3
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadPendiente.ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, Serie:=Dr1("Serie").ToString(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=CveSeccionAlmacen) Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un Error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("FueTraspaso") = 1
DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("CveVentaDetalle") = Dr("CveVentaDetalle")
Dr("CantidadTraspaso") = Dr("CantidadTraspaso").ToString().ToDecimal + CantidadPendiente
Exit For
Next
End If
If ErrorMovInv Then Exit For
Next
ElseIf CBool(Dr("AplicaLote")) Then
DtDetalle = DtDatosDetalleLote.FiltraParametros(String.Format("ConsecId = {0}", Dr("Consec")))
For Each Dr1 As DataRow In DtDetalle.Rows
If ObjInventario.GetExistenciasProducto(Dr1("CvePS").ToString().ToEntero(), Dr1("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, -1, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), Lote:=Dr1("Lote").ToString(), CveTipoAlmacen:=9, CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), ExcluyeApartados:=-1, Caducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), CveSeccionAlmacen:=-1) Then
CantidadSaldo = Dr("CantidadGV").ToString().ToDecimal
For Each Dr2 As DataRow In ObjInventario.DtResultados.FiltraParametros("CveAlmacen > 0 AND ExistenciaFinal > 0").Rows
'BUSCA SI EXISTE YA UN TRASPASO DEL ALMACEN DE APARTADO
CveMovimientoSalida = DtTraspasos.FiltroPrimeroValor("CveMovimientoSalida", $"CveAlmacen = {Dr2("CveAlmacen")}").ToEntero()
If Not CveMovimientoSalida > 0 Then
CveMovimientoSalida = ObjInventario.AddMovimiento(Dr2("CveAlmacen").ToString().ToEntero(), 8, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, Observaciones:=TxtObservaciones.Text.Trim,
Guia:=TxtGuia.Text, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente),
CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), Modulo:="RE/G2")
FolioSalida = ObjInventario.Folio
If Not CveMovimientoSalida > 0 Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
Dim DrMovto = DtTraspasos.NewRow
DrMovto("Almacen") = Dr2("Almacen").ToString().ToEntero()
DrMovto("CveAlmacen") = Dr2("CveAlmacen").ToString().ToEntero()
DrMovto("CveMovimientoSalida") = CveMovimientoSalida
DrMovto("FolioSalida") = FolioSalida
DrMovto("CveTipoAlmacen") = 9
DrMovto("CveConceptoMovimientoSalida") = 8
DtTraspasos.Rows.Add(DrMovto)
End If
CantidadPendiente = If(Dr1("Cantidad").ToString().ToDecimal > CantidadSaldo, CantidadSaldo, Dr1("Cantidad").ToString().ToDecimal)
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadPendiente.ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, Lote:=Dr1("Lote").ToString(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("FueTraspaso") = 1
DtDatosDetalle.Select($"Consec = {Dr1("Consec")}")(0)("CveVentaDetalle") = Dr("CveVentaDetalle")
CantidadSaldo -= CantidadPendiente
Dr("CantidadTraspaso") = Dr("CantidadTraspaso").ToString().ToDecimal + CantidadPendiente
If CantidadSaldo <= 0 Then Exit For
Next
End If
Next
Else
If ObjInventario.GetExistenciasProducto(Dr("CvePS").ToString().ToEntero(), Dr("CveUM").ToString().ToEntero(), UsuarioActual.CveEmpresa, -1, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveTipoAlmacen:=9, CveVendedor:=CveVendedor, CveSubProyecto:=CveSubProyecto, CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), ExcluyeApartados:=-1, Caducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-1) Then
CantidadSaldo = Dr("CantidadGV").ToString().ToDecimal
For Each Dr1 As DataRow In ObjInventario.DtResultados.FiltraParametros("CveAlmacen > 0 AND ExistenciaFinal > 0").Rows
'BUSCA SI EXISTE YA UN TRASPASO DEL ALMACEN DE APARTADO
CveMovimientoSalida = DtTraspasos.FiltroPrimeroValor("CveMovimientoSalida", $"CveAlmacen = {Dr1("CveAlmacen")}").ToEntero()
If Not CveMovimientoSalida > 0 Then
CveMovimientoSalida = ObjInventario.AddMovimiento(Dr1("CveAlmacen").ToString().ToEntero(), 8, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1,
Observaciones:=TxtObservaciones.Text.Trim, Guia:=TxtGuia.Text, CveContrato:=CveContrato, CveVendedor:=CveVendedor,
CveCliente:=If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), Modulo:="RE/G3")
FolioSalida = ObjInventario.Folio
If Not CveMovimientoSalida > 0 Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
Dim DrMovto = DtTraspasos.NewRow
DrMovto("Almacen") = Dr1("Almacen").ToString().ToEntero()
DrMovto("CveAlmacen") = Dr1("CveAlmacen").ToString().ToEntero()
DrMovto("CveMovimientoSalida") = CveMovimientoSalida
DrMovto("FolioSalida") = FolioSalida
DrMovto("CveTipoAlmacen") = 9
DrMovto("CveConceptoMovimientoSalida") = 8
DtTraspasos.Rows.Add(DrMovto)
End If
CantidadPendiente = If(Dr1("ExistenciaFinal").ToString().ToDecimal > CantidadSaldo, CantidadSaldo, Dr1("ExistenciaFinal").ToString().ToDecimal)
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, CantidadPendiente.ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0,
Serie:=Dr("Serie").ToString(),
CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(),
FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha),
Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"),
CveSeccionAlmacen:=-3) Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
CantidadSaldo -= CantidadPendiente
Dr("CantidadTraspaso") = Dr("CantidadTraspaso").ToString().ToDecimal + CantidadPendiente
If CantidadSaldo <= 0 Then Exit For
Next
If ErrorMovInv Then Exit For
Else
ErrorMovInv = True
End If
End If
If ErrorMovInv Then Exit For
End If
Next
'ENTRADA POR TRASPASO AL ALMACEN GENERAL
If Not ErrorMovInv Then
For Each Dr1 As DataRow In DtTraspasos.Select("CveTipoAlmacen = 9")
CveMovimientoSalida = Dr1("CveMovimientoSalida").ToString().ToEntero()
CveMovimientoEntradaApartado = ObjInventario.AddMovimiento(DdlAlmacen.SelectedValue.ToEntero(), 9, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1,
Observaciones:=TxtObservaciones.Text.Trim, CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), CveMovimientoRelacionado:=CveMovimientoSalida,
Guia:=TxtGuia.Text, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=CveCliente, Modulo:="RE/G4")
FolioEntrada = ObjInventario.Folio
If Not CveMovimientoEntradaApartado > 0 Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
Dr1("CveMovimientoEntrada") = CveMovimientoEntradaApartado
Dr1("FolioEntrada") = FolioEntrada
If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then
For Each Dr As DataRow In ObjInventario.DtResultados.Rows
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntradaApartado, Dr("Cantidad").ToString().ToDouble, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3) Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
Next
End If
If ErrorMovInv Then Exit For
Next
End If
End If
End If
'' TERMINA: APARTADOS
Dim TotalGarantia As Decimal = 0
' COMIENZA: GARANTIAS
If Not ErrorMovInv AndAlso TipoDocto.Contiene("Ing", "Rem") AndAlso UsuarioActual.Empresa.Funcionalidad(531) = "1" AndAlso TipoMovimiento = 1 Then
Dim CveAlmacenGarantia As Integer = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 6).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto={CveSubProyecto}").ToEntero()
Dim DtGarantias As DataTable = Nothing
If ObjAcumuladores.GetGarantiasDetalle(CveVentaSurtir) Then
DtGarantias = ObjAcumuladores.DtResultados.Copy()
End If
If DtGarantias IsNot Nothing AndAlso DtGarantias.Rows.Count > 0 AndAlso CveAlmacenGarantia > 0 Then
CveMovimientoGarantia = ObjInventario.AddMovimiento(CveAlmacenGarantia, 2, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, Guia:=TxtGuia.Text, Modulo:="RE/G5")
FolioGarantia = ObjInventario.Folio
For Each RowGarantia As DataRow In DtGarantias.Rows
Dim CvePS = RowGarantia("CvePS").ToString().ToEntero()
Dim CveTamaño As Integer = RowGarantia("CveTamaño").ToString().ToEntero()
Dim CveUM As Integer = RowGarantia("CveUnidadMedida").ToString().ToEntero()
Dim PU As Decimal = RowGarantia("Importe").ToString().ToDecimal() ' / RowGarantia("Cantidad").ToString().ToDouble()
Dim Serie As String = RowGarantia("Comprobante").ToString
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoGarantia, RowGarantia("Cantidad").ToString().ToDouble(), CveUM, CvePS, PU, Serie:=Serie) Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
TotalGarantia += (RowGarantia("Cantidad").ToString().ToDecimal() * PU)
Next
End If
End If
' TERMINA: GARANTIAS
'DEVOLUCION DE SIN COSTO
Dim CantidadEntradaSinCosto As Decimal = 0
If Not ErrorMovInv AndAlso TipoMovimiento = 2 AndAlso UsuarioActual.Empresa.Funcionalidad(587) = "1" Then
For Each Dr1 As DataRow In DtExistencias.FiltraParametros("CveTipoAlmacenDevolucion = 26").Rows
Dim CveMovimientoSalidaSinCosto = Dr1("CveMovimiento").ToString().ToEntero()
'Dim CveAlmacenSinCosto As Integer = Dr1("CveAlmacenDevolucion").ToString().ToEntero()
'Dim AlmacenSinCosto As String = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveTipoAlmacen:=26).FiltroPrimeroValor("Almacen", $"CveAlmacen={CveAlmacenSinCosto}").ToString()
Dim CveMovimientoDevolucionSinCosto = ObjInventario.AddMovimiento(DdlAlmacen.SelectedValue.ToEntero(), 41, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1,
Observaciones:=TxtObservaciones.Text.Trim, CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), CveMovimientoRelacionado:=CveMovimientoSalida,
Guia:=TxtGuia.Text, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=CveCliente, Modulo:="RE/G4")
Dim FolioDevSinCosto = ObjInventario.Folio
If Not CveMovimientoDevolucionSinCosto > 0 Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
If ObjInventario.GetMovimientosDetalle(CveMovimientoSalidaSinCosto, UsuarioActual.CveEmpresa) Then
For Each Dr As DataRow In ObjInventario.DtResultados.Rows
CantidadEntradaSinCosto += Dr("Cantidad").ToString().ToDecimal()
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoDevolucionSinCosto, Dr("Cantidad").ToString().ToDouble, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)) Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
Next
End If
If ErrorMovInv Then Exit For
Dim DrMovto = DtDevSinCosto.NewRow
DrMovto("Almacen") = DdlAlmacen.SelectedItem.Text
DrMovto("CveAlmacen") = DdlAlmacen.SelectedValue.ToEntero()
DrMovto("CveMovimientoEntrada") = CveMovimientoDevolucionSinCosto
DrMovto("FolioEntrada") = FolioDevSinCosto
DrMovto("CveTipoAlmacen") = 10
DrMovto("CveConceptoMovimientoSalida") = 41
DtDevSinCosto.Rows.Add(DrMovto)
If Not ErrorMovInv Then
ErrorMovInv = Not GenerarPrePoliza(ObjInventario, ObjVentas, ObjConta, CveMovimientoDevolucionSinCosto, TextoError)
End If
Next
End If
Dim CantidadPendientePorSalir As Decimal = DtDatos.SUM("CantidadGV").ToDecimal()
If TipoMovimiento = 1 Then
CantidadPendientePorSalir = CantidadPendientePorSalir - CantidadSalidaSinCosto
ElseIf TipoMovimiento = 2 Then
CantidadPendientePorSalir = CantidadPendientePorSalir - CantidadEntradaSinCosto
End If
'si el alamcen del que salio, es el mismo que entra, no hay traspasos.
If CveAlmacenTraspasoDestino = DdlAlmacen.SelectedValue.ToEntero() And TipoDocto <> "Rem" Then CveAlmacenTraspasoDestino = 0
If Not ErrorMovInv AndAlso CantidadPendientePorSalir > 0 Then
Dim ConceptoMovimiento = 3
ConceptoMovimiento = If(TipoMovimiento = 1, ConceptoMovimiento, 18)
ConceptoMovimiento = If(CveAlmacenTraspasoDestino > 0, 8, ConceptoMovimiento)
Dim Almacen1 As Integer = DdlAlmacen.SelectedValue.ToEntero()
If TipoDocto = "Rem" AndAlso CveAlmacenTraspasoDestino = 0 Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error. no se tiene definido el almacen destino")
End If
'DEVOLUCION REMISION
If TipoMovimiento = 2 And TipoDocto = "Rem" Then
ConceptoMovimiento = 8
Almacen1 = CveAlmacenTraspasoDestino
CveAlmacenTraspasoDestino = DdlAlmacen.SelectedValue.ToEntero()
End If
'CANCELACION DE DEVOLUCION
If TipoMovimiento = 2 And TipoDocto = "Dev" And EsDevolucionVenta = 1 Then
ConceptoMovimiento = 3
Almacen1 = DdlAlmacen.SelectedValue.ToEntero()
CveAlmacenTraspasoDestino = DdlAlmacen.SelectedValue.ToEntero()
End If
'DEVOLUCION DIRECTA A ENTREGA POR ADELANTADO
If TipoMovimiento = 2 And ConceptoMovimiento = 18 AndAlso EsDevolucionDirecta Then
ConceptoMovimiento = 41
End If
CveMovimiento = ObjInventario.AddMovimiento(Almacen1, ConceptoMovimiento, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, Guia:=TxtGuia.Text,
CveContrato:=CveContrato, CveAlmacenDestino:=CveAlmacenTraspasoDestino, Modulo:="RE/G7")
Folio = ObjInventario.Folio
'SALIDA DE ALMACEN - SALIDA POR TRASPASO CUANDO ES REMISION - DEVOLUCION (SI ES TRASPASO Y TIENE CONTRATO NO HACE DEVOLUCIóN)
'If Not (CveContrato > 0 And CveAlmacenTraspasoDestino > 0) Then
If CveMovimiento > 0 Then
'SACA LO DE TRASPASOS - APARTADO
For Each Dr1 As DataRow In DtTraspasos.Select("CveTipoAlmacen = 9")
CveMovimientoSalida = Dr1("CveMovimientoEntrada").ToString().ToEntero()
If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then
If ObjInventario.DtResultados.Rows.Count = 0 Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error, no se tienen registros que ingresar")
Exit Sub
End If
For Each Dr As DataRow In ObjInventario.DtResultados.Rows
If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, Dr("Cantidad").ToString().ToDouble, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3, EsInterno:=EsInterno) Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
Next
Else
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al obtener los registros")
End If
If ErrorMovInv Then Exit For
Next
'ES EL MOVIMIENTO PRINCIPAL
CantidadPendiente = 0
Dim Cont As Integer = 0
For Each Dr As DataRow In DtDatos.Rows
CantidadPendiente = Dr("CantidadGV").ToString().ToDecimal - Dr("CantidadTraspaso").ToString().ToDecimal - CantidadEntradaSinCosto
If CantidadPendiente > 0 Then
Dim PU As Decimal = 0
Dim CveSeccionAlmacen As Integer = If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)
'SI FUE POR SERIE
DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0} AND FueTraspaso IS NULL", Dr("Consec")))
DtDetalleLote = DtDatosDetalleLote.FiltraParametros(String.Format("ConsecId = {0} AND FueTraspaso IS NULL", Dr("Consec")))
If DtDetalle.Rows.Count > 0 Then
For Each Dr1 As DataRow In DtDetalle.Rows
If TipoMovimiento = 2 AndAlso DtExistencias IsNot Nothing Then
'CveSeccionAlmacen = DtExistencias.FiltroPrimeroValor("CveSeccionAlmacen", $"ISNULL(CveTipoAlmacenDevolucion,0) <> 26 AND CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString().ToEntero()} AND Serie = '{Dr1("Serie").ToString()}'").ToString().ToEntero
PU = DtExistencias.FiltroPrimeroValor("PU", $"CveTipoAlmacenDevolucion <> 26 AND CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString().ToEntero()} AND Serie = '{Dr1("Serie").ToString()}'").ToString().ToDecimal
End If
If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, 1, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), PU, Serie:=Dr1("Serie").ToString(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3) Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los conceptos con serie. Por favor vuelva a intentar.")
Exit For
End If
Next
ElseIf DtDetalleLote.Rows.Count > 0 Then
For Each Dr1 As DataRow In DtDetalleLote.Rows
If TipoMovimiento = 2 AndAlso DtExistencias IsNot Nothing Then
'CveSeccionAlmacen = DtExistencias.FiltroPrimeroValor("CveSeccionAlmacen", $"CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString().ToEntero()} AND Serie = '{Dr1("Serie").ToString()}'").ToString().ToEntero
PU = DtExistencias.FiltroPrimeroValor("PU", $"CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString().ToEntero()} AND Serie = '{Dr1("Serie").ToString()}'").ToString().ToDecimal
End If
If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, Dr1("Cantidad").ToString().ToDouble, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), PU, CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3) Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los conceptos con serie. Por favor vuelva a intentar.")
Exit For
End If
Next
Else
If TipoMovimiento = 2 AndAlso DtExistencias IsNot Nothing Then
PU = DtExistencias.FiltroPrimeroValor("PU", $"CvePS = {Dr("CvePS")} AND CveUM = {Dr("CveUM").ToString().ToEntero()}").ToString().ToDecimal
End If
If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, CantidadPendiente, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), PU, CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), FechaCaducidad:=If(CBool(Dr("AplicaCaducidad")), Dr("FechaCaducidad").ToString().ToDate, MinFecha), Lote:=If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1"), CveSeccionAlmacen:=-3) Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de salida. Por favor vuelva a intentar.")
Exit For
End If
End If
'If ObjInventario.CveMovimientoDetalle > 0 AndAlso DtSeccionAlmacen.Rows.Count > 0 Then
' For Each Dr2 As DataRow In DtSeccionAlmacen.FiltraParametros($"IndexSeccionAlmacen = {Cont}").Rows
' If Not ObjInventario.AddMovimientosDetalleSeccionesAlmacen(ObjInventario.CveMovimientoDetalle, Dr2("CveSeccionAlmacen").ToString().ToEntero(), -Dr2("CantidadSeccionAlmacen").ToString().ToDecimal) Then
' ErrorMovInv = True
' TextoError = "Ocurrió un error al procesar las secciones de almacen. Por favor vuelva a intentar."
' Exit For
' End If
' Next
'End If
Cont += 1
End If
Next
Else
ErrorMovInv = True
End If
'ENTRADA POR TRASPASO CUANDO ES REMISION
If Not ErrorMovInv Then
If CveAlmacenTraspasoDestino > 0 AndAlso Not (TipoMovimiento = 2 And TipoDocto = "Dev" And EsDevolucionVenta = 1) Then ' TRASPASO CUANDO ES REMISION
CveMovimientoEntrada = ObjInventario.AddMovimiento(CveAlmacenTraspasoDestino, 9, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, Guia:=TxtGuia.Text, CveContrato:=CveContrato,
CveMovimientoRelacionado:=CveMovimiento, CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(), Modulo:="RE/G8")
FolioEntrada = ObjInventario.Folio
Dim ImporteAlmacen As Decimal = 0
If CveMovimientoEntrada <= 0 Then
TextoError.AppendFormat("No se pudo generar el movimiento de entrada correctamente")
ErrorMovInv = True
Else
If ObjInventario.GetMovimientosDetalle(CveMovimiento, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then
ImporteAlmacen = ObjInventario.DtResultados.SUMD("Total").RoundSQL
For Each Dr As DataRow In ObjInventario.DtResultados.Rows
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Dr("Cantidad").ToString().ToDouble, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), CveSeccionAlmacen:=-3, Serie:=Dr("Serie").ToString(), Lote:=Dr("Lote").ToString(), FechaCaducidad:=Dr("FechaCaducidad").ToString().ToDate, CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), EsInterno:=EsInterno, CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero()) Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al guardar los movimientos de entrada")
Exit For
End If
Next
Else
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al guardar los movimientos de entrada")
End If
End If
'se registra
If ContabilizaMovimientoAlmacen(ObjConta, TxtFecha.Text.ToDate, HLFolio.Text, "EntregaAlmacen", CveMovimiento, CveMovimientoEntrada, ImporteAlmacen, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, False) <= 0 Then
ErrorMovInv = True
End If
Else 'REGISTRO LA PREPOLIZA DE COSTO VS ALMACEN - SALIDA ALMACEN
ErrorMovInv = Not GenerarPrePoliza(ObjInventario, ObjVentas, ObjConta, CveMovimiento, TextoError)
End If
End If
End If
'DEVOLUCION APARTADOS
If Not ErrorMovInv Then
If TipoMovimiento = 2 Then
If ObjInventario.VentasAlmacenApartadosGet(CveVentaSurtir) Then
Dim DtTempApartados = ObjInventario.DtResultados.FiltraParametros("CveTipoAlmacen = 9", "CveAlmacen")
Dim CveMovimientoSalidaApartado = -1
Dim CveAlmacenApartado = -1
Dim CveAlmacenOrigen = If(CveAlmacenTraspasoDestino > 0, CveAlmacenTraspasoDestino, DdlAlmacen.SelectedValue.ToEntero())
Dim CveSeccionAlmacen As Integer = 0
Dim ValorTraspaso As Decimal = 0
If DtTempApartados IsNot Nothing AndAlso DtTempApartados.Rows.Count > 0 Then
For Each Dr As DataRow In DtTempApartados.Rows
If CveMovimientoSalidaApartado = -1 Or CveAlmacenApartado <> Dr("CveAlmacen").ToString().ToEntero() Then
CveMovimientoSalidaApartado = ObjInventario.AddMovimiento(CveAlmacenOrigen, 8, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1,
Observaciones:=TxtObservaciones.Text.Trim, Guia:=TxtGuia.Text, CveContrato:=CveContrato, CveVendedor:=CveVendedor, CveCliente:=CveCliente,
CveAlmacenDestino:=Dr("CveAlmacen").ToString().ToEntero(), Modulo:="RE/G9")
FolioSalida = ObjInventario.Folio
CveAlmacenApartado = Dr("CveAlmacen").ToString().ToEntero()
Dim DrMovto = DtTraspasos.NewRow
DrMovto("Almacen") = Dr("Almacen").ToString().ToEntero()
DrMovto("CveAlmacen") = Dr("CveAlmacen").ToString().ToEntero()
DrMovto("CveMovimientoSalida") = CveMovimientoSalidaApartado
DrMovto("FolioSalida") = FolioSalida
DtTraspasos.Rows.Add(DrMovto)
End If
If Not CveMovimientoSalidaApartado > 0 Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al guardar los movimientos de control de apartados")
Exit For
End If
'If CBool(Dr("AplicaSeccion")) Then
' CveSeccionAlmacen = GlobalDTInvPSSeccionesAlmacen(UsuarioActual.CveEmpresa, CveAlmacenOrigen, Dr("CvePS").ToString().ToEntero()).FiltroPrimeroValor("CveSeccionAlmacen").ToEntero()
' Dim a As String = String.Format("CveAlmacen={0}-CvePS:{1}-CveseccionAlmacen={2}", CveAlmacenOrigen, Dr("CvePS"), CveSeccionAlmacen)
'Else
' CveSeccionAlmacen = -1
'End If
CveSeccionAlmacen = -3
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalidaApartado, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero(), Lote:=Dr("Lote").ToString(), CveSeccionAlmacen:=CveSeccionAlmacen) Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al guardar los movimientos de control de apartados")
Exit For
End If
Next
If Not ErrorMovInv Then
Dim CvePrePolizaTraspaso As Integer = ObjConta.AddPrePolizas("EA/Apart", 53, 0, 0, 1, TxtFecha.Text.ToDate, "Traspaso Apartado", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
If CvePrePolizaTraspaso > 0 Then
If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, True, ValorTraspaso, TxtObservaciones.Text, 68, TxtObservaciones.Text, TxtFecha.Text.ToDate, -1, -1, CveMovimientoAlmacen:=CveMovimientoSalidaApartado, Contabilizable:=False, ImporteMX:=ValorTraspaso) Then
ErrorMovInv = True
End If
For Each Dr1 As DataRow In DtTraspasos.Rows
CveMovimientoSalida = Dr1("CveMovimientoSalida").ToString().ToEntero()
CveMovimientoEntradaApartado = ObjInventario.AddMovimiento(Dr1("CveAlmacen").ToString().ToEntero(), 9, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa,
-1, CveVentaSurtir, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, CveAlmacenDestino:=DdlAlmacen.SelectedValue.ToEntero(),
CveMovimientoRelacionado:=CveMovimientoSalida, Guia:=TxtGuia.Text, CveContrato:=CveContrato, CveVendedor:=CveVendedor,
CveCliente:=CveCliente, Modulo:="RE/G10")
FolioEntrada = ObjInventario.Folio
If Not CveMovimientoEntradaApartado > 0 Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los movimientos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
Dr1("CveMovimientoEntrada") = CveMovimientoEntradaApartado
Dr1("FolioEntrada") = FolioEntrada
If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then
ValorTraspaso = ObjInventario.DtResultados.SUMD("Total").RoundSQL
For Each Dr As DataRow In ObjInventario.DtResultados.Rows
CveSeccionAlmacen = -3
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntradaApartado, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), Serie:=Dr("Serie").ToString(), CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), Lote:=Dr("Lote").ToString(), CveSeccionAlmacen:=CveSeccionAlmacen) Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
Next
End If
If ErrorMovInv Then Exit For
If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, False, ValorTraspaso, TxtObservaciones.Text, 68, TxtObservaciones.Text, TxtFecha.Text.ToDate, -1, -1, CveMovimientoAlmacen:=CveMovimientoEntradaApartado, Contabilizable:=False, ImporteMX:=ValorTraspaso) Then
ErrorMovInv = True
End If
Next
Else
ErrorMovInv = True
End If
End If
End If
End If
End If
End If
'QUEMAR REMISIONES
If Not ErrorMovInv And EsDevolucionVenta = 1 And TipoDocto = "Ing" Then
Dim DtDevRem As New DataTable
'CARGA REMISIONES DE LA VENTA DEVUELTA
If ObjInventario.GetDevolucionRemisionesFacturadas(CveVentaSurtir) Then
DtDevRem = ObjInventario.DtResultados.FiltraParametros("CantidadAlmacen = 0")
Else
ErrorMovInv = True
End If
If Not ErrorMovInv Then
If DtDevRem.Rows.Count > 0 Then
For Each DrMovtos As DataRow In DtDevRem.FiltraParametros("", "CveRem", {"CveRem"}).Rows
If Not ObjInventario.ActualizarEsDevolucionVenta(DrMovtos("CveRem").ToString().ToEntero(), 2) Then
TextoError.AppendFormat("Ocurrió un error al hacer la devolución hacia la remision. Por favor vuelva a intentar.")
ErrorMovInv = True
Exit For
End If
Next
End If
Else
TextoError.AppendFormat("Ocurrió un error al hacer la devolucion a remisión. Por favor vuelva a intentar.")
ErrorMovInv = True
End If
End If
'QUEMA DEVOLUCION | QUEMA = LA QUITA DE PENDIENTE POR RECIBIR (DEVOLVER)
If Not ErrorMovInv And EsDevolucionVenta = 1 Then
If Not ObjVentas.UpdateVentasDevolucionAlmacen(2, CveVentaSurtir) Then
TextoError.AppendFormat("Ocurrió un error al hacer la devolución. Por favor vuelva a intentar.")
ErrorMovInv = True
End If
End If
If Not ErrorMovInv And EsDevolucionVenta = 0 Then
If Not ObjVentas.UpdateVentasDevolucionAlmacen(0, CveVentaSurtir) Then
TextoError.AppendFormat("Ocurrió un error al hacer la devolucion. Por favor vuelva a intentar.")
ErrorMovInv = True
End If
End If
Dim TotalVirtual As Decimal = 0
' COMIENZA: VIRTUAL
If Not ErrorMovInv AndAlso TipoDocto.Contiene("Ing", "Dev") AndAlso UsuarioActual.Empresa.Funcionalidad(573) = "1" AndAlso CveMovimiento > 0 Then
Dim DtPSVirtual As New DataTable("DtTamanios")
Dim tCveAlmacen As Integer = -1
If ObjInventario.GetMovimientos(CveMovimiento, -1, -1, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then
tCveAlmacen = ObjInventario.DtResultados.FiltroPrimeroValor("CveAlmacen").ToEntero()
End If
If ObjInventario.GetMovimientosDetalleVirtual(CveMovimiento, UsuarioActual.CveEmpresa) Then
DtPSVirtual = ObjInventario.DtResultados
End If
'
'DtPSVirtual.Columns.Add(New DataColumn("CvePS", GetType(Integer)))
'DtPSVirtual.Columns.Add(New DataColumn("Cantidad", GetType(Decimal)))
'DtPSVirtual.Columns.Add(New DataColumn("PU", GetType(Decimal)))
'DtPSVirtual.Columns.Add(New DataColumn("CveUM", GetType(Integer)))
'Dim DtTamanios As DataTable = Nothing
'If ObjAcumuladores.TamañoGet(-1, UsuarioActual.CveEmpresa) Then
' DtTamanios = ObjAcumuladores.DtResultados.Copy()
'End If
Dim CveConceptoMovimientoVirtual As Integer = -1
Dim CveAlmacenVirtual As Integer = -1
Dim CveMovimientoRelacionadoVirtual As Integer = CveMovimiento
Dim ValidaVirtual As Boolean = False
CveAlmacenVirtual = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=tCveAlmacen).FiltroPrimeroValor("CveAlmacenVirtual").ToEntero()
If TipoMovimiento = 1 Then
CveConceptoMovimientoVirtual = 37
ElseIf TipoMovimiento = 2 Then
ValidaVirtual = True
CveConceptoMovimientoVirtual = 36
End If
'SI NO TIENE ALMACEN VIRTUAL ASIGNADO NO GENERA EL MOVIMIENTO VIRTUAL
If CveAlmacenVirtual <= 0 Then
ValidaVirtual = False
End If
'SI NO APLICA VIRTUAL EN LOS PRODUCTOS NO VALIDA
If CveAlmacenVirtual > 0 AndAlso DtPSVirtual IsNot Nothing AndAlso DtPSVirtual.Rows.Count = 0 Then
ValidaVirtual = False
End If
If DtPSVirtual IsNot Nothing AndAlso DtPSVirtual.Rows.Count > 0 AndAlso CveAlmacenVirtual > 0 AndAlso CveConceptoMovimientoVirtual > 0 Then
CveMovimientoVirtual = ObjInventario.AddMovimiento(CveAlmacenVirtual, CveConceptoMovimientoVirtual, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVentaSurtir, -1, -1,
Observaciones:=TxtObservaciones.Text.Trim, Guia:=TxtGuia.Text, CveMovimientoRelacionado:=CveMovimientoRelacionadoVirtual, Modulo:="RE/G6")
FolioVirtual = ObjInventario.Folio
If CveMovimientoVirtual > 0 Then
For Each RowUsado As DataRow In DtPSVirtual.Rows
Dim CvePS = RowUsado("CvePS").ToString().ToEntero()
Dim CantidadUsado As Decimal = RowUsado("Cantidad").ToString().ToDecimal()
Dim PU As Decimal = RowUsado("Cargo").ToString().ToDecimal()
Dim CveUM As Integer = RowUsado("CveUM").ToString().ToEntero()
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoVirtual, CantidadUsado, CveUM, CvePS, PU) Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar los conceptos de traspaso de apartado. Por favor vuelva a intentar.")
Exit For
End If
TotalVirtual += (CantidadUsado * PU)
Next
'insertar en prepóliza de la salida virtual
If Not ErrorMovInv Then
ErrorMovInv = Not GenerarPrePoliza(ObjInventario, ObjVentas, ObjConta, CveMovimientoVirtual, TextoError)
End If
Else
ErrorMovInv = True
End If
Else
If ValidaVirtual Then
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un error al procesar el movimiento en almacen virtual. Por favor vuelva a intentar.")
End If
End If
If DtPSVirtual.Rows.Count = 0 AndAlso ValidaVirtual = True Then
ErrorMovInv = True
TextoError.AppendFormat("No se tienen productos para el almacen virtual.")
End If
End If
' TERMINA: VIRTUAL
'AGREGA BITACORA A VENTA
If Not ErrorMovInv Then
Dim MensajeBitacora = If(TipoMovimiento = 1, "Surtida", "Devuelta")
If Not ObjEventos.AddEventoBitacora(String.Format("Venta {2} en Folio: <a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}"" target=""_blank"">{1}</a>", CveMovimiento, Folio, MensajeBitacora), "-1", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveVenta:=CveVentaSurtir) Then
ErrorMovInv = True
End If
End If
'Paqueterias guias
If RbEntregaInterna.Checked AndAlso Not ErrorMovInv Then
Dim CveEstatus As Integer = 1 ' DdlEstatus.SelectedValue.ToEntero()
Dim Fecha As String = Now.ToString() 'TxtFechaPaqInterna.Text
Dim FechaEstimada As String = "-1" 'If(TxtFechaEstimada.Text = "", "-1", TxtFechaEstimada.Text)
Dim NoCajas As Integer = 0 'TxtNoCajas.Text.ToEntero()
Dim Observaciones As String = "" 'TxtObservacionesPaqInterna.Text
Dim CvePaqueteria As Integer = GlobalDTPaqueterias(UsuarioActual.CveEmpresa, 0).FiltroPrimeroValor("CvePaqueteria", "").ToEntero()
If CveSubProyecto > 0 Then
Dim CvePaqueteriaGuia As Integer = ObjGeneral.AddPaqueteriasGuias(CvePaqueteria, 9, CveEstatus, CveSubProyecto, Fecha, "", "", NoCajas, 0.00, "-1", FechaEstimada, Observaciones, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, EsEntregaInterna:=True)
If CvePaqueteriaGuia > 0 Then
If CveVentaSurtir > 0 OrElse CveSubProyecto > 0 Then
If Not ObjGeneral.AddPaqueteriasGuiasDetalles(CvePaqueteriaGuia, CveVentaSurtir, -1, CveMovimientoSalida, -1) Then
''manda correo
ErrorMovInv = True
End If
End If
If ErrorMovInv Then
Alert("Error en el paqueteria guia detalle", TipoMensaje.MsgError)
End If
Else
ErrorMovInv = True
Alert("Error en el paqueteria guia", TipoMensaje.MsgError)
End If
Else
Alert("Hace falta indicar un Sub Proyecto", TipoMensaje.MsgAdvertencia)
ErrorMovInv = True
End If
ElseIf RbSinEntrega.Checked AndAlso Not ErrorMovInv Then
MandaCorreoEntrega(CveVentaSurtir)
End If
Catch ex As Exception
ErrorMovInv = True
OnError("Ocurrió un error al guardar", ex)
End Try
If Not ErrorMovInv Then
ObjInventario.Commit()
ObjGeneral.Dispose()
RegistraScript("playsonidito('beep-07.wav')")
Dim Msg As New StringBuilder
Msg.AppendFormat("Movimiento {2}: <b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}"" target=""_blank"">{1}</a></b>", CveMovimiento, Folio, If(TipoMovimiento = 1, "Salida", "Entrada"))
Msg.AppendFormat("<br/><a class=""Texto"" target='_blank' href=""/Compras/PopUpVerFactura.aspx?P={0}"">Imprimir Movimiento</a> ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimiento)))
If CveMovimientoEntrada > 0 Then
Msg.AppendFormat("<br/><br/> Movimiento Entrada (Traspaso): <b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}"" target=""_blank"">{1}</a></b>", CveMovimientoEntrada, FolioEntrada)
Msg.AppendFormat("<br/> <a class=""Texto"" target='_blank' href=""/Compras/PopUpVerFactura.aspx?P={0}"">Imprimir Movimiento</a> ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoEntrada)))
End If
If DtTraspasos.FiltraParametros("CveTipoAlmacen=9").Rows.Count > 0 Then
Msg.AppendFormat("<br/><br/> Movimientos de Control (Apartados):")
For Each Dr As DataRow In DtTraspasos.Rows
Msg.AppendFormat("<br/>Almacén {0} | Salida por Traspaso: <b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={1}"" target=""_blank"">{2}</a></b> | Entrada por Traspaso: <b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={3}"" target=""_blank"">{4}</a></b> ", Dr("Almacen"), Dr("CveMovimientoSalida"), Dr("FolioSalida"), Dr("CveMovimientoEntrada"), Dr("FolioEntrada"))
Next
End If
If DtTraspasos.FiltraParametros("CveTipoAlmacen=26").Rows.Count > 0 Then
Msg.AppendFormat("<br/><br/> Movimientos de Control (Sin Costo):")
For Each Dr As DataRow In DtTraspasos.FiltraParametros("CveConceptoMovimientoSalida=40").Rows
Msg.AppendFormat("<br/>Almacén {0} | Salida directa de almacen: <b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={1}"" target=""_blank"">{2}</a></b> ", Dr("Almacen"), Dr("CveMovimientoSalida"), Dr("FolioSalida"), Dr("CveMovimientoEntrada"), Dr("FolioEntrada"))
Next
For Each Dr As DataRow In DtTraspasos.FiltraParametros("CveConceptoMovimientoSalida=8").Rows
Msg.AppendFormat("<br/>Almacén {0} | Salida por Traspaso: <b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={1}"" target=""_blank"">{2}</a></b> ", Dr("Almacen"), Dr("CveMovimientoSalida"), Dr("FolioSalida"), Dr("CveMovimientoEntrada"), Dr("FolioEntrada"))
Next
End If
If DtDevSinCosto.Rows.Count > 0 Then
Msg.AppendFormat("<br/><br/> Movimientos de Control (Sin Costo):")
For Each Dr As DataRow In DtDevSinCosto.Rows
Msg.AppendFormat("<br/>Almacén {0} | Devolución directa de almacen: <b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={1}"" target=""_blank"">{2}</a></b> ", Dr("Almacen"), Dr("CveMovimientoEntrada"), Dr("FolioEntrada"))
Next
End If
If CveMovimientoGarantia > 0 Then
Msg.AppendFormat("<br/>Movimiento de Entrada (garantías): <b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}"" target=""_blank"">{1}</a></b>", CveMovimientoGarantia, FolioGarantia)
Msg.AppendFormat("<br/><a class=""Texto"" target='_blank' href=""/Compras/PopUpVerFactura.aspx?P={0}"">Imprimir Movimiento</a> ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoGarantia)))
End If
If CveMovimientoVirtual > 0 Then
Msg.AppendFormat("<br/><br/> {0} Almacen Virtual: ", If(TipoMovimiento = 1, "Salida", "Entrada"))
Msg.AppendFormat("<b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}"" target=""_blank"">{1}</a></b>", CveMovimientoVirtual, FolioVirtual)
Msg.AppendFormat("<br/><a class=""Texto"" target='_blank' href=""/Compras/PopUpVerFactura.aspx?P={0}"">Imprimir Movimiento</a> ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoVirtual)))
End If
If RbEntregaInterna.Checked Then
Msg.AppendFormat("<br/><br/>Se agregó una guía de paquetería interna")
End If
Alert(Msg.ToString(), TipoMensaje.MsgInformacion)
Limpia()
CargaPendientes()
LimpiaCampos()
Else
ObjInventario.RollBack()
Alert(TextoError.ToString(), TipoMensaje.MsgError)
RegistraScript("playsonidito('142608__autistic-lucario__error.wav')")
End If
ObjAcumuladores.Dispose()
ObjInventario.Dispose()
ObjConta.Dispose()
ObjVentas.Dispose()
ObjEventos.Dispose()
End Sub
Private Function GenerarPrePoliza(ByRef ObjInventario As ClsInventarios, ByRef ObjVentas As ClsVentas, ByRef ObjConta As ClsContabilidad, CveMovimiento As Integer, ByRef TextoError As StringBuilder) As Boolean
Dim ErrorMovInv As Boolean = False
Dim DtCostos As DataTable = Nothing
Dim ValorInventario As Decimal = 0
If ObjInventario.GetMovimientosDetalle(CveMovimiento, UsuarioActual.CveEmpresa) Then
DtCostos = ObjInventario.DtResultados
Dim tmpCostos As DataTable = DtCostos.FiltraParametros("", "", {"CveClasificacion"})
Dim IdCtaContableAlmacen As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", $"CveAlmacen = {DdlAlmacen.SelectedValue}").ToEntero()
'Dim CveCuentaAlmacen As Integer = 0 'GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContableSIG", $"CveAlmacen = {DdlAlmacen.SelectedValue}").ToEntero()
Dim IdCtaContable As Integer = 0
If tmpCostos.Rows.Count > 0 Then
If ObjVentas.GetVenta(CveVentaSurtir, UsuarioActual.CveEmpresa) Then
Dim Fecha As Date = TxtFecha.Text.ToDate ' If(TipoMovimiento <> 1, TxtFecha.Text.ToDate, ObjVentas.DtResultados(0)("Fecha").ToString().ToDate)
Dim CveCliente As Integer = ObjVentas.DtResultados(0)("CveCliente").ToString().ToEntero()
Dim ClienteNombre As String = ObjVentas.DtResultados(0)("ClienteNombre").ToString()
Dim Serie As String = ObjVentas.DtResultados(0)("SerieFolio").ToString()
Dim TotalCosto As Decimal = DtCostos.SUMD("Total").RoundSQL()
Dim TotalCostoAcumulado As Decimal = 0
Dim cont As Integer = 1
Dim ValorMultiplicador As Decimal = 1
If TipoMovimiento = 1 Then
ValorMultiplicador = 1
ElseIf TipoMovimiento = 2 AndAlso TipoDocto.Contiene({"Dev"}) AndAlso (EsDevolucionVenta = 1) Then
ValorMultiplicador = 1
ElseIf TipoMovimiento = 2 Then
ValorMultiplicador = -1
End If
Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Inventario/EntregaAlmacen", 4, TotalCosto, TotalCosto, 1, Fecha, ClienteNombre, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
'Se agrega movimiento separado por la cuenta de ventas (ER)
If CvePrePoliza > 0 Then
For Each RowInv As DataRow In tmpCostos.Rows
ValorInventario = DtCostos.SUMD("Total", $"CveClasificacion = {RowInv("CveClasificacion")}").RoundSQL()
TotalCostoAcumulado += ValorInventario
'cuando es el último movimiento y hay diferencias en los importes
If cont = DtCostos.FiltraParametros("", "", {"CveClasificacion"}).Rows.Count AndAlso TotalCosto <> TotalCostoAcumulado Then
ValorInventario = ValorInventario + (TotalCosto - TotalCostoAcumulado)
End If
'Concepto = String.Format("{0} - {1}", Row2("Clasificacion").ToString(), Row2("SubProyecto").ToString())
IdCtaContable = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaCostos", $"CveClasificacion = {RowInv("CveClasificacion")}").ToEntero()
If Not ErrorMovInv Then
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ValorMultiplicador * ValorInventario, Serie, 69, Serie, Fecha, IdCtaContable, -1, CveVenta:=CveVentaSurtir, CveCliente:=CveCliente, CveMovimientoAlmacen:=CveMovimiento, CveSubProyecto:=CveSubProyecto, ImporteMX:=ValorMultiplicador * ValorInventario, CveClasificacion:=RowInv("CveClasificacion").ToString().ToEntero()) Then
ErrorMovInv = True
End If
End If
cont += 1
Next
If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ValorMultiplicador * TotalCosto, Serie, 68, Serie, Fecha, IdCtaContableAlmacen, -1, CveVenta:=CveVentaSurtir, CveCliente:=CveCliente, CveMovimientoAlmacen:=CveMovimiento, CveSubProyecto:=CveSubProyecto, ImporteMX:=ValorMultiplicador * TotalCosto) Then
ErrorMovInv = True
End If
'AutoConta - El movimiento 1 es el de Venta
Dim AutoConta As Boolean = UsuarioActual.Empresa.Funcionalidad(200) = "1"
If AutoConta And Not ErrorMovInv Then
Dim ObjContPaq = New ClsContPAQi(UsuarioActual.Empresa)
If IdCtaContable > 0 Then
If Not ObjConta.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa, ObjConta:=ObjContPaq) Then
Alert("Ocurrio un Error al contabilizar, pongase en contacto con Soporte Técnico")
ErrorMovInv = True
TextoError.AppendFormat("Ocurrio un Error al contabilizar, pongase en contacto con Soporte Técnico")
End If
Else
Alert(String.Format("No se puede contabilizar ya que falta asignación de las cuentas contables"), TipoMensaje.MsgAdvertencia)
End If
ObjContPaq.Dispose()
End If
Else
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un Error al ingresar la prepoliza.1")
End If
Else
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un Error al ingresar las prepolizas.2")
End If
Else
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un Error al ingresar las prepolizas.3")
End If
Else
ErrorMovInv = True
TextoError.AppendFormat("Ocurrió un Error al ingresar las prepolizas.4")
End If
Return Not ErrorMovInv
End Function
Private Sub GuardaTraspaso()
'OBLIGA A SURTIR TODO
For Each Gvr As GridViewRow In GvDatos.Rows
If Not Gvr.FCCheckBox("cbInv").Checked Or (Gvr.FCCheckBox("cbInv").Checked AndAlso Gvr.FCTextBox("TbCantidadF").Text.ToDecimal <> Gvr.DataKey("CantidadC").ToString().ToDecimal) Then
Alert("Es necesario surtir todos los productos. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
RegistraScript("playsonidito('142608__autistic-lucario__error.wav')")
Exit Sub
End If
Next
Dim ValidaSeccion As Boolean = False : Dim ValidaCaducidad As Boolean = False : Dim ValidaLote As Boolean = False
'VALIDA CANTIDAD DE SALIDA
Dim Cantidad As Decimal = 0.0D
For Each Gvr As GridViewRow In GvDatos.Rows
If CBool(Gvr.DataKey("AplicaSeccion")) AndAlso Gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero() <= 0 Then
ValidaSeccion = True
End If
If CBool(Gvr.DataKey("AplicaCaducidad")) AndAlso Gvr.FCTextBox("TxtCaducidad").Text.Trim = "" Then
ValidaCaducidad = True
End If
If CBool(Gvr.DataKey("AplicaLote")) AndAlso Gvr.FCTextBox("TxtLote").Text.Trim = "" Then
ValidaLote = True
End If
If Gvr.FCCheckBox("cbInv").Checked AndAlso Gvr.FCTextBox("TbCantidadF").Text.ToDecimal > 0 Then
Cantidad = Gvr.FCTextBox("TbCantidadF").Text.ToDecimal
Exit For
End If
Next
If ValidaSeccion Then
Alert("La sección de almacen no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If ValidaCaducidad Then
Alert("La caducidad no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If ValidaLote Then
Alert("El lote de almacen no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
'VALIDA TRANSITORIO
If ChkTransitorio.Checked Then
If TxtResponsable.Text.Trim = "" Then
Alert("Debe seleccionar un responsable para el traspaso transitorio.", TipoMensaje.MsgAdvertencia)
RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')")
If ChkTransitorio.Checked Then RegistraScript("$('#DivTransitorio').show(200);")
Exit Sub
End If
If DdlAlmacenTransitorio.SelectedValue.ToEntero() <= 0 Then
Alert("Debe seleccionar un almacen transitorio.", TipoMensaje.MsgAdvertencia)
RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')")
If ChkTransitorio.Checked Then RegistraScript("$('#DivTransitorio').show(200);")
Exit Sub
End If
End If
Dim ObjInventario As New ClsInventarios : ObjInventario.IniciaTransacSQL()
Dim ObjGeneral As New ClsGenerales(ObjInventario.IniciaTransacSQL())
Dim ObjConta As New ClsContabilidad(ObjInventario.IniciaTransacSQL())
Dim CveMovimientoSalida As Integer
Dim ConceptoMovimiento = 0
Dim FolioSalida As Integer
Dim CveMovimientoEntrada As Integer
Dim FolioEntrada As Integer
Dim ErrorMovInv As Boolean
Dim DtDetalle As New DataTable
Dim TextoError = ""
'PASA DATOS DEL GV A DATATABLE PARA MANEJOR CON FOR EACH
Dim Index = 0
For Each gvr As GridViewRow In GvDatos.Rows
If gvr.FCCheckBox("cbInv").Checked AndAlso gvr.FCTextBox("TbCantidadF").Text.ToDecimal > 0 Then
DtDatos.Rows(Index)("CantidadGV") = gvr.FCTextBox("TbCantidadF").Text.ToDecimal
DtDatos.Rows(Index)("CveSeccion") = gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero()
DtDatos.Rows(Index)("FechaCaducidad") = gvr.FCTextBox("TxtCaducidad").Text.ToDate
DtDatos.Rows(Index)("Lote") = gvr.FCTextBox("TxtLote").Text
End If
Index += 1
Next
'VALIDA SI HUBO CAMBIOS EN LA EXISTENCIA
Dim DtDatosTraspaso As New DataTable
If ObjInventario.EntregaAlmacenTraspasosGet(CveTraspasoSurtir) Then
DtDatosTraspaso = ObjInventario.DtResultados
End If
Dim CantidadGV = GvDatos.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.DataKey("CantidadF").ToDecimal)
If DtDatos.SUM("CantidadF") <> DtDatosTraspaso.SUM("CantidadF") Then
ObjInventario.RollBack()
ObjInventario.Dispose()
CargaTraspasoPorSurtir(CveTraspasoSurtir)
CargaPendientes()
Alert("Ha sido cambiada la informacion de existencias del traspaso actual. Por favor verifique.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
'VALIDA QUE EL TRASPASO SIGA VIGENTE
If ObjInventario.AddTrasladoSolicitudGet(CveTraspasoSurtir, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 AndAlso ObjInventario.DtResultados.Rows(0)("CveTrasladoEstatus").ToString() = "2" Then
ObjInventario.RollBack()
ObjInventario.Dispose()
CargaTraspasoPorSurtir(CveTraspasoSurtir)
CargaPendientes()
Alert("Ha sido cambiada la informacion del traspaso actual. Por favor verifique.", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
'VALIDA ALMACENES
Dim Almacen1 = DdlAlmacen.SelectedValue.ToEntero()
Dim Almacen2 = CveAlmacenTraspasoDestino
If Almacen1 <= 0 Or Almacen2 <= 0 Then
Alert("Ocurrió un error al obtener los almacenes del movimiento. Por favor recargue y vuelva a intentar.", TipoMensaje.MsgAdvertencia)
ObjInventario.RollBack()
ObjInventario.Dispose()
Exit Sub
End If
'VERIFICAR EXISTENCIA
Dim StrXML As New StringBuilder
Dim Lote As String = ""
Dim FechaCaducidad As Date
StrXML.Append("<conceptos>")
For Each Dr As DataRow In DtDatos.Rows
FechaCaducidad = If(CBool(Dr("AplicaCaducidad")) AndAlso Dr("FechaCaducidad").ToString() <> "", Dr("FechaCaducidad").ToString().ToDate, MinFecha)
Lote = If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1")
If Dr("CantidadGV").ToString().ToDecimal > 0 Then
If CBool(Dr("AplicaSerie")) Then
DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Dr("Consec")))
For Each Dr1 As DataRow In DtDetalle.Rows
StrXML.AppendFormat("<concepto CvePS=""{0}"" CveUM=""{1}"" Cantidad= ""{2}"" CveSeccionAlmacen=""{3}"" Serie=""{4}"" Lote=""{5}"" FechaCaducidad=""{6}"" ></concepto>", Dr1("CvePS"), Dr1("CveUM"), 1, IfNull(Dr("CveSeccion"), -1), Dr1("Serie"), Lote, FechaCaducidad.ToString("yyyy/MM/dd"))
Next
Else
StrXML.AppendFormat("<concepto CvePS=""{0}"" CveUM=""{1}"" Cantidad= ""{2}"" CveSeccionAlmacen=""{3}"" Serie=""{4}"" Lote=""{5}"" FechaCaducidad=""{6}"" ></concepto>", Dr("CvePS"), Dr("CveUM"), Dr("CantidadGV"), IfNull(Dr("CveSeccion"), -1), "-1", Lote, FechaCaducidad.ToString("yyyy/MM/dd"))
End If
End If
Next
StrXML.Append("</conceptos>")
Dim TieneErrorExistencia = False
If ObjInventario.GetExistenciasPSXML(StrXML.ToString(), DdlAlmacen.SelectedValue.ToEntero(), TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm"), CveSubProyecto, CveVendedor, If(UsuarioActual.Empresa.Funcionalidad(146) = "1", -1, CveCliente), If(TipoEntrega = 2, 1, -1), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then
If ObjInventario.DtResultados.Rows.Count > 0 Then
TieneErrorExistencia = True
For Each Dr As DataRow In ObjInventario.DtResultados.Rows
TextoError += $"<b> - {Dr("CodigoPS")}</b> Existencia: {Dr("Existencia").ToString().ToDecimal.ToString("#,##0.##")} <br/>"
Next
End If
Else
TieneErrorExistencia = True
End If
If TieneErrorExistencia Then
ObjInventario.RollBack()
ObjInventario.Dispose()
If TextoError.Length > 0 Then
Alert($" Lo(s) siguiente(s) Productos <b>no tienen</b> existencia suficiente:<br/><br/>{TextoError}", TipoMensaje.MsgAdvertencia)
End If
RegistraScript("playsonidito('142608__autistic-lucario__error.wav')")
Exit Sub
End If
'SALIDA POR TRASPASO
If Not ErrorMovInv Then
ConceptoMovimiento = 26
CveMovimientoSalida = ObjInventario.AddMovimiento(Almacen1, ConceptoMovimiento, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, Guia:="",
CveContrato:=-1, CveAlmacenDestino:=CveAlmacenTraspasoDestino, Recibio:=If(ChkTransitorio.Checked, TxtResponsable.Text.Trim, ""), Modulo:="RE/GT", CveOP:=CveOP)
FolioSalida = ObjInventario.Folio
If CveMovimientoSalida > 0 Then
Dim CantidadPendiente As Decimal = 0
Dim CveSeccionAlmacen As Integer = -1
For Each Dr As DataRow In DtDatos.Rows
FechaCaducidad = If(CBool(Dr("AplicaCaducidad")) AndAlso Dr("FechaCaducidad").ToString() <> "", Dr("FechaCaducidad").ToString().ToDate, MinFecha)
Lote = If(CBool(Dr("AplicaLote")), Dr("Lote").ToString(), "-1")
CveSeccionAlmacen = If(CBool(Dr("AplicaSeccion")), Dr("CveSeccion").ToString().ToEntero(), -1)
DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0} AND FueTraspaso IS NULL", Dr("Consec")))
'DtDetalleLote = DtDatosDetalleLote.FiltraParametros(String.Format("ConsecId = {0} AND FueTraspaso IS NULL", Dr("Consec")))
If DtDetalle.Rows.Count > 0 Then 'SI FUE POR SERIE
For Each Dr1 As DataRow In DtDetalle.Rows
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, 1, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, Serie:=Dr1("Serie").ToString(), Lote:=Lote, FechaCaducidad:=FechaCaducidad, CveSeccionAlmacen:=CveSeccionAlmacen, CveVentaDetalle:=-1, CveContratoDetalle:=Dr("CveContratoDetalle").ToString().ToEntero()) Then
ErrorMovInv = True
TextoError = "Ocurrió un error al procesar los conceptos con serie. Por favor vuelva a intentar."
Exit For
End If
Next
'ElseIf DtDetalleLote.Rows.Count > 0 Then 'SI FUE POR LOTE BATCH
' For Each Dr1 As DataRow In DtDetalleLote.Rows
' If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, Dr1("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, Serie:="", Lote:=Dr1("Lote").ToString(), FechaCaducidad:=FechaCaducidad, CveSeccionAlmacen:=CveSeccionAlmacen, CveVentaDetalle:=-1, CveContratoDetalle:=Dr("CveContratoDetalle").ToString().ToEntero()) Then
' ErrorMovInv = True
' TextoError = "Ocurrió un error al procesar los conceptos con serie. Por favor vuelva a intentar."
' Exit For
' End If
' Next
Else 'NORMAL
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, Dr("CantidadGV").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), 0, -1, Lote:=Lote, FechaCaducidad:=FechaCaducidad, CveSeccionAlmacen:=CveSeccionAlmacen, CveContratoDetalle:=Dr("CveContratoDetalle").ToString().ToEntero()) Then
ErrorMovInv = True
TextoError = "Ocurrió un error al procesar los conceptos de salida. Por favor vuelva a intentar."
Exit For
End If
End If
Next
Else
TextoError = "Ocurrió un error al generar el movimiento de salida."
ErrorMovInv = True
End If
End If
Dim ValorTraspaso As Decimal = 0
'ENTRADA POR TRASPASO
If Not ErrorMovInv Then
'sino es transitorio, los transitorios, ya no se hace otro movimiento
ConceptoMovimiento = If(ChkTransitorio.Checked, 2, 27)
Almacen2 = If(ChkTransitorio.Checked, DdlAlmacenTransitorio.SelectedValue.ToEntero(), CveAlmacenTraspasoDestino)
CveMovimientoEntrada = ObjInventario.AddMovimiento(Almacen2, ConceptoMovimiento, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim,
Guia:="", CveContrato:=CveContrato, CveMovimientoRelacionado:=CveMovimientoSalida, CveAlmacenDestino:=CveAlmacenTraspasoDestino,
Recibio:=If(ChkTransitorio.Checked, TxtResponsable.Text.Trim, ""), Modulo:="RE/GT1", CveOP:=CveOP)
FolioEntrada = ObjInventario.Folio
If CveMovimientoEntrada > 0 Then
If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then
Dim CveSeccionAlmacen As Integer = -1
ValorTraspaso = ObjInventario.DtResultados.SUMD("Total").RoundSQL
For Each Dr As DataRow In ObjInventario.DtResultados.Rows
CveSeccionAlmacen = -3
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Dr("Cantidad").ToString().ToDecimal, Dr("CveUM").ToString().ToEntero(), Dr("CvePS").ToString().ToEntero(), Dr("PU").ToString().ToDecimal, CveAF:=Dr("CveAF").ToString().ToEntero(), CveSeccionAlmacen:=CveSeccionAlmacen, Serie:=Dr("Serie").ToString(), Lote:=Dr("Lote").ToString(), FechaCaducidad:=Dr("FechaCaducidad").ToString().ToDate, CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString().ToEntero(), CveVentaDetalle:=Dr("CveVentaDetalle").ToString().ToEntero()) Then
ErrorMovInv = True
TextoError = "Ocurrió un error al guardar los movimientos de entrada"
Exit For
End If
Next
End If
Else
TextoError = "Ocurrió un error al generar el movimiento de entrada"
ErrorMovInv = True
End If
End If
'MARCA SOLICITUD CON EL MOVIMIENTO GENERADO
If Not ErrorMovInv Then
If Not ObjInventario.UpdateTraspasoSolicitudMovimiento(CveTraspasoSurtir, CveMovimientoSalida) Then
TextoError = "Ocurrió un error al vincular los movimientos con la solicitud de traspaso. Por favor verifique y vuelva a intentar"
ErrorMovInv = True
End If
End If
Dim Fecha As Date = TxtFecha.Text.ToDate
'Paqueterias Guias
If RbEntregaInterna.Checked AndAlso Not ErrorMovInv Then
Dim CveEstatus As Integer = 0 ' DdlEstatus.SelectedValue.ToEntero()
Dim FechaEstimada As String = "-1" 'If(TxtFechaEstimada.Text = "", "-1", TxtFechaEstimada.Text)
Dim NoCajas As Integer = 0 'TxtNoCajas.Text.ToEntero()
Dim Observaciones As String = "" 'TxtObservacionesPaqInterna.Text
Dim CvePaqueteria As Integer = GlobalDTPaqueterias(UsuarioActual.CveEmpresa, 0).FiltroPrimeroValor("CvePaqueteria", "").ToEntero()
Dim CvePaqueteriaGuia As Integer = ObjGeneral.AddPaqueteriasGuias(CvePaqueteria, 9, CveEstatus, CveSubProyecto, Fecha.ToShortDateString, "-1", "-1", NoCajas, 0.00, "-1", FechaEstimada, Observaciones, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, EsEntregaInterna:=True)
If CvePaqueteriaGuia > 0 Then
If CveVentaSurtir > 0 OrElse CveSubProyecto > 0 Then
ErrorMovInv = Not ObjGeneral.AddPaqueteriasGuiasDetalles(CvePaqueteriaGuia, CveVentaSurtir, -1, CveMovimientoEntrada, -1)
End If
If ErrorMovInv Then
Alert("Error en el paqueteria guia detalle", TipoMensaje.MsgError)
End If
Else
ErrorMovInv = True
Alert("Error en el paqueteria guia", TipoMensaje.MsgError)
End If
End If
'AGREGAMOS PREPOLIZAS TRASPASO DIRECTO:
Dim CvePrePolizaTraspaso As Integer = ObjConta.AddPrePolizas("EA/GT", 53, 0, 0, 1, Fecha, "Traspaso", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
If CvePrePolizaTraspaso > 0 Then
If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, True, ValorTraspaso, TxtObservaciones.Text, 68, TxtObservaciones.Text, Fecha, -1, -1, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=False, ImporteMX:=ValorTraspaso) Then
ErrorMovInv = True
End If
If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, False, ValorTraspaso, TxtObservaciones.Text, 68, TxtObservaciones.Text, Fecha, -1, -1, CveMovimientoAlmacen:=CveMovimientoEntrada, Contabilizable:=False, ImporteMX:=ValorTraspaso) Then
ErrorMovInv = True
End If
Else
ErrorMovInv = True
End If
If Not ErrorMovInv Then
ObjInventario.Commit()
ObjGeneral.Dispose()
RegistraScript("playsonidito('beep-07.wav')")
Dim Msg As New StringBuilder
Msg.AppendFormat("Movimiento Salida: <b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}"" target=""_blank"">{1}</a></b>", CveMovimientoSalida, FolioSalida)
Msg.AppendFormat("<br/><a class=""Texto"" target='_blank' href=""/Compras/PopUpVerFactura.aspx?P={0}"">Imprimir Movimiento</a> ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoSalida)))
Msg.AppendFormat("<br/><br/> Movimiento Entrada (Traspaso): <b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={0}"" target=""_blank"">{1}</a></b>", CveMovimientoEntrada, FolioEntrada)
Msg.AppendFormat("<br/> <a class=""Texto"" target='_blank' href=""/Compras/PopUpVerFactura.aspx?P={0}"">Imprimir Movimiento</a> ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoEntrada)))
If RbEntregaInterna.Checked Then
Msg.AppendFormat("<br/><br/>Se agregó una guía de paquetería interna")
End If
Alert(Msg.ToString(), TipoMensaje.MsgInformacion)
Limpia()
LimpiaCampos()
CargaPendientes()
Else
Alert(TextoError, TipoMensaje.MsgError)
RegistraScript("playsonidito('142608__autistic-lucario__error.wav')")
ObjInventario.RollBack()
End If
ObjInventario.Dispose()
End Sub
Private Sub MandaCorreoEntrega(tCveVenta As Integer)
EnviarCorreoEntrega(tCveVenta, UsuarioActual)
End Sub
Private Sub EnviarCorreoEntrega(tCveVenta As Integer, UsuarioActual As Usuario)
'Dim Correo As New ClsSisMail
Dim SerieFolio As String = ""
Dim Asunto As String = String.Format("{0} Envio de pedido: {1}", UsuarioActual.Empresa.NombreCorto, SerieFolio)
Dim Cuerpo As New StringBuilder()
Dim Destinatario As String = ""
Dim MensajeEnviado = False
Dim tCvecliente As Integer
Dim tCveVendedor As Integer
Dim bytes() As Byte = Nothing
Dim ObjVentas As New ClsVentas()
Dim strBody As New StringBuilder
If ObjVentas.GetVenta(tCveVenta, UsuarioActual.CveEmpresa) Then
Dim dr As DataRow = ObjVentas.DtResultados.FiltroPrimero("")
tCveVendedor = dr("CveVendedor").ToString().ToEntero()
Dim CorreoVendedor As String = GlobalDTVendedores(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Correo", String.Format("CveVendedor = {0}", tCveVendedor))
Dim CorreoAsistente As String = GlobalDTVendedores(UsuarioActual.CveEmpresa, VendedorTipo:=3).FiltroPrimeroValor("Correo", String.Format("CveSuperior = {0}", CveVendedor))
Destinatario = String.Format("{0};{1};{2}", dr("CorreoNotificacion"), CorreoVendedor, CorreoAsistente)
tCvecliente = dr("CveCliente").ToString().ToEntero()
Dim drC As DataRow = GlobalDTCliente(UsuarioActual.CveEmpresa, CveCliente:=tCvecliente).FiltroPrimero("")
If drC IsNot Nothing Then
Destinatario += String.Format(";{0};{1}", drC("CorreoEntregaCompras"), drC("CorreoEntregaAlmacen"))
Dim ClienteNombre As String = dr("ClienteNombre").ToString()
Dim FolioVenta As String = dr("SerieFolio").ToString()
Dim Pedido As String = dr("PedidoContrato").ToString()
Dim OrdenCompra As String = dr("OrdenCompra").ToString()
Dim CveVenta As Integer = dr("CveVenta").ToString().ToEntero()
Dim TipoDocto As String = dr("TipoDocto").ToString()
Dim dtDetalle As New DataTable
If ObjVentas.GetVentaDetalle(CveVenta) Then
dtDetalle = ObjVentas.DtResultados
End If
Dim DetalleTable As String = ""
For Each dRow As DataRow In dtDetalle.Rows
Dim detalle As String = String.Format("<tr><td style='width:25%'>{0}</td><td style='width:25%'>{1}</td><td style='width:50%'>{2}</td></tr>", dRow("Codigo"), dRow("Cantidad"), dRow("PS"))
DetalleTable += detalle
Next
strBody.Append("<html>")
strBody.Append("<head>")
strBody.Append("<meta charset='UTF-8'>")
strBody.Append("</head>")
strBody.Append(" <body style='width:800px'>")
strBody.Append("<div>")
strBody.Append($"<img src='http://sig.adssistemas.mx/Empresas/{UsuarioActual.CveEmpresa}/Logo.png' style='width:200px'></img>")
strBody.Append("</div>")
strBody.Append(" <p style='font-family:Segoe UI Semibold;font-size:12pt;width:100%'>")
strBody.Append($" Apreciable {ClienteNombre}, le confirmamos los")
strBody.Append(" productos surtidos y entregados en mostrador conforme a la")
strBody.Append($" {TipoDocto}:")
strBody.Append(" </p>")
strBody.Append($" <p style='width:100%;text-align:center;font-family:Segoe UI Semibold;font-size:12pt'>{FolioVenta} - Pedido {Pedido} - Orden de Compra {OrdenCompra}</P>")
strBody.Append(" <div style='width:100%;text-align:center'>")
strBody.Append(" <table style='width:100%;font-family:Segoe UI Semibold;font-size:12pt'>")
strBody.Append(DetalleTable)
strBody.Append(" ")
strBody.Append(" </table>")
strBody.Append(" </div>")
strBody.Append(" <p style='font-family:Segoe UI Semibold;font-size:12pt;width:100%'>")
strBody.Append(" Se entregaron los productos conforme a las especificaciones de su pedido y verificamos que no se presentara alguno de los siguientes inconvenientes:")
strBody.Append(" </p>")
strBody.Append(" <p style='font-family:Segoe UI Semibold;font-size:12pt;width:100%'>")
strBody.Append(" • Empaque violado.<br/>")
strBody.Append("• Daño físico en la caja.<br/>")
strBody.Append("• Producto incompleto o distinto al solicitado.<br/>")
strBody.Append("• Alguna otra situación que se considere que compromete la integridad de la mercancía.<br/>")
strBody.Append("")
strBody.Append(" </p>")
strBody.Append(" <br/>")
strBody.Append(" <p style='font-family:Segoe UI Semibold;font-size:12pt;width:100%'>")
strBody.Append($" Aceptando a entera satisfacción a las {Today.Hour}:{Today.Minute} hrs del {Today.ToString()}")
strBody.Append(" </p>")
strBody.Append(" <br/>")
strBody.Append(" <p style='font-family:Segoe UI Semibold;font-size:12pt;width:100%'>")
strBody.Append(" Gracias por su compra <br/>")
'strBody.Append(" Compuproveedores")
strBody.Append(" </p>")
strBody.Append(" <p style='font-family:Segoe UI Semibold;font-size:12pt;width:100%;text-align:center'>")
strBody.Append(" Sigue disfrutando de nuestros productos y servicios<br/>")
'strBody.Append(" <a href='https://www.compuproveedoresti.com/'>www.compuproveedores.com</a>")
strBody.Append("")
strBody.Append(" </p>")
strBody.Append(" </body>")
strBody.Append("</html>")
End If
End If
ObjVentas.Dispose()
Dim MailCls As New ClsSisMail
Dim LSRutasMail As New List(Of ClsSisMail.ArchivoMail)
Dim itemMail As New ClsSisMail.ArchivoMail()
LSRutasMail.Add(New ClsSisMail.ArchivoMail With {.ArchivoBinario = bytes, .NombreArchivo = "Entrega en mostrador"})
MailCls.SendMail(ClsPaginas.EmpresaNotificaciones, Destinatario, "Enviado desde Entrega Almacen", strBody.ToString(), Destinatario)
MailCls = Nothing
End Sub
Private Sub Limpia()
'DATOS DE LA VENTA
LbCantidad.Text = ""
LbCliente.Text = ""
LbObservaciones.Text = ""
'LbFolio.Text = ""
HLFolio.Text = ""
'DATOS DEL MOVIMINETO
TxtObservaciones.Text = ""
TxtFecha.Text = Now.ToShortDateString
DdlAlmacen.SelectedValueExist(-1)
CargaFolios()
'VARIABLES GENERALES
CveVentaSurtir = -1
DtDatosDetalle = Nothing
DtDatosDetalleLote = Nothing
DtDatos = Nothing
DivTipoCambioAdvertencia.Visible = False
'TRASPASO
DivTransitorio1.Visible = False
ChkTransitorio.Checked = False
TxtResponsable.Text = ""
DivTransitorio2.Visible = False
LbSurtida.Visible = False
TimmerRefresh.Enabled = True
UpGenerales.Update()
CargaGvDatos()
UpDatos.Update()
End Sub
#End Region
#Region " TRASPASO - TRANSITORIO "
Protected Sub ChkTransitorio_CheckedChanged(sender As Object, e As EventArgs)
TxtResponsable.Text = ""
DivTransitorio2.Visible = ChkTransitorio.Checked
End Sub
#End Region
#Region "SECCION ALMACEN"
'Private Sub CreaDtSeccionAlmacen()
' DtSeccionAlmacen = New DataTable
' DtSeccionAlmacen.Columns.Add("CantidadSeccionAlmacen", GetType(Decimal))
' DtSeccionAlmacen.Columns.Add("IndexSeccionAlmacen", GetType(Integer))
' DtSeccionAlmacen.Columns.Add("CveSeccionAlmacen", GetType(Integer))
' DtSeccionAlmacen.Columns.Add("CvePS", GetType(Integer))
' DtSeccionAlmacen.Columns.Add("SeccionAlmacen", GetType(String))
' DtSeccionAlmacen.Columns.Add("Consec", GetType(Integer))
'End Sub
'Private Sub CargaDdlAlmacen()
' DdlSeccionAlmacen.DataSource = GlobalDTSeccionAlmacen(UsuarioActual.CveEmpresa, -1)
' DdlSeccionAlmacen.Items.Insert(0, New ListItem("Seleccione", "-1"))
' DdlSeccionAlmacen.DataBind()
'End Sub
'Protected Sub LnkSeccionAlmacen_Click(sender As Object, e As EventArgs)
' Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow)
' If Not DdlAlmacen.SelectedValue.ToEntero() > 0 Then
' Alert("Tiene que tener seleccionado un almacen para registrar seccion almacen.", TipoMensaje.MsgAdvertencia)
' Exit Sub
' End If
' CantidadTotal = gvRow.FCTextBox("TbCantidadF").Text.ToDecimal
' IndexSeccionAlmacen = gvRow.RowIndex
' CvePS = gvRow.DataKey("CvePS").ToEntero()
' CargaSeccionAlmacen()
' RegistraScript("$('#DModalSeccionAlmacen').modal()")
'End Sub
'Private Sub CargaSeccionAlmacen()
' Dim CantidadTotalSeccion As Decimal = DtSeccionAlmacen.FiltraParametros($"IndexSeccionAlmacen = {IndexSeccionAlmacen}").SUMD("CantidadSeccionAlmacen")
' GvSeccion.DataSource = DtSeccionAlmacen.FiltraParametros($"IndexSeccionAlmacen = {IndexSeccionAlmacen}")
' GvSeccion.DataBind()
' TxtCantidadSeccion.Text = ""
' DdlSeccionAlmacen.SelectedIndex = 0
' Dim CantidadRestante As Decimal = CantidadTotal - CantidadTotalSeccion
' If CantidadRestante = 0 Then
' RVTxtCantidad.MaximumValue = "1"
' TxtCantidadSeccion.Enabled = False
' Else
' RVTxtCantidad.MaximumValue = CantidadRestante.ToString()
' TxtCantidadSeccion.Enabled = True
' End If
' If CantidadTotalSeccion > 0 Then
' GvDatos.Rows(IndexSeccionAlmacen).FCTextBox("TbCantidadF").Enabled = False
' GvDatos.Rows(IndexSeccionAlmacen).FCTextBox("TbCantidadF").ToolTip = "Cuenta con sección almacen"
' Else
' GvDatos.Rows(IndexSeccionAlmacen).FCTextBox("TbCantidadF").Enabled = True
' GvDatos.Rows(IndexSeccionAlmacen).FCTextBox("TbCantidadF").ToolTip = ""
' End If
' If DtSeccionAlmacen.SUMD("CantidadSeccionAlmacen") > 0 Then
' DdlAlmacen.Enabled = False
' DdlAlmacen.ToolTip = "Cuenta con sección almacen"
' Else
' DdlAlmacen.Enabled = True
' DdlAlmacen.ToolTip = ""
' End If
' UpModalSeccionAlmacen.Update()
' UpDatos.Update()
' UpGenerales.Update()
'End Sub
'Protected Sub LnkAddSeccionAlmacen_Click(sender As Object, e As EventArgs)
' Dim ObjInv As New ClsInventarios
' Dim CantidadDisponible As Decimal = 0
' If ObjInv.GetMovimientosDetalleSeccionesAlmacen(DdlSeccionAlmacen.SelectedValue.ToEntero(), DdlAlmacen.SelectedValue.ToEntero(),
' CvePS, UsuarioActual.CveEmpresa) Then
' If ObjInv.DtResultados.Rows.Count > 0 Then
' CantidadDisponible = ObjInv.DtResultados.Rows(0)("CantidadRestante").ToString().ToDecimal
' End If
' End If
' ObjInv.Dispose()
' CantidadDisponible -= DtSeccionAlmacen.FiltraParametros($"CvePS = {CvePS} AND CveSeccionAlmacen = {DdlSeccionAlmacen.SelectedValue}").SUMD("CantidadSeccionAlmacen")
' If TxtCantidadSeccion.Text.ToDecimal > CantidadDisponible Then
' Alert($"No tiene cantidad de producto suficiente en esta seccion de almacen, su cantidad restante es: <b>{CantidadDisponible}</b>", TipoMensaje.MsgAdvertencia)
' Exit Sub
' End If
' Dim Row As DataRow = Nothing
' DtSeccionAlmacen.AcceptChanges()
' Row = DtSeccionAlmacen.NewRow
' Row("CantidadSeccionAlmacen") = TxtCantidadSeccion.Text.ToDecimal
' Row("IndexSeccionAlmacen") = IndexSeccionAlmacen
' Row("CveSeccionAlmacen") = DdlSeccionAlmacen.SelectedValue.ToEntero()
' Row("SeccionAlmacen") = DdlSeccionAlmacen.SelectedItem.Text
' Row("CvePS") = CvePS
' Row("Consec") = DtSeccionAlmacen.Rows.Count + 1
' DtSeccionAlmacen.Rows.Add(Row)
' DtSeccionAlmacen.AcceptChanges()
' CargaSeccionAlmacen()
'End Sub
'Protected Sub LnkEliminarSeccion_Click(sender As Object, e As EventArgs)
' Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow)
' Dim Index As Integer = 0
' For Each Dr As DataRow In DtSeccionAlmacen.Rows
' If Dr("Consec").ToString().ToEntero() = gvRow.DataKey("Consec").ToEntero() Then
' Exit For
' End If
' Index += 1
' Next
' DtSeccionAlmacen.Rows.RemoveAt(Index)
' DtSeccionAlmacen.AcceptChanges()
' CargaSeccionAlmacen()
'End Sub
'Protected Sub LnkVerSecciones_Click(sender As Object, e As EventArgs)
' If Not CveVentaSurtir > 0 Then
' Alert("Tiene que seleccionar la venta a surtir", TipoMensaje.MsgAdvertencia)
' Exit Sub
' End If
' If Not DdlAlmacen.SelectedValue.ToEntero() > 0 Then
' Alert("Tiene que seleccionar el almacen", TipoMensaje.MsgAdvertencia)
' Exit Sub
' End If
' Dim ObjInv As New ClsInventarios
' If ObjInv.GetExistenciaSeccionAlmacen(CveVentaSurtir, DdlAlmacen.SelectedValue.ToEntero(), UsuarioActual.CveEmpresa) Then
' GvVerSeccionesAlmacen.DataSource = ObjInv.DtResultados
' End If
' ObjInv.Dispose()
' GvVerSeccionesAlmacen.DataBind()
' UpVerSeccionesAlmacen.Update()
' RegistraScript("$('#ModalVerSeccionesAlmacen').modal()")
'End Sub
#End Region
#Region "DIVIDIR"
Protected Sub Dividir(sender As Object, e As EventArgs)
Dim index2 As Integer = 0
For Each Row As DataRow In DtDatos.Rows
Row("Seleccionado") = GvDatos.Rows(index2).FCCheckBox("cbInv").Checked
If GvDatos.Rows(index2).FCTextBox("TbCantidadF").Text <> "" Then
Row("CantidadSeleccionada") = GvDatos.Rows(index2).FCTextBox("TbCantidadF").Text
End If
If GvDatos.Rows(index2).FCTextBox("TxtLote").Text <> "" Then
Row("Lote") = GvDatos.Rows(index2).FCTextBox("TxtLote").Text
End If
If GvDatos.Rows(index2).FCDropDownList("DdlSeccionAlmacen").SelectedValue <> "-1" Then
Row("CveSeccion") = GvDatos.Rows(index2).FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero()
End If
If GvDatos.Rows(index2).FCTextBox("TxtCaducidad").Text <> "" Then
Row("FechaCaducidad") = GvDatos.Rows(index2).FCTextBox("TxtCaducidad").Text.ToDate
End If
index2 += 1
Next
DtDatos.AcceptChanges()
Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, Button)).NamingContainer, GridViewRow)
Dim Index As Integer = gvRow.RowIndex
Dim Cantidad As String = HdnCantidadMovimiento.Value
Dim dr1 As DataRow = DtDatos.Rows(Index)
Dim dr As DataRow = DtDatos.NewRow
dr.ItemArray = dr1.ItemArray
dr1("CantidadC") = (dr1("CantidadC").ToString().ToDouble - Cantidad.ToDouble)
Dim CantidadFOriginal As Double = dr1("CantidadF").ToString().ToDouble
dr1("CantidadF") = (dr1("CantidadF").ToString().ToDouble - Cantidad.ToDouble)
Dim CantidadSOriginal As Double = dr1("CantidadS").ToString().ToDouble
dr1("CantidadS") = (CantidadSOriginal * dr1("CantidadF").ToString().ToDouble) / CantidadFOriginal
Dim CantidadSeleccionadaOriginal As Double = dr1("CantidadSeleccionada").ToString().ToDouble
dr1("CantidadSeleccionada") = If(CantidadSeleccionadaOriginal > dr1("CantidadF").ToString().ToDouble, dr1("CantidadF").ToString().ToDouble, CantidadSeleccionadaOriginal)
CantidadSeleccionadaOriginal = CantidadSeleccionadaOriginal - dr1("CantidadF").ToString().ToDouble
'Dim CostoIndirectoOriginal As Double = dr1("CostoIndirecto").ToString().ToDouble
'dr1("CostoIndirecto") = (CostoIndirectoOriginal * dr1("CantidadF").ToString().ToDouble) / CantidadFOriginal
'Dim CostoIndirectoExtranjeroOriginal As Double = dr1("CostoIndirectoExtranjero").ToString().ToDouble
'dr1("CostoIndirectoExtranjero") = (CostoIndirectoExtranjeroOriginal * dr1("CantidadF").ToString().ToDouble) / CantidadFOriginal
DtDatos.AcceptChanges()
dr("CantidadC") = Cantidad.ToDouble
dr("CantidadF") = Cantidad.ToDouble
dr("CantidadS") = (CantidadSOriginal * dr("CantidadF").ToString().ToDouble) / CantidadFOriginal
dr("CantidadSeleccionada") = If(CantidadSeleccionadaOriginal > 0, CantidadSeleccionadaOriginal, 0)
dr("Seleccionado") = If(CantidadSeleccionadaOriginal > 0, True, False)
'dr("CostoIndirecto") = (CostoIndirectoOriginal * dr("CantidadF").ToString().ToDouble) / CantidadFOriginal
'dr("CostoIndirectoExtranjero") = (CostoIndirectoExtranjeroOriginal * dr("CantidadF").ToString().ToDouble) / CantidadFOriginal
DtDatos.Rows.InsertAt(dr, Index)
DtDatos.AcceptChanges()
index2 = 1
For Each Row As DataRow In DtDatos.Rows
Row("Consec") = index2
index2 += 1
Next
DtDatos.AcceptChanges()
CargaGvDatos()
index2 = 0
For Each Row As DataRow In DtDatos.Rows
GvDatos.Rows(index2).FCCheckBox("cbInv").Checked = CBool(Row("Seleccionado"))
If Row("CantidadSeleccionada").ToString() <> "" Then
GvDatos.Rows(index2).FCTextBox("TbCantidadF").Text = Row("CantidadSeleccionada").ToString()
End If
If Row("Lote").ToString() <> "" Then
GvDatos.Rows(index2).FCTextBox("TxtLote").Text = Row("Lote").ToString()
End If
If Row("CveSeccion").ToString() <> "" Then
GvDatos.Rows(index2).FCDropDownList("DdlSeccionAlmacen").SelectedValue = Row("CveSeccion").ToString()
End If
If Row("FechaCaducidad").ToString() <> "" Then
GvDatos.Rows(index2).FCTextBox("TxtCaducidad").Text = Row("FechaCaducidad").ToString().ToDate.ToShortDateString
End If
index2 += 1
Next
End Sub
#End Region
#Region " GUIAS - SABE QUE ES PORQUE NO VEO QUE SE UTILIZE EN ALGUNA PARTE - EN MIRAS DE ELIMINAR - IPP 24 AGOSTO 2017 "
Private Sub BtnNumeroGuia_Click(sender As Object, e As EventArgs) Handles BtnNumeroGuia.Click
Dim Objeto As New ClsInventarios
If Objeto.UpdateMovimientoGuia(TxtGuia.Text, CveMovimiento, UsuarioActual.CveEmpresa) Then
Alert("Se ha guardado correctamente la póliza", TipoMensaje.MsgConfirmacion)
End If
Objeto.Dispose()
End Sub
Private Sub GvDocs_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDocs.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ImgDownLoad As Literal = e.Row.FCLiteral("HplDown")
Dim Adjunto As String = e.Row.DBCampo("Adjunto").ToString()
Dim ArchivoRuta As String = ""
If Adjunto.Trim.Length > 0 Then
ArchivoRuta = UsuarioActual.Empresa.Ruta & "Documentacion\Ventas\" & Adjunto
Dim fi As New FileInfo(ArchivoRuta)
Dim linkDescarga As String = ""
If fi.Exists() Then
linkDescarga = $"/Empresas/{UsuarioActual.CveEmpresa}/Documentacion/ventas/{fi.Name}"
ImgDownLoad.Visible = True
ImgDownLoad.Text = String.Format(" <a class='btn btn-circle btn-sm blue' href='{0}' target='_black'><i class='fa fa-download' title='Descargar documento'></i></a>", linkDescarga)
End If
End If
End If
End Sub
#End Region
#Region "SUGERENCIAS"
Protected Sub BtnVerSugerencias_Click(sender As Object, e As EventArgs)
If Not CveVentaSurtir > 0 Then
Alert("Tiene que seleccionar la venta a surtir", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If Not DdlAlmacen.SelectedValue.ToEntero() > 0 Then
Alert("Tiene que seleccionar el almacen", TipoMensaje.MsgAdvertencia)
Exit Sub
End If
Dim ObjInv As New ClsInventarios
If ObjInv.GetSugerenciasSalidaAlmacen(CveVentaSurtir, DdlAlmacen.SelectedValue.ToEntero(), UsuarioActual.CveEmpresa) Then
GvSugerencias.DataSource = ObjInv.DtResultados
DtDatosSugerencias = ObjInv.DtResultados
DtDatosSugerencias.Columns.Add("Consec", GetType(Integer))
DtDatosSugerencias.Columns.Add("CantidadGV", GetType(Double))
DtDatosSugerencias.Columns.Add("CantidadTraspaso", GetType(Double))
If Not DtDatosSugerencias.Columns.Contains("Lote") Then
DtDatosSugerencias.Columns.Add("Lote", GetType(String))
End If
If Not DtDatosSugerencias.Columns.Contains("CveSeccion") Then
DtDatosSugerencias.Columns.Add("CveSeccion", GetType(Integer))
End If
If Not DtDatosSugerencias.Columns.Contains("Seleccionado") Then
DtDatosSugerencias.Columns.Add("Seleccionado", GetType(Boolean))
End If
If Not DtDatosSugerencias.Columns.Contains("CantidadSeleccionada") Then
DtDatosSugerencias.Columns.Add("CantidadSeleccionada", GetType(Double))
End If
Dim Index = 1
For Each Dr As DataRow In DtDatosSugerencias.Rows
Dr("Consec") = Index
Index += 1
Next
DtDatosSugerencias.AcceptChanges()
If DtDatosSugerencias IsNot Nothing AndAlso DtDatosSugerencias.Rows.Count > 0 Then
GvSugerencias.Columns(2).Visible = DtDatosSugerencias.MAX("Seccion") <> ""
GvSugerencias.Columns(3).Visible = DtDatosSugerencias.MAX("Serie") <> ""
GvSugerencias.Columns(4).Visible = DtDatosSugerencias.MAX("Lote") <> ""
GvSugerencias.Columns(5).Visible = DtDatosSugerencias.MAX("FechaCaducidad") <> ""
End If
End If
ObjInv.Dispose()
GvSugerencias.DataBind()
UpVerSugerencias.Update()
RegistraScript("$('#ModalVerSugerencias').modal()")
End Sub
Protected Sub BtnAplicarSugerencias_Click(sender As Object, e As EventArgs)
DtDatos = Nothing
DtDatos = New DataTable
DtDatos = DtDatosSugerencias
DtDatosDetalle = Nothing
CreaDtDetalle()
DtDatosDetalleLote = Nothing
CreaDtDetalleLote()
CargaGvDatos()
RegistraScript("$('#ModalVerSugerencias').modal('hide')")
End Sub
Protected Sub DdlAlmacen_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlAlmacen.SelectedIndexChanged
If DdlAlmacen.SelectedValue <> "-1" Then
CargaGvDatos(DdlAlmacen.SelectedValue.ToEntero)
End If
End Sub
Protected Sub BtnImprimirSugerencias_Click(sender As Object, e As EventArgs)
Dim LogoRutaFisica As String = String.Format("Empresas\{0}\Logo.png", UsuarioActual.CveEmpresa)
Dim logouri = String.Format("{0}://{1}:{2}/ashx/sigfiles.ashx?P={3}", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, Encripta(LogoRutaFisica))
Dim Imagen As New System.IO.FileInfo(String.Format("{0}Logo.png", UsuarioActual.Empresa.Ruta))
Dim params As New List(Of ReportParameter)
If Imagen.Exists Then
params.Add(New ReportParameter("LogoPath", logouri))
Else
params.Add(New ReportParameter("LogoPath", ""))
End If
params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa))
params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Usuario))
ImprimirPDF("Empresas/Grales/Formatos/RepEntregaAlmacenSugerencia.rdlc", DtDatosSugerencias, params, "Equipo GPS")
End Sub
#End Region
#Region "TipoEntrega"
Protected Sub EntregaRadioGroup_Click(sender As Object, e As EventArgs)
If RbEntregaExterna.Checked Then
RegistraScript($"AbrirVentana('/General/PopUpPaqueteriasGuias.aspx?CveVenta={CveVentaSurtir}',800,547,'N')")
ElseIf RbEntregaInterna.Checked Then
'RegistraScript("$('#ModalPaqueteriaInterna').modal('show')")
'RegistraScript($"AbrirVentana('/General/PopUpPaqueteriasGuiasInternas.aspx?CveVenta={CveVentaSurtir}&CveSubProyecto={CveSubProyecto}',800,547,'N')")
'CveVentaSurtir
ElseIf RbSinEntrega.Checked Then
LimpiaCampos()
End If
End Sub
Protected Sub LimpiaCampos()
DdlEstatus.SelectedValue = "1"
TxtFechaPaqInterna.Text = ""
TxtFechaEstimada.Text = ""
TxtNoCajas.Text = ""
TxtObservacionesPaqInterna.Text = ""
UpPaqInterna.Update()
End Sub
Protected Sub PaqueteriaDetalle_Click(sender As Object, e As EventArgs)
If RbEntregaExterna.Checked Then
RegistraScript($"AbrirVentana('/General/PopUpPaqueteriasGuias.aspx?CveVenta={CveVentaSurtir}',800,547,'N')")
ElseIf RbEntregaInterna.Checked Then
'RegistraScript("$('#ModalPaqueteriaInterna').modal('show')")
End If
End Sub
#End Region
#Region "Cliente entrega personal"
Private Sub ClienteEntregaPersonal(CveCliente As Integer)
Dim ObjVentas As New ClsVentas()
If ObjVentas.GetClientesPersonalEntrega(-1, CveCliente, UsuarioActual.CveEmpresa, 1) Then
If ObjVentas.DtResultados.Rows.Count > 0 Then
GvClentesPersonalEntrega.DataSource = ObjVentas.DtResultados
GvClentesPersonalEntrega.DataBind()
DivPersonalEntrega.Visible = True
Else
DivPersonalEntrega.Visible = False
End If
End If
ObjVentas.Dispose()
UpClentesPersonalEntrega.Update()
End Sub
#End Region
#Region "sugerir caducidad"
Private Sub SugiereLoteCaducidad(CveAlmacen As Integer)
Dim TempDT As New DataTable
Dim DtLotesCaducidad As New DataTable
TempDT = DtDatos.Clone
Dim CvePSAnterior As Integer = 0
Dim ObjInventarios As New ClsInventarios()
For Each dr As DataRow In DtDatos.Rows
If CBool(dr("AplicaLote")) Then
If CvePSAnterior <> dr("CvePS").ToString.ToEntero Then
CvePSAnterior = dr("CvePS").ToString.ToEntero
If ObjInventarios.GetExistenciasCaducidad(dr("CvePS").ToString.ToEntero, CveAlmacen, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then
DtLotesCaducidad.Merge(ObjInventarios.DtResultados)
End If
End If
End If
Next
ObjInventarios.Dispose()
For Each dr As DataRow In DtDatos.Rows
If CBool(dr("AplicaLote")) Then
Dim dtta As DataTable = DtLotesCaducidad.FiltraParametros(String.Format("CvePS = {0}", dr("CvePS")))
If dtta IsNot Nothing AndAlso dtta.Rows.Count > 0 Then
'recorre que cumplan con la cantidad total a llenar
Dim CantidadSurtir As Decimal = dr("CantidadF").ToString.ToDecimal
For Each drl As DataRow In dtta.Rows
If CantidadSurtir < drl("Cantidad").ToString.ToDecimal Then
dr("CantidadF") = CantidadSurtir
dr("CantidadC") = CantidadSurtir
dr("Lote") = drl("Lote")
dr("FechaCaducidad") = drl("FechaCaducidad")
TempDT.ImportRow(dr)
CantidadSurtir = 0
Else
CantidadSurtir -= drl("Cantidad").ToString.ToDecimal
dr("CantidadF") = drl("Cantidad").ToString.ToDecimal
dr("CantidadC") = drl("Cantidad").ToString.ToDecimal
dr("Lote") = drl("Lote")
dr("FechaCaducidad") = drl("FechaCaducidad")
TempDT.ImportRow(dr)
End If
If CantidadSurtir <= 0 Then Exit For
Next
Else
'error, no hay lote sugerido
End If
Else
TempDT.ImportRow(dr)
End If
Next
DtDatos = TempDT
End Sub
#End Region
'Protected void LnkEditarDir_Click(Object sender, EventArgs e)
'{
' int CveCliente = GvRow.DataKey("CveCliente").ToEntero();
' int CveDireccion = GvRow.DataKey("CveDireccionEnvio").ToEntero();
' HdnCveVenta.Value = GvRow.DataKey("CveVenta");
' CargaModalCombosDirecciones(CveCliente, CveDireccion);
' UpModalEditarentrega.Update();
' this.RegistraScript("$('#DivEditarEntrega').modal('show');");
'}
Protected Sub LnkEditarDir_Click(sender As Object, e As EventArgs)
HdnCveVenta.Value = CveVentaSurtir.ToString
CargaModalCombosDirecciones(CveCliente, CveDireccionEnvio)
RegistraScript("$('#DivEditarEntrega').modal('show');")
End Sub
Private Sub CargaModalCombosDirecciones(CveCliente As Integer, CveDireccionEnvio As Integer)
DdlModalDireccionEnvio.Items.Clear()
Dim dtt As New DataTable()
Dim ObjClientes As New ClsClientes()
If (ObjClientes.DireccionEnvioGet(-1, CveCliente, -1)) Then
dtt = ObjClientes.DtResultados
End If
ObjClientes.Dispose()
DdlModalDireccionEnvio.DataSource = dtt
DdlModalDireccionEnvio.DataBind()
DdlModalDireccionEnvio.SelectedValueExist(CveDireccionEnvio)
UpModalEditarentrega.Update()
dtt.Dispose()
End Sub
Protected Sub BtnModalEditarentrega_Click(sender As Object, e As EventArgs)
Dim ProcesoOK As Boolean = True
Dim ObjVentas As New ClsVentas()
If Not ObjVentas.UpdateDireccionEnvioVenta(HdnCveVenta.Value.ToEntero(), DdlModalDireccionEnvio.SelectedValue.ToEntero(), UsuarioActual.CveEmpresa) Then
ProcesoOK = False
End If
ObjVentas.Dispose()
If ProcesoOK Then
RegistraScript("$('#DivEditarEntrega').modal('hide');")
Alert("Dirección Actualizada correctamente.", ModExtensiones.TipoMensaje.ToastInformacion)
'CargaDatos()
End If
End Sub
End Class