Option Strict On Option Explicit On Imports Microsoft.Reporting.WebForms Imports System.Data Imports Extensiones Imports System.IO Imports GemBox.Spreadsheet Partial Class Inventarios_RecepcionAlmacen Inherits ClsPaginas #Region "PROPIEDADES" Private Property EstatusInicial As String Get EstatusInicial = ViewState("EstatusInicial").ToString End Get Set(value As String) ViewState("EstatusInicial") = value End Set End Property Private Property EstatusFinalOK As String Get EstatusFinalOK = ViewState("EstatusFinalOK").ToString End Get Set(value As String) ViewState("EstatusFinalOK") = 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 Private Property CveTipoAlmacen As Integer Get Return CType(ViewState("CveTipoAlmacen"), Integer) End Get Set(value As Integer) ViewState("CveTipoAlmacen") = value End Set End Property Private Property DtInv As DataTable Get If ViewState("DtInv") Is Nothing Then Return New DataTable Else Return CType(ViewState("DtInv"), DataTable) End If End Get Set(value As DataTable) ViewState("DtInv") = value End Set End Property Private Property dt As DataTable Get Return CType(ViewState("dt"), DataTable) End Get Set(value As DataTable) ViewState("dt") = value End Set End Property Private Property CveMoneda As Integer Get Return CType(ViewState("CveMoneda"), Integer) End Get Set(value As Integer) ViewState("CveMoneda") = value End Set End Property Private Property CveCompraParametro As Integer Get Return CType(ViewState("CveCompraParametro"), Integer) End Get Set(value As Integer) ViewState("CveCompraParametro") = value End Set End Property Private Property CveTipoCompra As Integer Get Return CType(IfNull(ViewState("CveTipoCompra"), 0), Integer) End Get Set(value As Integer) ViewState("CveTipoCompra") = value End Set End Property Private Property DtCuentas As DataTable Get Return CType(ViewState("DtCuentas"), DataTable) End Get Set(value As DataTable) ViewState("DtCuentas") = value End Set End Property Private ReadOnly Property IdPoliza As Integer Get Return ViewState("IdPoliza").ToString.ToEntero End Get End Property Private Property DtAlmacenesDevolucion As DataTable Get Return CType(ViewState("DtAlmacenesDevolucion"), DataTable) End Get Set(value As DataTable) ViewState("DtAlmacenesDevolucion") = 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 DtDatosLoteDetalle As DataTable Get Return CType(ViewState("DtDatosLoteDetalle"), DataTable) End Get Set(value As DataTable) ViewState("DtDatosLoteDetalle") = 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 CantidadTotal As Decimal Get Return CType(ViewState("CantidadTotal"), Decimal) End Get Set(value As Decimal) ViewState("CantidadTotal") = value End Set End Property Private Property PUSerie As Decimal Get Return CType(ViewState("PUSerie"), Decimal) End Get Set(value As Decimal) ViewState("PUSerie") = 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 TotalGV As Decimal Get Return CType(ViewState("TotalGV"), Decimal) End Get Set(value As Decimal) ViewState("TotalGV") = value End Set End Property Private Property TotalCompraOC As Decimal Get Return CType(ViewState("TotalCompraOC"), Decimal) End Get Set(value As Decimal) ViewState("TotalCompraOC") = value End Set End Property Private Property TipoCambio As Decimal Get Return ViewState("TipoCambio").ToString.ToDecimal End Get Set(value As Decimal) ViewState("TipoCambio") = value End Set End Property Private Property DtBitacora As DataTable Get Return CType(ViewState("DtBitacora"), DataTable) End Get Set(value As DataTable) ViewState("DtBitacora") = 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 EntregaDirecta As Boolean Get Return CBool(ViewState("EntregaDirecta")) End Get Set(value As Boolean) ViewState("EntregaDirecta") = value End Set End Property Private Property RecibidaCompleta As Boolean Get Return CBool(ViewState("RecibidaCompleta")) End Get Set(value As Boolean) ViewState("RecibidaCompleta") = value End Set End Property Private Property Apartado As Boolean Get Return CBool(ViewState("Apartado")) End Get Set(value As Boolean) ViewState("Apartado") = value End Set End Property Private Property BuscaEntregaDirecta As Integer Get Return CType(ViewState("BuscaEntregaDirecta"), Integer) End Get Set(value As Integer) ViewState("BuscaEntregaDirecta") = value End Set End Property Private Property CveAlmacenApartado As Integer Get Return CType(ViewState("CveAlmacenApartado"), Integer) End Get Set(value As Integer) ViewState("CveAlmacenApartado") = value End Set End Property Private Property CveAlmacenDevolucionProveedor As Integer Get Return CType(ViewState("CveAlmacenDevolucionProveedor"), Integer) End Get Set(value As Integer) ViewState("CveAlmacenDevolucionProveedor") = 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 CveCompraSurtir As Integer Get Return CType(ViewState("CveCompraSurtir"), Integer) End Get Set(value As Integer) ViewState("CveCompraSurtir") = value End Set End Property Private Property CveProveedor As Integer Get Return CType(ViewState("CveProveedor"), Integer) End Get Set(value As Integer) ViewState("CveProveedor") = value End Set End Property Private Property CvePrePolizaCompra As Integer Get Return CType(ViewState("CvePrePolizaCompra"), Integer) End Get Set(value As Integer) ViewState("CvePrePolizaCompra") = value End Set End Property Private Property CveOCSurtir As Integer Get Return CType(ViewState("CveOCSurtir"), Integer) End Get Set(value As Integer) ViewState("CveOCSurtir") = value End Set End Property Private Property CveImportacionSurtir As Integer Get Return CType(ViewState("CveImportacionSurtir"), Integer) End Get Set(value As Integer) ViewState("CveImportacionSurtir") = value End Set End Property Private Property CveImportacionCompra As Integer Get Return CType(ViewState("CveImportacionCompra"), Integer) End Get Set(value As Integer) ViewState("CveImportacionCompra") = value End Set End Property Private Property CveImportacionProveedor As Integer Get Return CType(ViewState("CveImportacionProveedor"), Integer) End Get Set(value As Integer) ViewState("CveImportacionProveedor") = value End Set End Property Private Property CveFleteSurtir As Integer Get Return CType(ViewState("CveFleteSurtir"), Integer) End Get Set(value As Integer) ViewState("CveFleteSurtir") = value End Set End Property Private Property CveFleteOrdenCompra As Integer Get Return CType(ViewState("CveFleteOrdenCompra"), Integer) End Get Set(value As Integer) ViewState("CveFleteOrdenCompra") = value End Set End Property Private Property CveFleteCompra As Integer Get Return CType(ViewState("CveFleteCompra"), Integer) End Get Set(value As Integer) ViewState("CveFleteCompra") = 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 CveCliente As Integer Get Return CType(ViewState("CveCliente"), Integer) End Get Set(value As Integer) ViewState("CveCliente") = 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 RealizarTraspasoAlmacenDevolucion As Boolean Get Return If(IsNothing(ViewState("RealizarTraspasoAlmacenDevolucion")), False, CBool(ViewState("RealizarTraspasoAlmacenDevolucion"))) End Get Set ViewState("RealizarTraspasoAlmacenDevolucion") = Value End Set End Property Private Property RealizarMovimientoVirtual As Boolean Get Return If(IsNothing(ViewState("RealizarMovimientoVirtual")), False, CBool(ViewState("RealizarMovimientoVirtual"))) End Get Set ViewState("RealizarMovimientoVirtual") = Value End Set End Property Private Property SumarImporteUsados As Boolean Get Return If(IsNothing(ViewState("SumarImporteUsados")), False, CBool(ViewState("SumarImporteUsados"))) End Get Set ViewState("SumarImporteUsados") = Value End Set End Property Private Property ValidarRecepcionUsados As Boolean Get Return If(IsNothing(ViewState("ValidarRecepcionUsados")), False, CBool(ViewState("ValidarRecepcionUsados"))) End Get Set ViewState("ValidarRecepcionUsados") = Value End Set End Property Private Property ArchivoBitacora As String Get Return CType(ViewState("ArchivoBitacora"), String) End Get Set(value As String) ViewState("ArchivoBitacora") = value End Set End Property Private Property ArchivoBitacoraDetalle As String Get Return CType(ViewState("ArchivoBitacoraDetalle"), String) End Get Set(value As String) ViewState("ArchivoBitacoraDetalle") = 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() CargaUrlParametros() CargaPendientes() CargaPermisos() If UsuarioActual.CveEmpresa.Contiene(72, 80) 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 " PERMISOS PAGINAS " Private Sub CargaPermisos() 'IMPORTES Dim TienePermisoImportes As Boolean = UsuarioActual.TienePermisoProceso(201) GvInv.Columns(8).Visible = TienePermisoImportes GvInv.Columns(10).Visible = TienePermisoImportes End Sub #End Region #Region " INICIALIZA VALORES " Private Sub InicializaValores() CveCompraParametro = -1 CveCompraSurtir = -1 CvePrePolizaCompra = -1 CveOCSurtir = -1 CveImportacionSurtir = -1 CveImportacionProveedor = -1 CveImportacionCompra = -1 CveFleteSurtir = -1 CveFleteOrdenCompra = -1 CveFleteCompra = -1 BuscaEntregaDirecta = -1 CveAlmacenApartado = -1 CveAlmacenDevolucionProveedor = -1 TipoMovimiento = 1 RealizarTraspasoAlmacenDevolucion = False CantidadTotal = 0 ddlAlmacenAdd.DataSource = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltraParametros("CveTipoAlmacen NOT IN (9)") ddlAlmacenAdd.DataBind() CargaAlmacenes(-1) ddlProveedor.setEsWebService(UsuarioActual.Empresa.Funcionalidad(105) = "1") If ddlProveedor.UsaWebService Then ddlProveedor.Attributes.Add("data-metodo", "getproveedores") Else ddlProveedor.DataSource = GlobalDTCompProveedores(UsuarioActual.CveEmpresa) ddlProveedor.DataBind() ddlProveedor.ddl.Items.Insert(0, New ListItem("Seleccione el Proveedor", "-1")) ddlProveedor.SelectedValue = "-1" End If DdlFolio.Items.Insert(0, New ListItem("Seleccione", "-1")) DdlFolioOC.Items.Insert(0, New ListItem("Seleccione", "-1")) ConfiguraTipoRecepcion() If UsuarioActual.CveEmpresa = 119 Then DivRemision.Visible = True End If TxtFechaPendientes.Text = Now.ToShortDateString TipoCambio = -1 CreaDtDetalle() ImgClose.Attributes.Add("onclick", "$('#DivAlmacen').hide();") ImgAdd.Attributes.Add("onclick", "$('#DivAlmacen').hide();") BtnGuardar.Visible = False 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 InicializaBitacoraTemporal() DdlMonedaTC.Enabled = False End Sub ''' ''' Recarga los almacenes [DdlAlmacen] que se pueden usar para el movimiento ''' ''' ''' Parametro sin espacios y separado por comas ["1,2,3,21"] Private Sub CargaAlmacenes(CveSubProyecto As Integer, Optional CveTiposAlmacen As String = "", Optional CveTipoCompra As Integer = -1) Dim StrAlmacenes As String = "" StrAlmacenes = $"CveTipoAlmacen IN ({If(CveTiposAlmacen.Length > 0, CveTiposAlmacen, "1,2,15,14,19")}) {If(CveSubProyecto > 0, $"And CveSubProyecto = {CveSubProyecto}", "")}" If CveTipoCompra = 10 Then StrAlmacenes = $"Modalidad = 0" End If DdlAlmacen.Items.Clear() 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() If UsuarioActual.CveAlmacen > 0 Then DdlAlmacen.SelectedValueExist(UsuarioActual.CveAlmacen) RecargaporAlmacenes() End If UpGenerales.Update() End Sub Protected Sub DdlAlmacen_SelectedIndexChanged(sender As Object, e As EventArgs) Recargaporalmacenes() End Sub Private Sub RecargaporAlmacenes() CveTipoAlmacen = -1 If DdlAlmacen.SelectedValue <> "-1" Then Dim drr As DataRow = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=DdlAlmacen.SelectedValue.ToEntero).FiltroPrimero("") If drr IsNot Nothing Then '("CveSubProyecto").ToEntero Dim CveSubProyecto As Integer = drr("CveSubProyecto").ToString.ToEntero 'RMF condición temporal If UsuarioActual.CveEmpresa = 119 AndAlso CveSubProyecto.ToString.Contiene(UsuarioActual.Empresa.Funcionalidad(347).Split(","c)) Then ValidaLoteCaducidad = True Else ValidaLoteCaducidad = False End If CveTipoAlmacen = drr("CveTipoAlmacen").ToString.ToEntero End If CargaGVInv() 'For Each Gvr As GridViewRow In GvInv.Rows ' If Gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue = "-1" Then ' Dim Dr As DataRow = GlobalDTSeccionAlmacen(UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero).FiltroPrimero("") ' If Dr IsNot Nothing Then ' Gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValueExist(Dr("CveSeccion")) ' End If ' End If 'Next 'UPInv.Update() End If End Sub Private Sub ConfiguraTipoRecepcion() DdlTipo.Items.Insert(0, New ListItem("Compra", "1")) If UsuarioActual.Empresa.Funcionalidad(131).ToEntero > 0 Then DdlTipo.Items.Add(New ListItem("OC", "2")) End If If UsuarioActual.Empresa.Funcionalidad(155).ToEntero > 0 Then DdlTipo.Items.Add(New ListItem("Importación", "3")) End If If UsuarioActual.Empresa.Funcionalidad(158).ToEntero > 0 Then DdlTipo.Items.Add(New ListItem("Costo Indirecto", "4")) End If UpFiltros.Update() End Sub #End Region #Region " CARGA URL PARAMETROS " Private Sub CargaUrlParametros() CveCompraParametro = IfNull(Request("CveCompra"), "-1").ToString.ToEntero BuscaEntregaDirecta = IfNull(Request("ED"), "-1").ToString.ToEntero If CveCompraParametro > 0 Then Dim ObjCompras As New ClsCompras If ObjCompras.GetCompras(CveCompraParametro, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then If ObjCompras.DtResultados.Rows.Count >= 1 Then ddlProveedor.SelectedValue = ObjCompras.DtResultados.Rows(0)("CveProveedor").ToString ddlProveedor.SelectedText = ObjCompras.DtResultados.Rows(0)("RazonSocial").ToString ddlProveedor_SelectedIndexChanged(ddlProveedor, EventArgs.Empty) If (DdlFolio.Items.FindByValue(CveCompraParametro.ToString) Is Nothing) Then DdlFolio.Items.Insert(1, New ListItem(ObjCompras.DtResultados.Rows(0)("SerieFolio").ToString, CveCompraParametro.ToString)) ' lo genera Obj.SelectedValue = Valor.ToString End If DdlFolio.SelectedValueExist(CveCompraParametro.ToString) btnBuscar_Click(BtnBuscar, EventArgs.Empty) Else Alert("La Compra solicitada no se pudo encontrar. Por favor vuelva a intentar.", TipoMensaje.MsgAdvertencia) End If Else Alert("Ocurrió un error al cargar los datos de la Compra. Por favor vuelva a intentar.", TipoMensaje.MsgError) End If ObjCompras.Dispose() End If End Sub #End Region #Region " MODALIDAD RECEPCION " Protected Sub DdlTipo_SelectedIndexChanged(sender As Object, e As EventArgs) ModalidadRecepcion() End Sub Private Sub ModalidadRecepcion() LblCompra.Visible = False DivCompra.Visible = False LblOC.Visible = False DivOC.Visible = False LblImportacion.Visible = False DivImportacion.Visible = False LblFletes.Visible = False DivFletes.Visible = False LblFactura.Visible = False DivDdlFactura.Visible = False Select Case DdlTipo.SelectedValue.ToEntero Case 1 LblCompra.Visible = True DivCompra.Visible = True Case 2 LblOC.Visible = True DivOC.Visible = True Case 3 LblImportacion.Visible = True DivImportacion.Visible = True LblFactura.Visible = True DivDdlFactura.Visible = True Case 4 LblFletes.Visible = True DivFletes.Visible = True LblIndirectoFactura.Visible = True DivDdlIndirectoFactura.Visible = True End Select CargaFoliosRecepcion() End Sub #End Region #Region " CARGA FOLIOS RECEPCION " Protected Sub ddlProveedor_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlProveedor.selectedindexchange CargaFoliosRecepcion() 'DdlTipo_SelectedIndexChanged(DdlTipo, EventArgs.Empty) End Sub Private Sub CargaFoliosRecepcion() Select Case DdlTipo.SelectedValue.ToEntero Case 1 CargaFolios() Case 2 CargaFoliosOC() Case 3 CargaFoliosImportacion() Case 4 CargaFletes() End Select UpFiltros.Update() End Sub Private Sub CargaFolios() DdlFolio.Items.Clear() Dim ObjInventarios As New ClsInventarios If ddlProveedor.SelectedValue.ToEntero > 0 Then If ObjInventarios.ComprasPendientesAlmacenGet(ddlProveedor.SelectedValue.ToEntero, MinFecha.ToShortDateString.ToDate, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then Dim FiltroTemporal = " AND TipoDocto IN ('Fac','NC','DEV')" DdlFolio.DataSource = ObjInventarios.DtResultados.FiltraParametros($"CantOC >= 0 {FiltroTemporal}") 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")) End Sub Private Sub CargaFoliosImportacion() DdlFolioImportacion.Items.Clear() Dim ObjInventarios As New ClsInventarios If ddlProveedor.SelectedValue.ToEntero > 0 Then If ObjInventarios.PendientesAlmacenImportacionGet(ddlProveedor.SelectedValue.ToEntero, MinFecha.ToShortDateString.ToDate, UsuarioActual.CveEmpresa) Then DdlFolioImportacion.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() DdlFolioImportacion.DataBind() DdlFolioImportacion.Items.Insert(0, New ListItem("Seleccione", "-1")) CargaFactura() End Sub Protected Sub DdlFolioImportacion_SelectedIndexChanged(sender As Object, e As EventArgs) CargaFactura() End Sub Private Sub CargaFactura() DdlFactura.Items.Clear() Dim ObjInventarios As New ClsInventarios If DdlFolioImportacion.SelectedValue.ToEntero > 0 Then If ObjInventarios.PendientesAlmacenImportacionComprasGet(DdlFolioImportacion.SelectedValue.ToEntero, ddlProveedor.SelectedValue.ToEntero) Then DdlFactura.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() DdlFactura.DataBind() DdlFactura.Items.Insert(0, New ListItem("Todos", "-1")) End Sub Private Sub CargaFletes() DdlFletes.Items.Clear() Dim ObjInventarios As New ClsInventarios If ddlProveedor.SelectedValue.ToEntero > 0 Then If ObjInventarios.GetFletes(UsuarioActual.CveEmpresa, CveProveedor:=ddlProveedor.SelectedValue.ToEntero, OpcionInventario:=1) Then DdlFletes.DataSource = ObjInventarios.DtResultados.FiltraParametros("CantRest > 0") Else Alert("Ocurrió un error al obtener las ordenes de compra pendientes de recibir del proveedor. Por favor vuelva a intentar", TipoMensaje.MsgError) End If End If ObjInventarios.Dispose() DdlFletes.DataBind() DdlFletes.Items.Insert(0, New ListItem("Seleccione", "-1")) End Sub Protected Sub DdlFletes_SelectedIndexChanged(sender As Object, e As EventArgs) CargaFletesFactura() End Sub Private Sub CargaFletesFactura() DdlIndirectoFactura.Items.Clear() Dim ObjInventarios As New ClsInventarios If DdlFletes.SelectedValue.ToEntero > 0 Then If ObjInventarios.GetFletesCompras(DdlFletes.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then DdlIndirectoFactura.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() DdlIndirectoFactura.DataBind() 'DdlIndirectoFactura.Items.Insert(0, New ListItem("Todos", "-1")) End Sub #End Region #Region " CARGA POR SURTIR - GV " 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() Dim ObjInventarios As New ClsInventarios Dim DtPendientes As New DataTable If ObjInventarios.ComprasPendientesAlmacenGet(-1, TxtFechaPendientes.Text.ToDate, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then Dim FiltroTemporal = If(UsuarioActual.CveEmpresa.Contiene(119, 140, 1, 72, 80, 153, 154), "AND TipoDocto IN ('Fac','NC','DEV')", "AND TipoDocto IN ('Fac')") DtPendientes = ObjInventarios.DtResultados.FiltraParametros($"CantOC >= 0 {FiltroTemporal}") 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(539) = "1" Then ' BtnGuardar.Enabled = False ' Dim FI As Date = Now.AddDays(-1) ' Dim FF As Date = Now.AddDays(-7) ' If ObjInventarios.RepNotasSinAlmacen(2, -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 recepción de mercancía si no se les da entrada a los documentos pendientes. Para más información ver el Reporte de notas sin entrada en la sección Compras.", 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() 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 = e.Row.DBCampo("CveCompra") If e.Row.DBCampo("TipoDocto").ToString.Contiene({"Fac"}) And e.Row.DBCampo("EstatusAlmacen").ToString.ToEntero = 0 Then e.Row.FCLinkButton("BtnSurtir").CssClass = "btn btn-primary input-sm" e.Row.FCLinkButton("BtnSurtir").Text = " Recibir" Else e.Row.FCLinkButton("BtnSurtir").CssClass = "btn yellow-gold input-sm" e.Row.FCLinkButton("BtnSurtir").Text = " Devolver " End If If UsuarioActual.TienePermisoProceso(201) Then Dim Css = "Texto" Dim Liga = $"/Compras/Compras.aspx?&CveCompra={e.Row.DataKey("CveCompra")}" e.Row.FCLabel("LblSerieFolio").Text = "" + e.Row.FCLabel("LblSerieFolio").Text + "" End If End If End Sub #End Region #Region " CARGA POR SURTIR " Protected Sub btnBuscar_Click(sender As Object, e As EventArgs) Handles BtnBuscar.Click 'REINICIA VALORES DdlMonedaTC.SelectedValueExist("1") TipoCambio = -1 DivBitacora.Visible = False DtBitacora.Clear() GvInv.Columns(2).Visible = False GvInv.Columns(3).Visible = False CveCompraSurtir = -1 CvePrePolizaCompra = -1 CveOCSurtir = -1 CveImportacionSurtir = -1 CveImportacionProveedor = -1 CveImportacionCompra = -1 CveFleteSurtir = -1 CveFleteOrdenCompra = -1 CveFleteCompra = -1 DivAdvertencia.Visible = False EntregaDirecta = False DivTipoCambio.Visible = False Apartado = False CveAlmacenApartado = -1 CveAlmacenDevolucionProveedor = -1 RealizarTraspasoAlmacenDevolucion = False RealizarMovimientoVirtual = False SumarImporteUsados = False ValidarRecepcionUsados = False BtnGuardar.Enabled = True CargaAlmacenes(-1) DtInv = Nothing TxtObservaciones.Text = "" TxtOC.Text = "" TxtFecha.Text = Now.ToShortDateString DdlAlmacen.SelectedValueExist(-1) TxtRemision.Text = "" UpTipoCambio.Update() UPInv.Update() UpGenerales.Update() UpFiltros.Update() UpDatosCompra.Update() If TxtOC.Text <> "" Then LtDocumento.Text = "ORDEN DE COMPRA" CargaOC() ElseIf DdlFolioOC.SelectedValue.ToEntero > 0 Then LtDocumento.Text = "ORDEN DE COMPRA" CargaOCPorSurtir(DdlFolioOC.SelectedValue.ToEntero) ElseIf DdlFolio.SelectedValue.ToEntero > 0 Then LtDocumento.Text = "COMPRA" CargaCompra(DdlFolio.SelectedValue.ToEntero, ddlProveedor.SelectedValue.ToEntero) ElseIf DdlFolioImportacion.SelectedValue.ToEntero > 0 Then LtDocumento.Text = "IMPORTACIÓN" CargaImportacionSurtir(DdlFolioImportacion.SelectedValue.ToEntero) ElseIf DdlFletes.SelectedValue.ToEntero > 0 Then LtDocumento.Text = "FLETE" CargaFleteSurtir(DdlFletes.SelectedValue.ToEntero) Else Alert("Debe seleccionar algun criterio de busqueda (Compra, OC, Importación). Por favor rectifique y vuelva a intentar", TipoMensaje.MsgAdvertencia) BtnGuardar.Visible = False End If CargaGVInv() 'DtSeccionAlmacen.Rows.Clear() 'DtSeccionAlmacen.AcceptChanges() End Sub Protected Sub BtnSurtir_Click(sender As Object, e As EventArgs) If CType(sender, LinkButton).CommandArgument.ToEntero > 0 Then CargaCompra(CType(sender, LinkButton).CommandArgument.ToEntero, -1) TimmerRefresh.Enabled = False End If End Sub Private Sub CargaCompra(pCveCompra As Integer, pCveProveedor As Integer) 'CargaAlmacenes(-1) RealizarTraspasoAlmacenDevolucion = False RealizarMovimientoVirtual = False SumarImporteUsados = False ValidarRecepcionUsados = False CveAlmacenDevolucionProveedor = -1 Dim ObjCompras As New ClsCompras Dim ObjInventario As New ClsInventarios If ObjCompras.GetCompras(pCveCompra, "-1", "-1", pCveProveedor, -1, UsuarioActual.CveEmpresa) Then If ObjCompras.DtResultados.Rows.Count > 0 Then CveCompraSurtir = pCveCompra CveProveedor = pCveProveedor CvePrePolizaCompra = ObjCompras.DtResultados.Rows(0)("CvePrePoliza").ToString.ToEntero LbProveedor.Text = ObjCompras.DtResultados.Rows(0)("RazonSocial").ToString HLFolio.Text = ObjCompras.DtResultados.Rows(0)("SerieFolio").ToString If UsuarioActual.TienePermisoProceso(201) Then HLFolio.NavigateUrl = $"/Compras/Compras.aspx?CveCompra={CveCompraSurtir}" End If LbDescripcionCompra.Text = ObjCompras.DtResultados.Rows(0)("Descripcion").ToString UpDatosCompra.Update() CveMoneda = ObjCompras.DtResultados.Rows(0)("CveMoneda").ToString.ToEntero lbDescripcion.Text = ObjCompras.DtResultados.Rows(0)("Descripcion").ToString HdnTipoDocto.Value = ObjCompras.DtResultados.Rows(0)("TipoDocto").ToString If UsuarioActual.CveEmpresa = 140 Then TxtObservaciones.Text = ObjCompras.DtResultados.Rows(0)("Descripcion").ToString TipoCambio = ObjCompras.DtResultados.Rows(0)("TipoCambio").ToString.ToDecimal TipoMovimiento = If(ObjCompras.DtResultados.Rows(0)("EstatusAlmacen").ToString.ToEntero = 1, 2, 1) TipoMovimiento = If(ObjCompras.DtResultados.Rows(0)("TipoDocto").ToString.Contiene("NC", "DEV"), 3, TipoMovimiento) TotalCompraOC = ObjCompras.DtResultados.Rows(0)("SubTotal").ToString.ToDecimal - ObjCompras.DtResultados.Rows(0)("Descuentos").ToString.ToDecimal CveTipoCompra = ObjCompras.DtResultados.Rows(0)("CveTipoCompra").ToString.ToEntero If CveTipoCompra = 9 Then ' apoyo logistico CargaAlmacenes(-1, "27", CveTipoCompra) ElseIf CveTipoCompra = 10 Then CargaAlmacenes(-1, CveTipoCompra:=CveTipoCompra) ElseIf TipoMovimiento = 3 Then 'devolucion al proveedor CargaAlmacenes(-1, "1,21,2,27", CveTipoCompra) Else CargaAlmacenes(-1) End If RecibidaCompleta = False '' carga desde excel ' HplCargaExcel.Enabled = True Dim CargaSoloUsados As Boolean = False If ObjInventario.RecepcionAlmacenGet(pCveCompra, BuscaEntregaDirecta, -1, UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then Dim DtRecepcion As DataTable = ObjInventario.DtResultados.Copy() DtInv = DtRecepcion Dim NumUsados = ObjInventario.DtResultados.COUNT("EsUsado", "EsUsado = True").ToEntero() Dim NumProductos = ObjInventario.DtResultados.COUNT("EsUsado", "EsUsado = False").ToEntero() Dim CveSubProyecto As Integer ArchivoBitacora = String.Format("{0}Temp\RecepcionDT_{1}_{2}.xml", UsuarioActual.Empresa.Ruta, UsuarioActual.CveUsuario, pCveCompra) ArchivoBitacoraDetalle = String.Format("{0}Temp\RecepcionDTD_{1}_{2}.xml", UsuarioActual.Empresa.Ruta, UsuarioActual.CveUsuario, pCveCompra) If ArchivoBitacora <> "" Then Dim Archivo = New System.IO.FileInfo(ArchivoBitacora) If Archivo.Exists() Then HplCargaBitacora.Visible = True uppCargaBitacora.Update() End If End If If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then 'SI LA COMPRA TIENE PRODUCTOS Y USADOS SOLO MOSTRAR LOS PRODUCTOS If NumProductos > 0 AndAlso NumUsados > 0 Then DtRecepcion = ObjInventario.DtResultados.FiltraParametros("EsUsado = False") SumarImporteUsados = True ValidarRecepcionUsados = True 'SI LA COMPRA TIENE PUROS USADOS, MOSTRAR LOS USADOS Y CARGAR LOS ALMACENES ElseIf NumProductos = 0 AndAlso NumUsados > 0 Then CargaSoloUsados = True SumarImporteUsados = True ValidarRecepcionUsados = True DtRecepcion = ObjInventario.DtResultados.Copy() If TipoMovimiento = 3 Then CargaAlmacenes(DtRecepcion.Rows(0)("CveSubProyecto").ToString.ToEntero, "21", CveTipoCompra) Else CargaAlmacenes(DtRecepcion.Rows(0)("CveSubProyecto").ToString.ToEntero, "22", CveTipoCompra) End If Else DtRecepcion = ObjInventario.DtResultados.Copy() 'VERIFICA LOS QUE TENGAN LAS CLASIFICACION DE USADOS If ObjCompras.GetCompraDetalle(pCveCompra) Then If ObjCompras.DtResultados.COUNT("Cantidad", "CveClasificacion=20519") > 0 Then SumarImporteUsados = True ValidarRecepcionUsados = True Else SumarImporteUsados = False ValidarRecepcionUsados = False End If End If End If End If CveSubProyecto = DtRecepcion.Rows(0)("CveSubProyecto").ToString.ToEntero CveAlmacenDevolucionProveedor = DtRecepcion.Rows(0)("CveAlmacenDevolucionProveedor").ToString.ToEntero 'SI ES MOTOBATERIA NO GENERA MOVIMIENTO VIRTUAL If UsuarioActual.Empresa.Funcionalidad(573) = "1" AndAlso (DtRecepcion.COUNT("CveTamaño", "CveTamaño > 0 AND CveTamaño <> 16") > 0) Then RealizarMovimientoVirtual = True DivVirtualAdvertencia.Visible = True Else RealizarMovimientoVirtual = False DivVirtualAdvertencia.Visible = False End If 'SI LA COMPRA ES DE TIPO "APOYO LOGISTICO" NO DEBE GENERAR VIRTUAL If Not SumarImporteUsados AndAlso CveTipoCompra = 9 Then RealizarMovimientoVirtual = False DivVirtualAdvertencia.Visible = False End If If TipoMovimiento = 2 AndAlso CveAlmacenDevolucionProveedor > 0 Then RealizarTraspasoAlmacenDevolucion = True DivTraspasoDevolucion.Visible = True LtlTextoDevolucion.Text = "La mercancía sera trasladada desde el almacen seleccionado al almacén de devolución" ElseIf TipoMovimiento = 2 AndAlso GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveTipoAlmacen:=21).Rows.Count = 0 Then LtlTextoDevolucion.Text = "La mercancía sera devuelta a el almacen seleccionado." DivTraspasoDevolucion.Visible = True End If If UsuarioActual.Empresa.Funcionalidad(594) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(314) Then DivDocumentos.Visible = True UpDocumentos.Update() End If DtDatosDetalle = Nothing CreaDtDetalle() DtDatosLoteDetalle = Nothing CreaDtLoteDetalle() CreaDTInv(DtRecepcion) BtnGuardar.Visible = True 'cuando están todos los detalles de la compra, nos indica que se va a recibir la totalidad de la compra If DtRecepcion.Rows.Count = DtRecepcion.Rows(0)("NumDetalles").ToString.ToEntero Then RecibidaCompleta = True End If ''MONEDA DIFERENTE If CveMoneda <> 1 Then 'DivTipoCambio.Visible = True DdlMonedaTC.SelectedValueExist("2") DdlMonedaTC_SelectedIndexChanged(DdlMonedaTC, EventArgs.Empty) 'TxtTipoCambio.Text = If(TipoCambio <= 0, GlobalTipoCambio(TxtFecha.Text.ToDate).ToString, TipoCambio.ToString) TipoCambio = If(TipoCambio <= 0, GlobalTipoCambio(TxtFecha.Text.ToDate).ToDecimal, TipoCambio) LtAdvertencia.Text = "El cambio de moneda se aplicara al guardar el movimiento con el tipo de cambio indicado." DivAdvertencia.Visible = True End If UpTipoCambio.Update() ''ENTREGA DIRECTA If BuscaEntregaDirecta > 0 Then If UsuarioActual.Empresa.Funcionalidad(149) = "1" Then LtAdvertencia.Text = "La mercancía tendra salida inmediata por ser entrega directa al cliente" DivAdvertencia.Visible = True EntregaDirecta = True CveCliente = DtRecepcion.Rows(0)("CveCliente").ToString.ToEntero CveVendedor = DtRecepcion.Rows(0)("CveVendedor").ToString.ToEntero If DtInv.COUNT("EntregaDirecta") <> DtInv.Rows.Count Then Alert("Todos los conceptos deben estar facturados.", TipoMensaje.MsgAdvertencia) BtnGuardar.Enabled = False End If End If End If If DtInv.Rows.Count = 0 Then Alert("No hay productos pendientes de surtir de esta compra. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) Else If DtRecepcion.Rows(0)("CveVendedor").ToString.ToEntero > 0 And DtRecepcion.Rows(0)("CveCliente").ToString.ToEntero > 0 Then If DtInv.SUM("EntregaDirecta") > 0 Then ''ENTREGA DIRECTA 'LtAdvertencia.Text = "La mercancía tendra salida inmediata por ser entrega directa al cliente" 'DivAdvertencia.Visible = True 'EntregaDirecta = True Else 'APARTADO 'If UsuarioActual.CveUsuario.Contiene(100) Or (DtRecepcion .Rows(0)("CveUsuarioOC").ToString.ToEntero = 1559 And DtRecepcion .Rows(0)("FechaIngOC").ToString.ToDateTime > "2017-04-24 12:00".ToDateTime) Then If UsuarioActual.Empresa.Funcionalidad(148) = "1" Then CveAlmacenApartado = DtRecepcion.Rows(0)("CveAlmacenApartado").ToString.ToEntero DivAdvertencia.Visible = True Apartado = True If CveAlmacenApartado <= 0 Then BtnGuardar.Enabled = False LtAdvertencia.Text = "No se puede recibir la mercancía por ser de apartados y no contar con un almacen de apartado." Else LtAdvertencia.Text = "La mercancía sera traspasada a apartados" If CargaSoloUsados Then CargaAlmacenes(DtRecepcion.Rows(0)("CveSubProyecto").ToString.ToEntero, "22", CveTipoCompra) Else If TipoMovimiento <> 3 Then 'cuando no es devolución CargaAlmacenes(DtRecepcion.Rows(0)("CveSubProyecto").ToString.ToEntero, CveTipoCompra:=CveTipoCompra) End If End If End If End If 'End If End If End If End If Dim CantidadFaltante As Decimal = DtRecepcion.SUMD("CantidadC", "CantidadF > 0") If UsuarioActual.Empresa.UsaAC AndAlso CantidadFaltante > 0 Then PnlAC.Visible = True CargaAC() LbTotalPorDevengar.Text = DtRecepcion.SUM("Total", "CantidadF > 0").FormatoNumero End If 'Existencias If TipoMovimiento = 2 Then If ObjInventario.ComprasDevolucionExistenciasGet(CveCompraSurtir) Then DtExistencias = ObjInventario.DtResultados.Copy Else Alert("No se pudieron cargar las existencias del movimiento de entrada, por lo cual no se podra hacer la devolución.", TipoMensaje.MsgError) BtnGuardar.Enabled = False End If End If End If DivBitacora.Visible = True If UsuarioActual.Empresa.Funcionalidad(132) = "1" Then DivCodigoSeriePS.Visible = True Else DivCodigoSeriePS.Visible = False End If End If Else BtnGuardar.Visible = False End If ObjCompras.Dispose() ObjInventario.Dispose() CargaGVInv() UpAdvertencias.Update() UpDocumentos.Update() End Sub Private Sub CargaImportacionSurtir(pCveImportacion As Integer) Dim ObjCompras As New ClsCompras Dim ObjInventario As New ClsInventarios If ObjCompras.GetImportaciones(pCveImportacion, -1, -1, "-1", "-1", UsuarioActual.CveEmpresa) Then If ObjCompras.DtResultados.Rows.Count > 0 Then CveImportacionSurtir = pCveImportacion CveImportacionProveedor = ddlProveedor.SelectedValue.ToEntero CveImportacionCompra = DdlFactura.SelectedValue.ToEntero LbProveedor.Text = ObjCompras.DtResultados.Rows(0)("ProveedorCompra").ToString HLFolio.Text = ObjCompras.DtResultados.Rows(0)("PedimentoDescripcion").ToString If UsuarioActual.TienePermisoProceso(201) Then HLFolio.NavigateUrl = $"/Compras/Importaciones.aspx?CveImportacion={CveImportacionSurtir}" End If UpDatosCompra.Update() CveMoneda = 1 lbDescripcion.Text = "" TipoMovimiento = 1 If ObjInventario.RecepcionAlmacenImportacionGet(CveImportacionSurtir, DdlFactura.SelectedValue.ToEntero, CveImportacionProveedor, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then DtDatosDetalle = Nothing CreaDtDetalle() DtDatosLoteDetalle = Nothing CreaDtLoteDetalle() CreaDTInv(ObjInventario.DtResultados) BtnGuardar.Visible = True End If If DtInv Is Nothing OrElse DtInv.Rows.Count = 0 Then Alert("No hay productos pendientes de surtir de esta importación. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) End If DivBitacora.Visible = True If UsuarioActual.Empresa.Funcionalidad(132) = "1" Then DivCodigoSeriePS.Visible = True Else DivCodigoSeriePS.Visible = False End If If UsuarioActual.Empresa.Funcionalidad(594) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(314) Then DivDocumentos.Visible = True UpDocumentos.Update() End If End If Else BtnGuardar.Visible = False End If ObjCompras.Dispose() ObjInventario.Dispose() CargaGVInv() End Sub Private Sub CargaFleteSurtir(pCveImportacion As Integer) Dim ObjInventario As New ClsInventarios If ObjInventario.GetFletes(UsuarioActual.CveEmpresa, CveFlete:=pCveImportacion) Then If ObjInventario.DtResultados.Rows.Count > 0 Then CveFleteSurtir = pCveImportacion CveFleteOrdenCompra = ObjInventario.DtResultados.Rows(0)("CveOC").ToString.ToEntero CveFleteCompra = DdlIndirectoFactura.SelectedValue.ToEntero 'ObjInventario.DtResultados.Rows(0)("CveCompra").ToString.ToEntero CveImportacionCompra = CveFleteCompra ' se iguala para que al guardar el movimiento, se toma esta variable LbProveedor.Text = ObjInventario.DtResultados.Rows(0)("RazonSocial").ToString HLFolio.Text = ObjInventario.DtResultados.Rows(0)("Folio").ToString If UsuarioActual.TienePermisoProceso(201) Then HLFolio.NavigateUrl = $"/Inventarios/Fletes.aspx?CveFlete={CveFleteSurtir}" End If UpDatosCompra.Update() CveMoneda = 1 lbDescripcion.Text = "" TipoMovimiento = 1 If ObjInventario.RecepcionAlmacenFleteGet(CveFleteSurtir, CveFleteOrdenCompra, CveFleteCompra, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then DtDatosDetalle = Nothing CreaDtDetalle() DtDatosLoteDetalle = Nothing CreaDtLoteDetalle() CreaDTInv(ObjInventario.DtResultados) BtnGuardar.Visible = True End If If DtInv Is Nothing OrElse DtInv.Rows.Count = 0 Then Alert("No hay productos pendientes de surtir de esta importación. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) End If DivBitacora.Visible = True If UsuarioActual.Empresa.Funcionalidad(132) = "1" Then DivCodigoSeriePS.Visible = True Else DivCodigoSeriePS.Visible = False End If If UsuarioActual.Empresa.Funcionalidad(594) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(314) Then DivDocumentos.Visible = True UpDocumentos.Update() End If End If Else BtnGuardar.Visible = False End If ObjInventario.Dispose() CargaGVInv() End Sub #End Region #Region " GVINV " Private Sub CreaDTInv(TmDT As DataTable) TmDT.Columns.Add("CveAlmacen", GetType(Integer)) TmDT.Columns.Add("PUExtranjero", GetType(Decimal)) TmDT.Columns.Add("CostoIndirectoExtranjero", GetType(Decimal)) TmDT.Columns.Add("Consec", GetType(Integer)) TmDT.Columns.Add("CantidadSurtidaPantalla", GetType(Decimal)) If Not TmDT.Columns.Contains("AplicaSeccion") Then TmDT.Columns.Add("AplicaSeccion", GetType(Decimal)) End If If Not TmDT.Columns.Contains("AplicaSerie") Then TmDT.Columns.Add("AplicaSerie", GetType(Decimal)) End If If Not TmDT.Columns.Contains("AplicaLote") Then TmDT.Columns.Add("AplicaLote", GetType(Decimal)) End If If Not TmDT.Columns.Contains("AplicaCaducidad") Then TmDT.Columns.Add("AplicaCaducidad", GetType(Decimal)) End If If Not TmDT.Columns.Contains("CostoIndirecto") Then TmDT.Columns.Add("CostoIndirecto", GetType(Decimal)) End If If Not TmDT.Columns.Contains("Lote") Then TmDT.Columns.Add("Lote", GetType(String)) End If If Not TmDT.Columns.Contains("CveSeccion") Then TmDT.Columns.Add("CveSeccion", GetType(Integer)) End If If Not TmDT.Columns.Contains("Caducidad") Then TmDT.Columns.Add("Caducidad", GetType(Date)) End If If Not TmDT.Columns.Contains("Seleccionado") Then TmDT.Columns.Add("Seleccionado", GetType(Boolean)) End If If Not TmDT.Columns.Contains("CantidadSeleccionada") Then TmDT.Columns.Add("CantidadSeleccionada", GetType(Decimal)) End If GvInv.Columns(2).Visible = False GvInv.Columns(3).Visible = False GvInv.Columns(9).Visible = TmDT.SUM("CostoIndirecto") > 0 Dim VariableCampo = If(TipoMovimiento.Contiene(1, 3), "CantidadF", "CantidadS") Dim Index = 1 For Each Dr As DataRow In TmDT.Rows Dr("PUExtranjero") = Dr("PU") Dr("CostoIndirectoExtranjero") = Dr("CostoIndirecto") Dr("Consec") = Index Index += 1 Dr("CantidadF") = Dr(VariableCampo) If Dr(VariableCampo).ToString.ToDecimal <> Dr("CantidadC").ToString.ToDecimal Then GvInv.Columns(3).Visible = True End If Dr("Caducidad") = Now Next DtInv = TmDT '.FiltraParametros("CantidadF > 0") dt = TmDT If DtInv.SUM("CantidadS") > 0 Then GvInv.Columns(2).Visible = True End If End Sub Private Sub CargaGVInv() If UsuarioActual.CveEmpresa = 119 Then DtInv = DtInv.FiltraParametros("", "PS") End If Dim AplicaSeccion, AplicaLote, AplicaCaducidad, AplicaSerie As Boolean If DtInv IsNot Nothing AndAlso DtInv.Rows.Count > 0 Then AplicaSerie = CBool(DtInv.MAX("AplicaSerie")) AplicaSeccion = CBool(DtInv.MAX("AplicaSeccion")) AplicaLote = CBool(DtInv.MAX("AplicaLote")) AplicaCaducidad = CBool(DtInv.MAX("AplicaCaducidad")) End If If AplicaSeccion Then GvInv.Columns(11).Visible = True If AplicaLote Then GvInv.Columns(12).Visible = True If Not String.IsNullOrWhiteSpace(UsuarioActual.Empresa.Funcionalidad(147)) Then GvInv.Columns(13).HeaderText = UsuarioActual.Empresa.Funcionalidad(147) If AplicaCaducidad Then GvInv.Columns(13).Visible = True If AplicaSerie OrElse AplicaSeccion OrElse AplicaLote OrElse AplicaCaducidad Then GvInv.Columns(14).Visible = True End If GvInv.DataSource = DtInv GvInv.DataBind() UPInv.Update() End Sub Protected Sub GvInv_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvInv.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then 'If e.Row.DBCampo("CveMetodoInventario").ToString.Contiene("5", "6") Then If CBool(e.Row.DBCampo("AplicaSerie")) Then 'If e.Row.DBCampo("CveMetodoInventario").ToString = "5" Then e.Row.FCButton("BtnSerie").Visible = True e.Row.FCButton("BtnSerie").CommandArgument = String.Format("{0}°{1}°{2}°{3}°{4}°{5}", e.Row.DBCampo("CvePS"), e.Row.DBCampo("CveUM"), e.Row.DBCampo("PU"), e.Row.DBCampo("PS"), e.Row.DBCampo("CantidadF"), e.Row.DBCampo("Consec")) e.Row.FCTextBox("TbCantidadF").Enabled = False e.Row.FCCheckBox("cbInv").Enabled = False Dim Contador = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", e.Row.DataKey("Consec"))).Rows.Count e.Row.FCTextBox("TbCantidadF").Text = Contador.ToString '' Empresa Acumuladores If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then If CveTipoAlmacen = 21 Then e.Row.FCButton("BtnSerie").Visible = False e.Row.FCTextBox("TbCantidadF").Enabled = True e.Row.FCCheckBox("cbInv").Enabled = True End If End If 'ElseIf e.Row.DBCampo("CveMetodoInventario").ToString = "6" Then ' e.Row.FCButton("BtnLote").Visible = True ' e.Row.FCButton("BtnLote").CommandArgument = String.Format("{0}°{1}°{2}°{3}°{4}°{5}", e.Row.DBCampo("CvePS"), e.Row.DBCampo("CveUM"), e.Row.DBCampo("PU"), e.Row.DBCampo("PS"), e.Row.DBCampo("CantidadF"), e.Row.DBCampo("Consec")) ' e.Row.FCTextBox("TbCantidadF").Enabled = False ' e.Row.FCCheckBox("cbInv").Enabled = False ' Dim Contador = DtDatosLoteDetalle.FiltraParametros(String.Format("ConsecId = {0}", e.Row.DataKey("Consec"))).Rows.Count ' e.Row.FCTextBox("TbCantidadF").Text = Contador.ToString 'End If Else e.Row.FCButton("BtnSerie").Visible = False e.Row.FCButton("BtnLote").Visible = False e.Row.FCTextBox("TbCantidadF").Enabled = True e.Row.FCTextBox("TbCantidadF").Attributes.Add("onblur", String.Format("ValidarCantidad(this,{0})", e.Row.DBCampo("CantidadF"))) e.Row.FCCheckBox("cbInv").Attributes.Add("onclick", String.Format("Check(this, {0}, {1});", e.Row.FCTextBox("TbCantidadF").ClientID, e.Row.DBCampo("CantidadF"))) If e.Row.DBCampo("EntregaDirecta").ToString = "1" And TipoMovimiento = 1 Then e.Row.FCCheckBox("cbInv").Checked = True e.Row.FCCheckBox("cbInv").Enabled = False e.Row.FCTextBox("TbCantidadF").Text = e.Row.DBCampo("CantidadF").FormatoNumero e.Row.FCTextBox("TbCantidadF").Enabled = False End If If UsuarioActual.CveRol = 1 Then 'carga la cantidad con el rol AD e.Row.FCTextBox("TbCantidadF").Text = e.Row.DBCampo("CantidadF").FormatoNumero End If 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 dtsec As DataTable = GlobalDTInvPSSeccionesAlmacen(UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero, e.Row.DBCampo("CvePS").ToEntero) 'e.Row.FCDropDownList("DdlSeccionAlmacen").DataSource = dtsec 'e.Row.FCDropDownList("DdlSeccionAlmacen").DataBind() 'If dtsec.Rows.Count = 1 Then ' e.Row.FCDropDownList("DdlSeccionAlmacen").SelectedIndex = 0 ' e.Row.FCDropDownList("DdlSeccionAlmacen").Enabled = False 'Else 'si es mayor a uno que por default seleccione el primero, que seria el predeterminado ' e.Row.FCDropDownList("DdlSeccionAlmacen").SelectedValueExist(dtsec.FiltroPrimeroValor("CveSeccionAlmacen", "Predeterminado = 1")) 'End If 'e.Row.FCDropDownList("DdlSeccionAlmacen").Items.Insert(0, New ListItem("Seleccione", "-1")) 'dtsec.Dispose() End If e.Row.FCTextBox("TxtDividir").Visible = True 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").Text = Now.ToShortDateString e.Row.FCTextBox("TxtDividir").Visible = True Else e.Row.FCTextBox("TxtCaducidad").Visible = False e.Row.FCLinkButton("LnkCaducidad").Visible = False End If If CBool(e.Row.DBCampo("AplicaLote")) Then e.Row.FCTextBox("TxtLote").Visible = True 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 <> "" And Not UsuarioActual.TienePermisoProceso(174) Then e.Row.FCTextBox("TbCantidadF").Enabled = False End If If e.Row.DBCampo("CantidadF").ToDecimal = 0 Then e.Row.FCTextBox("TbCantidadF").Visible = False e.Row.Cells(3).Text = "0" e.Row.FCCheckBox("cbInv").Visible = False End If e.Row.FCLabel("LbTotal").Text = ((e.Row.DBCampo("PU").ToDecimal + e.Row.DBCampo("CostoIndirecto").ToDecimal) * e.Row.DBCampo("CantidadF").ToDecimal).FormatoNumero TotalGV += (e.Row.DBCampo("PU").ToDecimal + e.Row.DBCampo("CostoIndirecto").ToDecimal) * e.Row.DBCampo("CantidadF").ToDecimal End If If e.Row.RowType = DataControlRowType.Footer Then Dim TienePermisoImportes As Boolean = UsuarioActual.TienePermisoProceso(201) e.Row.FCLabel("LbTotal").Visible = TienePermisoImportes If TienePermisoImportes Then e.Row.FCLabel("LbTotal").Text = TotalGV.FormatoNumero TotalGV = 0.0D e.Row.Font.Bold = True e.Row.Cells(6).Text = "Total" e.Row.Cells(6).HorizontalAlign = HorizontalAlign.Right End If End If End Sub #End Region #Region " AGREGAR " #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 For Each Gvr As GridViewRow In GvInv.Rows If Gvr.DataKey("CodigoBarras") = TxtCodigoPS.Text.Trim Then Dim TxtCantidad = GvInv.Rows(Gvr.RowIndex).FCTextBox("TbCantidadF") If Gvr.DataKey("CantidadF").ToDecimal - TxtCantidad.Text.ToDecimal - 1 >= 0 Then If Gvr.DataKey("AplicaSerieLote") = "True" Then TdSeriePS.Visible = True TxtSeriePS.Focus() CveConsecSerie = Gvr.DataKey("Consec").ToEntero 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 'VERIFICA EXISTENCIAS Dim MensajeSinExistencias As New StringBuilder If TipoMovimiento > 1 Then Dim ExistenciaActual = DtInv.SUM("CantidadSurtidaPantalla", $"CvePS = {Gvr.DataKey("CvePS").ToEntero} AND CveUM = {Gvr.DataKey("CveUM").ToEntero} ") + 1 Dim ObjInventarios As New ClsInventarios Dim Existencia = ObjInventarios.GetExistenciasPS(Gvr.DataKey("CvePS").ToEntero, Gvr.DataKey("CveUM").ToEntero, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm")) ObjInventarios.Dispose() If Existencia < ExistenciaActual Then Alert($"El producto con el codigo de barras {TxtCodigoPS.Text} no tiene la existencia suficiente.", TipoMensaje.MsgAdvertencia) Exit Sub End If 'EXISTENCIAS DE LA COMPRAR - PARA DEVOLUCION If TipoMovimiento = 2 Then If DtExistencias.SUM("Existencia", $"CvePS = {Gvr.DataKey("CvePS").ToEntero} AND CveUM = {Gvr.DataKey("CveUM").ToEntero}") < ExistenciaActual Then Alert($"El producto con el codigo de barras {TxtCodigoPS.Text} no tiene la existencia suficiente de recepción.", TipoMensaje.MsgAdvertencia) Exit Sub End If End If End If TxtCantidad.Text = (TxtCantidad.Text.ToDecimal + 1).ToString.FormatoNumero TxtCodigoPS.Text = "" RegistraScript("playsonidito('beep-07.wav')") UPInv.Update() Dim Dr = DtInv.Select($"Consec = {Gvr.DataKey("Consec")}")(0) Dr("CantidadSurtidaPantalla") = TxtCantidad.Text.ToDecimal DtInv.AcceptChanges() Exit Sub End If End If Alert($"Ya se ha cargado la totalidad del Producto ""{Gvr.DataKey("PS").ToString}"" con el Codigo ""{TxtCodigoPS.Text}"".", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);") RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") End If Next Alert($"No se ha encontrado un producto para surtir con el Codigo ""{TxtCodigoPS.Text}"". ", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);") RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") TxtCodigoPS.Text = "" 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() End Sub Protected Sub BtnGuardarCantidadEspecial_Click(sender As Object, e As EventArgs) AgregaCantidadEspecial() End Sub Private Sub AgregaCantidadEspecial() Dim TxtCantidad = GvInv.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);") UPInv.Update() TxtCodigoPS.Focus() RegistraScript("playsonidito('beep-07.wav')") 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 #Region " AGREGA POR SERIE/LOTE " Protected Sub BtnSerie_Click(sender As Object, e As EventArgs) Dim Argumentos = CType(sender, Button).CommandArgument.Split("°"c) LbProducto.Text = Argumentos(3) LbCantidad.Text = Argumentos(4).FormatoNumero CvePSSerie = Argumentos(0).ToEntero CveUMSerie = Argumentos(1).ToEntero PUSerie = Argumentos(2).ToDecimal CveConsecSerie = Argumentos(5).ToEntero CargaSerie(1) End Sub Private Sub CreaDtDetalle() If DtDatosDetalle Is Nothing Then DtDatosDetalle = New DataTable DtDatosDetalle.Columns.Add("Consec", GetType(Integer)) DtDatosDetalle.Columns.Add("ConsecId", GetType(Integer)) DtDatosDetalle.Columns.Add("CvePS", GetType(Integer)) DtDatosDetalle.Columns.Add("CveUM", GetType(Integer)) DtDatosDetalle.Columns.Add("PU", GetType(Decimal)) DtDatosDetalle.Columns.Add("Serie", GetType(String)) DtDatosDetalle.Columns.Add("FechaCaducidad", GetType(String)) End If End Sub Private Sub CreaDTAlmacenDevolucion() If DtAlmacenesDevolucion Is Nothing Then DtAlmacenesDevolucion = New DataTable DtAlmacenesDevolucion.Columns.Add("CveCompraDetalle", GetType(Integer)) DtAlmacenesDevolucion.Columns.Add("CveAlmacenOriginal", GetType(Integer)) End If End Sub Private Sub CargaSerie(Tipo As Integer, Optional CerrarCompletado As Boolean = False) 'RegistraScript("document.getElementById(""TxtSerie"").focus();") RegistraScript("$('#DivSerie').modal();", "ModalLote") GvSerie.DataSource = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", CveConsecSerie), "Consec DESC") GvSerie.DataBind() 'VALIDA QUE SIGA AGREGANDO If Not DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", CveConsecSerie)).Rows.Count < LbCantidad.Text.ToEntero Then BtnAgregarPS.Enabled = False If CerrarCompletado Then RegistraScript("$('#DivSerie').modal('hide');") End If Else BtnAgregarPS.Enabled = True End If 'SI TIENE ENTRADA POR SERIE LOTE, BLOQUEAMOS CHECK Y TXTCANTIDAD Dim Contador = 0 For Each Gvr As GridViewRow In GvInv.Rows If Gvr.DataKey("CvePS").ToEntero = CvePSSerie Then Contador = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", Gvr.DataKey("Consec"))).Rows.Count Gvr.FCCheckBox("cbInv").Enabled = False Gvr.FCTextBox("TbCantidadF").Enabled = False If DtDatosDetalle IsNot Nothing AndAlso Contador > 0 Then Gvr.FCCheckBox("cbInv").Checked = True Gvr.FCTextBox("TbCantidadF").Text = Contador.ToString ElseIf Gvr.DataKey("CantidadF").ToString.ToDecimal <> 0 Then Gvr.FCCheckBox("cbInv").Checked = False Gvr.FCTextBox("TbCantidadF").Text = "0" End If End If Dim Dr = DtInv.Select($"Consec = {Gvr.DataKey("Consec")}")(0) Dr("CantidadSurtidaPantalla") = Gvr.FCTextBox("TbCantidadF").Text.ToDecimal DtInv.AcceptChanges() Next UPInv.Update() UpSerie.Update() TxtSerie.Text = "" TxtSerie.Focus() If Tipo = 1 Then RegistraScript(String.Format("$('#{0}').on('shown.bs.modal', function () {{$('#{0}').focus(); $('#{0}').trigger(jQuery.Event('keypress', {{which: 13}})); }});$('#DivSerie').modal('show'); ", TxtSerie.ClientID)) End If End Sub Protected Sub BtnAgregarPS_Click(sender As Object, e As EventArgs) AgregaSerie(TxtSerie.Text.Replace(" ", String.Empty), 1) End Sub Private Sub AgregaSerie(Serie As String, Tipo As Integer) 'SerieLote = SerieLote.Trim.Replace(" ", " ") If Serie.Trim = "" Then Alert("El campo Serie es obligatorio. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim SeriesArreglo = Serie.Trim.Split(";"c) '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)) 'If CvePSS > 0 And CvePSSerie = 0 Then CvePSSerie = CvePSS 'PARA VALIDAR SI LA SERIE ES IGUAL AL CODIGO O CODIGOBARRAS Dim dr As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePSSerie).FiltroPrimero("", "PS") For Each Serie In SeriesArreglo DtDuplicado = DtDatosDetalle.FiltraParametros($"ConsecId = {CveConsecSerie} AND Serie = '{Serie}'") If DtDuplicado IsNot Nothing AndAlso DtDuplicado.Rows.Count > 0 Then MensajeAlert.Append($"
El numero de Serie ""{Serie}"" proporcionado ya se encuentra ingresado.") Continue For End If DtDuplicado = DtSeriesNuevas.FiltraParametros($"Serie = '{Serie}'") If DtDuplicado IsNot Nothing AndAlso DtDuplicado.Rows.Count > 0 Then MensajeAlert.Append($"
El numero de Serie ""{Serie}"" proporcionado se encuentra duplicado.") Continue For End If 'PARA VALIDAR SI LA SERIE ES IGUAL AL CODIGO O CODIGOBARRAS If Serie.ToUpper = dr("Codigo").ToString.ToUpper Or Serie.ToUpper = dr("CodigoBarras").ToString.ToUpper Then MensajeAlert.Append($"
El numero de Serie {Serie} coincide con el codigo o codigo de barras del producto. Por favor rectifique y vuelva a intentar.") Continue For End If Dim Row = DtSeriesNuevas.NewRow Row("Serie") = Serie DtSeriesNuevas.Rows.Add(Row) Next If MensajeAlert.ToString <> "" Then Alert(MensajeAlert.ToString, TipoMensaje.MsgAdvertencia) RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") Exit Sub End If Dim MensajeSinExistencias As New StringBuilder Dim ObjInventarios As New ClsInventarios Dim Index = 0 For Each Serie In SeriesArreglo If Serie <> "" Then Dim Row = DtDatosDetalle.NewRow Index = Index + 1 If Index > LbCantidad.Text.ToEntero Then Exit For End If 'VALIDA QUE SIGA AGREGANDO If Not DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", CveConsecSerie)).Rows.Count < LbCantidad.Text.ToEntero Then Exit For End If '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"), Serie:=Serie) If Existencia < 1 Then MensajeSinExistencias.Append($"Serie: {Serie}.
") Continue For End If If TipoMovimiento = 2 Then If DtExistencias.SUM("Existencia", $"Serie = '{Serie}'") = 0 Then MensajeSinExistencias.Append($"Serie: {Serie}.
") Continue For End If End If End If 'Dim AplicaCaducidad = False 'If GlobalDTPS(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 Row("ConsecId") = CveConsecSerie Row("Consec") = DtDatosDetalle.Rows.Count + 1 Row("CvePS") = CvePSSerie Row("CveUM") = CveUMSerie Row("PU") = PUSerie Row("Serie") = Serie Row("FechaCaducidad") = MinFecha.ToShortDateString DtDatosDetalle.Rows.Add(Row) ActualizaBitacora() End If Next ObjInventarios.Dispose() If Tipo = 1 Then TxtSerie.Text = "" End If CargaSerie(Tipo, True) If MensajeAlert.ToString <> "" Then RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") Else If MensajeSinExistencias.ToString <> "" Then Alert($"Las siguientes Series no cuentan con la existencia suficiente por lo cual se omitieron.
{MensajeSinExistencias.ToString}", TipoMensaje.MsgAdvertencia) End If RegistraScript("playsonidito('beep-07.wav')", "SoniditoSerie") End If End Sub #Region "Bitacora" Private Sub ActualizaBitacora(Optional Eliminar As Boolean = False) If Not Eliminar Then DtInv.TableName = "DtDatos" DtDatosDetalle.TableName = "DtDatosDetalle" DtInv.WriteXml(ArchivoBitacora, XmlWriteMode.WriteSchema) DtDatosDetalle.WriteXml(ArchivoBitacoraDetalle, XmlWriteMode.WriteSchema) Else File.Delete(ArchivoBitacora) End If End Sub Protected Sub HplCargaBitacora_Click(sender As Object, e As EventArgs) If IO.File.Exists(ArchivoBitacora) Then 'DtInv.Clear() 'DtDatosDetalle.Clear() DtInv.ReadXml(ArchivoBitacora) If IO.File.Exists(ArchivoBitacoraDetalle) Then Dim dtt As New DataTable dtt.ReadXml(ArchivoBitacoraDetalle) DtDatosDetalle = dtt Alert("Registro(s) Recuperados", TipoMensaje.ToastInformacion) End If CargaGVInv() Else Alert("No hay bitácora para recuperar.", TipoMensaje.ToastInformacion) End If End Sub #End Region Protected Sub GvSerie_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvSerie.RowDeleting Dim keySerieLote As String = e.Keys("Serie").ToString Try For Each dr As DataRow In DtDatosDetalle.Rows If dr("Serie").ToString = keySerieLote Then dr.Delete() End If Next Catch ex As Exception End Try DtDatosDetalle.AcceptChanges() ActualizaBitacora() CargaSerie(1) End Sub #End Region #Region " AGREGAR POR LOTE BATCH " Private Sub CreaDtLoteDetalle() If DtDatosLoteDetalle Is Nothing Then DtDatosLoteDetalle = New DataTable DtDatosLoteDetalle.Columns.Add("Consec", GetType(Integer)) DtDatosLoteDetalle.Columns.Add("ConsecId", GetType(Integer)) DtDatosLoteDetalle.Columns.Add("Cantidad", GetType(Decimal)) DtDatosLoteDetalle.Columns.Add("CvePS", GetType(Integer)) DtDatosLoteDetalle.Columns.Add("CveUM", GetType(Integer)) DtDatosLoteDetalle.Columns.Add("PU", GetType(Decimal)) DtDatosLoteDetalle.Columns.Add("Lote", GetType(String)) DtDatosLoteDetalle.Columns.Add("FechaCaducidad", GetType(String)) End If End Sub Protected Sub BtnLote_Click(sender As Object, e As EventArgs) Dim Argumentos = CType(sender, Button).CommandArgument.Split("°"c) LbLoteProducto2.Text = Argumentos(3) LbLoteCantidad2.Text = Argumentos(4).FormatoNumero CvePSSerie = Argumentos(0).ToEntero CveUMSerie = Argumentos(1).ToEntero PUSerie = Argumentos(2).ToDecimal CveConsecSerie = Argumentos(5).ToEntero CargaLote(1) End Sub Private Sub CargaLote(Tipo As Integer, Optional CerrarCompletado As Boolean = False) RegistraScript("$('#DivLote').modal();", "ModalLote") GvLote.Columns(2).HeaderText = UsuarioActual.Empresa.Funcionalidad(147) GvLote.DataSource = DtDatosLoteDetalle.FiltraParametros(String.Format("ConsecId = {0}", CveConsecSerie), "Consec DESC") GvLote.DataBind() 'VALIDA QUE SIGA AGREGANDO If Not DtDatosLoteDetalle.SUM("Cantidad", String.Format("ConsecId = {0}", CveConsecSerie)) < LbLoteCantidad2.Text.ToDecimal Then BtnAddPSLote.Enabled = False If CerrarCompletado Then RegistraScript("$('#DivLote').modal('hide');") End If Else BtnAddPSLote.Enabled = True End If 'SI TIENE ENTRADA POR LOTE, BLOQUEAMOS CHECK Y TXTCANTIDAD Dim Contador = 0.0 For Each Gvr As GridViewRow In GvInv.Rows If Gvr.DataKey("CvePS").ToEntero = CvePSSerie Then Contador = DtDatosLoteDetalle.SUM("Cantidad", String.Format("ConsecId = {0}", Gvr.DataKey("Consec"))) Gvr.FCCheckBox("cbInv").Enabled = False Gvr.FCTextBox("TbCantidadF").Enabled = False If DtDatosLoteDetalle IsNot Nothing AndAlso Contador > 0 Then Gvr.FCCheckBox("cbInv").Checked = True Gvr.FCTextBox("TbCantidadF").Text = Contador.ToString ElseIf Gvr.DataKey("CantidadF").ToString.ToDecimal <> 0 Then Gvr.FCCheckBox("cbInv").Checked = False Gvr.FCTextBox("TbCantidadF").Text = "0" End If End If Dim Dr = DtInv.Select($"Consec = {Gvr.DataKey("Consec")}")(0) Dr("CantidadSurtidaPantalla") = Gvr.FCTextBox("TbCantidadF").Text.ToDecimal DtInv.AcceptChanges() Next RVCantidadLote.MaximumValue = (If((LbLoteCantidad2.Text.ToDecimal - Contador) = 0, 0.02, LbLoteCantidad2.Text.ToDecimal - Contador)).ToString.FormatoNumero TxtCantidadLote.Text = "1" TxtLote.Text = "" TxtBatch.Text = "" TxtFechaCaducidadLote.Text = If(TxtFechaCaducidadLote.Text.Trim = "", Now.ToShortDateString(), TxtFechaCaducidadLote.Text) TxtLote.Focus() UPInv.Update() UpLote.Update() If Tipo = 1 Then RegistraScript(String.Format("$('#{0}').on('shown.bs.modal', function () {{$('#{0}').focus(); $('#{0}').trigger(jQuery.Event('keypress', {{which: 13}})); }});$('#DivLote').modal('show'); ", TxtLote.ClientID)) End If End Sub Protected Sub BtnAddPSLote_Click(sender As Object, e As EventArgs) AgregaLote(TxtLote.Text.Trim, 1) End Sub Private Sub AgregaLote(Lote As String, Tipo As Integer) If Lote.Trim = "" 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 = DtDatosLoteDetalle.FiltraParametros($"ConsecId = {CveConsecSerie} AND Lote = '{Lote}' ") If DtDuplicado IsNot Nothing AndAlso DtDuplicado.Rows.Count > 0 Then Alert($"
El numero de Lote ""{Lote}"" proporcionado ya se encuentra ingresado.", TipoMensaje.MsgAdvertencia) RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") Exit Sub End If Dim Row = DtDatosLoteDetalle.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"), Lote:=Lote) If Existencia < CantidadLote Then Alert($"
El numero de Lote ""{Lote}"" proporcionado ya se encuentra ingresado.", TipoMensaje.MsgAdvertencia) RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") End If If TipoMovimiento = 2 Then If Not DtExistencias.SUM("Existencia", $"Lote = '{Lote}' ") = 0 Then Alert($"
El numero de Lote ""{Lote}"" proporcionado ya se encuentra ingresado.", TipoMensaje.MsgAdvertencia) RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") End If End If End If Row("ConsecId") = CveConsecSerie Row("Consec") = DtDatosDetalle.Rows.Count + 1 Row("Cantidad") = CantidadLote Row("CvePS") = CvePSSerie Row("CveUM") = CveUMSerie Row("PU") = PUSerie Row("Lote") = Lote 'Row("FechaCaducidad") = FechaCaducidad 'Row("FechaCaducidad") = If(IsDate(TxtFechaCaducidadLote.Text), TxtFechaCaducidadLote.Text, MinFecha.ToShortDateString) 'Row("FechaCaducidad") = If(AplicaCaducidad, TxtFechaCaducidadLote.Text, MinFecha.ToShortDateString) DtDatosLoteDetalle.Rows.Add(Row) ObjInventarios.Dispose() If Tipo = 1 Then TxtLote.Text = "" End If CargaLote(1, 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 DtDatosLoteDetalle.Rows If dr("Lote").ToString = keyLote Then dr.Delete() End If Next Catch ex As Exception End Try DtDatosLoteDetalle.AcceptChanges() CargaLote(1) End Sub #End Region #End Region #Region " GUARDAR " Private Function ValidaGuardar() As Boolean Dim TotalCantidad As Decimal = GvInv.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.FCTextBox("TbCantidadF").Text.ToDecimal) If TotalCantidad <= 0 Then Alert("No se seleccionó ninguna cantidad de productos a guardar. Por favor verifique e intente nuevamente.", TipoMensaje.MsgAdvertencia) RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") Return False End If 'verifica si recibió al 100% la compra 'bandera que me indica que se cargaron todos los productos, yque se verifique si los detalle s se van a recibir al 100 ' que la cantidad orginal sea igual a la recibida. para considedrarse completa If RecibidaCompleta Then For Each Gvr As GridViewRow In GvInv.Rows If Not Gvr.FCCheckBox("cbInv").Checked Or Gvr.FCTextBox("TbCantidadF").Text.ToDecimal <> Gvr.DataKey("CantidadF").ToString.ToDecimal OrElse Gvr.DataKey("CantidadC").ToString.ToDecimal <> Gvr.DataKey("CantidadF").ToString.ToDecimal Then RecibidaCompleta = False End If Next End If If EntregaDirecta Then For Each Gvr As GridViewRow In GvInv.Rows If Not Gvr.FCCheckBox("cbInv").Checked Or Gvr.FCTextBox("TbCantidadF").Text.ToDecimal <> Gvr.DataKey("CantidadF").ToString.ToDecimal Then Alert("La compra se debe surtir completa por ser entrega directa. Por favor verifique e intente nuevamente.", TipoMensaje.MsgAdvertencia) RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") Return False End If Next End If Dim TotalPorDevengar As Decimal = 0 If UsuarioActual.Empresa.UsaAC Then TotalPorDevengar += GvAC.Rows.Cast(Of GridViewRow)().Sum(Function(Gvr) Gvr.FCTextBox("TxtImporte").Text.ToDecimal) If TotalPorDevengar <= 0 Then Alert("Especifique el importe del presupuesto", TipoMensaje.MsgAdvertencia) RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") Return False End If End If If DdlMonedaTC.SelectedValue = "2" Then AplicarTipoCambio() If TipoCambio <= 0 Then Alert("Ocurrió un error al obtener el tipo de cambio. Por favor verifique e intente de nuevo.", TipoMensaje.MsgAdvertencia) RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") Return False End If End If 'VALIDA SI HUBO CAMBIOS EN LOS DETALLES COMPRA If CveCompraSurtir > 0 Then Dim VariableCampo = If(TipoMovimiento.Contiene(1, 3), "CantidadF", "CantidadS") Dim ObjComprasDif As New ClsInventarios Dim DtDatosCompra As New DataTable If ObjComprasDif.RecepcionAlmacenGet(CveCompraSurtir, BuscaEntregaDirecta, -1, UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario) Then DtDatosCompra = ObjComprasDif.DtResultados End If Dim CantidadGV = GvInv.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.DataKey("CantidadF").ToDecimal) Dim CantConsulta = DtDatosCompra.SUM(VariableCampo) If Math.Abs(CantidadGV - CantConsulta) > 0.01 Then CargaCompra(CveCompraSurtir, -1) CargaPendientes() Alert("Ha sido cambiada la información de existencias de la compra actual, se han recargado la información.", TipoMensaje.MsgAdvertencia) ObjComprasDif.Dispose() Return False End If ObjComprasDif.Dispose() End If 'VALIDA SI HUBO CAMBIOS EN LOS DETALLES OC If CveOCSurtir > 0 Then Dim VariableCampo = If(TipoMovimiento = 1, "CantidadF", "CantidadS") Dim ObjComprasDif As New ClsInventarios Dim DtDatosOC As New DataTable If ObjComprasDif.RecepcionAlmacenOCGet(CveOCSurtir, UsuarioActual.CveEmpresa) Then DtDatosOC = ObjComprasDif.DtResultados.FiltraParametros("CantidadCompra = 0") End If Dim CantidadGV = GvInv.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.DataKey("CantidadF").ToDecimal) Dim CantConsulta = DtDatosOC.SUM(VariableCampo) If Math.Abs(CantidadGV - CantConsulta) > 0.1 Then CargaOCPorSurtir(CveOCSurtir) Alert("Ha sido cambiada la información de existencias de la orden de compra actual, se han recargado la información.", TipoMensaje.MsgAdvertencia) ObjComprasDif.Dispose() Return False End If ObjComprasDif.Dispose() End If 'VALIDA SI HUBO CAMBIOS EN LOS DETALLES IMPORTACION If CveImportacionSurtir > 0 Then Dim VariableCampo = If(TipoMovimiento = 1, "CantidadF", "CantidadS") Dim ObjComprasDif As New ClsInventarios Dim DtDatosImportacion As New DataTable If ObjComprasDif.RecepcionAlmacenImportacionGet(CveImportacionSurtir, CveImportacionCompra, CveImportacionProveedor, UsuarioActual.CveEmpresa) Then DtDatosImportacion = ObjComprasDif.DtResultados End If Dim CantidadGV = GvInv.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.DataKey("CantidadF").ToDecimal) Dim CantConsulta = DtDatosImportacion.SUM(VariableCampo) If CantidadGV <> CantConsulta Then CargaImportacionSurtir(CveImportacionSurtir) Alert("Ha sido cambiada la información de existencias de la importación actual, se han recargado la información.", TipoMensaje.MsgAdvertencia) ObjComprasDif.Dispose() Return False End If ObjComprasDif.Dispose() End If 'VALIDA SI HUBO CAMBIOS EN LOS DETALLES FLETES If CveFleteSurtir > 0 Then Dim VariableCampo = If(TipoMovimiento = 1, "CantidadF", "CantidadS") Dim ObjComprasDif As New ClsInventarios Dim DtDatosImportacion As New DataTable If ObjComprasDif.RecepcionAlmacenFleteGet(CveFleteSurtir, CveFleteOrdenCompra, CveFleteCompra, UsuarioActual.CveEmpresa) Then DtDatosImportacion = ObjComprasDif.DtResultados End If Dim CantidadGV = GvInv.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.DataKey("CantidadF").ToDecimal) Dim CantConsulta = DtDatosImportacion.SUM(VariableCampo) If CantidadGV <> CantConsulta Then CargaFleteSurtir(CveFleteSurtir) Alert(String.Format("Ha sido cambiada la informacion de existencias costo indirecto actual, se han recargado la información.[{0}-{1}]", CantidadGV, CantConsulta), TipoMensaje.MsgAdvertencia) ObjComprasDif.Dispose() Return False End If ObjComprasDif.Dispose() End If Dim ValidaSeccion As Boolean = False : Dim ValidaCaducidad As Boolean = False : Dim ValidaLote As Boolean = False 'PASA DATOS DEL GV A DATATABLE PARA MANEJOR CON FOR EACH Dim Index = 0 For Each gvr As GridViewRow In GvInv.Rows If gvr.FCCheckBox("cbInv").Checked AndAlso gvr.FCTextBox("TbCantidadF").Text.ToDecimal > 0 Then DtInv.Rows(Index)("CantidadSurtidaPantalla") = gvr.FCTextBox("TbCantidadF").Text.ToDecimal 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 End If Index += 1 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) Return False End If If ValidaCaducidad Then Alert("La caducidad no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia) Return False End If If ValidaLote Then Alert("El lote de almacen no ha sido especificada en todos los productos.", TipoMensaje.MsgAdvertencia) Return False End If If UsuarioActual.Empresa.Funcionalidad(594) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(314) Then Dim Filesgral As List(Of Archivo) = TxtDocumento.getfiles().Archivos If Filesgral Is Nothing OrElse Filesgral.Count = 0 Then Alert("Es necesario agregar un documento.", TipoMensaje.MsgAdvertencia) Return False End If End If 'VERIFICA EXISTENCIAS If TipoMovimiento > 1 Then Dim MensajeExistencias As New StringBuilder Dim ObjInventarios As New ClsInventarios For Each gvr As GridViewRow In GvInv.Rows Dim ExistenciaActual = DtInv.SUM("CantidadSurtidaPantalla", $"CvePS = {gvr.DataKey("CvePS").ToEntero} AND CveUM = {gvr.DataKey("CveUM").ToEntero} ") If TipoMovimiento = 2 Then 'If gvr.DataKey("CantidadC").ToString.ToDecimal <> ExistenciaActual Then ' Alert("La devolución debe de ser completa.", TipoMensaje.MsgAdvertencia) ' Exit Sub 'End If If DtExistencias.SUM("Existencia", $"CvePS = {gvr.DataKey("CvePS").ToEntero} AND CveUM = {gvr.DataKey("CveUM").ToEntero}") < ExistenciaActual Then MensajeExistencias.Append($"Producto: {GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=gvr.DataKey("CvePS").ToString.ToEntero).FiltroPrimeroValor("PSCodigo")}.
") Continue For End If End If Dim Existencia = ObjInventarios.GetExistenciasPS(gvr.DataKey("CvePS").ToEntero, gvr.DataKey("CveUM").ToEntero, UsuarioActual.CveEmpresa, DdlAlmacen.SelectedValue.ToEntero, FechaMovto:=TxtFecha.Text.ToDateTime.ToString("yyyy/MM/dd HH:mm")) If Existencia < ExistenciaActual Then MensajeExistencias.Append($"Producto: {GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=gvr.DataKey("CvePS").ToString.ToEntero).FiltroPrimeroValor("PSCodigo")}.
") Continue For End If Next ObjInventarios.Dispose() If MensajeExistencias.ToString <> "" Then Alert($"Los siguientes productos no cuentan con la existencia suficiente para hacer la devolución.

{MensajeExistencias.ToString}", TipoMensaje.MsgAdvertencia) Return False End If End If Return True End Function Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click 'VALIDACIONES If Not ValidaGuardar() Then Exit Sub End If If CveCompraSurtir > 0 Or CveOCSurtir > 0 Then GuardaCompraOC() ElseIf CveImportacionSurtir > 0 Then GuardaImportacionFlete() ElseIf CveFleteSurtir > 0 Then GuardaImportacionFlete() Else Alert("Ocurrio un error al procesar la informacion para guardar el movimiento. Por favor comuniquese con atencion SIG.", TipoMensaje.MsgError) End If End Sub Private Function GeneraPrePolizaSalidaEntregaDirecta(CveMovimiento As Integer, ByRef ObjInventario As ClsInventarios, ByRef ObjConta As ClsContabilidad, ByRef ObjContaContPAQ As ClsContPAQi, EsContabilizable As Boolean) As Boolean Dim Retorno As Boolean = True Try Dim DtCostos As DataTable = Nothing Dim ValorInventario As Decimal = 0 Dim ValorInventarioME As Decimal = 0 Dim CveConcepto As Integer = 3 ObjInventario.GetMovimientos(CveMovimiento, -1, -1, UsuarioActual.CveEmpresa) Dim CveVenta As Integer = ObjInventario.CveVenta Dim CveAlmacen As Integer = ObjInventario.CveAlmacen Dim SerieFolio As String = ObjInventario.DtResultados.Rows(0)("SerieFolioVenta").ToString Dim MovAlmacen As Boolean = True Dim OrigenMov As Integer = GlobalDTInvConceptos.FiltroPrimeroValor("Origen", "CveConcepto = " & CveConcepto).ToEntero If OrigenMov = 1 Then MovAlmacen = False Else MovAlmacen = True If ObjInventario.GetMovimientosDetalle(CveMovimiento, UsuarioActual.CveEmpresa) Then DtCostos = ObjInventario.DtResultados Dim tmpCostos As DataTable = DtCostos.FiltraParametros("", "", {"CveClasificacion"}) Dim IdCtaContable As Integer = 0 Dim ConceptoPoliza As String = String.Format("{0}-{1}", "Salida de Almacen", SerieFolio) If tmpCostos.Rows.Count > 0 Then Dim Concepto As String = ConceptoPoliza Dim CvePrePoliza = ObjConta.AddPrePolizas("Inv_EntradaSalida", 74, DtCostos.SUM("Total"), DtCostos.SUM("Total"), 1, TxtFecha.Text.ToDate, ConceptoPoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Dim tCveSubProyecto = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", $"CveAlmacen={CveAlmacen}").ToEntero Dim tCveConcepto As Integer = 69 For Each RowInv As DataRow In tmpCostos.Rows ValorInventario = DtCostos.SUMD("Total", $"CveClasificacion = {RowInv("CveClasificacion")}").RoundSQL If tCveConcepto = 69 Then IdCtaContable = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaCostos", $"CveClasificacion = {RowInv("CveClasificacion")}").ToEntero End If If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not MovAlmacen, ValorInventario, Concepto, tCveConcepto, Concepto, TxtFecha.Text.ToDate, IdCtaContable, -1, CveVenta:=CveVenta, CveClasificacion:=RowInv("CveClasificacion").ToString.ToEntero, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=ValorInventario, CveSubProyecto:=tCveSubProyecto, Contabilizable:=EsContabilizable) Then Retorno = False Exit For End If Next IdCtaContable = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", $"CveAlmacen={CveAlmacen}").ToEntero If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, MovAlmacen, DtCostos.SUMD("Total").RoundSQL, Concepto, 68, Concepto, TxtFecha.Text.ToDate, IdCtaContable, -1, CveVenta:=CveVenta, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=DtCostos.SUMD("Total").RoundSQL, Contabilizable:=If(CveTipoCompra = 10, False, EsContabilizable)) Then Retorno = False End If If ObjConta.ValidacionPrePolizaCuadre(CvePrePoliza, 6) Then If ObjConta.ValorPolizaDescuadre > 0 Then GuardaLogAD($"Inventarios/RecepcionAlmacen-PPCompOC | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") Retorno = False End If End If 'CONTABILIZAR - SIMPLIFICAR If Retorno Then If UsuarioActual.Empresa.Funcionalidad(220) <> "" Then If Not ObjConta.PrePolizaSimplificacion(CvePrePoliza, UsuarioActual.CveEmpresa) Then Retorno = False End If End If If UsuarioActual.Empresa.Funcionalidad(200) = "1" Then If ObjContaContPAQ Is Nothing Then ObjContaContPAQ = New ClsContPAQi(UsuarioActual.Empresa) ObjContaContPAQ.IniciaTransacSQL() End If If Not ObjConta.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa, ObjConta:=ObjContaContPAQ) Then Retorno = False End If End If End If Else Retorno = False End If Else Retorno = False End If Catch ex As Exception OnError("Ocurrió un error al guadar la prepoliza", ex) Retorno = False End Try Return Retorno End Function Private Function GeneraPrePolizaMovimientoAlmacen(CveMovimientoEntrada As Integer, CveMovimientoSalida As Integer, ByRef ObjInventario As ClsInventarios, ByRef ObjConta As ClsContabilidad, ByRef ObjContaContPAQ As ClsContPAQi, EsContabilizable As Boolean) As Boolean Dim Retorno As Boolean = True Try Dim DtCostos As DataTable = Nothing Dim ValorInventario As Decimal = 0 Dim ValorInventarioME As Decimal = 0 Dim CveConcepto As Integer = 3 ObjInventario.GetMovimientos(CveMovimientoEntrada, -1, -1, UsuarioActual.CveEmpresa) Dim CveVenta As Integer = ObjInventario.CveVenta Dim CveAlmacen As Integer = ObjInventario.CveAlmacen Dim SerieFolio As String = ObjInventario.DtResultados.Rows(0)("SerieFolioVenta").ToString Dim MovAlmacen As Boolean = True Dim OrigenMov As Integer = GlobalDTInvConceptos.FiltroPrimeroValor("Origen", "CveConcepto = " & CveConcepto).ToEntero If OrigenMov = 1 Then MovAlmacen = False Else MovAlmacen = True If ObjInventario.GetMovimientosDetalle(CveMovimientoEntrada, UsuarioActual.CveEmpresa) Then DtCostos = ObjInventario.DtResultados Dim tmpCostos As DataTable = DtCostos.FiltraParametros("", "", {"CveClasificacion"}) Dim IdCtaContable As Integer = 0 Dim ConceptoPoliza As String = String.Format("{0}-{1}", "Salida de Almacen", SerieFolio) If tmpCostos.Rows.Count > 0 Then Dim Concepto As String = ConceptoPoliza Dim CvePrePoliza = ObjConta.AddPrePolizas("RA-01", 74, DtCostos.SUM("Total"), DtCostos.SUM("Total"), 1, TxtFecha.Text.ToDate, ConceptoPoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Dim tCveSubProyecto = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", $"CveAlmacen={CveAlmacen}").ToEntero If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, Not MovAlmacen, ValorInventario, Concepto, 68, Concepto, TxtFecha.Text.ToDate, IdCtaContable, -1, CveVenta:=CveVenta, CveMovimientoAlmacen:=CveMovimientoEntrada, ImporteMX:=ValorInventario, CveSubProyecto:=tCveSubProyecto, Contabilizable:=EsContabilizable) Then Retorno = False End If If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, MovAlmacen, ValorInventario, Concepto, 68, Concepto, TxtFecha.Text.ToDate, IdCtaContable, -1, CveVenta:=CveVenta, CveMovimientoAlmacen:=CveMovimientoSalida, ImporteMX:=ValorInventario, Contabilizable:=If(CveTipoCompra = 10, False, EsContabilizable)) Then Retorno = False End If If ObjConta.ValidacionPrePolizaCuadre(CvePrePoliza, 6) Then If ObjConta.ValorPolizaDescuadre > 0 Then GuardaLogAD($"Inventarios/RecepcionAlmacen-PPCompOC | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") Retorno = False End If End If 'CONTABILIZAR - SIMPLIFICAR If Retorno Then If UsuarioActual.Empresa.Funcionalidad(220) <> "" Then If Not ObjConta.PrePolizaSimplificacion(CvePrePoliza, UsuarioActual.CveEmpresa) Then Retorno = False End If End If If UsuarioActual.Empresa.Funcionalidad(200) = "1" Then If ObjContaContPAQ Is Nothing Then ObjContaContPAQ = New ClsContPAQi(UsuarioActual.Empresa) ObjContaContPAQ.IniciaTransacSQL() End If If Not ObjConta.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa, ObjConta:=ObjContaContPAQ) Then Retorno = False End If End If End If Else Retorno = False End If Else Retorno = False End If Catch ex As Exception OnError("Ocurrió un error al guadar la prepoliza", ex) Retorno = False End Try Return Retorno End Function Private Sub GuardaCompraOC() Dim CveMovimiento As Integer Dim CveMovimientoOriginal As Integer 'Dim CveMovimientoS Dim InvFolio As String = "" Dim FechaMovto As Date = TxtFecha.Text.ToDate Dim ErrorMovInv As Boolean Dim MensajeError = "" Dim ObjInventario As New ClsInventarios Dim ObjBitacora As New ClsOIEventos(ObjInventario.IniciaTransacSQL()) Dim ObjCompras As New ClsCompras(ObjInventario.IniciaTransacSQL()) Dim ObjConta As New ClsContabilidad(ObjInventario.IniciaTransacSQL()) Dim ObjOC As New ClsOC(ObjInventario.IniciaTransacSQL()) Dim ObjAcum As New ClsAcumuladores(ObjInventario.IniciaTransacSQL()) Dim ObjVentas As New ClsVentas(ObjInventario.IniciaTransacSQL()) Dim ObjContaAC As ClsContPAQi = Nothing Dim ObjContaContPAQ As ClsContPAQi = Nothing Dim MensajeOC As New StringBuilder 'ENTREGA DIRECTA Dim MovtosEntradaExA As New List(Of Integer) Dim FoliosEntradaExA As New List(Of Integer) Dim MovtosSalidaDirecta As New List(Of Integer) Dim FoliosSalidaDirecta As New List(Of Integer) 'APARTADOS Dim MovtosSalida As New List(Of Integer) Dim FoliosSalida As New List(Of Integer) Dim MovtosEntrada As New List(Of Integer) Dim FoliosEntrada As New List(Of Integer) 'VIRUAL Dim CveMovimientoVirtual As Integer = -1 Dim FolioVirtual As Integer = -1 'TRASPASO DEVOLUCION Dim CveMovimientoSalidaTraspaso As Integer = -1 Dim FolioSalidaTraspaso As String = "" 'CONTABILIDAD Dim CvePrePoliza = -1 Dim MensajeContabilidad = "" If UsuarioActual.Empresa.Funcionalidad(531) = "1" Then 'VALIDA SI SE VAN A RECIBIR TODOS LOS PRODUCTOS If ValidarRecepcionUsados Then For Each gvr As GridViewRow In GvInv.Rows If gvr.FCTextBox("TbCantidadF").Text.ToDecimal() <> gvr.DataKey("CantidadC").ToDecimal() Then ValidarRecepcionUsados = False Exit For End If Next End If End If Try 'RECARGA TC CUANDO ES RECEPCION CON OC Y DOLARES If CveOCSurtir > 0 And CveMoneda <> 1 Then TipoCambio = GlobalTipoCambio(TxtFecha.Text.ToDate).ToDecimal End If If HdnTipoDocto.Value <> "Fac" Then RecibidaCompleta = False Dim CveConceptoAlmacen As Integer = If(TipoMovimiento > 1, 13, 2) Dim CveAlmacen As Integer = DdlAlmacen.SelectedValue.ToEntero Dim CveModalidad As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=CveAlmacen).FiltroPrimeroValor("CveModalidad").ToEntero() Dim EsContabilizable As Boolean = (CveModalidad = 1) If RealizarTraspasoAlmacenDevolucion AndAlso TipoMovimiento = 2 Then CveConceptoAlmacen = 26 'For Each gvr As GridViewRow In GvInv.Rows ' If gvr.FCCheckBox("cbInv").Checked AndAlso gvr.FCTextBox("TbCantidadF").Text.ToDecimal > 0 Then ' Dim Row As DataRow = DtAlmacenesDevolucion.NewRow() ' Row("CveCompraDetalle") = gvr.DataKey("CveCompraDetalle").ToEntero() ' Row("CveAlmacenOriginal") = gvr.DataKey("CveAlmacenOriginal").ToEntero() ' DtAlmacenesDevolucion.Rows.Add(Row) ' End If 'Next Dim DtDetalle As New DataTable Dim DtDetalleLote As New DataTable Dim PU As Decimal = 0.0D Dim PUExtranjero As Decimal = 0.0D Dim CostoIndirecto As Decimal = 0.0D Dim SumaTotal As Decimal = 0.0D Dim Cont As Integer = 0 Dim CveMovtoSalidaActual = -1 Dim CveMovtoEntradaActual = -1 Dim CveVendedorActual = -1 Dim CveClienteActual = -1 Dim CveAlmacenDestino = CveAlmacenDevolucionProveedor Dim CveSeccionDestino As Integer = -1 'For Each RowAlmacen As DataRow In DtAlmacenesDevolucion.FiltraParametros("", DistinctColumns:={"CveAlmacenOrignal"}).Rows 'SALIDA DE ALMACEN POR TRASPASO CveMovimientoSalidaTraspaso = ObjInventario.AddMovimiento(CveAlmacen, CveConceptoAlmacen, 1, FechaMovto, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompraSurtir, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, TipoCambio:=If(DdlMonedaTC.SelectedValue.ToEntero = 1, -1, TipoCambio), MovimientoFijo:=If(TipoMovimiento = 2, True, False), CveAlmacenDestino:=CveAlmacenDestino, Remision:=TxtRemision.Text, Modulo:="RA/G11") If CveMovimientoSalidaTraspaso > 0 Then FolioSalidaTraspaso = ObjInventario.Folio.ToString() For Each gvr As GridViewRow In GvInv.Rows '.Cast(Of GridViewRow).Where(Function(row) row.DataKey("CveAlmacenOrignal") = RowAlmacen("CveAlmacenOrignal").ToString()) If gvr.FCCheckBox("cbInv").Checked AndAlso gvr.FCTextBox("TbCantidadF").Text.ToDecimal > 0 Then PU = DtInv.Rows(gvr.RowIndex)("PU").ToString.ToDecimal CostoIndirecto = DtInv.Rows(gvr.RowIndex)("CostoIndirecto").ToString.ToDecimal PUExtranjero = DtInv.Rows(gvr.RowIndex)("PUExtranjero").ToString.ToDecimal ' por redondeo If gvr.FCTextBox("TbCantidadF").Text.ToDouble = 1 Then PU = PU.RoundAD 'SI FUE POR SERIE LOTE DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", gvr.DataKey("Consec").ToEntero)) DtDetalleLote = DtDatosLoteDetalle.FiltraParametros(String.Format("ConsecId = {0}", gvr.DataKey("Consec").ToEntero)) If DtDetalle.Rows.Count > 0 Then Dim ContDt As Integer = 0 ' por redondeo If gvr.FCTextBox("TbCantidadF").Text.ToDouble = 1 Then PU = PU.RoundAD For Each Dr As DataRow In DtDetalle.Rows SumaTotal += PU + CostoIndirecto If RecibidaCompleta AndAlso Cont + 1 = GvInv.Rows.Count AndAlso ContDt + 1 = DtDetalle.Rows.Count AndAlso (TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)).RoundSQL <> SumaTotal Then If Not UsuarioActual.Empresa.Funcionalidad(531) = "1" Then PU = (TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)).RoundSQL - (SumaTotal - (PU)) End If End If If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalidaTraspaso, 1, gvr.DataKey("CveUM").ToEntero, gvr.DataKey("CvePS").ToEntero, PU, -1, PUTC:=If(DdlMonedaTC.SelectedValue.ToEntero = 1, -1, PUExtranjero), Serie:=Dr("Serie").ToString, CveCompraDetalle:=gvr.DataKey("CveCompraDetalle").ToEntero, CveOrdenCompraDetalle:=gvr.DataKey("CveOrdenCompraDetalle").ToEntero, CveVentaDetalle:=gvr.DataKey("CveVentaDetalle").ToEntero, CostoIndirecto:=CostoIndirecto, CveUsuarioModifico:=UsuarioActual.CveUsuario, FechaCaducidad:=If(CBool(gvr.DataKey("AplicaCaducidad")), gvr.FCTextBox("TxtCaducidad").Text.ToDate, MinFecha), Lote:=If(CBool(gvr.DataKey("AplicaLote")), gvr.FCTextBox("TxtLote").Text, ""), CveSeccionAlmacen:=If(CBool(gvr.DataKey("AplicaSeccion")), gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero, -1)) Then ErrorMovInv = True Exit For End If ContDt += 1 Next ElseIf DtDetalleLote.Rows.Count > 0 Then Dim ContDt As Integer = 0 ' por redondeo If gvr.FCTextBox("TbCantidadF").Text.ToDouble = 1 Then PU = PU.RoundSQL For Each Dr As DataRow In DtDetalleLote.Rows SumaTotal += Dr("Cantidad").ToString.ToDecimal * (PU + CostoIndirecto) If RecibidaCompleta AndAlso Cont + 1 = GvInv.Rows.Count AndAlso ContDt + 1 = DtDetalleLote.Rows.Count AndAlso (TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)).RoundSQL <> SumaTotal Then If Not UsuarioActual.Empresa.Funcionalidad(531) = "1" Then PU = ((TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)).RoundSQL - (SumaTotal - (Dr("Cantidad").ToString.ToDecimal * (PU)))) / Dr("Cantidad").ToString.ToDecimal End If End If If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalidaTraspaso, Dr("Cantidad").ToString.ToDouble, gvr.DataKey("CveUM").ToEntero, gvr.DataKey("CvePS").ToEntero, PU, -1, PUTC:=If(DdlMonedaTC.SelectedValue.ToEntero = 1, -1, PUExtranjero), Lote:=Dr("Lote").ToString, FechaCaducidad:=Dr("FechaCaducidad").ToString.ToDate, CveCompraDetalle:=gvr.DataKey("CveCompraDetalle").ToEntero, CveOrdenCompraDetalle:=gvr.DataKey("CveOrdenCompraDetalle").ToEntero, CveVentaDetalle:=gvr.DataKey("CveVentaDetalle").ToEntero, CostoIndirecto:=CostoIndirecto, CveUsuarioModifico:=UsuarioActual.CveUsuario, CveSeccionAlmacen:=If(CBool(gvr.DataKey("AplicaSeccion")), gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero, -1)) Then ErrorMovInv = True Exit For End If ContDt += 1 Next Else ' por redondeo If gvr.FCTextBox("TbCantidadF").Text.ToDouble = 1 Then PU = PU.RoundAD SumaTotal += gvr.FCTextBox("TbCantidadF").Text.ToDecimal * (PU + CostoIndirecto) ' considerar el costo indirecto para el ajuste If RecibidaCompleta AndAlso Cont + 1 = GvInv.Rows.Count AndAlso (TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)).RoundSQL <> SumaTotal.RoundSQL Then Dim tTotal As Decimal = gvr.FCTextBox("TbCantidadF").Text.ToDecimal * (PU) If Not UsuarioActual.Empresa.Funcionalidad(531) = "1" Then PU = ((TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)).RoundSQL - (SumaTotal - tTotal)) / gvr.FCTextBox("TbCantidadF").Text.ToDecimal End If End If If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalidaTraspaso, gvr.FCTextBox("TbCantidadF").Text.ToDouble, gvr.DataKey("CveUM").ToEntero, gvr.DataKey("CvePS").ToEntero, PU, -1, PUTC:=If(DdlMonedaTC.SelectedValue.ToEntero = 1, -1, PUExtranjero), CveCompraDetalle:=gvr.DataKey("CveCompraDetalle").ToEntero, CveOrdenCompraDetalle:=gvr.DataKey("CveOrdenCompraDetalle").ToEntero, CveVentaDetalle:=gvr.DataKey("CveVentaDetalle").ToEntero, CostoIndirecto:=CostoIndirecto, CveUsuarioModifico:=UsuarioActual.CveUsuario, FechaCaducidad:=If(CBool(gvr.DataKey("AplicaCaducidad")), gvr.FCTextBox("TxtCaducidad").Text.ToDate, MinFecha), Lote:=If(CBool(gvr.DataKey("AplicaLote")), gvr.FCTextBox("TxtLote").Text, ""), CveSeccionAlmacen:=If(CBool(gvr.DataKey("AplicaSeccion")), gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero, -1)) Then ErrorMovInv = True Exit For End If End If 'If ObjInventario.CveMovimientoDetalle > 0 AndAlso DtSeccionAlmacen.Rows.Count > 0 Then ' For Each Dr As DataRow In DtSeccionAlmacen.FiltraParametros($"IndexSeccionAlmacen = {gvr.RowIndex}").Rows ' If Not ObjInventario.AddMovimientosDetalleSeccionesAlmacen(ObjInventario.CveMovimientoDetalle, Dr("CveSeccionAlmacen").ToString.ToEntero, Dr("CantidadSeccionAlmacen").ToString.ToDecimal) Then ' ErrorMovInv = True ' Exit For ' End If ' Next 'End If Cont += 1 End If Next Else ErrorMovInv = True End If 'Next 'MODIFICA EL CONCEPTO PARA REALIZAR LA ENTRADA CveConceptoAlmacen = 27 CveAlmacen = CveAlmacenDevolucionProveedor End If 'ENTRADA ALMACÉN CveMovimiento = ObjInventario.AddMovimiento(CveAlmacen, CveConceptoAlmacen, 1, FechaMovto, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompraSurtir, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, TipoCambio:=If(DdlMonedaTC.SelectedValue.ToEntero = 1, -1, TipoCambio), MovimientoFijo:=If(TipoMovimiento = 2, True, False), CveMovimientoRelacionado:=CveMovimientoSalidaTraspaso, Remision:=TxtRemision.Text, Modulo:="RA/G1") If CveMovimiento > 0 Then CveMovimientoOriginal = CveMovimiento InvFolio = ObjInventario.Folio.ToString Dim DtDetalle As New DataTable Dim DtDetalleLote As New DataTable Dim PU As Decimal = 0.0D Dim PUExtranjero As Decimal = 0.0D Dim CostoIndirecto As Decimal = 0.0D Dim SumaTotal As Decimal = 0.0D Dim Cont As Integer = 0 Dim ListaOC As New List(Of DetalleOC) For Each gvr As GridViewRow In GvInv.Rows If gvr.FCCheckBox("cbInv").Checked AndAlso gvr.FCTextBox("TbCantidadF").Text.ToDecimal > 0 Then PU = DtInv.Rows(gvr.RowIndex)("PU").ToString.ToDecimal CostoIndirecto = DtInv.Rows(gvr.RowIndex)("CostoIndirecto").ToString.ToDecimal PUExtranjero = DtInv.Rows(gvr.RowIndex)("PUExtranjero").ToString.ToDecimal 'SI FUE POR SERIE LOTE DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", gvr.DataKey("Consec").ToEntero)) DtDetalleLote = DtDatosLoteDetalle.FiltraParametros(String.Format("ConsecId = {0}", gvr.DataKey("Consec").ToEntero)) If DtDetalle.Rows.Count > 0 Then Dim ContDt As Integer = 0 ' por redondeo PU = PU.RoundAD For Each Dr As DataRow In DtDetalle.Rows SumaTotal += PU.RoundAD + CostoIndirecto ' se redondea a dos decimales. por la unidad es uno If RecibidaCompleta AndAlso Cont + 1 = GvInv.Rows.Count AndAlso ContDt + 1 = DtDetalle.Rows.Count AndAlso (TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)).RoundSQL <> SumaTotal Then If Not UsuarioActual.Empresa.Funcionalidad(531) = "1" Then PU = (TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)).RoundSQL - (SumaTotal - (PU)) End If End If If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, 1, gvr.DataKey("CveUM").ToEntero, gvr.DataKey("CvePS").ToEntero, PU, -1, PUTC:=If(DdlMonedaTC.SelectedValue.ToEntero = 1, -1, PUExtranjero), Serie:=Dr("Serie").ToString, CveCompraDetalle:=gvr.DataKey("CveCompraDetalle").ToEntero, CveOrdenCompraDetalle:=gvr.DataKey("CveOrdenCompraDetalle").ToEntero, CveVentaDetalle:=gvr.DataKey("CveVentaDetalle").ToEntero, CostoIndirecto:=CostoIndirecto, CveUsuarioModifico:=UsuarioActual.CveUsuario, FechaCaducidad:=If(CBool(gvr.DataKey("AplicaCaducidad")), gvr.FCTextBox("TxtCaducidad").Text.ToDate, MinFecha), Lote:=If(CBool(gvr.DataKey("AplicaLote")), gvr.FCTextBox("TxtLote").Text, ""), CveSeccionAlmacen:=If(CBool(gvr.DataKey("AplicaSeccion")), gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero, -1)) Then ErrorMovInv = True Exit For End If ContDt += 1 Next ElseIf DtDetalleLote.Rows.Count > 0 Then Dim ContDt As Integer = 0 ' por redondeo If gvr.FCTextBox("TbCantidadF").Text.ToDouble = 1 Then PU = PU.RoundSQL For Each Dr As DataRow In DtDetalleLote.Rows SumaTotal += Dr("Cantidad").ToString.ToDecimal * (PU + CostoIndirecto) If RecibidaCompleta AndAlso Cont + 1 = GvInv.Rows.Count AndAlso ContDt + 1 = DtDetalleLote.Rows.Count AndAlso (TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)).RoundSQL <> SumaTotal Then If Not UsuarioActual.Empresa.Funcionalidad(531) = "1" Then PU = ((TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)).RoundSQL - (SumaTotal - (Dr("Cantidad").ToString.ToDecimal * (PU)))) / Dr("Cantidad").ToString.ToDecimal End If End If If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, Dr("Cantidad").ToString.ToDouble, gvr.DataKey("CveUM").ToEntero, gvr.DataKey("CvePS").ToEntero, PU, -1, PUTC:=If(DdlMonedaTC.SelectedValue.ToEntero = 1, -1, PUExtranjero), Lote:=Dr("Lote").ToString, FechaCaducidad:=Dr("FechaCaducidad").ToString.ToDate, CveCompraDetalle:=gvr.DataKey("CveCompraDetalle").ToEntero, CveOrdenCompraDetalle:=gvr.DataKey("CveOrdenCompraDetalle").ToEntero, CveVentaDetalle:=gvr.DataKey("CveVentaDetalle").ToEntero, CostoIndirecto:=CostoIndirecto, CveUsuarioModifico:=UsuarioActual.CveUsuario, CveSeccionAlmacen:=If(CBool(gvr.DataKey("AplicaSeccion")), gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero, -1)) Then ErrorMovInv = True Exit For End If ContDt += 1 Next Else ' por redondeo If gvr.FCTextBox("TbCantidadF").Text.ToDouble = 1 Then PU = PU.RoundSQL SumaTotal += gvr.FCTextBox("TbCantidadF").Text.ToDecimal * (PU + CostoIndirecto) ' considerar el costo indirecto para el ajuste If RecibidaCompleta AndAlso Cont + 1 = GvInv.Rows.Count AndAlso (TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)).RoundSQL <> SumaTotal.RoundSQL Then Dim tTotal As Decimal = gvr.FCTextBox("TbCantidadF").Text.ToDecimal * (PU) If Not UsuarioActual.Empresa.Funcionalidad(531) = "1" Then PU = ((TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)).RoundSQL - (SumaTotal - tTotal)) / gvr.FCTextBox("TbCantidadF").Text.ToDecimal End If End If If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, gvr.FCTextBox("TbCantidadF").Text.ToDouble, gvr.DataKey("CveUM").ToEntero, gvr.DataKey("CvePS").ToEntero, PU, -1, PUTC:=If(DdlMonedaTC.SelectedValue.ToEntero = 1, -1, PUExtranjero), CveCompraDetalle:=gvr.DataKey("CveCompraDetalle").ToEntero, CveOrdenCompraDetalle:=gvr.DataKey("CveOrdenCompraDetalle").ToEntero, CveVentaDetalle:=gvr.DataKey("CveVentaDetalle").ToEntero, CostoIndirecto:=CostoIndirecto, CveUsuarioModifico:=UsuarioActual.CveUsuario, FechaCaducidad:=If(CBool(gvr.DataKey("AplicaCaducidad")), gvr.FCTextBox("TxtCaducidad").Text.ToDate, MinFecha), Lote:=If(CBool(gvr.DataKey("AplicaLote")), gvr.FCTextBox("TxtLote").Text, ""), CveSeccionAlmacen:=If(CBool(gvr.DataKey("AplicaSeccion")), gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero, -1)) Then ErrorMovInv = True Exit For End If End If Cont += 1 End If If DdlTipo.SelectedValue = "2" Then ListaOC.Add(New DetalleOC With {.CveOCDetalle = gvr.DataKey("CveOrdenCompraDetalle").ToEntero, .Cantidad = gvr.FCTextBox("TbCantidadF").Text.ToDecimal, .CantidadOC = gvr.DataKey("CantidadF").ToDecimal, .PS = gvr.DataKey("PS")}) End If Next '' SI ES ENTRADA POR OC. VERIFICA QUE SE RECIBA LA TOTALIDAD POR PARTIDA. SINO SE DIVIDE 'si es entrada por oc, se verifican las cantidades, si la cantidad recibida es menor, se ajusta la cantidad en la OC. y se genera una nueva partida con la diferencia If DdlTipo.SelectedValue = "2" Then 'se actualiza ListaOC Dim resultsOC = ListaOC.GroupBy( Function(row) row.CveOCDetalle) _ .Select(Function(group) New With { .CveOCDetalle = group.Key, .CantidadOC = group.Sum(Function(row) row.CantidadOC), .Cantidad = group.Sum(Function(row) row.Cantidad), .PS = group.Max(Function(row) row.PS), .Data = group }) 'comentado para subir versión, dividirOC 'For Each oc In resultsOC ' If oc.Cantidad < oc.CantidadOC Then ' MensajeOC.AppendFormat("- {0}
", oc.PS) ' If Not ObjOC.UpdateOrdenCompraDetalleDivideCantidad(CveOCSurtir, oc.CveOCDetalle, oc.Cantidad, UsuarioActual.CveUsuario) Then ' ErrorMovInv = True ' End If ' End If 'Next End If Else ErrorMovInv = True End If ''VALIDACIÓN DE IMPORTES INGRESADOS VS LA COMPRA U OC If Not UsuarioActual.Empresa.Funcionalidad(531) = "1" Then If Not ErrorMovInv AndAlso RecibidaCompleta AndAlso ObjInventario.GetMovimientosDetalle(CveMovimientoOriginal, UsuarioActual.CveEmpresa) Then Dim dtt As DataTable = ObjInventario.DtResultados Dim tTotalInsertado As Decimal = dtt.SUMD("TotalOriginal") If CveTipoCompra = 8 Then 'entrada almacen con costo indirecto cargado en la misma compra tTotalInsertado = dtt.SUMD("Total") ' está incluido el costo indirecto en la factura End If If (TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)).RoundSQL <> tTotalInsertado.RoundSQL Then ErrorMovInv = True Alert("La Entrada no coincide con el valor del documento.." & (TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)) & " -" & tTotalInsertado, TipoMensaje.MsgError) GuardaLog("La Entrada no coincide con el valor del documento.." & (TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)) & " -" & tTotalInsertado) End If End If End If Dim ImporteIngresoAdicional As Decimal = 0 'SI RECEPCION VALIDA [ENTREGADIRECTA, APARTADOS, AC] If TipoMovimiento = 1 Then 'ENTREGA DIRECTA If EntregaDirecta Then If Not ErrorMovInv Then Dim Dt As DataTable = Nothing If ObjInventario.GetMovimientosDetalle(CveMovimiento, UsuarioActual.CveEmpresa) Then If ObjInventario.DtResultados.Rows.Count > 0 Then Dt = ObjInventario.DtResultados End If End If 'GENERA UN MOVIMIENTO POR CADA VENTA For Each DrVenta As DataRow In Dt.FiltraParametros("", DistinctColumns:={"CveVenta"}).Rows Dim CveMovtoSalidaDirecta As Integer = -1 Dim FolioSalidaDirecta As Integer = -1 Dim CveVenta As Integer = DrVenta("CveVenta").ToString().ToEntero() Dim ObjFactura As New Modelos.Factura(UsuarioActual, CveVenta, UsuarioActual.CveEmpresa) Dim DtDetalleMovimiento As DataTable = Dt.FiltraParametros($"CveVenta={ObjFactura.CveVenta}") If ObjFactura.TipoDocto = "Ing" Then Dim MovSalida = GenerarMovimientoAlmacenVenta(DdlAlmacen.SelectedValue.ToEntero(), 3, ObjFactura.CveVenta, CveMovimiento, DtDetalleMovimiento, ObjInventario, ObjConta, ObjContaContPAQ, EsContabilizable, "RA/G2") ErrorMovInv = MovSalida.CveMovimiento <= 0 If Not ErrorMovInv Then MovtosSalidaDirecta.Add(MovSalida.CveMovimiento) FoliosSalidaDirecta.Add(MovSalida.Folio) End If ElseIf ObjFactura.TipoDocto = "Rem" Then Dim MovSalidaExA = GenerarMovimientoAlmacenVenta(DdlAlmacen.SelectedValue.ToEntero(), 8, ObjFactura.CveVenta, -1, DtDetalleMovimiento, ObjInventario, ObjConta, ObjContaContPAQ, False, "RA/G2R1") ErrorMovInv = MovSalidaExA.CveMovimiento <= 0 If Not ErrorMovInv Then MovtosSalidaDirecta.Add(MovSalidaExA.CveMovimiento) FoliosSalidaDirecta.Add(MovSalidaExA.Folio) Dim dttexa As DataTable = DtDetalleMovimiento.Copy 'se limpia la seccion, para que lo tome automaticamente For Each drr As DataRow In dttexa.Rows drr("CveSeccionAlmacen") = -3 Next Dim MovEntradaExA = GenerarMovimientoAlmacenVenta(ObjFactura.CveAlmacenTraspasoDestino, 9, ObjFactura.CveVenta, MovSalidaExA.CveMovimiento, dttexa, ObjInventario, ObjConta, ObjContaContPAQ, False, "RA/G2R2") ErrorMovInv = MovEntradaExA.CveMovimiento <= 0 If Not ErrorMovInv Then MovtosEntradaExA.Add(MovEntradaExA.CveMovimiento) FoliosEntradaExA.Add(MovEntradaExA.Folio) 'SI LA REMISION FUE FACTURADA GENERA EL MOVIMIENTO DE SALIDA DIRECTA If ObjFactura.DtRemisionesDocumentosRelacionados.Rows.Count > 0 Then If ObjVentas.VerificarRemisionFacturada(ObjFactura.CveVenta) Then Dim dttsalida As DataTable = dttexa.Copy 'se limpia la seccion, para que lo tome automaticamente For Each drr As DataRow In dttsalida.Rows Dim RowFactura As DataRow = ObjVentas.DtResultados.FiltroPrimero($"CveVentaDetalleRemision={drr("CveVentaDetalle")}") drr("CveVentaDetalle") = RowFactura("CveVentaDetalleFacturada") drr("CveVenta") = RowFactura("CveVenta") Next For Each DrFactura As DataRow In Dt.FiltraParametros("", DistinctColumns:={"CveVenta"}).Rows Dim dtSalidaFactura As DataTable = dttsalida.FiltraParametros($"CveVenta={DrFactura("CveVenta")}") Dim MovSalidaDirectaExA = GenerarMovimientoAlmacenVenta(ObjFactura.CveAlmacenTraspasoDestino, 40, DrFactura("CveVenta").ToString().ToEntero(), MovEntradaExA.CveMovimiento, dtSalidaFactura, ObjInventario, ObjConta, ObjContaContPAQ, False, "RA/G2R3") ErrorMovInv = MovSalidaDirectaExA.CveMovimiento <= 0 If ErrorMovInv Then Exit For Else MovtosSalidaDirecta.Add(MovSalidaDirectaExA.CveMovimiento) FoliosSalidaDirecta.Add(MovSalidaDirectaExA.Folio) End If Next End If End If End If End If End If Next If Not ErrorMovInv Then If Not ObjInventario.LimpiaEntregaDirecta(CveMovimiento) Then ErrorMovInv = True End If End If End If End If 'APARTADOS If Apartado Then If ObjInventario.GetMovimientosDetalleVendedor(CveMovimiento) Then Dim CveMovtoSalidaActual = -1 Dim CveMovtoEntradaActual = -1 Dim CveVendedorActual = -1 Dim CveClienteActual = -1 Dim CveAlmacenDestino = CveAlmacenApartado Dim CveSeccionDestino As Integer = -1 For Each Dr As DataRow In ObjInventario.DtResultados.Rows If CveVendedorActual = -1 Or (Dr("CveVendedor").ToString.ToEntero <> CveVendedorActual Or Dr("CveCliente").ToString.ToEntero <> CveClienteActual) Then CveMovtoSalidaActual = ObjInventario.AddMovimiento(DdlAlmacen.SelectedValue.ToEntero, 8, 1, FechaMovto, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompraSurtir, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, TipoCambio:=If(DdlMonedaTC.SelectedValue.ToEntero = 1, -1, TipoCambio), CveAlmacenDestino:=CveAlmacenDestino, MovimientoFijo:=True, CveVendedor:=Dr("CveVendedor").ToString.ToEntero, CveCliente:=Dr("CveCliente").ToString.ToEntero, Remision:=TxtRemision.Text, Modulo:="RA/G3") MovtosSalida.Add(CveMovtoSalidaActual) FoliosSalida.Add(ObjInventario.Folio) CveMovtoEntradaActual = ObjInventario.AddMovimiento(CveAlmacenDestino, 9, 1, FechaMovto, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompraSurtir, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, TipoCambio:=If(DdlMonedaTC.SelectedValue.ToEntero = 1, -1, TipoCambio), CveAlmacenDestino:=CveAlmacenDestino, CveMovimientoRelacionado:=CveMovtoSalidaActual, CveVendedor:=Dr("CveVendedor").ToString.ToEntero, CveCliente:=Dr("CveCliente").ToString.ToEntero, Remision:=TxtRemision.Text, Modulo:="RA/G7") MovtosEntrada.Add(CveMovtoEntradaActual) FoliosEntrada.Add(ObjInventario.Folio) CveVendedorActual = Dr("CveVendedor").ToString.ToEntero CveClienteActual = Dr("CveCliente").ToString.ToEntero End If If CveMovtoSalidaActual <= 0 Or CveMovtoEntradaActual <= 0 Then ErrorMovInv = True Exit For End If If Not ObjInventario.AddMovimientoDetalle(CveMovtoSalidaActual, Dr("Cantidad").ToString.ToDouble, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, Dr("PU").ToString.ToDecimal, CveAF:=Dr("CveAF").ToString.ToEntero, CveSeccionAlmacen:=Dr("CveSeccionAlmacen").ToString.ToEntero, Serie:=Dr("Serie").ToString, Lote:=Dr("Lote").ToString, FechaCaducidad:=Dr("FechaCaducidad").ToString.ToDate, CveVentaDetalle:=Dr("CveVentaDetalle").ToString.ToEntero, CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString.ToEntero, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then ErrorMovInv = True Exit For End If CveSeccionDestino = -3 'se madna este dato, para que el trigger, obtenga la seccion automaticamente If Not ObjInventario.AddMovimientoDetalle(CveMovtoEntradaActual, Dr("Cantidad").ToString.ToDouble, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, Dr("PU").ToString.ToDecimal, CveAF:=Dr("CveAF").ToString.ToEntero, CveSeccionAlmacen:=CveSeccionDestino, Serie:=Dr("Serie").ToString, Lote:=Dr("Lote").ToString, FechaCaducidad:=Dr("FechaCaducidad").ToString.ToDate, CveVentaDetalle:=Dr("CveVentaDetalle").ToString.ToEntero, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then ErrorMovInv = True Exit For End If Next If Not ErrorMovInv Then 'registra la prepóliza en el traspaso If Not GeneraPrePolizaMovimientoAlmacen(CveMovtoEntradaActual, CveMovtoSalidaActual, ObjInventario, ObjConta, ObjContaContPAQ, False) Then ErrorMovInv = True End If End If End If End If 'VIRTUAL If RealizarMovimientoVirtual 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 Dim CveAlmacenVirtual As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=tCveAlmacen).FiltroPrimeroValor("CveAlmacenVirtual").ToEntero() 'VERIFICA SI TIENE ALMACEN VIRTUAL If CveAlmacenVirtual > 0 Then ValidarRecepcionUsados = RecibidaCompleta If ObjInventario.GetMovimientosDetalleVirtual(CveMovimiento, UsuarioActual.CveEmpresa, CveCompra:=CveCompraSurtir, ValidaUsadosCompra:=ValidarRecepcionUsados) Then 'ValidarRecepcionUsados DtPSVirtual = ObjInventario.DtResultados End If If DtPSVirtual IsNot Nothing AndAlso DtPSVirtual.Rows.Count > 0 Then Dim CveTipoAlmacenFiltro As Integer = If(CveTipoCompra = 9, 25, 24) CveMovimientoVirtual = ObjInventario.AddMovimiento(CveAlmacenVirtual, If(TipoMovimiento > 1, 37, 36), 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompraSurtir, -1, -1, -1, CveMovimientoRelacionado:=CveMovimiento, Observaciones:=TxtObservaciones.Text.Trim, Modulo:="RA/G4") FolioVirtual = ObjInventario.Folio 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, -1, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then ErrorMovInv = True Exit For End If Next If SumarImporteUsados Then If ObjInventario.GetMovimientosDetalle(CveMovimientoVirtual, UsuarioActual.CveEmpresa) Then ImporteIngresoAdicional = ObjInventario.DtResultados.SUMD("TotalOriginal") End If End If Dim tConcepto As String = String.Format("Entrada Virtual {0}", HLFolio.Text) Dim tReferencia As String = HLFolio.Text Dim tCvePrePoliza = ObjConta.AddPrePolizas("Inv_RAlmVirtual", 74, 0, 0, 1, TxtFecha.Text.ToDate, tConcepto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If tCvePrePoliza > 0 Then If ObjConta.AddPrePolizasDetalle(tCvePrePoliza, True, ImporteIngresoAdicional, tReferencia, 205, tConcepto, TxtFecha.Text.ToDate, 0, -1, CveCompra:=CveCompraSurtir, CveMovimientoAlmacen:=CveMovimientoVirtual, ImporteMX:=ImporteIngresoAdicional) Then If Not ObjConta.AddPrePolizasDetalle(tCvePrePoliza, False, ImporteIngresoAdicional, tReferencia, 68, tConcepto, TxtFecha.Text.ToDate, 0, -1, CveCompra:=CveCompraSurtir, CveMovimientoAlmacen:=CveMovimientoVirtual, ImporteMX:=ImporteIngresoAdicional) Then ErrorMovInv = True End If Else ErrorMovInv = True End If Else ErrorMovInv = True End If Else ErrorMovInv = True End If End If End If 'DEVENGAR AC If Not ErrorMovInv AndAlso UsuarioActual.Empresa.UsaAC AndAlso EsContabilizable Then Dim IDPoliza As Integer Dim TotalDetalle As Decimal = 0 Dim TotalPorDevengar = 0.0 TotalPorDevengar += GvInv.Rows.Cast(Of GridViewRow)().Sum(Function(Gvr) Math.Round(Gvr.DataKey("PU").ToString.ToDecimal, 4) * Math.Round(Gvr.DataKey("CantidadF").ToString.ToDecimal, 4)) TotalPorDevengar = Math.Round(TotalPorDevengar, 4) If ObjContaAC Is Nothing Then ObjContaAC = New ClsContPAQi(UsuarioActual.Empresa) ObjContaAC.IniciaTransacSQL() End If IDPoliza = ObjContaAC.AddPoliza(4, "Devengado", TotalPorDevengar * 2, TotalPorDevengar * 2, UsuarioActual.CveUsuario, FechaMovto) If IDPoliza > 0 AndAlso ObjContaAC.GetCuentas(-1, "-1", -1) Then DtCuentas = ObjContaAC.DtResultados.Copy Dim drRegistroMatriz As DataRow Dim CuentaCargo As Integer Dim CuentaAbono As Integer Dim Importe As Decimal = 0 For Each gvr As GridViewRow In GvInv.Rows Importe = gvr.FCTextBox("TbCantidadF").Text.ToDecimal * gvr.DataKey("PU").ToString.ToDecimal TotalDetalle += Importe If Importe > 0 Then If ObjContaAC.AddMovimiento(IDPoliza, 1, False, Importe, "", "", 0, FechaMovto, "") Then 'actualizo el idcuenta del presupuesto If Not ObjContaAC.AddMovimiento(IDPoliza, gvr.DataKey("IdCuentaComprometido").ToString.ToEntero, True, Importe, "", "", 0, FechaMovto, "") Then ErrorMovInv = True Exit For End If Else ErrorMovInv = True Exit For End If 'AFECTAR MATRIZ EGRESOS drRegistroMatriz = GlobalDTAC_MatrizEgresos.FiltroPrimero(String.Format("Partida = {0} And TipoGasto = {1}", gvr.DataKey("CodigoClasificacion").ToString, gvr.DataKey("CveTipoGasto").ToString)) If drRegistroMatriz IsNot Nothing AndAlso drRegistroMatriz("CuentaCargo").ToString.ToEntero > 0 Then CuentaCargo = DtCuentas.FiltroPrimeroValor("Id", String.Format("Codigo = '{0}'", drRegistroMatriz("CuentaCargo").ToString)).ToEntero CuentaAbono = DtCuentas.FiltroPrimeroValor("Id", String.Format("Codigo = '{0}'", drRegistroMatriz("CuentaAbono").ToString)).ToEntero If CuentaCargo > 0 AndAlso CuentaAbono > 0 Then If ObjContaAC.AddMovimiento(IDPoliza, CuentaCargo, False, Importe, "", "", 0, FechaMovto, "") Then If Not ObjContaAC.AddMovimiento(IDPoliza, CuentaAbono, True, Importe, "", "", 0, FechaMovto, "") Then ErrorMovInv = True Exit For End If Else ErrorMovInv = True Exit For End If Else ErrorMovInv = True Exit For End If End If 'TERMINA AFECTAR MATRIZ INGRESOS End If Next If TotalDetalle <= 0 AndAlso TotalPorDevengar >= TotalDetalle Then ErrorMovInv = True End If Else ErrorMovInv = True End If If ErrorMovInv Then Alert("Error al registrar los movimientos Contables", TipoMensaje.MsgError) RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") End If End If 'TERMINA: DEVENGAR Else 'VIRTUAL If CveTipoCompra = 9 And RealizarMovimientoVirtual Then Dim DtPSVirtual As New DataTable("DtTamanios") 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 DtComprasDetalle As DataTable = Nothing Dim DtTamanios As DataTable = Nothing If ObjCompras.GetCompraDetalle(CveCompraSurtir) Then DtComprasDetalle = ObjCompras.DtResultados.Copy() End If If ObjAcum.TamañoGet(-1, UsuarioActual.CveEmpresa) Then DtTamanios = ObjAcum.DtResultados.Copy() End If For Each GvRow As GridViewRow In GvInv.Rows If GvRow.RowType = DataControlRowType.DataRow Then For Each Tam As DataRow In DtTamanios.Rows If Tam("CveTamaño").ToString() = GvRow.DataKey("CveTamaño") Then Dim CvePSCargo = Tam("CvePSCargo").ToString().ToEntero() Dim RowCompraDetalle = DtComprasDetalle.FiltroPrimero($"CvePS = {CvePSCargo}") If RowCompraDetalle IsNot Nothing Then Dim Row As DataRow = DtPSVirtual.NewRow() Row("CvePS") = CvePSCargo Row("Cantidad") = GvRow.FCTextBox("TbCantidadF").Text.ToDecimal() Row("PU") = RowCompraDetalle("PU").ToString().ToDecimal() Row("CveUM") = GvRow.DataKey("CveUM").ToEntero() DtPSVirtual.Rows.Add(Row) End If End If Next End If Next If DtPSVirtual IsNot Nothing AndAlso DtPSVirtual.Rows.Count > 0 Then 'Dim CveSubProyecto As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", $"CveAlmacen= {DdlAlmacen.SelectedValue}").ToEntero() Dim CveAlmacenVirtual As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=CveAlmacen).FiltroPrimeroValor("CveAlmacenVirtual").ToEntero() CveMovimientoVirtual = ObjInventario.AddMovimiento(CveAlmacenVirtual, If(TipoMovimiento > 1, 37, 36), 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompraSurtir, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, Modulo:="RA/G5") FolioVirtual = ObjInventario.Folio 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("PU").ToString().ToDecimal() Dim CveUM As Integer = RowUsado("CveUM").ToString().ToEntero() If Not ObjInventario.AddMovimientoDetalle(CveMovimientoVirtual, CantidadUsado, CveUM, CvePS, PU, -1, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then ErrorMovInv = True Exit For End If Next End If If SumarImporteUsados Then If ObjInventario.GetMovimientosDetalle(CveMovimientoVirtual, UsuarioActual.CveEmpresa) Then ImporteIngresoAdicional = ObjInventario.DtResultados.SUMD("TotalOriginal") End If End If Else If RealizarMovimientoVirtual Then Dim DtPSVirtual As New DataTable("DtTamanios") Dim CveMovimientoRef As Integer = -1 If RealizarTraspasoAlmacenDevolucion Then CveMovimientoRef = CveMovimientoSalidaTraspaso Else CveMovimientoRef = CveMovimiento End If If ObjInventario.GetMovimientosDetalleVirtual(CveMovimientoRef, UsuarioActual.CveEmpresa, CveCompra:=CveCompraSurtir, ValidaUsadosCompra:=ValidarRecepcionUsados) Then DtPSVirtual = ObjInventario.DtResultados End If If DtPSVirtual IsNot Nothing AndAlso DtPSVirtual.Rows.Count > 0 Then Dim CveTipoAlmacenFiltro As Integer = 24 Dim CveAlmacenVirtual As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=DdlAlmacen.SelectedValue.ToEntero()).FiltroPrimeroValor("CveAlmacenVirtual").ToEntero() CveMovimientoVirtual = ObjInventario.AddMovimiento(CveAlmacenVirtual, 13, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCompraSurtir, -1, -1, -1, CveMovimientoRelacionado:=CveMovimientoRef, Observaciones:=TxtObservaciones.Text.Trim, Modulo:="RA/VD") If CveMovimientoVirtual > 0 Then FolioVirtual = ObjInventario.Folio 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, -1, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then ErrorMovInv = True Exit For End If Next If SumarImporteUsados Then If ObjInventario.GetMovimientosDetalle(CveMovimientoVirtual, UsuarioActual.CveEmpresa) Then ImporteIngresoAdicional = ObjInventario.DtResultados.SUMD("TotalOriginal") End If End If Else ErrorMovInv = True End If Else ErrorMovInv = True End If End If End If End If ''VALIDACIÓN DE IMPORTES INGRESADOS VS LA COMPRA U OC 'If Not UsuarioActual.Empresa.Funcionalidad(531) = "1" Then If Not ErrorMovInv AndAlso RecibidaCompleta AndAlso UsuarioActual.CveEmpresa <> 140 Then If ObjInventario.GetMovimientosDetalle(CveMovimientoOriginal, UsuarioActual.CveEmpresa) Then Dim dtt As DataTable = ObjInventario.DtResultados Dim tTotalInsertado As Decimal = dtt.SUMD("TotalOriginal") + ImporteIngresoAdicional If CveTipoCompra = 8 Then 'entrada almacen con costo indirecto cargado en la misma compra tTotalInsertado = dtt.SUMD("Total") + ImporteIngresoAdicional ' está incluido el costo indirecto en la factura End If If (TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)).RoundSQL <> tTotalInsertado.RoundSQL Then ErrorMovInv = True Alert("La Entrada no coincide con el valor del documento." & (TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)).RoundSQL & " -" & tTotalInsertado.RoundSQL.ToString, TipoMensaje.MsgError) GuardaLog("La Entrada no coincide con el valor del documento." & (TotalCompraOC * If(TipoCambio > 1, TipoCambio, 1)).RoundSQL & " -" & tTotalInsertado.RoundSQL.ToString) End If Else ErrorMovInv = True End If End If ' End If 'ACTUALIZA ESTATUS ALMACEN If TipoMovimiento = 2 Then If Not ObjCompras.UpdateEstatusAlmacen(CveCompraSurtir, 0, UsuarioActual.CveUsuario) Then ErrorMovInv = True End If End If 'VERIFICA SI TIENE PENDIENTE POR SURTIR If UsuarioActual.CveEmpresa = 140 AndAlso TipoMovimiento = 3 Then If ObjInventario.RecepcionAlmacenGet(CveCompraSurtir, -1, -1, UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then Dim DtFaltante As DataTable = ObjInventario.DtResultados.FiltraParametros("CantidadF > 0") If DtFaltante.Rows.Count = 0 Then If Not ObjCompras.UpdateEstatusAlmacen(CveCompraSurtir, 2, UsuarioActual.CveUsuario) Then ErrorMovInv = True End If End If DtFaltante.Dispose() End If End If 'AGREGA BITACORA TEMPORAL If DtBitacora IsNot Nothing AndAlso DtBitacora.Rows.Count > 0 Then ErrorMovInv = GuardaBitacoraTemporal(ObjBitacora, CveMovimiento) End If 'PREPOLIZA - SOLO CUANDO SEA RECEPCIÓN If TipoMovimiento = 1 AndAlso Not ErrorMovInv Then If ObjInventario.GetMovimientosDetalle(CveMovimiento, UsuarioActual.CveEmpresa) Then Dim DtCostos As DataTable = Nothing Dim ValorInventario As Decimal = 0 DtCostos = ObjInventario.DtResultados Dim TotalCosto As Decimal = DtCostos.SUMD("Total").RoundSQL Dim TotalCostoExtranjero As Decimal = DtCostos.SUMD("TotalExtranjero") 'VARIABLES Dim IdCtaContableAlmacen As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", $"CveAlmacen = {DdlAlmacen.SelectedValue}").ToEntero ' Dim CveCuentaAlmacen As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContableSIG", $"CveAlmacen = {DdlAlmacen.SelectedValue}").ToEntero Dim IdCtaContableRecepcion = -1 Dim IdCtaContableRecepcionME = -1 Dim IdCtaContableRecepcionComplementaria = -1 Dim Fecha As Date = Now Dim CveProveedor As Integer = -1 Dim ProveedorNombre As String = "" Dim SerieFolio As String = "" Dim CveConceptoContableCosto = -1 Dim CveConceptoContableCostoME = -1 Dim CveConceptoContableCostoComplementaria = -1 Dim UsaComplementariaFleteImportaciones As Boolean = False If UsuarioActual.CveEmpresa = 119 Then UsaComplementariaFleteImportaciones = False If DtCostos.Rows.Count > 0 Then If CveCompraSurtir > 0 Then If ObjCompras.GetCompras(CveCompraSurtir, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then 'Fecha = ObjCompras.DtResultados(0)("Fecha").ToString.ToDate Fecha = TxtFecha.Text.ToDate CveProveedor = ObjCompras.DtResultados(0)("CveProveedor").ToString.ToEntero ProveedorNombre = ObjCompras.DtResultados(0)("RazonSocial").ToString SerieFolio = $"Compra: {ObjCompras.DtResultados(0)("SerieFolio").ToString}" CveConceptoContableCosto = 205 CveConceptoContableCostoME = 230 CveConceptoContableCostoComplementaria = 231 If ObjConta.GetRetCuenta(205, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then IdCtaContableRecepcion = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero End If If UsaComplementariaFleteImportaciones AndAlso ObjConta.GetRetCuenta(230, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then IdCtaContableRecepcionME = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero End If If UsaComplementariaFleteImportaciones AndAlso ObjConta.GetRetCuenta(231, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then IdCtaContableRecepcionComplementaria = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero End If Else ErrorMovInv = True End If ElseIf CveOCSurtir > 0 Then If ObjOC.GetOC(CveOCSurtir, UsuarioActual.CveEmpresa) Then 'Fecha = ObjOC.DtResultados(0)("Fecha").ToString.ToDate Fecha = TxtFecha.Text.ToDate CveProveedor = ObjOC.DtResultados(0)("CveProveedor").ToString.ToEntero ProveedorNombre = ObjOC.DtResultados(0)("RazonSocial").ToString SerieFolio = String.Format("{0} OC# {1} - Almacén# {2}", ProveedorNombre, ObjOC.DtResultados(0)("Folio"), ObjInventario.Folio) CveConceptoContableCosto = 176 CveConceptoContableCostoME = 228 CveConceptoContableCostoComplementaria = 229 If UsuarioActual.CveEmpresa = 119 Then UsaComplementariaFleteImportaciones = True If UsaComplementariaFleteImportaciones AndAlso ObjConta.GetRetCuenta(176, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then IdCtaContableRecepcion = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero End If If UsaComplementariaFleteImportaciones AndAlso ObjConta.GetRetCuenta(228, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then IdCtaContableRecepcionME = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero End If If UsaComplementariaFleteImportaciones AndAlso ObjConta.GetRetCuenta(229, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then IdCtaContableRecepcionComplementaria = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero End If Else ErrorMovInv = True End If End If If Not ErrorMovInv Then Dim CveSubProyecto As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", $"CveAlmacen= {DdlAlmacen.SelectedValue}").ToEntero CvePrePoliza = ObjConta.AddPrePolizas("Inventario/RecepcionAlmacen", 74, TotalCosto, TotalCosto, 1, Fecha, ProveedorNombre, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If CvePrePoliza > 0 Then If ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, TotalCosto, SerieFolio, 68, SerieFolio, Fecha, IdCtaContableAlmacen, -1, CveCompra:=CveCompraSurtir, CveSubProyecto:=CveSubProyecto, CveOC:=CveOCSurtir, CveProveedor:=CveProveedor, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=TotalCosto, Contabilizable:=If(CveTipoCompra = 10, False, EsContabilizable)) Then 'AGREGA POR CONCEPTO POR CVEOCDETALLE If CveOCSurtir > 0 Then Dim TotalCostoDetalle As Decimal = 0 Dim TotalCostoAcumulado As Decimal = 0 Dim cont As Integer = 1 For Each Dr As DataRow In DtCostos.Rows TotalCostoDetalle = (Dr("Total").ToString.ToDecimal) TotalCostoExtranjero = Dr("TotalExtranjero").ToString.ToDecimal TotalCostoAcumulado += TotalCostoDetalle.RoundSQL 'si es el último movimiento verifica los importes que sean igual If cont = DtCostos.Rows.Count AndAlso (TotalCosto.RoundSQL <> TotalCostoAcumulado.RoundSQL) Then TotalCostoDetalle = TotalCostoDetalle + (TotalCosto.RoundSQL(3) - TotalCostoAcumulado.RoundSQL(3)) TotalCostoExtranjero = TotalCostoExtranjero + (TotalCosto.RoundSQL(3) - TotalCostoAcumulado.RoundSQL(3)) End If If CveMoneda <> 1 AndAlso UsaComplementariaFleteImportaciones Then 'COMPLEMENTARIA If ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TotalCostoExtranjero, SerieFolio, CveConceptoContableCostoME, SerieFolio, Fecha, IdCtaContableRecepcionME, -1, CveCompra:=CveCompraSurtir, CveOC:=CveOCSurtir, CveSubProyecto:=CveSubProyecto, CveProveedor:=CveProveedor, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=TotalCostoExtranjero, ImporteME:=TotalCostoExtranjero, TipoCambio:=TipoCambio, CveOCDetalle:=Dr("CveOrdenCompraDetalle").ToString.ToEntero, Contabilizable:=EsContabilizable) Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TotalCostoDetalle - TotalCostoExtranjero, SerieFolio, CveConceptoContableCostoComplementaria, SerieFolio, Fecha, IdCtaContableRecepcionComplementaria, -1, CveCompra:=CveCompraSurtir, CveOC:=CveOCSurtir, CveProveedor:=CveProveedor, CveSubProyecto:=CveSubProyecto, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=TotalCostoDetalle - TotalCostoExtranjero, ImporteME:=TotalCostoExtranjero, TipoCambio:=TipoCambio, CveOCDetalle:=Dr("CveOrdenCompraDetalle").ToString.ToEntero, Contabilizable:=EsContabilizable) Then ErrorMovInv = True Exit For End If Else ErrorMovInv = True Exit For End If Else If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TotalCostoDetalle, SerieFolio, CveConceptoContableCosto, SerieFolio, Fecha, IdCtaContableRecepcion, -1, CveCompra:=CveCompraSurtir, CveOC:=CveOCSurtir, CveSubProyecto:=CveSubProyecto, CveProveedor:=CveProveedor, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=TotalCostoDetalle, CveCuenta:=-1, CveOCDetalle:=Dr("CveOrdenCompraDetalle").ToString.ToEntero) Then ErrorMovInv = True Exit For End If End If cont = cont + 1 Next Else TotalCosto = DtCostos.SUMD("Total").RoundSQL TotalCostoExtranjero = DtCostos.SUMD("TotalExtranjero") If CveMoneda <> 1 AndAlso UsaComplementariaFleteImportaciones Then 'COMPLEMENTARIA If ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TotalCostoExtranjero, SerieFolio, CveConceptoContableCostoME, SerieFolio, Fecha, IdCtaContableRecepcionME, -1, CveCompra:=CveCompraSurtir, CveOC:=CveOCSurtir, CveProveedor:=CveProveedor, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=TotalCostoExtranjero, ImporteME:=TotalCostoExtranjero, TipoCambio:=TipoCambio, Contabilizable:=EsContabilizable) Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TotalCosto - TotalCostoExtranjero, SerieFolio, CveConceptoContableCostoComplementaria, SerieFolio, Fecha, IdCtaContableRecepcionComplementaria, -1, CveCompra:=CveCompraSurtir, CveOC:=CveOCSurtir, CveProveedor:=CveProveedor, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=TotalCosto - TotalCostoExtranjero, ImporteME:=TotalCostoExtranjero, TipoCambio:=TipoCambio, Contabilizable:=EsContabilizable) Then ErrorMovInv = True End If Else ErrorMovInv = True End If Else If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, TotalCosto, SerieFolio, CveConceptoContableCosto, SerieFolio, Fecha, IdCtaContableRecepcion, -1, CveCompra:=CveCompraSurtir, CveOC:=CveOCSurtir, CveProveedor:=CveProveedor, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=TotalCosto, CveCuenta:=-1, Contabilizable:=EsContabilizable) Then ErrorMovInv = True End If End If End If Else ErrorMovInv = True End If Else ErrorMovInv = True End If End If If ObjConta.ValidacionPrePolizaCuadre(CvePrePoliza, -1) Then If ObjConta.ValorPolizaDescuadre > 0 Then GuardaLogAD($"Inventarios/RecepcionAlmacen-PPCompOC | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") MensajeError = "El Movimiento presenta una diferencia en el registro." ErrorMovInv = True End If End If 'CONTABILIZAR - UNIFICAR Y SIMPLIFICAR CON PP DE LA COMPRA If Not ErrorMovInv Then If CvePrePolizaCompra > 0 Then If UsuarioActual.Empresa.Funcionalidad(219) = "1" Then If Not ObjConta.PrePolizaUnificacion(CvePrePoliza, CvePrePolizaCompra) Then ErrorMovInv = True MensajeError = "Error al unificar los conceptos contables" End If End If End If If UsuarioActual.Empresa.Funcionalidad(220) <> "" Then If Not ObjConta.PrePolizaSimplificacion(CvePrePoliza, UsuarioActual.CveEmpresa) Then ErrorMovInv = True MensajeError = "Error al simplificar los conceptos contables" End If End If If UsuarioActual.Empresa.Funcionalidad(200) = "1" Then If ObjContaContPAQ Is Nothing Then ObjContaContPAQ = New ClsContPAQi(UsuarioActual.Empresa) ObjContaContPAQ.IniciaTransacSQL() End If If ObjConta.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa, ObjConta:=ObjContaContPAQ) Then MensajeContabilidad = $"
Movimiento contabilizado en el folio: {ObjConta.ContaFolio}
" Else ErrorMovInv = True MensajeError = "Error al contabilizar los conceptos contables" End If End If End If End If Else ErrorMovInv = True MensajeError = "Error al obtener movimientos" End If End If 'PREPOLIZA - NC If TipoMovimiento = 3 AndAlso Not ErrorMovInv Then If ObjInventario.GetMovimientosDetalle(CveMovimiento, UsuarioActual.CveEmpresa) Then Dim DtCostos As DataTable = Nothing DtCostos = ObjInventario.DtResultados Dim TotalCosto As Decimal = DtCostos.SUMD("Total").RoundSQL Dim TotalNC As Decimal = 0 Dim CveClasificacionDifCostoNC = -1 Dim tTipoCambio As Decimal = 1 If CveMoneda <> 1 Then tTipoCambio = TipoCambio For Each gvr As GridViewRow In GvInv.Rows TotalNC += gvr.FCTextBox("TbCantidadF").Text.ToDecimal * gvr.DataKey("PU").ToDecimal * tTipoCambio CveClasificacionDifCostoNC = gvr.DataKey("CveClasificacion").ToEntero Next Dim IdCtaContableClasificacion As Integer = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaCostos", $"CveClasificacion = {CveClasificacionDifCostoNC}").ToEntero Dim CveCuentaClasificacion As Integer = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaCostosSIG", $"CveClasificacion = {CveClasificacionDifCostoNC}").ToEntero TotalNC = TotalNC.RoundSQL Dim DifCostoNC As Decimal = (TotalCosto - TotalNC).RoundSQL 'VARIABLES 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 Fecha As Date = TxtFecha.Text.ToDate Dim CveProveedor As Integer = -1 Dim ProveedorNombre As String = "" Dim SerieFolio As String = "" Dim IdCtaContableNC = 0 Dim CveConceptoContableNC = -1 If DtCostos.Rows.Count > 0 Then If CveCompraSurtir > 0 Then If ObjCompras.GetCompras(CveCompraSurtir, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then CveProveedor = ObjCompras.DtResultados(0)("CveProveedor").ToString.ToEntero ProveedorNombre = ObjCompras.DtResultados(0)("RazonSocial").ToString SerieFolio = $"NC: {ObjCompras.DtResultados(0)("SerieFolio").ToString}" CveConceptoContableNC = 225 If ObjConta.GetRetCuenta(CveConceptoContableNC, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then IdCtaContableNC = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero End If Else ErrorMovInv = True End If End If Dim CveSubProyecto As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", $"CveAlmacen= {DdlAlmacen.SelectedValue}").ToEntero() If Not ErrorMovInv Then CvePrePoliza = ObjConta.AddPrePolizas("Inventario/RecepcionAlmacen-NC", 74, TotalCosto, TotalCosto, 1, Fecha, ProveedorNombre, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If CvePrePoliza > 0 Then If ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, TotalNC, SerieFolio, CveConceptoContableNC, SerieFolio, Fecha, IdCtaContableNC, -1, CveCompra:=CveCompraSurtir, CveProveedor:=CveProveedor, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=TotalNC, Contabilizable:=EsContabilizable) Then If ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, TotalCosto * -1, SerieFolio, 68, SerieFolio, Fecha, IdCtaContableAlmacen, -1, CveCompra:=CveCompraSurtir, CveProveedor:=CveProveedor, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=TotalCosto * -1, Contabilizable:=If(CveTipoCompra = 10, False, EsContabilizable)) Then If DifCostoNC <> 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, DifCostoNC * -1, SerieFolio, 69, SerieFolio, Fecha, IdCtaContableClasificacion, -1, CveClasificacion:=CveClasificacionDifCostoNC, CveCompra:=CveCompraSurtir, CveProveedor:=CveProveedor, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=DifCostoNC * -1, CveCuenta:=CveCuentaClasificacion, Contabilizable:=EsContabilizable, CveSubProyecto:=CveSubProyecto) Then ErrorMovInv = True End If End If Else ErrorMovInv = True End If Else ErrorMovInv = True End If Else ErrorMovInv = True End If End If If ObjConta.ValidacionPrePolizaCuadre(CvePrePoliza, -1) Then If ObjConta.ValorPolizaDescuadre > 0 Then GuardaLogAD($"Inventarios/RecepcionAlmacen-PPNC | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") ErrorMovInv = True End If End If 'CONTABILIZAR - UNIFICAR Y SIMPLIFICAR CON PP DE LA COMPRA If Not ErrorMovInv Then If CvePrePolizaCompra > 0 Then If UsuarioActual.Empresa.Funcionalidad(219) = "1" Then If Not ObjConta.PrePolizaUnificacion(CvePrePoliza, CvePrePolizaCompra) Then ErrorMovInv = True MensajeError = "Error al unificar los conceptos contables" End If End If End If If UsuarioActual.Empresa.Funcionalidad(220) <> "" Then If Not ObjConta.PrePolizaSimplificacion(CvePrePoliza, UsuarioActual.CveEmpresa) Then ErrorMovInv = True MensajeError = "Error al simplificar los conceptos contables" End If End If If UsuarioActual.Empresa.Funcionalidad(200) = "1" Then ObjContaContPAQ = New ClsContPAQi(UsuarioActual.Empresa) ObjContaContPAQ.IniciaTransacSQL() If ObjConta.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa, ObjConta:=ObjContaContPAQ) Then MensajeContabilidad = $"
Movimiento contabilizado en el folio: {ObjConta.ContaFolio}
" Else ErrorMovInv = True MensajeError = "Error al contabilizar los conceptos contables" End If End If End If End If Else ErrorMovInv = True MensajeError = "Error al obtener movimientos" End If End If If Not ErrorMovInv AndAlso TipoMovimiento = 2 AndAlso CveMovimientoSalidaTraspaso > 0 Then 'VARIABLES Dim Fecha As Date = Now Dim CveProveedor As Integer = -1 Dim ProveedorNombre As String = "" Dim SerieFolio As String = "" 'Dim DrAlmO, DrAlmD As DataRow 'Dim CveSucursalOrigen, CveSucursalDestino As Integer 'Dim TipoAlmacenOrigen, TipoAlmacenDestino As Integer 'Dim CveSubProyectoOrigen, CveSubProyectoDestino As Integer Dim IdCtaContableOrigen, IdCtaContableDestino As Integer If ObjCompras.GetCompras(CveCompraSurtir, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then 'Fecha = ObjCompras.DtResultados(0)("Fecha").ToString.ToDate Fecha = TxtFecha.Text.ToDate CveProveedor = ObjCompras.DtResultados(0)("CveProveedor").ToString.ToEntero ProveedorNombre = ObjCompras.DtResultados(0)("RazonSocial").ToString SerieFolio = $"Compra: {ObjCompras.DtResultados(0)("SerieFolio").ToString}" Else ErrorMovInv = True End If 'DrAlmO = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=DdlAlmacen.SelectedValue.ToEntero).FiltroPrimero("") 'DrAlmD = GlobalDTAlmacen(UsuarioActual.CveEmpresa, CveAlmacen:=CveAlmacenDevolucionProveedor).FiltroPrimero("") 'If Not ErrorMovInv AndAlso DrAlmO IsNot Nothing AndAlso DrAlmD IsNot Nothing Then ' CveSucursalOrigen = DrAlmO("CveSubProyecto").ToString.ToEntero ' TipoAlmacenOrigen = DrAlmO("CveTipoAlmacen").ToString.ToEntero ' CveSubProyectoOrigen = DrAlmO("CveSubProyecto").ToString.ToEntero ' IdCtaContableOrigen = DrAlmO("IdCtaContable").ToString.ToEntero ' CveSucursalDestino = DrAlmD("CveSubProyecto").ToString.ToEntero ' TipoAlmacenDestino = DrAlmD("CveTipoAlmacen").ToString.ToEntero ' CveSubProyectoDestino = DrAlmD("CveSubProyecto").ToString.ToEntero ' IdCtaContableDestino = DrAlmO("IdCtaContable").ToString.ToEntero 'Else ' ErrorMovInv = True 'End If Dim resultado As DataTable = Nothing If ObjInventario.GetMovimientosDetalle(CveMovimientoSalidaTraspaso, UsuarioActual.CveEmpresa) Then resultado = ObjInventario.DtResultados.Copy() Else ErrorMovInv = True End If 'Dim CveSubProyecto As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", $"CveAlmacen= {CveAlmacenDevolucionProveedor}").ToEntero() 'AGREGAMOS PREPOLIZAS TRASPASO DIRECTO: Dim CvePrePolizaTraspaso As Integer = ObjConta.AddPrePolizas("RecepcionAlmacen/TraspasoAlmacen", 53, 0, 0, 1, Now, ProveedorNombre, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) If CvePrePolizaTraspaso > 0 AndAlso ObjInventario.GetMovimientosDetalle(CveMovimientoSalidaTraspaso, UsuarioActual.CveEmpresa) Then Dim importe As Decimal = resultado.SUMD("Total").RoundSQL If Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, True, importe, TxtObservaciones.Text, 68, TxtObservaciones.Text, Fecha, IdCtaContableOrigen, -1, CveMovimientoAlmacen:=CveMovimientoSalidaTraspaso, Contabilizable:=False, ImporteMX:=importe) Then ErrorMovInv = True End If If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePolizaTraspaso, False, importe, TxtObservaciones.Text, 68, TxtObservaciones.Text, Fecha, IdCtaContableDestino, -1, CveMovimientoAlmacen:=CveMovimiento, Contabilizable:=False, ImporteMX:=importe) Then ErrorMovInv = True End If Else ErrorMovInv = True End If End If 'AGREGA SALDOS A OC SURTIDAS If Not ErrorMovInv And CveOCSurtir > 0 Then If ObjInventario.GetMovimientosDetalle(CveMovimiento, UsuarioActual.CveEmpresa) Then For Each Dr As DataRow In ObjInventario.DtResultados.Rows If Not ObjOC.OrdenesCompraDetalleSaldosInvCompraAdd(Dr("CveOrdenCompraDetalle").ToString.ToEntero, Dr("CveMovimientoDetalle").ToString.ToEntero, Dr("Cantidad").ToString.ToDecimal, -1, -1) Then ErrorMovInv = True Exit For End If Next Else ErrorMovInv = True End If End If 'DOCUMENTOS RELACIONADOS AL MOVIMIENTO If Not ErrorMovInv AndAlso UsuarioActual.Empresa.Funcionalidad(594) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(314) Then If Not ErrorMovInv AndAlso Not GuardaDocumentoBitacora(ObjBitacora, CveMovimiento) Then ErrorMovInv = True Alert("Ocurrió un error al guardar los datos adjuntos de la bitácora", TipoMensaje.MsgError) End If End If Catch ex As Exception OnError("Ocurrió un error al guardar RA.", ex) ErrorMovInv = True End Try 'FINAL If Not ErrorMovInv Then ObjInventario.Commit() ' aplica los movimientos insertados If ObjContaAC IsNot Nothing Then ObjContaAC.Commit() If ObjContaContPAQ IsNot Nothing Then ObjContaContPAQ.Commit() RegistraScript("playsonidito('beep-07.wav')") ' 'ENVIO DE CORREO NOTIFICACION A VENDEDORES DE OC MandaCorreoOCVendedores(CveCompraSurtir, CveMovimiento) Dim Msg As New StringBuilder Dim link As String = String.Format("{1}", CveMovimiento, InvFolio) 'SI LO SOLO GENERO EL MOVIMIENTO DE ENTRADA O SALIDA If CveMovimiento > 0 AndAlso CveMovimientoSalidaTraspaso <= 0 Then Msg.AppendFormat("Movimiento Registrado: Folio: {0}", link) Msg.AppendFormat("
Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimiento))) If MensajeOC.Length > 0 Then Msg.AppendFormat("
La Orden de Compra se dividió en los siguientes productos:
{0}", MensajeOC) End If If UsuarioActual.CveEmpresa.Contiene(1, 119) Then Msg.AppendFormat("
Imprimir Etiqueta Individual ", Encripta(String.Format("OP=Etiqueta&CveMovimiento={0}&Modalidad={1}", CveMovimiento, "Individual"))) 'Msg.AppendFormat("
Imprimir Etiqueta Por Caja ", Encripta(String.Format("OP=Etiqueta&CveMovimiento={0}&Modalidad={1}", CveMovimiento, "Caja"))) End If 'SI GENERO UN TRASPASO AL ALMACEN DE DEVOLUCION ElseIf CveMovimiento > 0 AndAlso CveMovimientoSalidaTraspaso > 0 Then Msg.AppendFormat("Movimiento de Salida: Folio: {0}", String.Format("{1}", CveMovimientoSalidaTraspaso, FolioSalidaTraspaso)) Msg.AppendFormat("
Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoSalidaTraspaso))) Msg.AppendFormat("

Movimiento de control: Folio: {0}", link) Msg.AppendFormat("
Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimiento))) End If 'If CveMovtoSalidaDirecta > 0 Then ' Msg.AppendFormat("

Movimientos de control:
") ' link = String.Format("{1}", CveMovtoSalidaDirecta, FolioSalidaDirecta) ' Msg.AppendFormat("Movimiento de Salida Folio: {0}", link) 'End If 'ENTREGA DIRECTA If MovtosSalidaDirecta.Count > 0 Then Msg.AppendFormat("

Movimientos de control:
") If MovtosEntradaExA.Count > 0 Then For index = 0 To MovtosEntradaExA.Count - 1 link = String.Format("{1}", MovtosEntradaExA(index), FoliosEntradaExA(index)) Msg.AppendFormat("
Movimiento de Entrada Folio: {0}", link) Next End If For index = 0 To MovtosSalidaDirecta.Count - 1 link = String.Format("{1}", MovtosSalidaDirecta(index), FoliosSalidaDirecta(index)) Msg.AppendFormat("
Movimiento de Salida Folio: {0}", link) Next End If 'APARTADO If MovtosSalida.Count > 0 Then Msg.AppendFormat("

Movimientos de control:
") For index = 0 To MovtosSalida.Count - 1 link = String.Format("{1}", MovtosSalida(index), FoliosSalida(index)) Msg.AppendFormat("
Movimiento de Salida por Traspaso: Folio: {0}", link) link = String.Format("{1}", MovtosEntrada(index), FoliosEntrada(index)) Msg.AppendFormat("
Movimiento de Entrada por Traspaso: Folio: {0}
", link) Next End If 'VIRTUAL If CveMovimientoVirtual > 0 Then link = String.Format("{1}", CveMovimientoVirtual, FolioVirtual) Msg.AppendFormat("
Movimiento de Entrada al Almacen Virtual: Folio: {0}", link) Msg.AppendFormat("
Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoVirtual))) End If 'CONTABILIDAD Msg.Append(MensajeContabilidad) Alert(Msg.ToString, TipoMensaje.MsgInformacion) If ObjInventario.RecepcionAlmacenGet(CveCompraSurtir, -1, -1, UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario) Then CreaDTInv(ObjInventario.DtResultados) CargaGVInv() BtnGuardar.Visible = True End If Limpia() Else ObjInventario.RollBack() If ObjContaAC IsNot Nothing Then ObjContaAC.RollBack() If ObjContaContPAQ IsNot Nothing Then ObjContaContPAQ.RollBack() RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") Alert($"Ocurrió un error al guardar el movimiento de almacén. Por favor vuelva a intentar.

{MensajeError}", TipoMensaje.MsgError) End If ObjInventario.Dispose() If ObjContaAC IsNot Nothing Then ObjContaAC.Dispose() If ObjContaContPAQ IsNot Nothing Then ObjContaContPAQ.Dispose() End Sub Private Function GenerarMovimientoAlmacenVenta(CveAlmacen As Integer, CveConceptoAlmacen As Integer, CveVenta As Integer, CveMovimientoRelacionado As Integer, DtDetalle As DataTable, ObjInventario As ClsInventarios, ObjConta As ClsContabilidad, ObjContaContPAQ As ClsContPAQi, EsContabilizable As Boolean, Modulo As String) As MMovimientoAlmacen Dim ErrorMovInv As Boolean = False Dim Retorno As New MMovimientoAlmacen Dim CveMovtoSalidaDirecta As Integer = -1 Dim FolioSalidaDirecta As Integer = -1 CveMovtoSalidaDirecta = ObjInventario.AddMovimiento(CveAlmacen, CveConceptoAlmacen, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, CveVenta, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, TipoCambio:=If(DdlMonedaTC.SelectedValue.ToEntero = 1, -1, TipoCambio), MovimientoFijo:=True, CveMovimientoRelacionado:=CveMovimientoRelacionado, Remision:=TxtRemision.Text, CveVendedor:=CveVendedor, CveCliente:=CveCliente, Modulo:=Modulo) FolioSalidaDirecta = ObjInventario.Folio If Not CveMovtoSalidaDirecta > 0 Then ErrorMovInv = True End If If Not ErrorMovInv AndAlso DtDetalle IsNot Nothing Then For Each Dr As DataRow In DtDetalle.Rows If Not ObjInventario.AddMovimientoDetalle(CveMovtoSalidaDirecta, Dr("Cantidad").ToString.ToDouble, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, Dr("PU").ToString.ToDecimal, CveAF:=Dr("CveAF").ToString.ToEntero, CveSeccionAlmacen:=Dr("CveSeccionAlmacen").ToString.ToEntero, Serie:=Dr("Serie").ToString, Lote:=Dr("Lote").ToString, FechaCaducidad:=Dr("FechaCaducidad").ToString.ToDate, CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString.ToEntero, CveVentaDetalle:=Dr("CveVentaDetalle").ToString.ToEntero, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then ErrorMovInv = True Exit For End If Next End If If Not ErrorMovInv AndAlso CveConceptoAlmacen = 3 Then If Not GeneraPrePolizaSalidaEntregaDirecta(CveMovtoSalidaDirecta, ObjInventario, ObjConta, ObjContaContPAQ, EsContabilizable) Then ErrorMovInv = True End If End If If Not ErrorMovInv Then Retorno.CveMovimiento = CveMovtoSalidaDirecta Retorno.Folio = FolioSalidaDirecta End If Return Retorno End Function Private Sub GuardaImportacionFlete() Dim CveMovimiento As Integer Dim InvFolio As String = "" Dim FechaMovto As Date = TxtFecha.Text.ToDate Dim ErrorMovInv As Boolean Dim MensajeError = "" Dim ObjInventario As New ClsInventarios Dim ObjBitacora As New ClsOIEventos(ObjInventario.IniciaTransacSQL()) Dim ObjCompras As New ClsCompras(ObjInventario.IniciaTransacSQL()) Dim ObjConta As New ClsContabilidad(ObjInventario.IniciaTransacSQL()) Dim ObjOC As New ClsOC(ObjInventario.IniciaTransacSQL()) Dim ObjContaAC As ClsContPAQi = Nothing 'ENTRADA ALMACÉN CveMovimiento = ObjInventario.AddMovimiento(DdlAlmacen.SelectedValue.ToEntero, 2, 1, FechaMovto, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveImportacionCompra, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, TipoCambio:=-1, Remision:=TxtRemision.Text, Modulo:="RA/G6") If CveMovimiento > 0 Then InvFolio = ObjInventario.Folio.ToString Dim DtDetalle As New DataTable Dim DtDetalleLote As New DataTable Dim PU As Decimal = 0 Dim CostoIndirecto As Decimal = 0 Dim PUExtranjero As Decimal = 0 For Each gvr As GridViewRow In GvInv.Rows If gvr.FCCheckBox("cbInv").Checked AndAlso gvr.FCTextBox("TbCantidadF").Text.ToDecimal > 0 Then PU = DtInv.Rows(gvr.RowIndex)("PU").ToString.ToDecimal CostoIndirecto = DtInv.Rows(gvr.RowIndex)("CostoIndirecto").ToString.ToDecimal PUExtranjero = DtInv.Rows(gvr.RowIndex)("PUExtranjero").ToString.ToDecimal 'SI FUE POR SERIE LOTE DtDetalle = DtDatosDetalle.FiltraParametros(String.Format("ConsecId = {0}", gvr.DataKey("Consec").ToEntero)) DtDetalleLote = DtDatosLoteDetalle.FiltraParametros(String.Format("ConsecId = {0}", gvr.DataKey("Consec").ToEntero)) If DtDetalle.Rows.Count > 0 Then For Each Dr As DataRow In DtDetalle.Rows If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, 1, gvr.DataKey("CveUM").ToEntero, gvr.DataKey("CvePS").ToEntero, PU, -1, PUTC:=If(DdlMonedaTC.SelectedValue.ToEntero = 1, -1, PUExtranjero), Serie:=Dr("Serie").ToString, CveCompraDetalle:=gvr.DataKey("CveCompraDetalle").ToEntero, CveOrdenCompraDetalle:=gvr.DataKey("CveOrdenCompraDetalle").ToEntero, CveVentaDetalle:=gvr.DataKey("CveVentaDetalle").ToEntero, CostoIndirecto:=CostoIndirecto, FechaCaducidad:=If(CBool(gvr.DataKey("AplicaCaducidad")), gvr.FCTextBox("TxtCaducidad").Text.ToDate, MinFecha), Lote:=If(CBool(gvr.DataKey("AplicaLote")), gvr.FCTextBox("TxtLote").Text, ""), CveSeccionAlmacen:=If(CBool(gvr.DataKey("AplicaSeccion")), gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero, -1)) Then ErrorMovInv = True Exit For End If Next ElseIf DtDetalleLote.Rows.Count > 0 Then For Each Dr As DataRow In DtDetalleLote.Rows If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, Dr("Cantidad").ToString.ToDouble, gvr.DataKey("CveUM").ToEntero, gvr.DataKey("CvePS").ToEntero, PU, -1, PUTC:=If(DdlMonedaTC.SelectedValue.ToEntero = 1, -1, PUExtranjero), Lote:=Dr("Lote").ToString, FechaCaducidad:=Dr("FechaCaducidad").ToString.ToDate, CveCompraDetalle:=gvr.DataKey("CveCompraDetalle").ToEntero, CveOrdenCompraDetalle:=gvr.DataKey("CveOrdenCompraDetalle").ToEntero, CveVentaDetalle:=gvr.DataKey("CveVentaDetalle").ToEntero, CostoIndirecto:=CostoIndirecto, CveSeccionAlmacen:=If(CBool(gvr.DataKey("AplicaSeccion")), gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero, -1)) Then ErrorMovInv = True Exit For End If Next Else If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, gvr.FCTextBox("TbCantidadF").Text.ToDouble, gvr.DataKey("CveUM").ToEntero, gvr.DataKey("CvePS").ToEntero, PU, -1, PUTC:=If(DdlMonedaTC.SelectedValue.ToEntero = 1, -1, PUExtranjero), CveCompraDetalle:=gvr.DataKey("CveCompraDetalle").ToEntero, CveOrdenCompraDetalle:=gvr.DataKey("CveOrdenCompraDetalle").ToEntero, CveVentaDetalle:=gvr.DataKey("CveVentaDetalle").ToEntero, CostoIndirecto:=CostoIndirecto, FechaCaducidad:=If(CBool(gvr.DataKey("AplicaCaducidad")), gvr.FCTextBox("TxtCaducidad").Text.ToDate, MinFecha), Lote:=If(CBool(gvr.DataKey("AplicaLote")), gvr.FCTextBox("TxtLote").Text, ""), CveSeccionAlmacen:=If(CBool(gvr.DataKey("AplicaSeccion")), gvr.FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero, -1)) Then ErrorMovInv = True Exit For End If End If End If Next Else ErrorMovInv = True End If 'AGREGA BITACORA TEMPORAL If DtBitacora IsNot Nothing AndAlso DtBitacora.Rows.Count > 0 Then ErrorMovInv = GuardaBitacoraTemporal(ObjBitacora, CveMovimiento) End If Dim CvePrePoliza As Integer = 0 Dim UsaComplementariaCostoIndirecto As Boolean = False Dim ConceptoPrePoliza As String = String.Format("{0}-{1}", LbProveedor.Text, HLFolio.Text) If UsuarioActual.CveEmpresa = 119 Then UsaComplementariaCostoIndirecto = False Dim PorcentajeCompraImportacion As Decimal = 0 ' si hay mas de una factura de importación saber lo que se está recibiendo 'SE REGISTRAN LAS PREPOLIZAS If Not ErrorMovInv Then CvePrePoliza = ObjConta.AddPrePolizas("Inventario/RecepcionAlmacen CostoInd", 74, 0, 0, 1, FechaMovto, ConceptoPrePoliza, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Dim DtTempCompras As DataTable = Nothing PorcentajeCompraImportacion = 1 If CveFleteSurtir > 0 Then If ObjInventario.GetFleteDetalle(CveFleteSurtir) Then DtTempCompras = ObjInventario.DtResultados ' faltaría agregar la factura de producto, If ObjCompras.GetCompras(CveFleteCompra, "-1", "-1", -1, -1, UsuarioActual.CveEmpresa) Then Dim drc As DataRow = DtTempCompras.NewRow Dim drr As DataRow = ObjCompras.DtResultados.FiltroPrimero("") If drr IsNot Nothing Then drc("CveCompra") = CveFleteCompra drc("SubTotal") = drr("SubTotal") drc("TipoCambio") = drr("TipoCambio") drc("CveProveedor") = drr("CveProveedor") drc("SubTotalTC") = drr("SubTotalTC") DtTempCompras.Rows.Add(drc) End If End If Else ErrorMovInv = True End If Else If CveImportacionSurtir > 0 Then If ObjCompras.GetImportacionesDetalle(CveImportacionSurtir, -1) Then DtTempCompras = ObjCompras.DtResultados Dim CveCompraImportacion As Integer = -1 If (DdlFactura.SelectedValue.ToEntero > 0) Then CveCompraImportacion = DdlFactura.SelectedValue.ToEntero If ObjCompras.GetImportacionCompras(CveImportacionSurtir, CveCompraImportacion) Then For Each drt As DataRow In ObjCompras.DtResultados.Rows PorcentajeCompraImportacion = If(CveCompraImportacion > 0, drt("PorcentajeCompra").ToString.ToDecimal, 1) Dim drc As DataRow = DtTempCompras.NewRow drc("CveCompra") = drt("CveCompra") drc("SubTotal") = drt("SubTotal") drc("TipoCambio") = drt("TipoCambio") drc("CveProveedor") = drt("CveProveedor") drc("SubTotalTC") = drt("SubTotalTC") DtTempCompras.Rows.Add(drc) Next End If Else ErrorMovInv = True End If End If End If If CvePrePoliza > 0 Then Dim IdCtaContableAlmacen As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", $"CveAlmacen = {DdlAlmacen.SelectedValue}").ToEntero ObjInventario.GetMovimientosDetalle(CveMovimiento, UsuarioActual.CveEmpresa) Dim TotalCosto As Decimal = ObjInventario.DtResultados.SUMD("Total").RoundSQL() Dim IdCtaContableCostoInd As Integer = 0 'si reciben parcialidades de producto. en base al total de la importacion y lo recibido. Dim PorcentajeRecepcionCompras As Decimal = TotalCosto / DtTempCompras.SUMD("SubTotalTC") Dim ConceptoPartida As String = String.Format("{0}- Inv#{1}", HLFolio.Text, InvFolio) If ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, TotalCosto, InvFolio, 68, InvFolio, FechaMovto, IdCtaContableAlmacen, -1, CveCompra:=CveCompraSurtir, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=TotalCosto, Contabilizable:=If(CveTipoCompra = 10, False, True)) Then 'se recorren las facturas a descontar el recepción If DtTempCompras IsNot Nothing AndAlso DtTempCompras.Rows.Count > 0 Then For Each dr As DataRow In DtTempCompras.Rows Dim CveComp As Integer = dr("CveCompra").ToString.ToEntero 'el porcentaje solo aplica a las facturas de costo indirecto Dim SubTotalPartida As Decimal = dr("SubTotal").ToString.ToDecimal * If(dr("TipoCompra").ToString = "CI", PorcentajeCompraImportacion, 1) * PorcentajeRecepcionCompras Dim ImporteAbono As Decimal = (SubTotalPartida * dr("TipoCambio").ToString.ToDecimal).RoundSQL Dim ImporteAbonoME As Decimal = 0 Dim CveConceptoCostoIndirecto As Integer = If(CveImportacionSurtir > 0, 240, 237) If ObjConta.GetRetCuenta(CveConceptoCostoIndirecto, UsuarioActual.CveEmpresa) AndAlso ObjConta.DtResultados.Rows.Count > 0 Then IdCtaContableCostoInd = ObjConta.DtResultados.FiltroPrimeroValor("IdCtaContable").ToEntero End If If UsaComplementariaCostoIndirecto Then CveConceptoCostoIndirecto = If(CveImportacionSurtir > 0, 241, 238) ImporteAbono = SubTotalPartida ImporteAbonoME = (SubTotalPartida * dr("TipoCambio").ToString.ToDecimal) - SubTotalPartida End If If ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImporteAbono, ConceptoPartida, CveConceptoCostoIndirecto, ConceptoPartida, FechaMovto, IdCtaContableCostoInd, -1, CveCompra:=CveComp, CveProveedor:=dr("CveProveedor").ToString.ToEntero, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=ImporteAbono) Then ' si tiene valor es que hay complementaria If ImporteAbonoME > 0 Then If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, ImporteAbono, ConceptoPartida, If(CveImportacionSurtir > 0, 242, 239), ConceptoPartida, FechaMovto, IdCtaContableCostoInd, -1, CveCompra:=CveComp, CveProveedor:=dr("CveProveedor").ToString.ToEntero, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=ImporteAbono) Then ErrorMovInv = True End If End If Else ErrorMovInv = True End If Next End If End If 'DOCUMENTOS RELACIONADOS AL MOVIMIENTO If Not ErrorMovInv AndAlso UsuarioActual.Empresa.Funcionalidad(594) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(314) Then If Not ErrorMovInv AndAlso Not GuardaDocumentoBitacora(ObjBitacora, CveMovimiento) Then ErrorMovInv = True Alert("Ocurrió un error al guardar los datos adjuntos de la bitácora", TipoMensaje.MsgError) End If End If Else ErrorMovInv = True End If End If If ObjConta.ValidacionPrePolizaCuadre(CvePrePoliza, 6) Then If ObjConta.ValorPolizaDescuadre > 0 Then GuardaLogAD($"Inventarios/RecepcionAlmacen-PPCompOC | Error:{ObjConta.MensajePolizaDescuadre} Diferencia:{ObjConta.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") ErrorMovInv = True End If End If If Not ErrorMovInv AndAlso UsuarioActual.Empresa.Funcionalidad(200) = "1" Then ObjContaAC = New ClsContPAQi(UsuarioActual.Empresa) ObjContaAC.IniciaTransacSQL() If ObjConta.ContabilizarPrePoliza(CvePrePoliza, UsuarioActual.CveUsuario, UsuarioActual.Empresa, ObjConta:=ObjContaAC) Then MensajeError = $"
Movimiento contabilizado en el folio: {ObjConta.ContaFolio}
" Else ErrorMovInv = True MensajeError = "Error al contabilizar los conceptos contables" End If End If 'FINAL If Not ErrorMovInv Then ObjInventario.Commit() ' aplica los movimientos insertados If ObjContaAC IsNot Nothing Then ObjContaAC.Commit() RegistraScript("playsonidito('beep-07.wav')") Dim Msg As New StringBuilder Dim link As String = String.Format("{1}", CveMovimiento, InvFolio) Msg.AppendFormat("Movimiento Registrado: Folio: {0}", link) Msg.AppendFormat("
Imprimir Movimiento ", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimiento))) Alert(Msg.ToString, TipoMensaje.MsgInformacion) Limpia() Else ObjInventario.RollBack() If ObjContaAC IsNot Nothing Then ObjContaAC.RollBack() RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") GuardaLog(MensajeError) Alert("Error al guardar el movimiento de almacen. Por favor vuelva a intentar.", TipoMensaje.MsgError) End If ObjInventario.Dispose() If ObjContaAC IsNot Nothing Then ObjContaAC.Dispose() End Sub Private Sub Limpia() CveCompraSurtir = -1 CvePrePolizaCompra = -1 CveOCSurtir = -1 CveImportacionSurtir = -1 CveImportacionProveedor = -1 CveImportacionCompra = -1 BuscaEntregaDirecta = -1 DivAdvertencia.Visible = False EntregaDirecta = False DtInv = Nothing CargaGVInv() TxtObservaciones.Text = "" TxtOC.Text = "" TxtFecha.Text = Now.ToShortDateString DdlAlmacen.SelectedValueExist(-1) TxtRemision.Text = "" 'ddlProveedor.SelectedValueExist(-1) ddlProveedor.SelectedValue = "-1" DdlFolio.Items.Clear() DdlFolio.Items.Insert(0, New ListItem("Seleccione", "-1")) DdlFolioOC.Items.Clear() DdlFolioOC.Items.Insert(0, New ListItem("Seleccione", "-1")) DdlFolioImportacion.Items.Clear() DdlFolioImportacion.Items.Insert(0, New ListItem("Seleccione", "-1")) CargaFoliosRecepcion() DtBitacora.Clear() DivBitacora.Visible = False CargaEventoBitacoraTemp() DdlMonedaTC.SelectedValueExist("1") TipoCambio = 0 'TxtTipoCambio.Text = GlobalTipoCambio(TxtFecha.Text.ToDate).ToString DivTipoCambio.Visible = False DivAdvertencia.Visible = False UpTipoCambio.Update() UPInv.Update() UpGenerales.Update() UpFiltros.Update() HLFolio.Text = "" HLFolio.NavigateUrl = "#" LbProveedor.Text = "" LbDescripcionCompra.Text = "" DivDocumentos.Visible = False 'If DtDocumentos IsNot Nothing Then ' DtDocumentos.Clear() ' TxtDocumento.Text = "" ' 'GvDocumentos.DataSource = DtDocumentos ' 'GvDocumentos.DataBind() 'End If UpDocumentos.Update() UpDatosCompra.Update() CargaPendientes() End Sub Private Function GuardaPrePoliza() As Boolean Return True End Function #End Region #Region " OC " Private Sub CargaFoliosOC() DdlFolioOC.Items.Clear() Dim ObjInventarios As New ClsInventarios If ddlProveedor.SelectedValue.ToEntero > 0 Then If ObjInventarios.PendientesAlmacenOCGet(ddlProveedor.SelectedValue.ToEntero, MinFecha.ToShortDateString.ToDate, UsuarioActual.CveEmpresa) Then DdlFolioOC.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() DdlFolioOC.DataBind() DdlFolioOC.Items.Insert(0, New ListItem("Seleccione", "-1")) End Sub Private Sub CargaPendientesOC() Dim ObjInventarios As New ClsInventarios Dim DtPendientesOC As New DataTable If ObjInventarios.PendientesAlmacenOCGet(ddlProveedor.SelectedValue.ToEntero, TxtFechaPendientes.Text.ToDate, UsuarioActual.CveEmpresa) Then DtPendientesOC = ObjInventarios.DtResultados Else DtPendientesOC = Nothing Alert("Ocurrió un error al obtener las OC pendientes de recibir del proveedor. Por favor vuelva a intentar", TipoMensaje.MsgError) End If ObjInventarios.Dispose() If DtPendientesOC IsNot Nothing Then GVPendientes.DataSource = DtPendientesOC End If LtActualizado.Text = String.Format("Actualizado: {0}", Now.ToString("H:mm")) GVPendientes.DataBind() UpPendientes.Update() End Sub Protected Sub BtnBuscarOC_Click(sender As Object, e As EventArgs) Handles BtnBuscarOC.Click CargaOC() End Sub Private Sub CargaOC() 'OBTENE CveOC Dim CveOC = -1 Dim MensajeCompra = "" Dim FolioOC = TxtOC.Text.Trim.ToEntero Dim ObjOC As New ClsOC If ObjOC.GetOrdenesCompraRep("OC", -1, -1, -1, -1, MinFecha, MaxFecha, -1, -1, FolioOC, -1, -1, UsuarioActual.CveEmpresa, -1) Then 'If ObjOC.DtResultados.FiltraParametros("TipoTermino = 3").Rows.Count = 1 Then If ObjOC.DtResultados.Rows(0)("TieneCompra").ToString.ToEntero > 0 Then 'Or UsuarioActual.Empresa.Funcionalidad(153).ToEntero > 0 MensajeCompra = String.Format("{1}", ObjOC.DtResultados.Rows(0)("CveCompraVinculada").ToString, ObjOC.DtResultados.Rows(0)("SerieFolioCompraVinculada").ToString) Else CveOC = ObjOC.DtResultados.FiltroPrimeroValor("CveOrdenCompra").ToString.ToEntero End If 'End If End If ObjOC.Dispose() RecibidaCompleta = False If CveOC > 0 Then CargaOCPorSurtir(CveOC) Else If MensajeCompra <> "" Then Alert($"La orden de compra ya esta vinculada y debe darse recepción por medio de su compra:
{MensajeCompra}", TipoMensaje.MsgAdvertencia) Else Alert("No se encontro ninguna orden de compra pendiente de recepción de almacén con el folio especificado.", TipoMensaje.MsgAdvertencia) End If End If UpGenerales.Update() UPInv.Update() End Sub Private Sub CargaOCPorSurtir(CveOC As Integer) 'REINICIALIZA VALORES DdlMonedaTC.SelectedValueExist("1") TipoCambio = 0 DivAdvertencia.Visible = False EntregaDirecta = False DivTipoCambio.Visible = False DivAdvertencia.Visible = False Apartado = False BtnGuardar.Enabled = True CargaAlmacenes(-1) LtDocumento.Text = "ORDEN DE COMPRA" CveCompraSurtir = -1 CvePrePolizaCompra = -1 Dim ObjOC As New ClsOC Dim ObjInventario As New ClsInventarios If ObjOC.GetOC(CveOC, UsuarioActual.CveEmpresa) Then If ObjOC.DtResultados.Rows.Count > 0 Then CveOCSurtir = CveOC LbProveedor.Text = ObjOC.DtResultados.Rows(0)("RazonSocial").ToString HLFolio.Text = ObjOC.DtResultados.Rows(0)("Folio").ToString If UsuarioActual.TienePermisoProceso(201) Then HLFolio.NavigateUrl = $"/OC/OC.aspx?OC={CveOCSurtir}" End If LbDescripcionCompra.Text = ObjOC.DtResultados.Rows(0)("Descripcion").ToString CveMoneda = ObjOC.DtResultados.Rows(0)("CveMoneda").ToString.ToEntero lbDescripcion.Text = ObjOC.DtResultados.Rows(0)("Descripcion").ToString TotalCompraOC = ObjOC.DtResultados.Rows(0)("SubTotal").ToString.ToDecimal 'TipoCambio = ObjOC.DtResultados.Rows(0)("TipoCambio").ToString.ToDecimal TipoCambio = 0 TipoMovimiento = 1 If ObjInventario.RecepcionAlmacenOCGet(CveOC, UsuarioActual.CveEmpresa) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then DtDatosDetalle = Nothing CreaDtDetalle() DtDatosLoteDetalle = Nothing CreaDtLoteDetalle() CreaDTInv(ObjInventario.DtResultados.FiltraParametros("CantidadCompra = 0")) BtnGuardar.Visible = True ''MONEDA DIFERENTE If CveMoneda <> 1 Then 'DivTipoCambio.Visible = True DdlMonedaTC.SelectedValueExist("2") DdlMonedaTC_SelectedIndexChanged(DdlMonedaTC, EventArgs.Empty) 'TxtTipoCambio.Text = If(TipoCambio <= 0, GlobalTipoCambio(TxtFecha.Text.ToDate).ToString, TipoCambio.ToString) TipoCambio = If(TipoCambio <= 0, GlobalTipoCambio(TxtFecha.Text.ToDate).ToDecimal, TipoCambio) If TipoCambio > 0 Then LtAdvertencia.Text = "El cambio de moneda se aplicara al guardar el movimiento con el tipo de cambio indicado." DivAdvertencia.Visible = True Else Alert("Ocurrió un error al cargar el tipo cambio. Por favor comuniquese con asistencia SIG.", TipoMensaje.MsgError) BtnGuardar.Visible = False End If End If UpTipoCambio.Update() DivBitacora.Visible = True If UsuarioActual.Empresa.Funcionalidad(132) = "1" Then DivCodigoSeriePS.Visible = True Else DivCodigoSeriePS.Visible = False End If If UsuarioActual.Empresa.Funcionalidad(594) = "1" AndAlso Not UsuarioActual.TienePermisoProceso(314) Then DivDocumentos.Visible = True UpDocumentos.Update() End If CargaGVInv() Else Alert("No hay productos pendientes de surtir de esta orden de compra. Por favor rectifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) HLFolio.Text = "" HLFolio.NavigateUrl = "#" LbProveedor.Text = "" LbDescripcionCompra.Text = "" DtInv = Nothing CargaGVInv() CargaFoliosRecepcion() End If End If Else BtnGuardar.Visible = False End If ObjOC.Dispose() ObjInventario.Dispose() UpDatosCompra.Update() End Sub Class DetalleOC Property CveOCDetalle As Integer Property CantidadOC As Decimal Property Cantidad As Decimal Property PS As String End Class #End Region #Region " TIPO DE CAMBIO " Protected Sub DdlMonedaTC_SelectedIndexChanged(sender As Object, e As EventArgs) Select Case DdlMonedaTC.SelectedValue.ToEntero Case 1 TrTC1.Visible = False TrTC2.Visible = False For Each Dr As DataRow In DtInv.Rows Dr("PU") = Dr("PUExtranjero") Dr("Total") = Dr("PU").ToString.ToDecimal * Dr("Cantidad").ToString.ToDecimal Dr("CostoIndirecto") = Dr("CostoIndirectoExtranjero") Next CargaGVInv() 'LtTotal.Text = DtMovimientos.SUM("Total", "").ToString.FormatoNumero UPInv.Update() Case 2 TrTC1.Visible = True TrTC2.Visible = True End Select End Sub Protected Sub BtnAplicarTC_Click(sender As Object, e As EventArgs) AplicarTipoCambio() CargaGVInv() End Sub Private Sub AplicarTipoCambio() 'TipoCambio = TxtTipoCambio.Text.ToDouble If CveOCSurtir > 0 Then TipoCambio = GlobalTipoCambio(TxtFecha.Text.ToDate).ToDecimal End If For Each Dr As DataRow In DtInv.Rows Dr("PU") = Dr("PUExtranjero").ToString.ToDecimal * TipoCambio Dr("Total") = Dr("PU").ToString.ToDecimal * Dr("CantidadC").ToString.ToDecimal Dr("CostoIndirecto") = Dr("CostoIndirectoExtranjero").ToString.ToDecimal * TipoCambio Next DtInv.AcceptChanges() End Sub #End Region #Region " BITACORA " Protected Sub GVEventoBitacora_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvBitacora.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.DBCampo("Archivo").ToString.Trim <> "" AndAlso -1 > 0 Then e.Row.FCLinkButton("LinkArchivo").Visible = True e.Row.FCLinkButton("LinkArchivo").CommandArgument = String.Format("OI\{0}", e.Row.DBCampo("Archivo").ToString) ScriptManager.GetCurrent(Me).RegisterPostBackControl(e.Row.FCLinkButton("LinkArchivo")) 'Registro un evento Postbacktrigger, que recargue toda la pagina para que funcione End If If e.Row.DBCampo("Archivo").ToString.Trim <> "" Then e.Row.Cells(5).Text = "SI" Else e.Row.Cells(5).Text = "NO" End If End If End Sub Private Sub InicializaBitacoraTemporal() DtBitacora = New DataTable DtBitacora.Columns.Add("FechaIng", GetType(String)) DtBitacora.Columns.Add("FechaInicio", GetType(String)) DtBitacora.Columns.Add("Usuario", GetType(String)) DtBitacora.Columns.Add("CveUsuario", GetType(String)) DtBitacora.Columns.Add("Descripcion", GetType(String)) DtBitacora.Columns.Add("Prioridad", GetType(String)) DtBitacora.Columns.Add("FileExtension", GetType(String)) DtBitacora.Columns.Add("Archivo", GetType(String)) DtBitacora.Columns.Add("CveOrdenCompra", GetType(String)) DtBitacora.Columns.Add("CveEmpresa", GetType(String)) End Sub Protected Sub BtnGuardarEventoBitacora_Click(sender As Object, e As EventArgs) Handles BtnGuardarEventoBitacora.Click AgregaBitacoraTemporal() End Sub Private Sub AgregaBitacoraTemporal() Dim ObjEventoBitacora As New ClsOIEventos 'Archivo Dim FileExtension As String = "" Dim Filename As String = "" Dim Filesgral As List(Of Archivo) = Anexo.getfiles().Archivos For Each fileItem As Archivo In Filesgral FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "") Filename = fileItem.filename Next Dim Archivo As New System.IO.FileInfo(String.Format("{0}OI\Temp\OI{1}{2}.{3}", UsuarioActual.Empresa.Ruta, UsuarioActual.CveUsuario, Now.ToString("HH-mm"), FileExtension)) If Archivo.Exists() Then Archivo.Delete() 'File.Delete(String.Format("\Empresas\{0}\OI\Temp\OI{1}{2}.{3}", CveEmpresaActual, UsuarioActual.CveUsuario, DtDetalle.Rows.Count, FileExtension)) End If If Filename <> "" Then Filename.FilesMove(String.Format("OI{0}{1}", UsuarioActual.CveUsuario, Now.ToString("HH-mm")), String.Format("{0}OI\Temp", UsuarioActual.Empresa.Ruta), ConcatenarDirectorioBase:=False) End If 'AGREGA Dim Dr = DtBitacora.NewRow Dr("FechaIng") = Now Dr("FechaInicio") = "" Dr("Usuario") = UsuarioActual.Usuario Dr("CveUsuario") = UsuarioActual.CveUsuario Dr("Descripcion") = TxtEventoDescripcion.Text.Trim Dr("Prioridad") = 1 Dr("Archivo") = If(FileExtension = "", "", $"{UsuarioActual.Empresa.Ruta}OI\Temp\OI{UsuarioActual.CveUsuario}{Now.ToString("HH-mm")}.{FileExtension}") Dr("FileExtension") = String.Format(".{0}", FileExtension) Dr("CveOrdenCompra") = -1 Dr("CveEmpresa") = UsuarioActual.CveEmpresa DtBitacora.Rows.Add(Dr) 'LIMPIA TxtEventoDescripcion.Text = "" 'ChkEventoPrioridad.Checked = False RegistraScript("$('#ModalBitacora').modal('hide')", "hidemodal") CargaEventoBitacoraTemp() End Sub Private Sub CargaEventoBitacoraTemp() GvBitacora.DataSource = DtBitacora GvBitacora.DataBind() UPAddEventoBitacora.Update() UPEventoBitacora.Update() End Sub Private Function GuardaBitacoraTemporal(ObjEventoBitacora As ClsOIEventos, CveMovimiento As Integer) As Boolean Dim Retorno = False Dim Archivo As System.IO.FileInfo = Nothing For Each Dr As DataRow In DtBitacora.Rows If ObjEventoBitacora.AddEventoBitacora(Dr("Descripcion").ToString, Dr("FileExtension").ToString, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveMovimientoAlmacen:=CveMovimiento) Then Try If Dr("Archivo").ToString <> "" Then Archivo = New System.IO.FileInfo(Dr("Archivo").ToString) If Archivo.Exists() Then File.Move(Archivo.ToString, String.Format("{0}OI\OI{1}{2}", UsuarioActual.Empresa.Ruta, ObjEventoBitacora.CveEvento.ToString, Archivo.Extension)) End If End If Catch ex As Exception Retorno = True Alert("Ocurrió un error al guardar los datos adjuntos de la Bitácora.", TipoMensaje.MsgError) Exit For End Try Else Retorno = True Exit For End If Next Return Retorno End Function #End Region #Region " FINANCIAMIENTO - AC " Protected Sub CargaAC() Dim Cont As New ClsContPAQi(UsuarioActual.Empresa) Dim DtAC As DataTable = Nothing If Cont.GetACSaldos(UsuarioActual.Empresa.EjercicioActual, 2) Then DtAC = Cont.DtResultados.Copy.FiltraParametros("PorDevengar > 0") Else Alert("Ocurrió un error al cargar los Presupuestos. Por favor vuelva a cargar la página", TipoMensaje.MsgError) End If Cont.Dispose() GvAC.DataSource = DtAC GvAC.DataBind() Dim Total As Double = GvAC.Rows.Cast(Of GridViewRow)().Sum(Function(gvr) gvr.DataKey("PorDevengar").ToDouble) Lbtotalsaldo.Text = Total.ToString.FormatoNumero UPPM.Update() End Sub Protected Sub GvAC_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvAC.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then e.Row.FCTextBox("TxtImporte").Attributes.Add("onkeyup", String.Format("ValidaImporte(this, {0});", e.Row.DBCampo("PorDevengar"))) e.Row.FCRangeValidator("RVA").MaximumValue = e.Row.DBCampo("PorDevengar").FormatoNumero End If End Sub #End Region #Region " ENVIA CORREO NOTICIACION - VENDEDOR " Private Sub MandaCorreoOCVendedores(CveCompra As Integer, CveMovimiento As Integer) 'SI NO TIENE FUNCIONALIDAD DATOS DE VENTA EN OC If Not UsuarioActual.Empresa.Funcionalidad(108) = "1" Then Exit Sub End If Dim DTCorreos As New DataTable Dim DTMovimientos As New DataTable Dim strBody As New StringBuilder Dim Asunto, Para, ArrayCC, Body As String Dim ObjOC As New ClsOC ObjOC.GetOrdenesCompraCorreo(CveCompra, CveMovimiento:=CveMovimiento) DTCorreos = ObjOC.DtResultados ObjOC.GetOrdenesCompraMovimiento(CveCompra, CveMovimiento:=CveMovimiento) DTMovimientos = ObjOC.DtResultados ObjOC.Dispose() For Each row As DataRow In DTCorreos.Rows strBody.Clear() 'SI DE UNA OC DE LA COMPRA NO SE RECIBIÓ NADA NO MANDA CORREO If DTMovimientos.FiltraParametros($"CveOrdenCompra = {row("CveOrdenCompra")}").Rows.Count = 0 Then Continue For End If strBody.Append(" ") strBody.Append(" ") strBody.Append(" ") strBody.Append(" ") strBody.Append("") strBody.Append("

Notificación de recepción de material

") strBody.Append("

") strBody.AppendFormat(" Se confirma recepción de material en almacén {0} vinculado la OC # {1} {2}.", DdlAlmacen.SelectedItem.Text, row("Folio").ToString, If(row("FolioREQ").ToString.Length > 0, $", relacionada a la(s) requisicion(es) # {row("FolioREQ")}", "")) strBody.Append("
") strBody.Append(" Con los siguientes productos:") strBody.Append("

") 'DETALLES strBody.Append(" ") strBody.Append(" ") strBody.Append(" ") strBody.Append(" ") strBody.Append(" ") strBody.Append(" ") strBody.Append(" ") strBody.Append(" ") For Each RowM As DataRow In DTMovimientos.FiltraParametros($"CveOrdenCompra = {row("CveOrdenCompra")}").Rows strBody.AppendFormat(" ") strBody.AppendFormat(" ", RowM("Cantidad").ToString.FormatoNumero) strBody.AppendFormat(" ", RowM("UnidadMedida")) strBody.AppendFormat(" ", RowM("Codigo")) strBody.AppendFormat(" ", RowM("PS")) strBody.AppendFormat(" ") Next strBody.Append("
CantidadUMCódigoProducto
{0}{0}{0}{0}
") strBody.Append("") strBody.Append("") '' ENVIO DEL CORREO Asunto = "Recepción de Material de OC " Para = row("Correo").ToString ArrayCC = row("CorreoAsistente").ToString Body = strBody.ToString Dim Mail As New ClsSisMail() Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body, ArrayCC) Next End Sub #End Region #Region "Imprimir PDF/Excel" Private Sub LnkExportar_Click(sender As Object, e As EventArgs) Handles LnkExportar.Click ImprimiReporte("EXCEL") End Sub Private Sub LnkImprimir_Click(sender As Object, e As EventArgs) Handles LnkImprimir.Click ImprimiReporte() End Sub Protected Sub ImprimiReporte(Optional Formato As String = "PDF") Dim Proveedor As String = ddlProveedor.SelectedText Dim Compra As String = DdlFolio.SelectedItem.Text Dim RutaPDF As String Dim Ruta As String = UsuarioActual.Empresa.Ruta RutaPDF = $"{Ruta}\Formatos\EntradaAlmacen.rdlc" If Not File.Exists(RutaPDF) Then RutaPDF = "Empresas/Grales/Formatos/EntradaAlmacen.rdlc" End If Dim params As New List(Of ReportParameter) params.Add(New ReportParameter("pEmp", UsuarioActual.Empresa.Empresa)) params.Add(New ReportParameter("pImg", New Uri(Server.MapPath(String.Format("~/Empresas/{0}/Logo.png", UsuarioActual.CveEmpresa))).AbsoluteUri)) params.Add(New ReportParameter("Proveedor", Proveedor)) params.Add(New ReportParameter("Compra", Compra)) params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre)) params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToShortDateString)) ImprimirPDF(RutaPDF, dt, params, "Reporte de Entrada Almacén", Formato:=Formato) End Sub #End Region #Region " VIEJO - POR ELIMINAR 22 NOVIEMBRE 2017 " Protected Sub ImgAlmacen_Click(sender As Object, e As ImageClickEventArgs) For i As Integer = 0 To GvInv.Rows.Count - 1 If Not DtInv.Rows(i)("CantidadF").ToString.ToEntero = 0 Then DtInv.Rows(i)("CveAlmacen") = GvInv.HeaderRow.FCDropDownList("ddlPAlmacen").SelectedValue End If Next CargaGVInv() End Sub Private Sub AddDTEnvio(Cantidad As Double, UM As String, CveUM As Integer, CvePS As Integer, PS As String, PU As Double, CveAlmacen As Integer) Dim dr As DataRow = DtInv.NewRow dr("CantidadF") = Cantidad dr("UM") = UM dr("CveUM") = CveUM dr("CvePS") = CvePS dr("PS") = PS dr("PU") = PU dr("CveAlmacen") = CveAlmacen DtInv.Rows.InsertAt(dr, hdnIndexInv.Value.ToEntero + 1) CargaGVInv() End Sub Protected Sub Enviar_Click(sender As Object, e As ImageClickEventArgs) Handles ImgAdd.Click If TbCantidadAlm.Text.ToDouble < DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("CantidadF").ToString.ToDouble And TbCantidadAlm.Text.ToDouble > 0 Then DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("CantidadF") = DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("CantidadF").ToString.ToDouble - TbCantidadAlm.Text.ToDouble AddDTEnvio(TbCantidadAlm.Text.ToDouble, DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("UM").ToString, DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("CveUM").ToString.ToEntero, DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("CvePS").ToString().ToEntero, DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("PS").ToString, DtInv.Rows.Item(hdnIndexInv.Value.ToEntero)("PU").ToString.ToDouble, ddlAlmacenAdd.SelectedValue.ToEntero) Else Alert("El campo cantidad es necesario que sea mayor que 0 y menor a la cantidad faltante.", TipoMensaje.MsgAdvertencia) End If CargaGVInv() TbCantidadAlm.Text = "" ddlAlmacenAdd.SelectedIndex = 0 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 DtInv.Rows Row("Seleccionado") = GvInv.Rows(index2).FCCheckBox("cbInv").Checked If GvInv.Rows(index2).FCTextBox("TbCantidadF").Text <> "" Then Row("CantidadSeleccionada") = GvInv.Rows(index2).FCTextBox("TbCantidadF").Text End If If GvInv.Rows(index2).FCTextBox("TxtLote").Text <> "" Then Row("Lote") = GvInv.Rows(index2).FCTextBox("TxtLote").Text End If If GvInv.Rows(index2).FCDropDownList("DdlSeccionAlmacen").SelectedValue <> "-1" Then Row("CveSeccion") = GvInv.Rows(index2).FCDropDownList("DdlSeccionAlmacen").SelectedValue.ToEntero End If If GvInv.Rows(index2).FCTextBox("TxtCaducidad").Text <> "" Then Row("Caducidad") = GvInv.Rows(index2).FCTextBox("TxtCaducidad").Text.ToDate End If index2 += 1 Next DtInv.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 = DtInv.Rows(Index) Dim dr As DataRow = DtInv.NewRow dr.ItemArray = dr1.ItemArray dr1("CantidadC") = (dr1("CantidadC").ToString.ToDecimal - Cantidad.ToDecimal) Dim CantidadFOriginal As Decimal = dr1("CantidadF").ToString.ToDecimal dr1("CantidadF") = (dr1("CantidadF").ToString.ToDecimal - Cantidad.ToDecimal) Dim CantidadSOriginal As Decimal = dr1("CantidadS").ToString.ToDecimal dr1("CantidadS") = (CantidadSOriginal * dr1("CantidadF").ToString.ToDecimal) / CantidadFOriginal Dim CantidadSeleccionadaOriginal As Decimal = dr1("CantidadSeleccionada").ToString.ToDecimal dr1("CantidadSeleccionada") = If(CantidadSeleccionadaOriginal > dr1("CantidadF").ToString.ToDecimal, dr1("CantidadF").ToString.ToDecimal, CantidadSeleccionadaOriginal) CantidadSeleccionadaOriginal = CantidadSeleccionadaOriginal - dr1("CantidadF").ToString.ToDecimal Dim CostoIndirectoOriginal As Decimal = dr1("CostoIndirecto").ToString.ToDecimal dr1("CostoIndirecto") = (CostoIndirectoOriginal * dr1("CantidadF").ToString.ToDecimal) / CantidadFOriginal Dim CostoIndirectoExtranjeroOriginal As Decimal = dr1("CostoIndirectoExtranjero").ToString.ToDecimal dr1("CostoIndirectoExtranjero") = (CostoIndirectoExtranjeroOriginal * dr1("CantidadF").ToString.ToDecimal) / CantidadFOriginal DtInv.AcceptChanges() dr("CantidadC") = Cantidad.ToDecimal dr("CantidadF") = Cantidad.ToDecimal dr("CantidadS") = (CantidadSOriginal * dr("CantidadF").ToString.ToDecimal) / CantidadFOriginal dr("CantidadSeleccionada") = If(CantidadSeleccionadaOriginal > 0, CantidadSeleccionadaOriginal, 0) dr("Seleccionado") = If(CantidadSeleccionadaOriginal > 0, True, False) dr("CostoIndirecto") = (CostoIndirectoOriginal * dr("CantidadF").ToString.ToDecimal) / CantidadFOriginal dr("CostoIndirectoExtranjero") = (CostoIndirectoExtranjeroOriginal * dr("CantidadF").ToString.ToDecimal) / CantidadFOriginal DtInv.Rows.InsertAt(dr, Index) DtInv.AcceptChanges() index2 = 1 For Each Row As DataRow In DtInv.Rows Row("Consec") = index2 index2 += 1 Next DtInv.AcceptChanges() CargaGVInv() index2 = 0 For Each Row As DataRow In DtInv.Rows GvInv.Rows(index2).FCCheckBox("cbInv").Checked = CBool(Row("Seleccionado")) If Row("CantidadSeleccionada").ToString <> "" Then GvInv.Rows(index2).FCTextBox("TbCantidadF").Text = Row("CantidadSeleccionada").ToString End If If Row("Lote").ToString <> "" Then GvInv.Rows(index2).FCTextBox("TxtLote").Text = Row("Lote").ToString End If If Row("CveSeccion").ToString <> "" Then GvInv.Rows(index2).FCDropDownList("DdlSeccionAlmacen").SelectedValue = Row("CveSeccion").ToString End If If Row("Caducidad").ToString <> "" Then GvInv.Rows(index2).FCTextBox("TxtCaducidad").Text = Row("Caducidad").ToString.ToDate.ToShortDateString End If index2 += 1 Next End Sub #End Region #Region "CargaExcel" Private Sub BtnCargaExcel_Click(sender As Object, e As EventArgs) Handles BtnCargaExcel.Click If TxtExcel.getfiles().Archivos.Count > 0 Then Dim file As Archivo = TxtExcel.getfiles().Archivos(0) Dim Directorio As String = AppDomain.CurrentDomain.BaseDirectory & file.path Dim Tipo As String = If(file.Extension.Contiene("xlsx", "xlsx", "xlsm", "xlsb", "xls"), "EXCEL", "CSV") If Tipo = "CSV" AndAlso UsuarioActual.Empresa.Funcionalidad(531) = "1" Then 'empresa de acumuladores CargaArchivoCSV(Directorio, file.filename, HLFolio.Text) Else CargarArchivoExcel(Directorio, file.filename) End If Else Alert("No existe el archivo. Favor de subir un archivo excel a la plataforma.", TipoMensaje.MsgError) End If End Sub Protected Sub CargarArchivoExcel(Ruta As String, FileName As String) SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet) Dim dt As DataTable = Nothing Dim ErrorArchivo = False Try dt = ReadExcelFile(Ruta + FileName, True) Catch ex As Exception ErrorArchivo = True OnError("Ocurrio un error al leer el archivo
" & ex.Message, ex) End Try If Not ErrorArchivo AndAlso dt IsNot Nothing Then If Not dt.Columns(0).ColumnName = "Cantidad" Then Alert("El nombre de la primera columna debe ser 'Cantidad'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(1).ColumnName = "Código" Then Alert("El nombre de la segunda columna debe ser 'Codigo'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(2).ColumnName = "Producto" Then Alert("El nombre de la tercera columna debe ser 'Producto'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(3).ColumnName = "Serie" Then Alert("El nombre de la cuarta columna debe ser 'Serie'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If ProcesaExcel(dt) End If End Sub Private Function ProcesaExcel(dt As DataTable) As Boolean dt.TableName = "Datos" Dim ProductosNoCargados As New StringBuilder() Dim RowsCargados As Integer = 0 Dim RowsNoCargados As Integer = 0 Dim NoPSConSerie As Integer = 0 If CveCompraSurtir > 0 Then Try For Each RowExcel As DataRow In dt.Rows If RowExcel("Código").ToString() <> "" Then Dim RowPS = DtInv.FiltroPrimero(String.Format("Codigo='{0}'", RowExcel("Código").ToString())) If RowPS IsNot Nothing AndAlso RowPS("CvePS").ToString().ToEntero() > 0 Then Dim CveProducto As Integer = RowPS("CvePS").ToString().ToEntero() Dim CveUnidadMedida As Integer = RowPS("CveUM").ToString().ToEntero() CvePSSerie = CveProducto CveConsecSerie = DtInv.FiltroPrimeroValor("Consec", "CvePS=" & CvePSSerie).ToEntero Dim Cantidad As Double = RowExcel("Cantidad").ToString().ToDecimal() Dim Serie As String = RowExcel("Serie").ToString() Dim Lote As String = "" Dim FechaCaducidad As Date = MinFecha Dim Observaciones As String = "" LbCantidad.Text = Cantidad.ToString Dim Valido As Boolean = True If RowPS("AplicaSerie").ToString() = "True" And (String.IsNullOrEmpty(Serie.Trim()) OrElse Serie = "-1") Then Valido = False Alert($"El producto '{RowPS("PS")}' requiere 'Serie'", TipoMensaje.MsgAdvertencia) ProductosNoCargados.AppendFormat("{0},", RowPS("PS").ToString()) End If If RowPS("AplicaSerie").ToString() = "True" AndAlso Not String.IsNullOrEmpty(Serie.Trim()) Then NoPSConSerie = NoPSConSerie + 1 End If If Valido Then CveConsecSerie = RowPS("Consec").ToString.ToEntero AgregaSerie(RowExcel("Serie").ToString, 1) 'AgregarPS(Cantidad, CveProducto, CveUnidadMedida, Observaciones, CveSeccionAlmacen:=DdlSeccionAlmacen.SelectedValue.ToEntero, SeccionAlmacen:=DdlSeccionAlmacen.SelectedItem.Text, Serie:=If(Not String.IsNullOrEmpty(Serie), Serie, ""), Lote:=Lote, FechaCaducidad:=FechaCaducidad, Limpia:=False) RowsCargados = RowsCargados + 1 Else RowsNoCargados = RowsNoCargados + 1 ProductosNoCargados.AppendFormat("{0},", RowPS("PS").ToString()) End If Else RowsNoCargados = RowsNoCargados + 1 ProductosNoCargados.AppendFormat("{0},", RowExcel("Producto").ToString()) End If End If Next Catch ex As Exception OnError("Ocurrió un error al cargar los productos." & ProductosNoCargados.ToString(), ex) Finally Dim MensajeFinal As New StringBuilder() If RowsNoCargados = 0 AndAlso RowsCargados > 0 Then MensajeFinal.Append("Los productos se cargaron correctamente.

") End If If RowsCargados > 0 Then MensajeFinal.Append("Se cargaron " & RowsCargados & " productos correctamente.") End If If RowsNoCargados > 0 Then MensajeFinal.Append("No se pudieron cargar " & RowsNoCargados & " productos.
Los siguientes productos no se pudieron cargar: " & ProductosNoCargados.ToString()) End If Alert(MensajeFinal.ToString()) End Try Else Alert("No hay seleccionada compra", TipoMensaje.MsgError) End If Return True End Function Protected Sub LbDescargarExcelConceptos_Click(sender As Object, e As EventArgs) DescargarFormato() End Sub Public Sub DescargarFormato() Dim Directorio As String = ModExtensiones.DirectorioBaseEmpresas & "Empresas\Grales\Formatos\FormatoRecepcionAlmacen.xlsx" Dim dtt As New DataTable dtt = DtInv.Copy() dtt.Columns.Remove("Cantidad") dtt.Columns("CantidadF").ColumnName = "Cantidad" dtt.Columns("PS").ColumnName = "Producto" dtt.Columns("Codigo").ColumnName = "Código" Dim existingcol As New List(Of String) '= {"Cantidad", "Producto", "Código"} For Each col As DataColumn In dtt.Columns If Not col.ColumnName.Contiene("Cantidad", "Producto", "Código") Then existingcol.Add(col.ColumnName) End If Next For Each colName As String In existingcol dtt.Columns.Remove(colName) Next dtt.Columns("Cantidad").SetOrdinal(0) dtt.Columns("Código").SetOrdinal(1) dtt.Columns("Producto").SetOrdinal(2) dtt.Columns.Add("Serie", GetType(String)) dtt.ExportToExcel("FormatoRecepcionAlmacen.xlsx") End Sub Private Sub CargaArchivoCSV(Ruta As String, FileName As String, Optional FolioFactura As String = "") 'Create a DataTable. Dim dt As New DataTable() dt.Columns.AddRange(New DataColumn(9) {New DataColumn("CodBarra", GetType(String)), New DataColumn("OVenta", GetType(String)), New DataColumn("Factura", GetType(String)), New DataColumn("FechaFac", GetType(String)), New DataColumn("Pallet", GetType(String)), New DataColumn("CodigoJCI", GetType(String)), New DataColumn("Producto", GetType(String)), New DataColumn("Serie", GetType(String)),'CodigoUnico New DataColumn("Cantidad", GetType(Integer)), New DataColumn("Código", GetType(String))}) FolioFactura = FolioFactura.Replace("-", "") 'Read the contents of CSV file. Dim csvData As String = File.ReadAllText(Ruta & FileName) Dim CodigoUnico As String = "CU no escaneado" 'texto constante para determinar que no se leyó Dim r As Integer = 1 'Execute a loop over the rows. For Each row As String In csvData.Split(ControlChars.Lf) If r > 2 Then ' si es la segundo renglon If Not String.IsNullOrEmpty(row) Then Dim i As Integer = 0 Dim rr As String() = row.Split(","c) If CodigoUnico <> rr(7).Trim AndAlso (FolioFactura = "" OrElse FolioFactura = rr(2).Trim) Then dt.Rows.Add() dt.Rows(dt.Rows.Count - 1)("CodBarra") = rr(0).Trim dt.Rows(dt.Rows.Count - 1)("OVenta") = rr(1).Trim dt.Rows(dt.Rows.Count - 1)("Factura") = rr(2).Trim dt.Rows(dt.Rows.Count - 1)("FechaFac") = rr(3).Trim dt.Rows(dt.Rows.Count - 1)("Pallet") = rr(4).Trim dt.Rows(dt.Rows.Count - 1)("CodigoJCI") = rr(5).Trim dt.Rows(dt.Rows.Count - 1)("Producto") = rr(6).Trim dt.Rows(dt.Rows.Count - 1)("Serie") = rr(7).Trim dt.Rows(dt.Rows.Count - 1)("Cantidad") = 1 dt.Rows(dt.Rows.Count - 1)("Código") = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Codigo", String.Format("Codigo2 = '{0}'", rr(5).Trim)) End If End If End If r += 1 Next ProcesaExcel(dt) End Sub #End Region Private Function GuardaDocumentoBitacora(ObjEventoBitacora As ClsOIEventos, CveMovimiento As Integer) As Boolean Dim Retorno = True Dim Archivo As System.IO.FileInfo = Nothing Dim Filesgral As List(Of Archivo) = TxtDocumento.getfiles().Archivos Dim archivoOriginal = Filesgral.FirstOrDefault() Dim Bitacora As String = "" If Not String.IsNullOrEmpty(TxtObservaciones.Text) Then Bitacora = TxtObservaciones.Text Else Bitacora = "Documento Relacionado" End If If ObjEventoBitacora.AddEventoBitacora(Bitacora, String.Format(".{0}", archivoOriginal.Extension), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveMovimientoAlmacen:=CveMovimiento) Then Try If archivoOriginal.filename <> "" Then Archivo = New System.IO.FileInfo(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, archivoOriginal.filename)) If Archivo.Exists() Then File.Move(Archivo.ToString, String.Format("{0}OI\OI{1}{2}", UsuarioActual.Empresa.Ruta, ObjEventoBitacora.CveEvento.ToString, Archivo.Extension)) Else Retorno = False End If End If Catch ex As Exception Retorno = False End Try Else Retorno = False End If Return Retorno End Function Public Class MMovimientoAlmacen Public Property CveMovimiento As Integer Public Property Folio As Integer End Class End Class