Option Explicit On Option Strict On Imports System.Data Imports System.IO Imports Extensiones Imports GemBox.Spreadsheet Imports Microsoft.Reporting.WebForms Partial Class Inventarios_TraspasoAlmacen Inherits ClsPaginas #Region "PROPIEDADES" Public Property DtMovimientos() As DataTable Get Return CType(ViewState("DtMovimientos"), DataTable) End Get Set(value As DataTable) ViewState("DtMovimientos") = value End Set End Property Private Property DtTraslado As DataTable Get Return CType(ViewState("DtTraslado"), DataTable) End Get Set(value As DataTable) ViewState("DtTraslado") = value End Set End Property Private Property CveAlmacenTransitorio As Integer Get Return CType(ViewState("CveAlmacenTransitorio"), Integer) End Get Set(value As Integer) ViewState("CveAlmacenTransitorio") = value End Set End Property Private Property CveAlmacenDestino As Integer Get Return CType(ViewState("CveAlmacenDestino"), Integer) End Get Set(value As Integer) ViewState("CveAlmacenDestino") = value End Set End Property Private Property CveUsuarioResponsable As Integer Get Return CType(ViewState("CveUsuarioResponsable"), Integer) End Get Set(value As Integer) ViewState("CveUsuarioResponsable") = value End Set End Property Private Property CvePSSerieLote As Integer Get Return CType(ViewState("CvePSSerieLote"), Integer) End Get Set(value As Integer) ViewState("CvePSSerieLote") = value End Set End Property Private Property CveUMSerieLote As Integer Get Return CType(ViewState("CveUMSerieLote"), Integer) End Get Set(value As Integer) ViewState("CveUMSerieLote") = value End Set End Property Private Property CargadoDeMov As Boolean Get Return CType(ViewState("CargadoDeMov"), Boolean) End Get Set(value As Boolean) ViewState("CargadoDeMov") = value End Set End Property Private Property CveMovimientoSalida As Integer Get Return CType(ViewState("CveMovimientoSalida"), Integer) End Get Set(value As Integer) ViewState("CveMovimientoSalida") = value End Set End Property Private Property CveMov As Integer Get Return CType(ViewState("CveMov"), Integer) End Get Set(value As Integer) ViewState("CveMov") = value End Set End Property Private Property ObjFactura As Modelos.Factura Get Return CType(ViewState("ObjFactura"), Modelos.Factura) End Get Set(value As Modelos.Factura) ViewState("ObjFactura") = value End Set End Property Private Property Folio As Integer Get Return CType(ViewState("Folio"), Integer) End Get Set(value As Integer) ViewState("Folio") = value End Set End Property Private Property MensajeAlert As StringBuilder Get Return CType(ViewState("MensajeAlert"), StringBuilder) End Get Set(value As StringBuilder) ViewState("MensajeAlert") = value End Set End Property Private Property CveMovimientoTimbrado As Integer Get Return CType(ViewState("CveMovimientoTimbrado"), Integer) End Get Set(value As Integer) ViewState("CveMovimientoTimbrado") = value End Set End Property Private Property DtSeccionAlmacen As DataTable Get Return CType(ViewState("DtSeccionAlmacen"), DataTable) End Get Set(value As DataTable) ViewState("DtSeccionAlmacen") = value End Set End Property Private Property IndexSeccionAlmacen As Integer Get Return CType(ViewState("IndexSeccionAlmacen"), Integer) End Get Set(value As Integer) ViewState("IndexSeccionAlmacen") = 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 CvePS As Integer Get Return CType(ViewState("CvePS"), Integer) End Get Set(value As Integer) ViewState("CvePS") = value End Set End Property Private Property TipoSeccionAlmacen As Integer Get Return CType(ViewState("TipoSeccionAlmacen"), Integer) End Get Set(value As Integer) ViewState("TipoSeccionAlmacen") = value End Set End Property Private Property FolioBusqueda As Integer Get Return CType(ViewState("FolioBusqueda"), Integer) End Get Set(value As Integer) ViewState("FolioBusqueda") = value End Set End Property #End Region Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not Page.IsPostBack Then TxtFecha.Text = Now.ToShortDateString CEFecha.EndDate = Now.AddDays(-1) RVFecha.MaximumValue = Now.ToShortDateString TxtFechaRecepcion.Text = Now.ToShortDateString CEFechaRecepcion.EndDate = Now.AddDays(-1) RVFechaRecepcion.MaximumValue = Now.ToShortDateString Folio = 0 CveMovimientoTimbrado = -1 CargaCombos() CreaDT() AlmacenTransitorioDefaults() If Request("CveEntrada") IsNot Nothing AndAlso Request("CveEntrada").ToString.ToEntero > 0 Then CargaMovimiento(Request("CveEntrada").ToString.ToEntero) Else GvDatos.Columns(7).Visible = UsuarioActual.Empresa.Funcionalidad(563) = "1" GvDatosRecepcion.Columns(7).Visible = UsuarioActual.Empresa.Funcionalidad(563) = "1" ThSeccionAlmacen.Visible = UsuarioActual.Empresa.Funcionalidad(563) = "1" End If If UsuarioActual.Empresa.Funcionalidad(132) = "1" Then DivCodigoSeriePS.Visible = True Else DivCodigoSeriePS.Visible = False End If If ChkTransitorio.Checked Then RegistraScript("$('#DivTransitorio').show(0);$('#DivGastoIndirecto').show(0);$('#DivDocChofer').show(0);") If UsuarioActual.CveEmpresa.Contiene(1, 119) Then DivEmiirTimbrado.Visible = True CantidadTotal = 0 IndexSeccionAlmacen = 0 CvePS = 0 CreaDtSeccionAlmacen() CargaDdlAlmacen() TipoSeccionAlmacen = 0 Else If ChkTransitorio.Checked Then RegistraScript("$('#DivTransitorio').show(0);$('#DivGastoIndirecto').show(0);$('#DivDocChofer').show(0);") End If End Sub #Region "CARGA DATOS" Protected Sub CreaDT() Dim dt As New DataTable Dim column As DataColumn = New DataColumn("No") column.DataType = Type.GetType("System.Int32") With column .AutoIncrement = True .AutoIncrementSeed = 1 .AutoIncrementStep = 1 End With dt.Columns.Add(column) 'dt.Columns.Add("CveMovimiento", Type.GetType("System.Int32")) 'dt.Columns.Add("CveMovimientoDetalle", Type.GetType("System.Int32")) dt.Columns.Add("Cantidad", Type.GetType("System.Double")) dt.Columns.Add("CveUM", Type.GetType("System.Int32")) dt.Columns.Add("UnidadMedida") dt.Columns.Add("UM") dt.Columns.Add("CvePS", Type.GetType("System.Int32")) dt.Columns.Add("CveAF", Type.GetType("System.Int32")) dt.Columns.Add("PS") dt.Columns.Add("Observaciones") dt.Columns.Add("SerieLote") dt.Columns.Add("Lote") dt.Columns.Add("Batch") 'dt.Columns.Add("PU", Type.GetType("System.Double")) 'dt.Columns.Add("Total", Type.GetType("System.Double")) dt.Columns.Add("CveClasificacion", Type.GetType("System.Int32")) dt.Columns.Add("EstatusExistencia") dt.Columns.Add("TotalImporte", Type.GetType("System.Double")) dt.Columns.Add("PU", Type.GetType("System.Double")) dt.Columns.Add("Descuento", Type.GetType("System.Double")) dt.Columns.Add("SATClaveUM") dt.Columns.Add("SATClaveProdServ") dt.Columns.Add("Noidentificacion") dt.Columns.Add("CuentaPredial") dt.Columns.Add("Obs") dt.Columns.Add("ImporteIVA", Type.GetType("System.Double")) dt.Columns.Add("PorcentajeIVA", Type.GetType("System.Double")) DtMovimientos = dt CargaGvDatos() End Sub Private Sub CargaMovimiento(CveMovimiento As Integer) Dim Mov As New ClsInventarios If Mov.GetMovimientos(CveMovimiento, 2, -1, UsuarioActual.CveEmpresa) Then If Mov.DtResultados.Rows.Count = 1 Then DivMov.Visible = True ltlFolio.Text = Mov.DtResultados(0)("Folio").ToString ltlFecha.Text = Mov.DtResultados(0)("FechaMovto").ToString.ToDate.ToShortDateString If Mov.CveCompra > 0 Then hplRef.NavigateUrl = $"/Compras/Compras.aspx?CveCompra={Mov.CveCompra}" lblCompraRef.Visible = True hplRef.Visible = True Else hplRef.Visible = False lblCompraRef.Visible = False End If CargadoDeMov = True If (DdlAlmacenOrigen.Items.FindByValue(Mov.CveAlmacen.ToString()) Is Nothing) Then Dim dr As DataRow = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimero(String.Format("CveAlmacen = {0}", Mov.CveAlmacen)) If dr IsNot Nothing Then DdlAlmacenOrigen.Items.Insert(0, New ListItem(dr("Almacen").ToString, dr("CveAlmacen").ToString)) ' lo genera Obj.SelectedValue = Valor.ToString DdlAlmacenOrigen.Enabled = False End If Else DdlAlmacenOrigen.SelectedValue = Mov.CveAlmacen.ToString End If DdlAlmacenOrigen.Enabled = False 'If GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveTipoAlmacen", $"CveAlmacen = {Mov.CveAlmacenDestino}").ToEntero = 16 Then ' CveMov = CveMovimiento ' LnkEnviarMail.Attributes.Add("onclick", "$('#ModalDivMail').modal();") ' LnkEnviarMail.Visible = True 'End If If Mov.GetMovimientosDetalle(CveMovimiento, UsuarioActual.CveEmpresa) Then DtMovimientos = Mov.DtResultados.DefaultView.ToTable("Cantidad, CveUM, CvePS, CveAF, PS, SerieLote, CveClasificacion, EstatusExistencia") CargaGvDatos() End If Else Alert("El movimiento solicitado no existe. ", TipoMensaje.MsgAdvertencia) End If Else Alert("Ocurrió un error al cargar el movimiento a traspasar. Por favor vuelva a intentar.", TipoMensaje.MsgError) End If Mov.Dispose() UpMov.Update() End Sub Private Sub AlmacenTransitorioDefaults() ChkTransitorio.Checked = UsuarioActual.Empresa.Funcionalidad(154).ToString.ToEntero > 0 ChkTransitorio.Enabled = Not UsuarioActual.Empresa.Funcionalidad(154).ToString.ToEntero > 0 End Sub Private Sub CargaCombos() 'Llenar Clasificaciones If UsuarioActual.CveEmpresa = 66 Then DdlClasificacion.DataSource = GlobalDTSubFamilias(UsuarioActual.CveEmpresa).FiltraParametros("", Orderby:="Clasificacion") Else DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros(" Codigo = '' OR Codigo IS NULL ", Orderby:="Clasificacion") End If DdlClasificacion.DataBind() 'Llena Almacen Origen CargaAlmacenOrigen() 'DdlAlmacenOrigen.Items.Insert(0, New ListItem("Seleccione", "-1")) 'Dim dtAlm As DataTable = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1) 'dtAlm.Merge(GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 2)) 'Llena Almacen Destino, todos los almacenes destino, DdlAlmacenDestino.DataSource = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltraParametros("CveTipoAlmacen NOT IN (3,4,9,10,11) AND Estatus = 'Activo'") 'DdlAlmacenDestino.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen <> 4") DdlAlmacenDestino.DataBind() DdlAlmacenDestino.Items.Insert(0, New ListItem("Seleccione", "-1")) 'Llena Almacen Transitorio DdlAlmacenTransitorio.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 3) DdlAlmacenTransitorio.DataBind() DdlAlmacenTransitorio.Items.Insert(0, New ListItem("Seleccione", "-1")) 'Llena Almacen Recepcion DdlAlmacenRecepcion.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen NOT IN (3,4,9,10,11)") DdlAlmacenRecepcion.DataBind() DdlAlmacenRecepcion.Items.Insert(0, New ListItem("Todos", "-1")) 'Llena Almacen Transitorio Recepcion DdlAlmacenTransitorioRecepcion.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 3) DdlAlmacenTransitorioRecepcion.DataBind() DdlAlmacenTransitorioRecepcion.Items.Insert(0, New ListItem("Seleccione", "-1")) ''Llena Almacen Recibe 'DdlAlmacenRecibe.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) 'DdlAlmacenRecibe.DataBind() 'Llena Unidaddes Medida DdlUnidad.DataSource = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa) DdlUnidad.DataBind() 'Llena Choferes Dim ObjAcar As New ClsAcarreos() If ObjAcar.GetChofer(-1, UsuarioActual.CveEmpresa, 1, -1) Then DldChofer.DataSource = ObjAcar.DtResultados DldChofer.DataBind() End If ObjAcar.Dispose() DldChofer.Items.Insert(0, New ListItem("Seleccione", "-1")) TxtFechaEntrega.Text = Now.ToShortDateString 'Llena Responsables Transitorio 'DdlResponsable.DataSource = GlobalDTUsuarios(-1, UsuarioActual.CveEmpresa) 'DdlResponsable.DataBind() 'DdlResponsable.Items.Insert(0, New ListItem("Seleccione", "-1")) 'Llena Responsables Transitorio recepcion 'DdlResponsableRecepcion.DataSource = GlobalDTUsuarios(-1, UsuarioActual.CveEmpresa) 'DdlResponsableRecepcion.DataBind() 'DdlResponsableRecepcion.Items.Insert(0, New ListItem("Seleccione", "-1")) 'Llenar el dropdownlist de Productos y servicios 'If UsuarioActual.Empresa.Funcionalidad(105) = "" Then ' DdlProducto.DataSource = GlobalDTProductosServicios(UsuarioActual.CveEmpresa) ' DdlProducto.DataBind() ' DdlProducto.Items.Insert(0, New ListItem("----", "-1")) ' DdlProductows.Visible = False 'Else ' DdlProducto.Visible = False 'End If CargaPS() 'Folio SiguienteFolio(If(ChkTransitorio.Checked, 9, 8)) 'DdlProducto.DataBind() End Sub Private Sub CargaAlmacenOrigen() DdlAlmacenOrigen.Enabled = True DdlAlmacenOrigen.Items.Clear() DdlAlmacenOrigen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen NOT IN (3,4,9,10,11,21)") DdlAlmacenOrigen.Items.Insert(0, New ListItem(" Seleccione ", "-1")) DdlAlmacenOrigen.SelectedValue = "-1" DdlAlmacenOrigen.DataBind() DdlAlmacenOrigen.SelectedValueExist(UsuarioActual.CveAlmacen) End Sub Private Sub CargaPS() 'DdlProducto2.setEsWebService(UsuarioActual.Empresa.Funcionalidad(105) = "1") 'If Not DdlProducto2.UsaWebService AndAlso CType(DdlProducto2.DataSource, DataTable) Is Nothing Then ' DdlProducto2.DataSource = GlobalDTProductosServicios(UsuarioActual.CveEmpresa) ' DdlProducto2.DataBind() 'End If Dim EsWS = If(UsuarioActual.Empresa.Funcionalidad(105) = "1" Or UsuarioActual.Empresa.Funcionalidad(141) = "1", True, False) DdlProducto2.setEsWebService(EsWS) If DdlProducto2.UsaWebService Then DdlProducto2.ddlWS.Attributes.Add("data-cveclasificacion", DdlClasificacion.SelectedValue) If UsuarioActual.Empresa.Funcionalidad(141) = "1" Then DdlProducto2.ddlWS.Attributes.Add("data-pagina", "inv/traspaso") DdlProducto2.ddlWS.Attributes.Add("Data-onresult", "CargaExistenciaAlmacenes") CargaExistenciasSucursal() DdlAlmacenOrigen.AutoPostBack = True End If ElseIf Not DdlProducto2.UsaWebService AndAlso CType(DdlProducto2.DataSource, DataTable) Is Nothing Then DdlProducto2.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=DdlClasificacion.SelectedValue.ToEntero).FiltraParametros("CveTipoPS = 2") DdlProducto2.DataBind() End If End Sub Protected Sub DdlAlmacenOrigen_SelectedIndexChanged(sender As Object, e As EventArgs) If UsuarioActual.Empresa.Funcionalidad(141) = "1" Then CargaExistenciasSucursal() End If End Sub Protected Sub DdlAlmacenDestino_SelectedIndexChanged(sender As Object, e As EventArgs) If GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveTipoAlmacen", $"CveAlmacen = {DdlAlmacenDestino.SelectedValue.ToEntero}").ToString.ToEntero = 21 Then ChkTransitorio.Checked = False ChkTransitorio.Enabled = False Else ChkTransitorio.Enabled = True End If End Sub Private Sub CargaExistenciasSucursal() DdlProducto2.Attributes.Remove("Data-cvesubproyecto") DdlProducto2.Attributes.Add("Data-cvesubproyecto", GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", $"CveAlmacen = {DdlAlmacenOrigen.SelectedValue}")) End Sub Private Sub SiguienteFolio(CveConcepto As Integer) 'Dim Inv As New ClsInventarios 'Dim Folio As Integer = Inv.GetFolioSiguiente(CveConcepto, UsuarioActual.CveEmpresa) 'Inv.Dispose() 'TxtFolio.Text = Folio.ToString End Sub #End Region #Region " AGREGAR " Protected Sub btnAgregar_Click(sender As Object, e As EventArgs) Handles LbAgregar.Click BtnAgregarPS(txtCantidad.Text.ToDecimal) End Sub Protected Sub BtnSerieAddNew_Click(sender As Object, e As EventArgs) BtnAgregarPS(1) End Sub Private Sub BtnAgregarPS(Cantidad As Decimal) Dim CveProducto As Integer = DdlProducto2.SelectedValue.ToEntero Dim FuncionalidadSinSerie = True If CveProducto > 0 Then If TxtnSerieLote.Visible Then Cantidad = 1 If TxtnSerieLote.Text = "" Then Alert("Serie-Lote es necesario", TipoMensaje.MsgAdvertencia) RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") Exit Sub End If If txtCantidad.Text.ToDouble > 1 Then FuncionalidadSinSerie = False End If End If Dim DrPS As DataRow = Nothing DrPS = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CveProducto).FiltroPrimero("") ' Estado = -1 If Cantidad > 0 AndAlso DrPS("VentaMinima").ToString.ToDecimal > 0 Then 'verifico que la cantidad sea multiplo de venta minima, es decir ventaminima =5, solo puede vender 5,10,15... If Cantidad Mod DrPS("VentaMinima").ToString.ToDecimal <> 0 Then Alert(String.Format("El producto se vende solo en cantidades de {0:#,###.####}", DrPS("VentaMinima"))) Exit Sub End If End If Dim Valido = ValidaExistencia(Cantidad, CveProducto, DdlUnidad.SelectedValue.ToEntero, If(TxtnSerieLote.Visible, TxtnSerieLote.Text, "-1"), If(TxtnLote.Visible, TxtnLote.Text, "-1"), If(TxtnBatch.Visible, TxtnBatch.Text, "-1")) If Valido Then AgregarPS(Cantidad, CveProducto, DdlUnidad.SelectedValue.ToEntero, TxtnObservaciones.Text, If(TxtnSerieLote.Visible, TxtnSerieLote.Text, ""), If(TxtnLote.Visible, TxtnLote.Text, ""), If(TxtnBatch.Visible, TxtnBatch.Text, ""), FuncionalidadSinSerie) End If End If End Sub Private Function ValidaExistencia(Cantidad As Double, CvePS As Integer, CveUnidadMedida As Integer, Optional SerieLote As String = "-1", Optional Lote As String = "-1", Optional Batch As String = "-1") As Boolean Dim Retorno = True Dim Inv As New ClsInventarios Dim Existencia As Double = Inv.GetExistenciasPS(CvePS, CveUnidadMedida, UsuarioActual.CveEmpresa, DdlAlmacenOrigen.SelectedValue.ToEntero, FechaMovto:=TxtFecha.Text.ToDate.ToString("yyyy/MM/dd 23:59"), SerieLote:=SerieLote, Lote:=Lote, Batch:=Batch, PendientePorSurtir:=1) Inv.Dispose() If Existencia - Cantidad - DtMovimientos.SUM("Cantidad", $"CvePS = {CvePS} AND CveUM = {CveUnidadMedida} {If(SerieLote <> "-1", $" AND SerieLote = '{SerieLote}'", "")}") < 0 Then If Existencia < 0 Then Alert("No hay existencia del producto", TipoMensaje.MsgAdvertencia) RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") Else Alert(String.Format("Solo hay en existencia: {0}", Existencia), TipoMensaje.MsgAdvertencia) RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") End If Retorno = False End If Return Retorno End Function Private Sub AgregarPS(Cantidad As Double, CvePS As Integer, CveUnidadMedida As Integer, Optional Observaciones As String = "", Optional SerieLote As String = "", Optional Lote As String = "", Optional Batch As String = "", Optional Limpia As Boolean = True) If Cantidad <= 0 Then Alert("La cantidad debe ser mayor a cero (0). Por favor verifique y vuelva a intentar", TipoMensaje.MsgAdvertencia) RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") End If Dim CveClasificacion As Integer Dim DrPS As DataRow = GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=CvePS).FiltroPrimero("") If DrPS IsNot Nothing Then CveClasificacion = DrPS("CveClasificacion").ToString.ToEntero Dim DrUM = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa).FiltroPrimero($"CveUnidadMedida = {CveUnidadMedida}") Dim registro As DataRow = DtMovimientos.NewRow registro.Item("Cantidad") = Cantidad registro.Item("CveUM") = CveUnidadMedida registro.Item("UM") = DrUM("UnidadMedida") registro.Item("UnidadMedida") = DrUM("UnidadMedida") registro.Item("CvePS") = CvePS registro.Item("PS") = DrPS("PSCodigo") registro.Item("Observaciones") = Observaciones registro.Item("SerieLote") = SerieLote registro.Item("Lote") = Lote registro.Item("Batch") = Batch registro.Item("CveClasificacion") = CveClasificacion registro.Item("CveAF") = -1 registro.Item("EstatusExistencia") = "1" registro.Item("TotalImporte") = 0 registro.Item("PU") = 0 registro.Item("Descuento") = 0 registro.Item("SATClaveUM") = DrPS("SATClaveUnidadMedida") registro.Item("SATClaveProdServ") = DrPS("SATClavePS") registro.Item("Noidentificacion") = DrPS("Codigo") registro.Item("CuentaPredial") = "" registro.Item("Obs") = "" registro.Item("ImporteIVA") = 0 registro.Item("PorcentajeIVA") = 0 DtMovimientos.Rows.Add(registro) RegistraScript("playsonidito('beep-07.wav')") CargaGvDatos() If Limpia Then LimpiaAgregar() Else txtCantidad.Text = (txtCantidad.Text.ToDouble - 1.0).ToString TxtnSerieLote.Text = "" TxtnSerieLote.Focus() End If End Sub Private Sub LimpiaAgregar() DdlClasificacion.SelectedValue = "-1" DdlClasificacion_SelectedIndexChanged(DdlClasificacion, EventArgs.Empty) txtCantidad.Text = "" TxtnObservaciones.Text = "" TxtnSerieLote.Text = "" TxtnSerieLote.Visible = False TxtnLote.Text = "" TxtnBatch.Text = "" txtCantidad.Focus() If TxtCodigoPS.Visible Then TxtCodigoPS.Focus() End If End Sub #End Region #Region " GUARDAR " Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click 'VALIDA ALMACEN ORIGEN Y DESTINO If DdlAlmacenOrigen.SelectedValue = DdlAlmacenDestino.SelectedValue Then Alert("No se puede realizar un traspaso entre el mismo almacén.", TipoMensaje.MsgAdvertencia) Exit Sub End If 'VALIDA TRANSITORIO If ChkTransitorio.Checked Then If TxtResponsable.Text.Trim = "" Then Alert("Debe seleccionar un responsable para el traspaso transitorio.", TipoMensaje.MsgAdvertencia) RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") If ChkTransitorio.Checked Then RegistraScript("$('#DivTransitorio').show(200);") Exit Sub End If If DdlAlmacenTransitorio.SelectedValue.ToEntero <= 0 Then Alert("Debe seleccionar un almacen transitorio.", TipoMensaje.MsgAdvertencia) RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") If ChkTransitorio.Checked Then RegistraScript("$('#DivTransitorio').show(200);") Exit Sub End If End If 'VALIDA ALMACEN DISTINTA SUCURSAL DEBE SER TRANSITORIO If Not UsuarioActual.CveEmpresa.Contiene(7, 140) Then '[IPP] EMPRESA VIGILANCIA NO OCUPA TRANSITORIOS - TIENEN MIL SUCURSALES Xd If Not ChkTransitorio.Checked Then Dim CveSucursalOrigen = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", $"CveAlmacen = {DdlAlmacenOrigen.SelectedValue.ToEntero}") Dim CveSucursalDestino = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", $"CveAlmacen = {DdlAlmacenDestino.SelectedValue.ToEntero}") If GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveTipoAlmacen", $"CveAlmacen = {DdlAlmacenDestino.SelectedValue.ToEntero}").ToEntero <> 21 Then 'NO SE VALIDA CUANDO EL TIPO DE ALMACEN DESTINO ES DE DEVOLUCION If CveSucursalOrigen <> CveSucursalDestino Then Alert("Por ser un traspaso entre sucursales es necesario indicar que el traspaso es transitorio.", TipoMensaje.MsgAdvertencia) RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'');", "SonidoError") ChkTransitorio.Checked = True If ChkTransitorio.Checked Then RegistraScript("$('#DivTransitorio').show(200);", "MuestraDivTransitorio") Exit Sub End If End If End If End If 'VALIDA QUE TENGA MOVTOS If Not GvDatos.Rows.Count > 0 Then Alert("No hay movimientos para el traspaso", TipoMensaje.MsgAdvertencia) RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") Exit Sub End If 'VALIDA ESTATUS EXISTENCIA For Each dr As DataRow In DtMovimientos.Rows If dr("EstatusExistencia").ToString = "-1" Then Alert("Tiene que rectificar los movimientos con error.", TipoMensaje.MsgError) If ChkTransitorio.Checked Then RegistraScript("$('#DivTransitorio').show(200);") Exit Sub End If Next Dim ObjInventario As New ClsInventarios 'VALIDA LA EXISTENCIA DEL ALMACEN DE ORIGEN Dim ErrorExistencia = False Dim TextoExistencia As StringBuilder = New StringBuilder Dim Existencia As Double TextoExistencia.Append("Los siguiente productos se ajustaron por falta de exitencia:
") If Not CargadoDeMov Then For Each dr As DataRow In DtMovimientos.Rows Existencia = ObjInventario.GetExistenciasPS(dr("CvePS").ToString.ToEntero, dr("CveUM").ToString.ToEntero, UsuarioActual.CveEmpresa, DdlAlmacenOrigen.SelectedValue.ToEntero, FechaMovto:=TxtFecha.Text.ToDate.ToString("yyyy/MM/dd 23:59"), SerieLote:=If(dr("SerieLote").ToString = "", "-1", dr("SerieLote").ToString), PendientePorSurtir:=1) Existencia -= DtMovimientos.SUM("Cantidad", $"CvePS = {dr("CvePS").ToString.ToEntero} AND CveUM = {dr("CveUM").ToString.ToEntero} {If(dr("SerieLote").ToString <> "-1", $" AND SerieLote = '{dr("SerieLote").ToString}'", "")}") 'DtMovimientos.SUM("Cantidad", String.Format("CvePS = {0}", dr("CvePS").ToString.ToEntero)) If Existencia < 0 Then ErrorExistencia = True dr("EstatusExistencia") = "-1" dr("Cantidad") = Existencia 'If Existencia <= 0 Then TextoExistencia.AppendFormat("- #{0} {1}
", dr("No").ToString, dr("PS").ToString) 'Else 'Alert(String.Format("Solo hay en existencia: {0}", Existencia), TipoMensaje.MsgError) 'End If End If Next Else For Each gvr As GridViewRow In GvDatos.Rows Existencia = ObjInventario.GetExistenciasPS(gvr.DataKey("CvePS").ToString.ToEntero, gvr.DataKey("CveUM").ToString.ToEntero, UsuarioActual.CveEmpresa, DdlAlmacenOrigen.SelectedValue.ToEntero, FechaMovto:=TxtFecha.Text.ToDate.ToString("yyyy/MM/dd 23:59"), SerieLote:=If(gvr.DataKey("SerieLote").ToString = "", "-1", gvr.DataKey("SerieLote").ToString), PendientePorSurtir:=1) Existencia -= gvr.FCTextBox("TxtCantidad2").Text.ToEntero If Existencia < 0 Then ErrorExistencia = True gvr.FCTextBox("TxtCantidad2").Text = (Existencia + gvr.FCTextBox("TxtCantidad2").Text.ToEntero).ToString TextoExistencia.AppendFormat("- #{0} {1}
", gvr.DataKey("No").ToString, gvr.DataKey("PS").ToString) End If Next End If If ErrorExistencia Then Alert(TextoExistencia.ToString, TipoMensaje.MsgError) RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") ObjInventario.Dispose() Exit Sub End If Dim TotalCantidad As Decimal = DtMovimientos.SUMD("Cantidad") If UsuarioActual.Empresa.Funcionalidad(563) = "1" Then If TotalCantidad <> DtSeccionAlmacen.FiltraParametros("TipoSeccionAlmacen = 1").SUMD("CantidadSeccionAlmacen") Then Alert("La seccion de almacen no ha sido agregada completamente.", TipoMensaje.MsgAdvertencia) Exit Sub End If End If Dim TipoAlmacenOrigen = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveTipoAlmacen", $"CveAlmacen = {DdlAlmacenOrigen.SelectedValue.ToEntero}").ToEntero Dim TipoAlmacenDestino = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveTipoAlmacen", $"CveAlmacen = {DdlAlmacenDestino.SelectedValue.ToEntero}").ToEntero ''[IPP-1Noviembre2018] SE COMENTA PORQUE NO TIENE NI PIES NI CABEZA. LE FALTA DESARROLLO 'If (TipoAlmacenOrigen = 14 Or TipoAlmacenDestino = 14) And TipoAlmacenOrigen <> TipoAlmacenDestino Then ' ObjInventario.Dispose() ' 'es consumo interno ' ConsumoInterno(TipoAlmacenOrigen, TipoAlmacenDestino) 'End If 'Inicia la transacción Dim ObjConta As New ClsContabilidad(ObjInventario.IniciaTransacSQL()) Dim CveMovimientoSalida = 0 Dim CveMovimientoEntrada = 0 Dim IDPoliza As Integer = 0 Dim FolioSalida = 0 Dim CveMovimientoVirtualEntrada As Integer = 0 Dim CveMovimientoVirtualSalida As Integer = 0 Dim FolioVirtualEntrada As Integer = 0 Dim FolioVirtualSalida As Integer = 0 Dim FolioEntrada = 0 Dim AlmacenEntrada = -1 Dim Fecha As Date = TxtFecha.Text.ToDate Dim ErrorMovInv As Boolean = False Dim ErrorAC As Boolean = False Dim TextoError = "" Dim TipoMovimientoSalida = If(ChkTransitorio.Checked, 26, If(TipoAlmacenOrigen = 24, 26, 8)) 'AGREGAMOS LA SALIDA DEL ALMACEN ORIGEN CveMovimientoSalida = ObjInventario.AddMovimiento(DdlAlmacenOrigen.SelectedValue.ToEntero, TipoMovimientoSalida, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, Recibio:=If(ChkTransitorio.Checked, TxtResponsable.Text.Trim, "-1"), CveAlmacenDestino:=DdlAlmacenDestino.SelectedValue.ToEntero, GastoIndirecto:=If(ChkTransitorio.Checked And TxtGastoIndirecto.Text.ToDouble > 0, TxtGastoIndirecto.Text, "-1").ToDouble, CveChofer:=If(ChkTransitorio.Checked, DldChofer.SelectedValue.ToEntero, -1), Placa:=If(ChkTransitorio.Checked, TxtPlaca.Text.Trim, "-1"), FechaEntrega:=If(ChkTransitorio.Checked, TxtFechaEntrega.Text.Trim.ToDateTime.ToString("dd/MM/yyyy"), "-1"), EspecifUnidad:=If(ChkTransitorio.Checked, TxtEspecifUnidad.Text.Trim, "-1"), ResponsableCarga:=If(ChkTransitorio.Checked, TxtResponsableCarga.Text.Trim, "-1"), ResponsableRecibio:=If(ChkTransitorio.Checked, TxtResponsableRecibio.Text.Trim, "-1"), Identificacion:=If(ChkTransitorio.Checked, TxtIdentificacion.Text.Trim, "-1"), Domicilio:=If(ChkTransitorio.Checked, TxtDomicilio.Text.Trim, "-1"), Telefono:=If(ChkTransitorio.Checked, TxtTelefono.Text.Trim, "-1"), Ciudad:=If(ChkTransitorio.Checked, TxtCiudad.Text.Trim, "-1"), Licencia:=If(ChkTransitorio.Checked, TxtLicencia.Text.Trim, "-1"), Modulo:="TA/G") FolioSalida = ObjInventario.Folio Folio = ObjInventario.Folio If CveMovimientoSalida <= 0 Then TextoError = "Ocurrió un error al generar el movimiento de salida" ErrorMovInv = True Else Dim Cont As Integer = 0 For Each Dr As DataRow In DtMovimientos.Rows If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, Dr("Cantidad").ToString.ToDouble, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, 0, Dr("CveAF").ToString.ToEntero, -1, Dr("SerieLote").ToString, Lote:=Dr("Lote").ToString, Batch:=Dr("Batch").ToString, Observaciones:=Dr("Observaciones").ToString) Then ErrorMovInv = True TextoError = "Ocurrió un error al guardar los movimientos de salida" Exit For Else If ObjInventario.CveMovimientoDetalle > 0 AndAlso DtSeccionAlmacen.Rows.Count > 0 Then For Each Dr2 As DataRow In DtSeccionAlmacen.FiltraParametros($"IndexSeccionAlmacen = {Cont} AND TipoSeccionAlmacen = 1").Rows If Not ObjInventario.AddMovimientosDetalleSeccionesAlmacen(ObjInventario.CveMovimientoDetalle, Dr2("CveSeccionAlmacenOrigen").ToString.ToEntero, -Dr2("CantidadSeccionAlmacen").ToString.ToDecimal) Then ErrorMovInv = True TextoError = "Ocurrió un error al procesar las secciones de almacen. Por favor vuelva a intentar." Exit For End If Next End If End If Cont += 1 Next End If 'VIRTUAL SALIDA If UsuarioActual.Empresa.Funcionalidad(573) = "1" Then Dim CveSubProyecto As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", $"CveAlmacen= {DdlAlmacenOrigen.SelectedValue}").ToEntero() Dim CveAlmacenVirtual As Integer = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 24).FiltroPrimeroValor("CveAlmacen", $"CveSubProyecto={CveSubProyecto}").ToEntero() CveMovimientoVirtualSalida = ObjInventario.AddMovimiento(CveAlmacenVirtual, 3, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, Modulo:="TA/V", CveMovimientoRelacionado:=CveMovimientoSalida) FolioVirtualSalida = ObjInventario.Folio Dim dtvirtual As DataTable = Nothing If ObjInventario.GetMovimientosDetalleVirtual(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then dtvirtual = ObjInventario.DtResultados For Each RowVirtual As DataRow In dtvirtual.Rows Dim CvePS = RowVirtual("CvePS").ToString().ToEntero() Dim CantidadUsado As Double = RowVirtual("Cantidad").ToString().ToDouble() Dim PU As Double = RowVirtual("PU").ToString().ToDouble() Dim CveUM As Integer = RowVirtual("CveUM").ToString().ToEntero() If Not ObjInventario.AddMovimientoDetalle(CveMovimientoVirtualSalida, CantidadUsado, CveUM, CvePS, PU, -1, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then ErrorMovInv = True Exit For End If Next Else ErrorMovInv = True End If End If 'AGREGAMOS LA ENTRADA If Not ChkTransitorio.Checked Then 'SI NO ES TRANSITORIO SE HACE LA RECEPCION DE INMEDIATO If Not ErrorMovInv Then Dim TipoMovimientoEntrada = 9 AlmacenEntrada = If(ChkTransitorio.Checked, DdlAlmacenTransitorio.SelectedValue.ToEntero, DdlAlmacenDestino.SelectedValue.ToEntero) CveMovimientoEntrada = ObjInventario.AddMovimiento(AlmacenEntrada, TipoMovimientoEntrada, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, Recibio:=If(ChkTransitorio.Checked, TxtResponsable.Text.Trim, "-1"), CveAlmacenDestino:=If(ChkTransitorio.Checked, DdlAlmacenDestino.SelectedValue.ToEntero, -1), CveMovimientoRelacionado:=CveMovimientoSalida, Modulo:="TA/G") FolioEntrada = ObjInventario.Folio If CveMovimientoEntrada <= 0 Then TextoError = "Ocurrió un error al generar el movimiento de entrada" ErrorMovInv = True Else If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then Dim Cont As Integer = 0 For Each Dr As DataRow In ObjInventario.DtResultados.Rows If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Dr("Cantidad").ToString.ToDouble, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, Dr("PU").ToString.ToDouble, Dr("CveAF").ToString.ToEntero, -1, Dr("SerieLote").ToString, CveMovimientoDetalleEntrada:=Dr("CveMovimientoDetalle").ToString.ToEntero, Lote:=Dr("Lote").ToString, Batch:=Dr("Batch").ToString, Observaciones:=Dr("Observaciones").ToString) Then ErrorMovInv = True TextoError = "Ocurrió un error al guardar los movimientos de entrada" Exit For Else If ObjInventario.CveMovimientoDetalle > 0 AndAlso DtSeccionAlmacen.Rows.Count > 0 Then For Each Dr2 As DataRow In DtSeccionAlmacen.FiltraParametros($"IndexSeccionAlmacen = {Cont} AND TipoSeccionAlmacen = 1").Rows If Not ObjInventario.AddMovimientosDetalleSeccionesAlmacen(ObjInventario.CveMovimientoDetalle, Dr2("CveSeccionAlmacenDestino").ToString.ToEntero, Dr2("CantidadSeccionAlmacen").ToString.ToDecimal) Then ErrorMovInv = True TextoError = "Ocurrió un error al procesar las secciones de almacen. Por favor vuelva a intentar." Exit For End If Next End If End If Cont += 1 Next End If End If 'VIRTUAL ENTRADA If UsuarioActual.Empresa.Funcionalidad(573) = "1" Then Dim CveSubProyecto As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", $"CveAlmacen= {DdlAlmacenDestino.SelectedValue}").ToEntero() Dim CveAlmacenVirtual As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveAlmacen", $" CveTipoAlmacen =24 AND CveSubProyecto={CveSubProyecto}").ToEntero() CveMovimientoVirtualEntrada = ObjInventario.AddMovimiento(CveAlmacenVirtual, 2, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, Modulo:="TA/S") FolioVirtualEntrada = ObjInventario.Folio Dim dtvirtual As DataTable = Nothing If CveMovimientoVirtualEntrada > 0 AndAlso ObjInventario.GetMovimientosDetalleVirtual(CveMovimientoEntrada, UsuarioActual.CveEmpresa) Then dtvirtual = ObjInventario.DtResultados For Each RowVirtual As DataRow In dtvirtual.Rows Dim CvePS = RowVirtual("CvePS").ToString().ToEntero() Dim CantidadUsado As Double = RowVirtual("Cantidad").ToString().ToDouble() Dim PU As Double = RowVirtual("PU").ToString().ToDouble() Dim CveUM As Integer = RowVirtual("CveUM").ToString().ToEntero() If Not ObjInventario.AddMovimientoDetalle(CveMovimientoVirtualEntrada, CantidadUsado, CveUM, CvePS, PU, -1, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then ErrorMovInv = True Exit For End If Next Else ErrorMovInv = True End If End If End If End If ''[IPP-1Noviembre2018] SE COMENTA PORQUE NO TIENE NI PIES NI CABEZA. LE FALTA DESARROLLO ''CONSUMO INTERNO 'If Not ErrorMovInv Then ' If (TipoAlmacenOrigen = 14 Or TipoAlmacenDestino = 14) And TipoAlmacenOrigen <> TipoAlmacenDestino Then ' ConsumoInterno(TipoAlmacenOrigen, TipoAlmacenDestino) ' End If 'End If If Not ErrorMovInv Then DtTraslado = DtMovimientos.Copy ObjInventario.Commit() MensajeAlert = New StringBuilder MensajeAlert.Append("Se realizó con éxito el traspaso.") MensajeAlert.AppendFormat("
Folio de Salida: {0}", FolioSalida, CveMovimientoSalida) MensajeAlert.AppendFormat("
Imprimir Reporte", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoSalida))) If CveMovimientoVirtualSalida > 0 Then MensajeAlert.AppendFormat("
Folio: {2} Imprimir Salida Virtual", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoVirtualSalida)), CveMovimientoVirtualSalida, FolioVirtualSalida) If Not ChkTransitorio.Checked Then MensajeAlert.AppendFormat("

Folio de Entrada: {0}", FolioEntrada, CveMovimientoEntrada) MensajeAlert.AppendFormat("
Imprimir Reporte", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoEntrada))) If CveMovimientoVirtualEntrada > 0 Then MensajeAlert.AppendFormat("
Folio: {2} Imprimir Entrada Virtual", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoVirtualEntrada)), CveMovimientoVirtualEntrada, FolioVirtualEntrada) End If 'DdlClasificacion.SelectedValue = "-1" 'DdlClasificacion_SelectedIndexChanged(DdlClasificacion, EventArgs.Empty) If ChkEmitirTimbrado.Checked Then CveMovimientoTimbrado = CveMovimientoSalida : Timbrar() Alert(MensajeAlert.ToString, TipoMensaje.MsgInformacion, "") If ChkTransitorio.Checked AndAlso UsuarioActual.CveEmpresa.Contiene(72, 80) Then RegistraScript(String.Format("AbrirVentana('/General/PopUpPaqueteriasGuias.aspx?CveMovimiento={0}',800,620);", CveMovimientoSalida)) End If If UsuarioActual.CveEmpresa.Contiene(72, 80) Then Dim Correo As String = "jorgegonzalez@compuproveedores.com" If GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveTipoAlmacen", $"CveAlmacen = {DdlAlmacenDestino.SelectedValue.ToEntero}").ToEntero = 16 Then MandaCorreo(CveMovimientoSalida, Correo) End If End If LimpiaMovimiento() Else ObjInventario.RollBack() Alert(TextoError, TipoMensaje.MsgError) RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") End If ' If ObjContaAC IsNot Nothing Then ObjContaAC.Dispose() 'SI OCURRIO UN ERROR EN LA EXISTENCIA RECARGAMOS EL GRID PARA COLOREAR LOS DETALLES CON ERROR If ErrorExistencia Then CargaGvDatos() End If ObjInventario.Dispose() End Sub Function ConsumoInterno(TipoAlmacenOrigen As Integer, TipoAlmacenDestino As Integer) As Boolean Dim Retorno As Boolean = False Dim ErrorMovInv As Boolean = False Dim TextoError As String = "" Dim Fecha As Date = TxtFecha.Text.ToDate Dim ObjInventario As New ClsInventarios Dim ObjConta As New ClsContabilidad(ObjInventario.IniciaTransacSQL()) Dim CveMovimiento As Integer = 0 Dim TipoMovto = If(TipoAlmacenOrigen = 14, -1, 1) Dim CveConceptoInventario As Integer = 8 Dim CveAlmacenCI = If(TipoAlmacenOrigen = 14, DdlAlmacenOrigen.SelectedValue.ToEntero, DdlAlmacenDestino.SelectedValue.ToEntero) Dim DtCostos As DataTable = Nothing Dim ValorInventario As Decimal = 0 'AGREGAMOS LA SALIDA DEL ALMACEN ORIGEN CveMovimiento = ObjInventario.AddMovimiento(DdlAlmacenOrigen.SelectedValue.ToEntero, CveConceptoInventario, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, Recibio:=If(ChkTransitorio.Checked, TxtResponsable.Text.Trim, ""), GastoIndirecto:=If(ChkTransitorio.Checked And TxtGastoIndirecto.Text.ToDouble > 0, TxtGastoIndirecto.Text, "-1").ToDouble, Modulo:="TA/G") Dim FolioMov As Integer = ObjInventario.Folio If CveMovimiento <= 0 Then TextoError = "No se pudo generar el movimiento de salida correctamente" ErrorMovInv = True Else For Each Dr As DataRow In DtMovimientos.Rows If Not ObjInventario.AddMovimientoDetalle(CveMovimiento, Dr("Cantidad").ToString.ToDouble, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, 0, Dr("CveAF").ToString.ToEntero, -1, Dr("SerieLote").ToString, Lote:=Dr("Lote").ToString, Batch:=Dr("Batch").ToString) Then ErrorMovInv = True TextoError = "Ocurrió un error al guardar los movimientos de salida" Exit For End If Next End If If ObjInventario.GetMovimientosDetalle(CveMovimiento, UsuarioActual.CveEmpresa) Then DtCostos = ObjInventario.DtResultados Dim tmpCostos As DataTable = DtCostos.FiltraParametros("", "", {"CveClasificacion"}) Dim IdCtaContable As Integer = 0 Dim CveCuenta As Integer = 0 If tmpCostos.Rows.Count > 0 Then Dim Concepto As String = $"Consumo Interno: {ObjInventario.Folio} - {TxtObservaciones.Text}" Dim CvePrePoliza = ObjConta.AddPrePolizas("Inv/ConsumoInterno", 53, DtCostos.SUM("Total") * TipoMovto, DtCostos.SUM("Total") * TipoMovto, 1, TxtFecha.Text.ToDate, $"Consumo Interno: {TxtObservaciones.Text}", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) For Each RowInv As DataRow In tmpCostos.Rows ValorInventario = DtCostos.SUM("Total", $"CveClasificacion = {RowInv("CveClasificacion")}").ToString.ToDecimal IdCtaContable = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGasto", $"CveClasificacion = {RowInv("CveClasificacion")}").ToEntero CveCuenta = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCuentaGastoSIG", $"CveClasificacion = {RowInv("CveClasificacion")}").ToEntero If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, ValorInventario * TipoMovto, Concepto, 181, Concepto, TxtFecha.Text.ToDate, IdCtaContable, -1, CveClasificacion:=RowInv("CveClasificacion").ToString.ToEntero, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=ValorInventario * TipoMovto, CveCuenta:=CveCuenta) Then ErrorMovInv = True Exit For End If Next IdCtaContable = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContable", $"CveAlmacen={CveAlmacenCI}").ToEntero CveCuenta = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("IdCtaContableSIG", $"CveAlmacen={CveAlmacenCI}").ToEntero If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, DtCostos.SUM("Total").ToDecimal * TipoMovto, Concepto, 68, Concepto, TxtFecha.Text.ToDate, IdCtaContable, -1, CveMovimientoAlmacen:=CveMovimiento, ImporteMX:=DtCostos.SUM("Total").ToDecimal * TipoMovto, CveCuenta:=CveCuenta) Then ErrorMovInv = True End If End If End If If Not ErrorMovInv Then ObjInventario.Commit() Dim Mensaje As StringBuilder = New StringBuilder Mensaje.Append("Se realizó el consumo interno.") Mensaje.AppendFormat("
Folio: {0}", FolioMov, CveMovimiento) Alert(Mensaje.ToString, TipoMensaje.MsgInformacion) LimpiaMovimiento() Else ObjInventario.RollBack() Alert(TextoError, TipoMensaje.MsgError) RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") End If Return Retorno End Function #End Region #Region " NUEVO - LIMPIA " Protected Sub BtnNuevo_Click(sender As Object, e As EventArgs) LimpiaMovimiento() End Sub Private Sub LimpiaMovimiento() CargaAlmacenOrigen() TxtResponsable.Text = "" TxtFecha.Text = Now.ToShortDateString TxtObservaciones.Text = "" txtCantidad.Text = "" SiguienteFolio(If(ChkTransitorio.Checked, 9, 8)) ChkTransitorio.Checked = False ChkTransitorio.Enabled = True TxtGastoIndirecto.Text = "" TxtPlaca.Text = "" TxtEspecifUnidad.Text = "" DtSeccionAlmacen.Rows.Clear() TxtResponsableCarga.Text = "" TxtResponsableRecibio.Text = "" TxtIdentificacion.Text = "" TxtDomicilio.Text = "" TxtTelefono.Text = "" TxtCiudad.Text = "" TxtLicencia.Text = "" DivMov.Visible = False CargadoDeMov = False UPDatosAlmacen.Update() UpMov.Update() DtMovimientos.Rows.Clear() CargaGvDatos() End Sub #End Region #Region "DDL CLASIFICACION" Protected Sub DdlClasificacion_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DdlClasificacion.SelectedIndexChanged ChangeDdlProducto() End Sub Private Sub ChangeDdlProducto() If UsuarioActual.Empresa.Funcionalidad(105) = "" Then DdlProducto2.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=DdlClasificacion.SelectedValue.ToEntero).FiltraParametros("", "PSCodigo") DdlProducto2.DataBind() DdlProducto2.ddl.Items.Insert(0, New ListItem(" ", "-1")) Else DdlProducto2.ddlWS.Attributes.Add("data-cveclasificacion", DdlClasificacion.SelectedValue) DdlProducto2.SelectedText = "" DdlProducto2.SelectedValue = "-1" End If End Sub Protected Sub DdlProducto_ValueChanged(sender As Object, e As EventArgs) Handles DdlProducto2.selectedindexchange ElProductoChange() End Sub Private Sub ElProductoChange() TxtnSerieLote.Visible = False TxtnLote.Visible = False TxtnBatch.Visible = False EscondeColumnasGVM(DtMovimientos) If DdlProducto2.SelectedValue.ToEntero > 0 Then If GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlProducto2.SelectedValue.ToEntero).FiltraParametros("Inv_CveMetodoInventario = 5 ", "PS").Rows.Count > 0 Then ThSerieLote.Visible = True TdSerieLote.Visible = True TxtnSerieLote.Visible = True GvDatos.Columns(5).Visible = True End If If GlobalDTPS(UsuarioActual.CveEmpresa, CvePS:=DdlProducto2.SelectedValue.ToEntero).FiltraParametros("Inv_CveMetodoInventario = 6", "PS").Rows.Count > 0 Then TxtnLote.Visible = True ThLote.Visible = True TdLote.Visible = True GvDatos.Columns(6).Visible = True TxtnBatch.Visible = True ThBatch.Visible = True TdBatch.Visible = True GvDatos.Columns(7).Visible = True End If End If DdlUnidad.Items.Clear() DdlUnidad.DataSource = GlobalDTProductosServiciosEquivalencias(DdlProducto2.SelectedValue.ToEntero, -1, UsuarioActual.CveEmpresa) DdlUnidad.DataBind() UpDatos.Update() End Sub Private Function isWhitFamily() As Boolean Return (UsuarioActual.CveEmpresa = 66) End Function Protected Sub DdlClasificacion_GV(sender As Object, e As System.EventArgs) Dim pDdlClasificacion As DropDownList = CType(sender, DropDownList) Dim pDdlProducto As DropDownList = CType(pDdlClasificacion.NamingContainer.FindControl("DdlProducto"), DropDownList) If pDdlClasificacion.SelectedValue = "-1" Then pDdlProducto.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa) pDdlProducto.DataBind() Else pDdlProducto.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=pDdlClasificacion.SelectedValue.ToEntero) pDdlProducto.DataBind() End If If pDdlClasificacion.SelectedValue = "-1" Then pDdlProducto.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa) Else pDdlProducto.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=DdlClasificacion.SelectedValue.ToEntero) End If pDdlProducto.DataBind() pDdlProducto.Items.Insert(0, New ListItem("----", "-1")) End Sub #End Region #Region "GV DATOS" Private Sub CargaGvDatos() EscondeColumnasGVM(DtMovimientos) GvDatos.DataSource = DtMovimientos GvDatos.DataBind() UpDatos.Update() End Sub Private Sub EscondeColumnasGVM(DtTemp As DataTable) TxtnSerieLote.Visible = False ThSerieLote.Visible = False TdSerieLote.Visible = False GvDatos.Columns(5).Visible = False TxtnLote.Visible = False ThLote.Visible = False TdLote.Visible = False GvDatos.Columns(6).Visible = False TxtnBatch.Visible = False ThBatch.Visible = False TdBatch.Visible = False GvDatos.Columns(7).Visible = False If DtTemp.MAX("SerieLote").ToString <> "" Then TxtnSerieLote.Visible = True ThSerieLote.Visible = True TdSerieLote.Visible = True GvDatos.Columns(5).Visible = True End If If DtTemp.MAX("Lote").ToString <> "" Then TxtnLote.Visible = True ThLote.Visible = True TdLote.Visible = True GvDatos.Columns(6).Visible = True TxtnBatch.Visible = True ThBatch.Visible = True TdBatch.Visible = True GvDatos.Columns(7).Visible = True End If End Sub Protected Sub GvDatos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDatos.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.DBCampo("EstatusExistencia").ToEntero < 0 Then e.Row.Cells(0).BackColor = Drawing.Color.Red End If If CargadoDeMov Then e.Row.FCLiteral("ltlCantidad").Visible = False e.Row.FCTextBox("TxtCantidad2").Visible = True e.Row.FCTextBox("TxtCantidad2").Attributes.Add("onblur", String.Format("ValidaCantidad(this,{0})", e.Row.DBCampo("Cantidad"))) End If If DtSeccionAlmacen.FiltraParametros($"IndexSeccionAlmacen = {e.Row.RowIndex}").SUMD("CantidadSeccionAlmacen") > 0 Then e.Row.FCLinkButton("lnkRemove").Visible = False e.Row.FCLinkButton("lnkRemove").ToolTip = "Cuenta con sección almacen" End If 'If If(e.Row.DBCampo("SerieLote").ToString = "", "-1", e.Row.DBCampo("SerieLote").ToString) <> "-1" Then ' TxtnSerieLote.Visible = True ' ThSerieLote.Visible = True ' TdSerieLote.Visible = True ' GvDatos.Columns(4).Visible = True ' e.Row.Cells(4).Text = e.Row.DBCampo("SerieLote").ToString 'Else ' e.Row.Cells(4).Text = "" 'End If 'If If(e.Row.DBCampo("Lote").ToString = "", "-1", e.Row.DBCampo("Lote").ToString) <> "-1" Then ' TxtnLote.Visible = True ' ThLote.Visible = True ' TdLote.Visible = True ' GvDatos.Columns(5).Visible = True ' e.Row.Cells(5).Text = e.Row.DBCampo("Lote").ToString ' TxtnBatch.Visible = True ' ThBatch.Visible = True ' TdBatch.Visible = True ' GvDatos.Columns(6).Visible = True ' e.Row.Cells(6).Text = e.Row.DBCampo("Batch").ToString 'Else ' e.Row.Cells(5).Text = "" ' e.Row.Cells(6).Text = "" 'End If 'If e.Row.RowState = DataControlRowState.Edit Then ' e.Row.FCDropDownList("DdlUnidad").DataSource = GlobalDTUnidadesMedida(UsuarioActual.CveEmpresa) ' e.Row.FCDropDownList("DdlUnidad").DataBind() ' e.Row.FCDropDownList("DdlUnidad").SelectedValue = e.Row.DBCampo("CveUM") ' e.Row.FCDropDownList("DdlClasificacion").DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa) ' e.Row.FCDropDownList("DdlClasificacion").DataBind() ' e.Row.FCDropDownList("DdlClasificacion").SelectedValue = e.Row.DBCampo("CveClasificacion") ' e.Row.FCDropDownList("DdlProducto").DataSource = GlobalDTProductosServicios(UsuarioActual.CveEmpresa) ' e.Row.FCDropDownList("DdlProducto").DataBind() ' e.Row.FCDropDownList("DdlProducto").SelectedValue = e.Row.DBCampo("CvePS") 'End If End If End Sub Protected Sub GvPS_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GvDatos.RowDeleting Dim DbRow As DataRow = Nothing DbRow = DtMovimientos.Rows(e.RowIndex) DtMovimientos.Rows.Remove(DbRow) CargaGvDatos() End Sub 'Protected Sub GvM_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles GvDatos.RowEditing ' GvDatos.EditIndex = e.NewEditIndex ' CargaGvDatos() 'End Sub 'Protected Sub GvM_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles GvDatos.RowUpdating ' Dim dr = GvDatos.Rows(e.RowIndex) ' Dim Cantidad = dr.FCTextBox("TxtCantidad").Text.ToDouble ' Dim CveUM = dr.FCDropDownList("DdlUnidad").SelectedValue.ToEntero ' Dim CveClasificacion = dr.FCDropDownList("DdlClasificacion").SelectedValue.ToEntero ' Dim CvePS = dr.FCDropDownList("DdlProducto").SelectedValue.ToEntero ' Dim No = dr.DataKey("No").ToEntero ' Dim SerieLote As String = dr.FCTextBox("TxtSerieLote").Text ' 'VALIDA EXISTENCIA ' Dim Valido = True ' Dim Inv As New ClsInventarios ' Dim Existencia As Double = Inv.GetExistenciasPS(CvePS, CveUM, UsuarioActual.CveEmpresa, DdlAlmacenOrigen.SelectedValue.ToEntero, -1, TxtFecha.Text.ToDate.ToString("yyyy/MM/dd 23:59"), If(SerieLote = "", "-1", SerieLote)) ' Inv.Dispose() ' If Existencia - txtCantidad.Text.ToDouble < 0 Then ' If Existencia <= 0 Then ' Alert("No hay existencia del producto", TipoMensaje.MsgError) ' Else ' Alert(String.Format("Solo hay en existencia: {0}", Existencia), TipoMensaje.MsgError) ' End If ' Valido = False ' End If ' If Valido Then ' Dim Drs As DataRow() = DtMovimientos.Select(String.Format("No = {0}", No)) ' If Drs.Count = 1 Then ' Drs(0)("Cantidad") = Cantidad ' Drs(0)("CveUM") = CveUM ' Drs(0)("CveClasificacion") = CveClasificacion ' Drs(0)("CvePS") = CvePS ' Drs(0)("EstatusExistencia") = "1" ' End If ' DtMovimientos.AcceptChanges() ' GvDatos.EditIndex = -1 ' End If ' CargaGvDatos() 'End Sub 'Protected Sub GvM_RowCancelingEdit(sender As Object, e As GridViewCancelEditEventArgs) Handles GvDatos.RowCancelingEdit ' GvDatos.EditIndex = -1 ' CargaGvDatos() 'End Sub #End Region #Region " TRANSITORIO - RECEPCION " Protected Sub ChkTransitorio_CheckedChanged(sender As Object, e As EventArgs) Dim TipoAlmacenOrigen = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveTipoAlmacen", $"CveAlmacen = {DdlAlmacenOrigen.SelectedValue.ToEntero}").ToEntero Dim TipoAlmacenDestino = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveTipoAlmacen", $"CveAlmacen = {DdlAlmacenDestino.SelectedValue.ToEntero}").ToEntero If TipoAlmacenOrigen = 14 Or TipoAlmacenDestino = 14 Then ChkTransitorio.Checked = False Alert("Un traspaso de consumo interno no puede ser transitorio.", TipoMensaje.MsgAdvertencia) Exit Sub End If If ChkTransitorio.Checked Then 'DdlResponsable.SelectedValue = "-1" TxtResponsable.Text = "" TxtGastoIndirecto.Text = "" RegistraScript("$('#DivTransitorio').show(200);$('#DivGastoIndirecto').show(100);$('#DivDocChofer').show(100);") Else RegistraScript("$('#DivTransitorio').hide(500);$('#DivGastoIndirecto').hide(500);$('#DivDocChofer').hide(500);") End If UpModalSeccionAlmacen.Update() SiguienteFolio(If(ChkTransitorio.Checked, 9, 8)) End Sub Protected Sub BtnCargaTransitorios_Click(sender As Object, e As EventArgs) CargaRecepcion() End Sub Private Sub CargaRecepcion() Dim ObjInventarios As New ClsInventarios Dim Dtt As DataTable = Nothing FolioBusqueda = If(TxtFolioRecepcion.Text = "", -1, TxtFolioRecepcion.Text.ToEntero) If ObjInventarios.GetMovimientosTransitorios(DdlAlmacenRecepcion.SelectedValue.ToEntero, -1, DdlAlmacenTransitorioRecepcion.SelectedValue.ToEntero, -1, FolioBusqueda, UsuarioActual.CveEmpresa) Then Dtt = ObjInventarios.DtResultados.FiltraParametros(String.Format("CveTipoAlmacenDestino <> 4")) If TxtFolioRecepcion.Text.Trim <> "" Then CveMovimientoSalida = ObjInventarios.DtResultados.FiltroPrimeroValor("CveMovimiento", "").ToEntero End If CveAlmacenDestino = DdlAlmacenRecepcion.SelectedValue.ToEntero CveAlmacenTransitorio = DdlAlmacenTransitorioRecepcion.SelectedValue.ToEntero 'CveUsuarioResponsable = DdlResponsableRecepcion.SelectedValue.ToEntero Else Alert("Ocurrió un error al consultar los movimientos transitorios. Por favor vuelva a intentar.", TipoMensaje.MsgAdvertencia) Dtt = Nothing End If ObjInventarios.Dispose() If Dtt IsNot Nothing Then GvDatosRecepcion.DataSource = Dtt GvDatosRecepcion.DataBind() 'Dt.Dispose() End If DtSeccionAlmacen.Rows.Clear() If TxtFolioRecepcion.Text = "" Then BtnRecibir.Visible = False BtnCancelarTraspaso.Visible = False Else BtnRecibir.Visible = True BtnCancelarTraspaso.Visible = True End If If UsuarioActual.Empresa.Funcionalidad(132) = "1" Then DivCodigoSeriePSRecepcion.Visible = True Else DivCodigoSeriePSRecepcion.Visible = False End If UpDatosRecepcion.Update() UPDivCodigoSeriePSRecepcion.Update() End Sub Protected Sub GvDatosRecepcion_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDatosRecepcion.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then e.Row.FCTextBox("TxtCantidad").Visible = True If TxtFolioRecepcion.Text = "" Then e.Row.FCCheckBox("Chk").Visible = False e.Row.FCTextBox("TxtCantidad").Enabled = False End If 'Cuando es titulo If e.Row.DBCampo("PS").ToString.Trim = "" Then e.Row.CssClass = "Totales" e.Row.FCCheckBox("Chk").Visible = False e.Row.FCTextBox("TxtCantidad").Visible = False e.Row.Cells(2).Text = String.Format("Folio: {0} ", e.Row.DBCampo("FolioSalida"), e.Row.DBCampo("CveMovimientoSalida")) e.Row.Cells(3).Text = String.Format("{0}", e.Row.DBCampo("FechaMovto").ToString.ToDate.ToShortDateString) e.Row.Cells(5).Text = String.Format("Almacen Origen: {0}     Almacen Destino: {1}       Responsable: {2}", e.Row.DBCampo("Almacen"), e.Row.DBCampo("AlmacenDestino"), e.Row.DBCampo("Recibio")) Else e.Row.FCTextBox("TxtCantidad").Attributes.Add("onkeyup", String.Format("ValidaCantidad(this,{0});", e.Row.DBCampo("Cantidad"))) End If 'FUNCIONALIDAD PISTOLA DE CODIGOS If UsuarioActual.Empresa.Funcionalidad(132) = "1" And e.Row.DBCampo("CodigoBarras").Trim <> "" Then e.Row.FCTextBox("TxtCantidad").Enabled = False End If End If End Sub Protected Sub BtnCancelarTraspaso_Click(sender As Object, e As EventArgs) If Not GvDatosRecepcion.Rows.Count > 0 Then Alert("No hay movimientos para el traspaso", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim ObjInventario As New ClsInventarios ObjInventario.IniciaTransacSQL() Dim CveMovimientoEntrada As Integer = 0 Dim Folio = 0 Dim ErrorMovInv As Boolean = False Dim TextoError = "" Dim Fecha As Date = TxtFechaRecepcion.Text.ToDate CveMovimientoEntrada = ObjInventario.AddMovimiento(GvDatosRecepcion.Rows(0).DataKey("CveAlmacenDestino").ToEntero, 27, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:=TxtObservacionesRecepcion.Text.Trim, Recibio:=TxtRecibio.Text, CveAlmacenDestino:=GvDatosRecepcion.Rows(0).DataKey("CveAlmacenDestino").ToEntero, CveMovimientoRelacionado:=CveMovimientoSalida, Modulo:="TA/G") Folio = ObjInventario.Folio If CveMovimientoEntrada <= 0 Then TextoError = "No se pudo generar el movimiento de entrada correctamente" ErrorMovInv = True Else Dim CveMovimientoDetalleSalida As Integer = 0 If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then For Each Dr As DataRow In ObjInventario.DtResultados.Rows CveMovimientoDetalleSalida = Dr("CveMovimientoDetalle").ToString.ToEntero If CveMovimientoDetalleSalida <= 0 Then ErrorMovInv = True TextoError = "Ocurrió un error al guardar los movimientos de salida" Exit For End If If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Dr("Cantidad").ToString.ToDouble, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, Dr("PU").ToString.ToDouble, Dr("CveAF").ToString.ToEntero, -1, Dr("SerieLote").ToString, Lote:=Dr("Lote").ToString, Batch:=Dr("Batch").ToString, CveMovimientoDetalleEntrada:=CveMovimientoDetalleSalida) Then ErrorMovInv = True TextoError = "Ocurrió un error al guardar los movimientos de entrada" Exit For End If Next End If End If If Not ErrorMovInv Then ObjInventario.Commit() TxtRecibio.Text = "" TxtFechaRecepcion.Text = Now.ToShortDateString TxtObservacionesRecepcion.Text = "" Dim Mensaje As StringBuilder = New StringBuilder Mensaje.AppendFormat("Se realizo correctamente la cancelación.
Folio de Entrada: {0}", Folio, CveMovimientoEntrada) Mensaje.AppendFormat("
Imprimir Reporte", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoEntrada))) 'onclick='ImprimirTraslado()' Alert(Mensaje.ToString, TipoMensaje.MsgInformacion) DivCodigoSeriePSRecepcion.Visible = False GvDatosRecepcion.DataBind() UpDatosRecepcion.Update() UPDatosAlmacen.Update() Else ObjInventario.RollBack() Alert(TextoError, TipoMensaje.MsgError) End If ObjInventario.Dispose() CargaRecepcion() End Sub Protected Sub BtnRecibir_Click(sender As Object, e As EventArgs) If GvDatosRecepcion.Rows.Count > 0 Then 'Valida Movimientos Dim ValidaMovtos = 0.0 For Each gvr As GridViewRow In GvDatosRecepcion.Rows If gvr.FCCheckBox("Chk").Checked AndAlso gvr.FCTextBox("TxtCantidad").Text.ToString.ToDecimal > 0 Then ValidaMovtos += gvr.FCTextBox("TxtCantidad").Text.ToString.ToDecimal End If Next If Not ValidaMovtos > 0 Then Alert("No hay movimientos que realizar. Por favor verifique y vuelva a intentar.", TipoMensaje.MsgAdvertencia) Exit Sub End If If UsuarioActual.Empresa.Funcionalidad(563) = "1" Then If ValidaMovtos <> DtSeccionAlmacen.FiltraParametros("TipoSeccionAlmacen = 2").SUMD("CantidadSeccionAlmacen") Then Alert("La seccion de almacen no ha sido agregada completamente.", TipoMensaje.MsgAdvertencia) Exit Sub End If End If Dim ObjInventario As New ClsInventarios Dim Dtt As DataTable = Nothing Dim CveMovimientoEntrada As Integer = 0 Dim Folio = 0 Dim ErrorMovInv As Boolean = False Dim TextoError = "" '' verifica que no se halla recibido previamente, si ya se recibió da salida If ObjInventario.GetMovimientosTransitorios(CveAlmacenDestino, -1, CveAlmacenTransitorio, -1, FolioBusqueda, UsuarioActual.CveEmpresa) Then Dtt = ObjInventario.DtResultados.FiltraParametros(String.Format("CveTipoAlmacenDestino <> 4"), "", {"CveMovimientoDetalle", "Codigo", "Cantidad"}) If Dtt IsNot Nothing AndAlso Dtt.FiltraParametros("Cantidad < 0").Rows.Count > 0 Then ObjInventario.Dispose() Alert("El traspaso no se ha puede completar, por inconsistencia en las cantidades recibidas") Exit Sub End If End If 'REGISTRA LA SALIDA Y ENTRADA (TRASPASO) ObjInventario.IniciaTransacSQL() 'Inicia la transacción Dim Fecha As Date = TxtFechaRecepcion.Text.ToDate 'AGREGAMOS LA ENTRADA CveMovimientoSalida = ObjInventario.AddMovimiento(GvDatosRecepcion.Rows(0).DataKey("CveAlmacenDestino").ToEntero, 27, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:=TxtObservacionesRecepcion.Text.Trim, CveAlmacenDestino:=GvDatosRecepcion.Rows(0).DataKey("CveAlmacenSalida").ToEntero, CveMovimientoRelacionado:=CveMovimientoSalida, Modulo:="TA/G") Folio = ObjInventario.Folio If CveMovimientoSalida <= 0 Then TextoError = "No se pudo generar el movimiento de salida correctamente" ErrorMovInv = True Else Dim CveMovimientoDetalleEntrada As Integer = 0 Dim Cont As Integer = 0 For Each gvr As GridViewRow In GvDatosRecepcion.Rows Dim dataRowAux As DataRow = Dtt.FiltroPrimero(String.Format(" CveMovimientoDetalle = '{0}'", If(gvr.DataKey("CveMovimientoDetalle").ToString = "", "0", gvr.DataKey("CveMovimientoDetalle").ToString))) Dim cantidadDisponibleValidacion As Decimal = 0 If gvr.DataKey("Codigo").ToString IsNot "" Then If dataRowAux IsNot Nothing Then cantidadDisponibleValidacion = dataRowAux.Item("Cantidad").ToString.ToDecimal - gvr.FCTextBox("TxtCantidad").Text.ToString.ToDecimal Else cantidadDisponibleValidacion = -1 End If End If If gvr.FCCheckBox("Chk").Checked AndAlso gvr.FCTextBox("TxtCantidad").Text.ToString.ToDecimal > 0 AndAlso cantidadDisponibleValidacion >= 0 Then CveMovimientoDetalleEntrada = gvr.DataKey("CveMovimientoDetalle").ToString.ToEntero If CveMovimientoDetalleEntrada <= 0 Then ErrorMovInv = True TextoError = "Ocurrió un error al guardar los movimientos de salida" Exit For End If If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, gvr.FCTextBox("TxtCantidad").Text.ToString.ToDecimal, gvr.DataKey("CveUM").ToString.ToEntero, gvr.DataKey("CvePS").ToString.ToEntero, gvr.DataKey("PU").ToString.ToDouble, gvr.DataKey("CveAF").ToString.ToEntero, CveMovimientoDetalleEntrada:=CveMovimientoDetalleEntrada, SerieLote:=gvr.DataKey("SerieLote").ToString, Lote:=gvr.DataKey("Lote").ToString, Batch:=gvr.DataKey("Batch").ToString) Then ErrorMovInv = True TextoError = "Ocurrió un error al guardar los movimientos de salida" Exit For Else If ObjInventario.CveMovimientoDetalle > 0 AndAlso DtSeccionAlmacen.Rows.Count > 0 Then For Each Dr2 As DataRow In DtSeccionAlmacen.FiltraParametros($"IndexSeccionAlmacen = {Cont} AND TipoSeccionAlmacen = 2").Rows If Not ObjInventario.AddMovimientosDetalleSeccionesAlmacen(ObjInventario.CveMovimientoDetalle, Dr2("CveSeccionAlmacenDestino").ToString.ToEntero, Dr2("CantidadSeccionAlmacen").ToString.ToDecimal) Then ErrorMovInv = True TextoError = "Ocurrió un error al procesar las secciones de almacen. Por favor vuelva a intentar." Exit For End If Next End If End If ElseIf cantidadDisponibleValidacion < 0 Then TextoError = String.Format("Se exceden la cantidad disponibles para {0}", gvr.DataKey("PS").ToString) ErrorMovInv = True End If Cont += 1 Next End If 'VIRTUAL ENTRADA Dim CveMovimientoVirtualEntrada As Integer = 0 Dim FolioVirtualEntrada As Integer = 0 If UsuarioActual.Empresa.Funcionalidad(573) = "1" Then Dim CveSubProyecto As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveSubProyecto", $"CveAlmacen= {DdlAlmacenRecepcion.SelectedValue}").ToEntero() Dim CveAlmacenVirtual As Integer = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveAlmacen", $" CveTipoAlmacen =24 AND CveSubProyecto={CveSubProyecto}").ToEntero() If CveAlmacenVirtual > 0 Then CveMovimientoVirtualEntrada = ObjInventario.AddMovimiento(CveAlmacenVirtual, 2, 1, TxtFecha.Text.ToDate, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, Observaciones:=TxtObservaciones.Text.Trim, Modulo:="TA/S2") FolioVirtualEntrada = ObjInventario.Folio Dim dtvirtual As DataTable = Nothing If CveMovimientoVirtualEntrada > 0 AndAlso ObjInventario.GetMovimientosDetalleVirtual(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then dtvirtual = ObjInventario.DtResultados For Each RowVirtual As DataRow In dtvirtual.Rows Dim CvePS = RowVirtual("CvePS").ToString().ToEntero() Dim CantidadUsado As Double = RowVirtual("Cantidad").ToString().ToDouble() Dim PU As Double = RowVirtual("PU").ToString().ToDouble() Dim CveUM As Integer = RowVirtual("CveUM").ToString().ToEntero() If Not ObjInventario.AddMovimientoDetalle(CveMovimientoVirtualEntrada, CantidadUsado, CveUM, CvePS, PU, -1, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then ErrorMovInv = True Exit For End If Next Else TextoError = "No se pudo registrar el movimiento virtual" ErrorMovInv = True End If Else TextoError = "La Sucursal no tiene creado un almacen virtual" ErrorMovInv = True End If End If ''AGREGAMOS LA ENTRADA 'If Not ErrorMovInv Then ' CveMovimientoEntrada = ObjInventario.AddMovimiento(GvDatosRecepcion.Rows(0).DataKey("CveAlmacenDestino").ToEntero, 9, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, ' Observaciones:=TxtObservacionesRecepcion.Text.Trim, Recibio:=TxtRecibio.Text, CveAlmacenDestino:=GvDatosRecepcion.Rows(0).DataKey("CveAlmacenSalida").ToEntero, CveMovimientoRelacionado:=CveMovimientoSalida) ' Folio = ObjInventario.Folio ' If CveMovimientoEntrada <= 0 Then ' TextoError = "No se pudo generar el movimiento de entrada correctamente" ' ErrorMovInv = True ' Else ' 'COSTO INDIRECTO ' Dim GastoIndirectoTotal As Double = GvDatosRecepcion.Rows(0).DataKey("GastoIndirectoSalida").ToDouble ' Dim Importe As Double = GvDatosRecepcion.Rows(0).DataKey("Importe").ToDouble ' If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then ' Dim CostoIndirecto As Double ' For Each Dr As DataRow In ObjInventario.DtResultados.Rows ' CostoIndirecto = 0 ' If GastoIndirectoTotal > 0 Then ' 'PRORRATEAMOS EL GASTO INDIRECTO ' CostoIndirecto = ((Dr("Total").ToString.ToDouble * GastoIndirectoTotal) / Importe) / Dr("Cantidad").ToString.ToDouble ' End If ' If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Dr("Cantidad").ToString.ToDouble, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, Dr("PU").ToString.ToDouble, Dr("CveAF").ToString.ToEntero, -1, Dr("SerieLote").ToString, Lote:=Dr("Lote").ToString, Batch:=Dr("Batch").ToString, CostoIndirecto:=CostoIndirecto) Then ' ErrorMovInv = True ' TextoError = "Ocurrió un error al guardar los movimientos de entrada" ' Exit For ' End If ' Next ' End If ' End If 'End If 'AGREGAMOS LA ENTRADA VIEJO 'If Not ErrorMovInv Then ' 'Folio = ObjInventario.GetFolioSiguiente(9, UsuarioActual.CveEmpresa) ' CveMovimientoEntrada = ObjInventario.AddMovimiento(GvDatosRecepcion.Rows(0).DataKey("CveAlmacenDestino").ToEntero, 9, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1) ' If CveMovimientoEntrada <= 0 Then ' TextoError = "No se pudo generar el movimiento de entrada correctamente" ' ErrorMovInv = True ' Else ' If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then ' For Each Dr As DataRow In ObjInventario.DtResultados.Rows ' If Not ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, Dr("Cantidad").ToString.ToDouble, Dr("CveUM").ToString.ToEntero, Dr("CvePS").ToString.ToEntero, Dr("PU").ToString.ToDouble, Dr("CveAF").ToString.ToEntero) Then ' ErrorMovInv = True ' TextoError = "Ocurrió un error al guardar los movimientos de salida" ' Exit For ' End If ' Next ' End If ' End If 'End If If Not ErrorMovInv Then ObjInventario.Commit() TxtRecibio.Text = "" TxtFechaRecepcion.Text = Now.ToShortDateString TxtObservacionesRecepcion.Text = "" Dim Mensaje As StringBuilder = New StringBuilder Mensaje.AppendFormat("Se realizo correctamente la recepción.
Folio de Entrada: {0}", Folio, CveMovimientoSalida) Mensaje.AppendFormat("
Imprimir Reporte", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoSalida))) 'onclick='ImprimirTraslado()' If CveMovimientoVirtualEntrada > 0 Then Mensaje.AppendFormat("

Virtual{2}Imprimir Reporte", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoVirtualEntrada)), CveMovimientoVirtualEntrada, FolioVirtualEntrada) 'onclick='ImprimirTraslado()' Alert(Mensaje.ToString, TipoMensaje.MsgInformacion) DivCodigoSeriePSRecepcion.Visible = False GvDatosRecepcion.DataBind() UpDatosRecepcion.Update() UPDatosAlmacen.Update() Else ObjInventario.RollBack() Alert(TextoError, TipoMensaje.MsgError) End If ObjInventario.Dispose() CargaRecepcion() Else Alert("No hay movimientos para el traspaso", TipoMensaje.MsgAdvertencia) If ChkTransitorio.Checked Then RegistraScript("$('#DivTransitorio').show(200);") End If End Sub 'Private Sub DdlProducto_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlProducto.SelectedIndexChanged ' 'CargarUM(DdlProducto.SelectedValue.ToEntero) ' ElProductoChange() 'End Sub 'Private Sub HFProducto_ValueChanged(sender As Object, e As EventArgs) Handles HFProducto.ValueChanged ' ElProductoChange() 'End Sub Private Sub CargarUM(CvePS As Integer) Dim ObjUM As New ClsProductosServicios() If ObjUM.GetPSEquivalencias(CvePS, UsuarioActual.CveEmpresa) Then DdlUnidad.Items.Clear() DdlUnidad.DataSource = ObjUM.DtResultados End If ObjUM.Dispose() DdlUnidad.DataBind() End Sub 'Protected Sub BtnImprimirTraspaso_Click(sender As Object, e As EventArgs) Handles BtnImprimirTraspaso.Click ' Dim params As New List(Of ReportParameter) ' params.Add(New ReportParameter("SubProyecto", DdlAlmacenDestino.SelectedItem.ToString)) ' params.Add(New ReportParameter("Folio", FolioTraspaso.ToString)) ' params.Add(New ReportParameter("Fecha", TxtFecha.Text)) ' params.Add(New ReportParameter("Observaciones", TxtObservaciones.Text)) ' params.Add(New ReportParameter("NombreEntrego", UsuarioActual.Nombre)) ' params.Add(New ReportParameter("NombreTraslado", TxtResponsable.Text)) ' params.Add(New ReportParameter("NombreRecibio", "")) ' ImprimirPDF(String.Format("{0}Formatos\Traslado.rdlc", UsuarioActual.Empresa.Ruta), DtTraslado, params, "Reporte Traslado", RDSName:="DsInventarios") 'End Sub #End Region #Region " AGREGA CON TXT | CODIGO - SERIE " Protected Sub BtnCodigoPS_Click(sender As Object, e As EventArgs) If TxtCodigoPS.Text = "" Then Exit Sub End If TdSeriePS.Visible = False Dim DrPS = GlobalDTPS(UsuarioActual.CveEmpresa).FiltroPrimero($"CodigoBarras = '{TxtCodigoPS.Text}'") If DrPS Is Nothing Then Alert($"No se ha encontrado un producto del Codigo ""{TxtCodigoPS.Text}"". ", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus,200);") RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") TxtCodigoPS.Text = "" Exit Sub End If If DrPS("Inv_CveMetodoInventario").ToString.ToEntero = 5 Then TdSeriePS.Visible = True TxtSeriePS.Focus() CvePSSerieLote = DrPS("CvePS").ToString.ToEntero CveUMSerieLote = DrPS("CveUnidadMedida").ToString.ToEntero Exit Sub End If AgregarPS(1, DrPS("CvePS").ToString.ToEntero, DrPS("CveUnidadMedida").ToString.ToEntero) TxtCodigoPS.Text = "" End Sub Protected Sub BtnSeriePS_Click(sender As Object, e As EventArgs) If TxtSeriePS.Text.Trim = "" Then Exit Sub End If txtCantidad.Text = "1" Dim Valido = ValidaExistencia(1, CvePSSerieLote, CveUMSerieLote, TxtSeriePS.Text.Trim) If Valido Then AgregarPS(1, CvePSSerieLote, CveUMSerieLote, TxtSeriePS.Text.Trim) Else TxtSeriePS.Text = "" TxtSeriePS.Focus() Exit Sub End If TdSeriePS.Visible = False TxtSeriePS.Text = "" TxtCodigoPS.Text = "" TxtCodigoPS.Focus() End Sub #End Region #Region " AGREGA CON TXT | CODIGO - SERIE --- RECEPCION " Protected Sub BtnCodigoPSRecepcion_Click(sender As Object, e As EventArgs) If TxtCodigoPSRecepcion.Text = "" Then Exit Sub End If Dim Existe = False Dim PSTemp = "" TdSeriePSRecepcion.Visible = False For Each Gvr As GridViewRow In GvDatosRecepcion.Rows If Gvr.DataKey("CodigoBarras") = TxtCodigoPSRecepcion.Text.Trim Then Dim TxtCantidad = GvDatosRecepcion.Rows(Gvr.RowIndex).FCTextBox("TxtCantidad") If Gvr.DataKey("Cantidad").ToDecimal - TxtCantidad.Text.ToDecimal - 1 >= 0 Then If Gvr.DataKey("AplicaSerieLote") = "True" Then TdSeriePSRecepcion.Visible = True TxtSeriePSRecepcion.Focus() Exit Sub End If TxtCantidad.Text = (TxtCantidad.Text.ToDecimal + 1).ToString.FormatoNumero TxtCodigoPSRecepcion.Text = "" RegistraScript("playsonidito('beep-07.wav')") UpDatosRecepcion.Update() Exit Sub End If Existe = True PSTemp = Gvr.DataKey("PS").ToString 'Alert($"Ya se ha cargado la totalidad del Producto ""{Gvr.DataKey("PS").ToString}"" con el Codigo ""{TxtCodigoPSRecepcion.Text}"".", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus1,200);") End If Next If Existe Then Alert($"Ya se ha cargado la totalidad del Producto ""{PSTemp}"" con el Codigo ""{TxtCodigoPSRecepcion.Text}"".", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus1,200);") Else Alert($"No se ha encontrado un producto para surtir con el Codigo ""{TxtCodigoPSRecepcion.Text}"". ", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus1,200);") End If RegistraScript("playsonidito('142608__autistic-lucario__error.wav')") TxtCodigoPSRecepcion.Text = "" End Sub Protected Sub BtnSeriePSRecepcion_Click(sender As Object, e As EventArgs) If TxtSeriePSRecepcion.Text = "" Then Exit Sub End If For Each Gvr As GridViewRow In GvDatosRecepcion.Rows If Gvr.DataKey("CodigoBarras") = TxtCodigoPSRecepcion.Text.Trim And Gvr.DataKey("SerieLote") = TxtSeriePSRecepcion.Text.Trim Then Dim TxtCantidad = GvDatosRecepcion.Rows(Gvr.RowIndex).FCTextBox("TxtCantidad") If Gvr.DataKey("Cantidad").ToDecimal - TxtCantidad.Text.ToDecimal - 1 >= 0 Then TxtCantidad.Text = (TxtCantidad.Text.ToDecimal + 1).ToString.FormatoNumero TxtCodigoPSRecepcion.Text = "" TdSeriePSRecepcion.Visible = False TxtSeriePSRecepcion.Text = "" UpDatosRecepcion.Update() Exit Sub End If Alert($"Ya se ha cargado la totalidad del Producto ""{Gvr.DataKey("PS").ToString}"" con el Codigo ""{TxtCodigoPSRecepcion.Text}"".", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus1,200);") RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") End If Next Alert($"No se ha encontrado un producto para surtir con el Codigo ""{TxtCodigoPSRecepcion.Text}"". ", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus1,200);") RegistraScript("playsonidito(''142608__autistic-lucario__error.wav'')") 'Alert($"Ya se han cargado todos los productos o no se ha encontrado un producto de la Serie ""{TxtSeriePSRecepcion.Text}"". ", TipoMensaje.MsgAdvertencia, "window.setTimeout(Focus2,200);") TxtSeriePSRecepcion.Text = "" End Sub #End Region #Region "CORREO" Private Sub MandaCorreo(CveMovimiento As Integer, Para As String, Optional CCP As String = "") Dim Mail As New ClsSisMail() Dim Asunto As String = "NOTIFICACION DE TRASPASO ENTRE ALMACENES" Dim Body As String = GeneraCorreo(CveMovimiento) If Not Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body, CCP) Then 'Dim objIE As New ClsBancos 'objIE.UpdateBancos_IENotificaciones(1, "-1", "-1", CveIE) 'objIE.Dispose() Alert("No se pudo enviar el correo electrónico.", TipoMensaje.MsgError) End If End Sub 'Private Sub BtnSendMail_Click(sender As Object, e As EventArgs) Handles BtnSendMail.Click ' MandaCorreo(CveMov, TxtParaMail.Text.Trim, TxtCC.Text.Trim) ' RegistraScript("$('#ModalDivMail').modal('hide');") 'End Sub Private Function GeneraCorreo(CveMovimientoSalida As Integer) As String Dim strBody As New StringBuilder Dim ObjInventario As New ClsInventarios If ObjInventario.GetMovimientos(CveMovimientoSalida, -1, -1, UsuarioActual.CveEmpresa) Then strBody.Append(" ") strBody.Append(" ") strBody.Append(" ") strBody.Append(" ") strBody.Append(" ") strBody.AppendFormat("
") strBody.AppendFormat("
") strBody.AppendFormat(" {0}", UsuarioActual.Empresa.Empresa) strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ", UsuarioActual.Empresa.Direccion) strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ", UsuarioActual.Empresa.Colonia) strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ", UsuarioActual.Empresa.Ciudad, UsuarioActual.Empresa.Estado, UsuarioActual.Empresa.CP) strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ", UsuarioActual.Empresa.RFC) strBody.AppendFormat(" ") strBody.AppendFormat("
{0}
Col. {0}
{0}, {1}, C.P.{2}
RFC {0}
") strBody.AppendFormat("
") strBody.AppendFormat("


") strBody.AppendFormat("
") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat("
") strBody.AppendFormat("
") strBody.AppendFormat(" TRASPASO ENTRE ALMACENES{0} ", " ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ", ObjInventario.Fecha.ToString("dd/MM/yyyy")) strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ", ObjInventario.Almacen) strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ", ObjInventario.AlmacenDestino) strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ", ObjInventario.Observaciones) strBody.AppendFormat(" ") 'strBody.AppendFormat(" ") 'strBody.AppendFormat(" ") 'strBody.AppendFormat(" ", objIE.Importe.FormatoNumero, objIE.Moneda) 'strBody.AppendFormat(" ") 'strBody.AppendFormat(" ") 'strBody.AppendFormat(" ") 'strBody.AppendFormat(" ", objIE.Observaciones) 'strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat("
Fecha:{0}
Almacén Origen:{0}
Almacén Destino:{0}
Observaciones:{0}
Importe:$ {0} {1}
Observaciones:{0}
") strBody.AppendFormat("
") strBody.AppendFormat("
") strBody.AppendFormat("
") strBody.AppendFormat("
") strBody.AppendFormat("
") 'MOVIMIENTOS CHEQUE 'Dim Textov33 As String = "" 'If UsuarioActual.Empresa.Funcionalidad(520) = "1" Then ' Textov33 = "Favor de emitir complemento de pago de los siguientes documentos" 'End If If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then strBody.AppendFormat("
") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat("
") strBody.AppendFormat("
") strBody.AppendFormat(" Productos / Servicios
{0}
", "") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") 'strBody.AppendFormat(" ") 'strBody.AppendFormat(" ") strBody.AppendFormat(" ") For Each dr As DataRow In ObjInventario.DtResultados.Rows strBody.AppendFormat(" ") strBody.AppendFormat(" ", dr("Cantidad").ToString.FormatoNumero) strBody.AppendFormat(" ", dr("UnidadMedida").ToString) strBody.AppendFormat(" ", dr("CodigoPS").ToString) 'strBody.AppendFormat(" ", dr("FolioFiscal")) 'strBody.AppendFormat(" ", dr("ImporteNC").ToString.FormatoNumero) strBody.AppendFormat(" ") Next strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat(" ") strBody.AppendFormat("
CantidadUnidadProducto / ServicioFolio FiscalNC Aplicadas
{0}{0}{0}{0}{0}
") strBody.AppendFormat("
") strBody.AppendFormat("
") strBody.AppendFormat("
") strBody.AppendFormat("
") strBody.AppendFormat("
") End If strBody.Append("
Favor de no responder a este correo.
") strBody.Append("") End If ObjInventario.Dispose() Return strBody.ToString End Function #End Region #Region "TIMBRADO" Private Sub CreaObjetosVenta() ObjFactura = New Modelos.Factura ObjFactura.Version = "3.3" ObjFactura.CveUsuario = UsuarioActual.CveUsuario ObjFactura.CveEmpresa = UsuarioActual.CveEmpresa ObjFactura.TipoCambio = 0 ObjFactura.ConvertirPesos = False ObjFactura.TipoCambio = 0 ObjFactura.CveMoneda = 1 ObjFactura.Moneda = GlobalDTMonedas.FiltroPrimeroValor("Moneda", $"CveMoneda = {ObjFactura.CveMoneda} ") ObjFactura.MonedaSAT = GlobalDTMonedas.FiltroPrimeroValor("AbreviaturaSAT", "CveMoneda = 1") ObjFactura.MonedaAbreviatura = GlobalDTMonedas.FiltroPrimeroValor("Abreviatura", $"CveMoneda = {ObjFactura.CveMoneda} ") ObjFactura.TipoDocto = "Tra" ObjFactura.RefDocto = "" ObjFactura.Folio = Folio.ToEntero ObjFactura.Serie = "Tra" ObjFactura.CveMesa = -1 ObjFactura.Fecha = Now ObjFactura.CvePrePoliza = -1 ObjFactura.FechaPago = Now ObjFactura.MotivoDescuento = "" ObjFactura.Observaciones = "" ObjFactura.FechaEjecucion = Now ObjFactura.UsuarioCreo = UsuarioActual.Usuario ObjFactura.CveCondicionEntrega = -1 ObjFactura.CondicionEntrega = "" ObjFactura.NumeroCuenta = "" ObjFactura.CondicionesPago = 0 ObjFactura.FormaPago = 0 ObjFactura.PedidoContrato = "" ObjFactura.OrdenCompra = "" ObjFactura.NumeroContrato = "" ObjFactura.NumeroDescripcionContrato = "" ObjFactura.DescripcionContrato = "" ObjFactura.CveCorte = -1 ObjFactura.TipoDocumento = "Traspaso" ObjFactura.Alfa1 = "" ObjFactura.Alfa2 = "" ObjFactura.Alfa3 = "" ObjFactura.Descuento = 0 ObjFactura.Amortizacion = 0 ObjFactura.CveContrato = 0 ObjFactura.CveVendedor = 0 ObjFactura.FechaVencimiento = Now ObjFactura.TipoEstatus = 0 ObjFactura.Det_OrdenCompra = "" ObjFactura.Inv_CveEstatusEntrega = 0 ObjFactura.FormaPago33 = "" ObjFactura.MetodoPago33 = "" ObjFactura.UsoCFDI = "" ObjFactura.CveClienteSucursal = 0 Dim CveSubProyecto As Integer = -1 If GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltraParametros($"CveAlmacen = {DdlAlmacenOrigen.SelectedValue}").Rows.Count > 0 Then CveSubProyecto = GlobalDTAlmacen(UsuarioActual.CveEmpresa).FiltraParametros($"CveAlmacen = {DdlAlmacenOrigen.SelectedValue}").Rows(0)("CveSubProyecto").ToString.ToEntero End If ObjFactura.CveSubProyecto = CveSubProyecto ObjFactura.CveSubProyectoCobranza = CveSubProyecto ObjFactura.CveSubProyectoEjecucion = CveSubProyecto ObjFactura.SubTotal = 0 ObjFactura.Descuento = 0 ObjFactura.Amortizacion = 0 ObjFactura.IVA = 0 ObjFactura.RetIVA = 0 ObjFactura.RetISR = 0 ObjFactura.IEPS = 0 ObjFactura.Total = 0 'DETALLES ObjFactura.DtDetalle = DtMovimientos 'SUBPROYECTO ObjFactura.SetSubProyectoMatriz(Me) ObjFactura.SetSubProyecto(Me) ObjFactura.Inv_CveMovimiento = CveMovimientoTimbrado ObjFactura.Timbre = PreParaTimbre(ObjFactura) End Sub Private Function PreParaTimbre(Obj As Modelos.Factura) As CFDITimbre Dim Timbre As New CFDITimbre Timbre.Comprobante.TipoComprobante = "T" Timbre.Comprobante.Folio = Obj.Folio.ToString Timbre.Comprobante.Serie = Obj.Serie Timbre.Comprobante.Fecha = Obj.Fecha Timbre.Comprobante.FormadePago = Obj.FormaPagoSAT33 Timbre.Comprobante.CondicionesdePago = Obj.FormaPago33 Timbre.Comprobante.MetodoPago = Obj.ClaveMetodoPagoSAT Timbre.Comprobante.Subtotal = Obj.SubTotal Timbre.Comprobante.Descuentos = Obj.Descuento Timbre.Comprobante.Moneda = Obj.MonedaSAT Timbre.Comprobante.TipoCambio = If(Obj.CveMoneda = 1, "1", Obj.TipoCambio.ToString) Timbre.Comprobante.Total = Obj.Total Timbre.Comprobante.LugarExpedicion = Obj.SubProyecto.CP Timbre.Comprobante.Confirmacion = "" Timbre.Receptor.RFC = "XAXX010101000" Timbre.Receptor.Nombre = UsuarioActual.Empresa.Empresa Timbre.Receptor.UsoCFDI = "P01" Dim totSubTotal As Decimal = Obj.SubTotal Dim totIVA As Decimal = Obj.IVA Dim totRetIVA As Decimal = Obj.RetIVA Dim totRetISR As Decimal = Obj.RetISR Dim i As Integer = 1 'DETALLES Dim tPS As String = "" For Each drr As DataRow In Obj.DtDetalle.Rows If drr("PS").ToString.Length = 1 Then tPS = drr("Obs").ToString Else If drr("PS").ToString.Length = 0 Then tPS = "" Else tPS = String.Format("{0} {1}", drr("PS"), drr("Obs")) End If End If 'CONDICIONANTE, ESPECIAL If UsuarioActual.CveEmpresa = 15 Then drr("UM") = "" 'LES COMENTAN QUE NO DEBE IR LA ETIQUETA DE LA UNIDAD EN EL PRODUCTO Dim concepto As New CFDIConceptos With {.Cantidad = drr("Cantidad").ToString.ToDecimal, .Descripcion = tPS, .ValorUnitario = drr("PU").ToString.ToDecimal, .Importe = drr("TotalImporte").ToString.ToDecimal, .Descuento = drr("Descuento").ToString.ToDecimal, .Unidad = drr("UM").ToString, .ClaveUnidad = drr("SATClaveUM").ToString, .ClaveProdServ = drr("SATClaveProdServ").ToString, .Noidentificacion = drr("Noidentificacion").ToString, .CuentaPredial = drr("CuentaPredial").ToString} 'VERIFICA SUMA SUBTOTALES If i = Obj.DtDetalle.Rows.Count AndAlso totSubTotal <> concepto.Importe Then 'PROCESO DE AJUSTA DE DECIMALES concepto.Importe = totSubTotal End If totSubTotal = totSubTotal - concepto.Importe 'SIEMPRE ESTAMOS AGREGANDO EL IVA 'concepto.Impuestos.Add(New CFDIConceptosImpuestos With {.TrasladooRetencion = "T", .Base = concepto.Importe - concepto.Descuento, .TasaOCuota = drr("PorcentajeIVA").ToString.ToDecimal, .Impuesto = "002", .Importe = drr("ImporteIVA").ToString.ToDecimal}) Timbre.Conceptos.Add(concepto) i += 1 Next Return Timbre End Function Private Sub PrepararTimbrado(ByRef FM As Modelos.FemsaFactura, ByRef TmpDT7Eleven As DataTable, ByRef TmpDTComplementosTimbrado As DataTable) FM.AplicaFEMSA = False FM.FEMSA_NumSociedad = "" FM.FEMSA_NumProveedor = "" FM.FEMSA_Mail = "" FM.FEMSA_Version = 0 FM.FEMSA_NumPedido = 0 FM.FEMSA_NumEntrada = "" FM.FEMSA_NumRemision = "" FM.FEMSA_NumSocio = "" FM.FEMSA_CentroCosto = "" FM.FEMSA_IPeriodoLiquidacion = "" FM.FEMSA_FPeriodoLiquidacion = "" FM.FEMSA_CodRetencion1 = "" FM.FEMSA_CodRetencion2 = "" TmpDT7Eleven.Columns.Add("sevenElevenNumProveedor") TmpDT7Eleven.Columns.Add("sevenElevenFolio") TmpDT7Eleven.Columns.Add("sevenElevenTienda") TmpDT7Eleven.Columns.Add("sevenElevenFecha") Dim Row As DataRow = TmpDT7Eleven.NewRow Row("sevenElevenNumProveedor") = "" Row("sevenElevenFolio") = "" Row("sevenElevenTienda") = "" Row("sevenElevenFecha") = "" TmpDT7Eleven.Rows.Add(Row) TmpDTComplementosTimbrado.Columns.Add("CveComplemento") TmpDTComplementosTimbrado.Columns.Add("IdContabilidad") TmpDTComplementosTimbrado.Columns.Add("TipoProceso") TmpDTComplementosTimbrado.Columns.Add("TipoAmbito") TmpDTComplementosTimbrado.Columns.Add("Entidad") Dim Row2 As DataRow = TmpDTComplementosTimbrado.NewRow Row2("CveComplemento") = "" Row2("IdContabilidad") = "" Row2("TipoProceso") = "" Row2("TipoAmbito") = "" Row2("Entidad") = "" TmpDTComplementosTimbrado.Rows.Add(Row2) End Sub Private Sub Timbrar() CreaObjetosVenta() Dim ObjTimbrado As New Timbrado Dim FM As New Modelos.FemsaFactura Dim TmpDT7Eleven As New DataTable Dim TmpDTComplementosTimbrado As New DataTable PrepararTimbrado(FM, TmpDT7Eleven, TmpDTComplementosTimbrado) MensajeAlert.Append("

") If ObjTimbrado.TimbrarFactura(UsuarioActual, ObjFactura) Then MensajeAlert.Append("Emitido con exito.") 'XML Dim ArchivoXML = String.Format("{0}/XML/{1}/{2}.xml", UsuarioActual.Empresa.Ruta, ObjFactura.TipoDocto, ObjFactura.SerieFolio) If File.Exists(ArchivoXML) Then MensajeAlert.AppendFormat("", Encripta(String.Format("OP=DesXmlTra&CVEMOVIMIENTO={0}&EXT={1}&FOLIO={2}&TIPODOCTO={3}", CveMovimientoTimbrado, "XML", ObjFactura.SerieFolio, ObjFactura.TipoDocto))) End If 'PDF GeneraPDFFactura() Dim ArchivoPDF = String.Format("{0}/PDF/{1}/{2}.pdf", UsuarioActual.Empresa.Ruta, ObjFactura.TipoDocto, ObjFactura.SerieFolio) If File.Exists(ArchivoPDF) Then MensajeAlert.AppendFormat("", Encripta(String.Format("OP=DesPdfTra&CVEMOVIMIENTO={0}&EXT={1}&FOLIO={2}&TIPODOCTO={3}", CveMovimientoTimbrado, "PDF", ObjFactura.SerieFolio, ObjFactura.TipoDocto))) End If MensajeAlert.AppendFormat("", Encripta(String.Format("OP=CARPO&CVEMOV={0}", CveMovimientoTimbrado))) Else MensajeAlert.AppendFormat(ObjTimbrado.MensajeErrorCFDI) End If End Sub Private Sub GeneraPDFFactura() Try PdfFactura(ObjFactura) Catch ex As Exception Alert("Ocurrió un error al generar el PDF", TipoMensaje.MsgError) End Try End Sub #End Region #Region "SECCION ALMACEN" Private Sub CreaDtSeccionAlmacen() DtSeccionAlmacen = New DataTable DtSeccionAlmacen.Columns.Add("CantidadSeccionAlmacen", GetType(Decimal)) DtSeccionAlmacen.Columns.Add("IndexSeccionAlmacen", GetType(Integer)) DtSeccionAlmacen.Columns.Add("CveSeccionAlmacenOrigen", GetType(Integer)) DtSeccionAlmacen.Columns.Add("CveSeccionAlmacenDestino", GetType(Integer)) DtSeccionAlmacen.Columns.Add("CvePS", GetType(Integer)) DtSeccionAlmacen.Columns.Add("SeccionAlmacenOrigen", GetType(String)) DtSeccionAlmacen.Columns.Add("SeccionAlmacenDestino", GetType(String)) DtSeccionAlmacen.Columns.Add("Consec", GetType(Integer)) DtSeccionAlmacen.Columns.Add("TipoSeccionAlmacen", GetType(Integer)) End Sub Private Sub CargaDdlAlmacen() DdlSeccionAlmacenOrigen.DataSource = GlobalDTSeccionAlmacen(UsuarioActual.CveEmpresa) DdlSeccionAlmacenOrigen.Items.Insert(0, New ListItem("Seleccione", "-1")) DdlSeccionAlmacenOrigen.DataBind() DdlSeccionAlmacenDestino.DataSource = GlobalDTSeccionAlmacen(UsuarioActual.CveEmpresa) DdlSeccionAlmacenDestino.Items.Insert(0, New ListItem("Seleccione", "-1")) DdlSeccionAlmacenDestino.DataBind() End Sub Protected Sub LnkSeccionAlmacen_Click(sender As Object, e As EventArgs) Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow) If Not DdlAlmacenOrigen.SelectedValue.ToEntero > 0 Then Alert("Tiene que tener seleccionado un almacen para registrar seccion almacen origen.", TipoMensaje.MsgAdvertencia) Exit Sub End If 'If Not DdlAlmacenDestino.SelectedValue.ToEntero > 0 AndAlso Not ChkTransitorio.Checked Then ' Alert("Tiene que tener seleccionado un almacen para registrar seccion almacen destino.", TipoMensaje.MsgAdvertencia) ' Exit Sub 'End If If ChkTransitorio.Checked Then GvSeccion.Columns(2).Visible = False DivSeccionAlmacenDestino.Visible = False Else GvSeccion.Columns(2).Visible = True DivSeccionAlmacenDestino.Visible = True End If DivSeccionAlmacenOrigen.Visible = True GvSeccion.Columns(1).Visible = True CantidadTotal = gvRow.DataKey("Cantidad").ToDecimal IndexSeccionAlmacen = gvRow.RowIndex CvePS = gvRow.DataKey("CvePS").ToEntero TipoSeccionAlmacen = 1 CargaSeccionAlmacen() RegistraScript("$('#DModalSeccionAlmacen').modal()") End Sub Protected Sub LnkSeccionAlmacenDestino_Click(sender As Object, e As EventArgs) Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow) If Not DdlAlmacenRecepcion.SelectedValue.ToEntero > 0 Then Alert("Tiene que tener seleccionado un almacen para registrar seccion almacen destino.", TipoMensaje.MsgAdvertencia) Exit Sub End If DivSeccionAlmacenOrigen.Visible = False DivSeccionAlmacenDestino.Visible = True GvSeccion.Columns(1).Visible = False GvSeccion.Columns(2).Visible = True CantidadTotal = gvRow.FCTextBox("TxtCantidad").Text.ToDecimal IndexSeccionAlmacen = gvRow.RowIndex CvePS = gvRow.DataKey("CvePS").ToEntero TipoSeccionAlmacen = 2 CargaSeccionAlmacen() RegistraScript("$('#DModalSeccionAlmacen').modal()") End Sub Private Sub CargaSeccionAlmacen() Dim CantidadTotalSeccion As Decimal = DtSeccionAlmacen.FiltraParametros($"IndexSeccionAlmacen = {IndexSeccionAlmacen} AND TipoSeccionAlmacen = {TipoSeccionAlmacen}").SUMD("CantidadSeccionAlmacen") GvSeccion.DataSource = DtSeccionAlmacen.FiltraParametros($"IndexSeccionAlmacen = {IndexSeccionAlmacen} AND TipoSeccionAlmacen = {TipoSeccionAlmacen}") GvSeccion.DataBind() TxtCantidadSeccion.Text = "" DdlSeccionAlmacenOrigen.SelectedIndex = 0 DdlSeccionAlmacenDestino.SelectedIndex = 0 Dim CantidadRestante As Decimal = CantidadTotal - CantidadTotalSeccion If CantidadRestante = 0 Then RVTxtCantidad.MaximumValue = "1" TxtCantidadSeccion.Enabled = False Else RVTxtCantidad.MaximumValue = CantidadRestante.ToString TxtCantidadSeccion.Enabled = True End If If TipoSeccionAlmacen = 1 Then If DtSeccionAlmacen.SUMD("CantidadSeccionAlmacen") > 0 Then DdlAlmacenOrigen.Enabled = False DdlAlmacenOrigen.ToolTip = "Cuenta con sección almacen" ChkTransitorio.Enabled = False ChkTransitorio.ToolTip = "Cuenta con sección almacen" GvDatos.Rows(IndexSeccionAlmacen).FCLinkButton("lnkRemove").Enabled = False GvDatos.Rows(IndexSeccionAlmacen).FCLinkButton("lnkRemove").ToolTip = "Cuenta con sección almacen" Else DdlAlmacenOrigen.Enabled = True DdlAlmacenOrigen.ToolTip = "" ChkTransitorio.Enabled = True ChkTransitorio.ToolTip = "" GvDatos.Rows(IndexSeccionAlmacen).FCLinkButton("lnkRemove").Enabled = True GvDatos.Rows(IndexSeccionAlmacen).FCLinkButton("lnkRemove").ToolTip = "" End If UpDatos.Update() ElseIf TipoSeccionAlmacen = 2 Then If CantidadTotalSeccion > 0 Then GvDatosRecepcion.Rows(IndexSeccionAlmacen).FCTextBox("TxtCantidad").Enabled = False GvDatosRecepcion.Rows(IndexSeccionAlmacen).FCTextBox("TxtCantidad").ToolTip = "Cuenta con sección almacen" Else GvDatosRecepcion.Rows(IndexSeccionAlmacen).FCTextBox("TxtCantidad").Enabled = True GvDatosRecepcion.Rows(IndexSeccionAlmacen).FCTextBox("TxtCantidad").ToolTip = "" End If UpDatosRecepcion.Update() End If UpModalSeccionAlmacen.Update() End Sub Protected Sub LnkAddSeccionAlmacen_Click(sender As Object, e As EventArgs) If TipoSeccionAlmacen = 1 Then Dim ObjInv As New ClsInventarios Dim CantidadDisponible As Decimal = 0 If ObjInv.GetMovimientosDetalleSeccionesAlmacen(DdlSeccionAlmacenOrigen.SelectedValue.ToEntero, DdlAlmacenOrigen.SelectedValue.ToEntero, CvePS, UsuarioActual.CveEmpresa) Then If ObjInv.DtResultados.Rows.Count > 0 Then CantidadDisponible = ObjInv.DtResultados.Rows(0)("CantidadRestante").ToString.ToDecimal End If End If ObjInv.Dispose() CantidadDisponible -= DtSeccionAlmacen.FiltraParametros($"CvePS = {CvePS} AND CveSeccionAlmacenOrigen = {DdlSeccionAlmacenOrigen.SelectedValue}").SUMD("CantidadSeccionAlmacen") If TxtCantidadSeccion.Text.ToDecimal > CantidadDisponible Then Alert($"No tiene cantidad de producto suficiente en esta seccion de almacen, su cantidad restante es: {CantidadDisponible}", TipoMensaje.MsgAdvertencia) Exit Sub End If End If Dim Row As DataRow = Nothing DtSeccionAlmacen.AcceptChanges() Row = DtSeccionAlmacen.NewRow Row("CantidadSeccionAlmacen") = TxtCantidadSeccion.Text.ToDecimal Row("IndexSeccionAlmacen") = IndexSeccionAlmacen Row("CveSeccionAlmacenOrigen") = DdlSeccionAlmacenOrigen.SelectedValue.ToEntero Row("SeccionAlmacenOrigen") = DdlSeccionAlmacenOrigen.SelectedItem.Text Row("CveSeccionAlmacenDestino") = DdlSeccionAlmacenDestino.SelectedValue.ToEntero Row("SeccionAlmacenDestino") = DdlSeccionAlmacenDestino.SelectedItem.Text Row("CvePS") = CvePS Row("Consec") = DtSeccionAlmacen.Rows.Count + 1 Row("TipoSeccionAlmacen") = TipoSeccionAlmacen DtSeccionAlmacen.Rows.Add(Row) DtSeccionAlmacen.AcceptChanges() CargaSeccionAlmacen() End Sub Protected Sub LnkEliminarSeccion_Click(sender As Object, e As EventArgs) Dim gvRow As GridViewRow = DirectCast((DirectCast(sender, LinkButton)).NamingContainer, GridViewRow) Dim Index As Integer = 0 For Each Dr As DataRow In DtSeccionAlmacen.Rows If Dr("Consec").ToString.ToEntero = gvRow.DataKey("Consec").ToEntero() Then Exit For End If Index += 1 Next DtSeccionAlmacen.Rows.RemoveAt(Index) DtSeccionAlmacen.AcceptChanges() CargaSeccionAlmacen() End Sub 'Protected Sub LnkVerSecciones_Click(sender As Object, e As EventArgs) ' If Not CveVentaSurtir > 0 Then ' Alert("Tiene que seleccionar la venta a surtir", TipoMensaje.MsgAdvertencia) ' Exit Sub ' End If ' If Not DdlAlmacen.SelectedValue.ToEntero > 0 Then ' Alert("Tiene que seleccionar el almacen", TipoMensaje.MsgAdvertencia) ' Exit Sub ' End If ' Dim ObjInv As New ClsInventarios ' If ObjInv.GetExistenciaSeccionAlmacen(CveVentaSurtir, DdlAlmacen.SelectedValue.ToEntero, UsuarioActual.CveEmpresa) Then ' GvVerSeccionesAlmacen.DataSource = ObjInv.DtResultados ' End If ' ObjInv.Dispose() ' GvVerSeccionesAlmacen.DataBind() ' UpVerSeccionesAlmacen.Update() ' RegistraScript("$('#ModalVerSeccionesAlmacen').modal()") 'End Sub #End Region Protected Sub DldChofer_SelectedIndexChanged(sender As Object, e As EventArgs) Dim ObjAcar As New ClsAcarreos() If ObjAcar.GetChofer(DldChofer.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, 1, -1) Then Dim dr As DataRow = ObjAcar.DtResultados.Rows(0) If dr IsNot Nothing Then TxtIdentificacion.Text = dr("Identificacion").ToString TxtDomicilio.Text = dr("Domicilio").ToString TxtTelefono.Text = dr("Telefono").ToString TxtCiudad.Text = dr("Ciudad").ToString TxtLicencia.Text = dr("Licencia").ToString End If End If ObjAcar.Dispose() End Sub Protected Sub BtnCargaExcelConceptos_Click(sender As Object, e As EventArgs) If TxtExcelConceptos.getfiles().Archivos.Count > 0 Then Dim file As Archivo = TxtExcelConceptos.getfiles().Archivos(0) Dim Directorio As String = AppDomain.CurrentDomain.BaseDirectory & file.patch CargarArchivoConceptos(Directorio, file.filename) RegistraScript("$('#DivCargaExcelConceptos').modal('hide');") Else Alert("No existe el archivo. Favor de subir un archivo excel a la plataforma.", TipoMensaje.MsgError) End If End Sub Protected Sub BtnDescargarFormatoExcelConceptos_Click(sender As Object, e As EventArgs) Dim DtExcel As New DataTable DtExcel.Columns.Add(New DataColumn("Cantidad", GetType(Decimal))) DtExcel.Columns.Add(New DataColumn("Codigo", GetType(String))) DtExcel.Columns.Add(New DataColumn("Producto", GetType(String))) DtExcel.Columns.Add(New DataColumn("SerieLote", GetType(String))) DtExcel.Columns.Add(New DataColumn("Observaciones", GetType(String))) DtExcel.TableName = "Traspaso" SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet) Dim FileExcel As New ExcelFile() Dim worksheet = FileExcel.Worksheets.Add(DtExcel.TableName) worksheet.InsertDataTable(DtExcel, New InsertDataTableOptions() With { .ColumnHeaders = True, .StartRow = 0, .StartColumn = 0 }) worksheet.Rows(0).Style.FillPattern.SetPattern(FillPatternStyle.Solid, SpreadsheetColor.FromArgb(75, 119, 190), SpreadsheetColor.FromArgb(255, 255, 255)) worksheet.Rows(0).Style.Font.Color = SpreadsheetColor.FromArgb(255, 255, 255) Dim columnCount = worksheet.CalculateMaxUsedColumns() For i = 0 To columnCount worksheet.Columns(i).AutoFit(1, worksheet.Rows(0), worksheet.Rows(worksheet.Rows.Count - 1)) Next FileExcel.Save(Response, "Traspaso.xlsx", SaveOptions.XlsxDefault) End Sub Protected Sub CargarArchivoConceptos(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 = "Codigo" 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 = "SerieLote" Then Alert("El nombre de la cuarta columna debe ser 'SerieLote'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If If Not dt.Columns(4).ColumnName = "Observaciones" Then Alert("El nombre de la quinta columna debe ser 'Observaciones'. Favor de corregirlo", TipoMensaje.MsgError) Exit Sub End If dt.TableName = "Datos" Dim ProductosNoCargados As New StringBuilder() Dim RowsCargados As Integer = 0 Dim RowsNoCargados As Integer = 0 Dim NoPSConSerieLote As Integer = 0 Try Dim DtPS As DataTable = GlobalDTPS(UsuarioActual.CveEmpresa) For Each RowExcel As DataRow In dt.Rows If RowExcel("Codigo").ToString() <> "" Then Dim RowPS = DtPS.FiltroPrimero(String.Format("Codigo='{0}'", RowExcel("Codigo").ToString())) Dim CveProducto As Integer = RowPS("CvePS").ToString().ToEntero() Dim CveUnidadMedida As Integer = RowPS("CveUnidadMedida").ToString().ToEntero() Dim Cantidad As Double = RowExcel("Cantidad").ToString().ToDecimal() Dim SerieLote As String = RowExcel("SerieLote").ToString() Dim Observaciones As String = RowExcel("Observaciones").ToString() If CveProducto > 0 Then Dim Valido As Boolean = True Dim CveMetodoInventario As Integer = RowPS("Inv_CveMetodoInventario").ToString().ToEntero() If CveMetodoInventario = 5 And (String.IsNullOrEmpty(SerieLote.Trim()) OrElse SerieLote = "-1") Then Valido = False Alert($"El producto '{RowPS("PS")}' requiere 'SerieLote'", TipoMensaje.MsgAdvertencia) ProductosNoCargados.AppendFormat("{0},", RowPS("PS").ToString()) End If If CveMetodoInventario = 5 AndAlso Not String.IsNullOrEmpty(SerieLote.Trim()) Then NoPSConSerieLote = NoPSConSerieLote + 1 End If If Valido AndAlso (Cantidad > 0 AndAlso RowPS("VentaMinima").ToString.ToDecimal > 0) Then If Cantidad Mod RowPS("VentaMinima").ToString.ToDecimal <> 0 Then Valido = False ProductosNoCargados.AppendFormat("{0},", RowPS("PS").ToString()) End If End If If Valido Then Valido = ValidaExistencia(Cantidad, CveProducto, CveUnidadMedida, If(Not String.IsNullOrEmpty(SerieLote), SerieLote, "-1"), "-1", "-1") End If If Valido Then AgregarPS(Cantidad, CveProducto, CveUnidadMedida, Observaciones, If(Not String.IsNullOrEmpty(SerieLote), SerieLote, ""), "", "", 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 If NoPSConSerieLote > 0 Then ThSerieLote.Visible = True TdSerieLote.Visible = True TxtnSerieLote.Visible = True GvDatos.Columns(5).Visible = True End If 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 UpDatos.Update() End If End Sub Private Function ReadExcelFile(ByVal flatFilePath As String, ByVal firstRowHasHeaders As Boolean) As DataTable SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet) Dim excelFile As ExcelFile = ExcelFile.Load(flatFilePath) Dim unnamed As Integer = 0 Dim cols As Integer Dim columns As String() Dim curRow As Integer = 0 Dim curCol As Integer = 0 Dim dataTable As DataTable = New DataTable() Dim worksheet As ExcelWorksheet = excelFile.Worksheets(0) For cols = 0 To worksheet.Rows(0).AllocatedCells.Count - 1 If firstRowHasHeaders Then If worksheet.Rows(0).Cells(cols).Value IsNot Nothing Then dataTable.Columns.Add(worksheet.Rows(0).Cells(cols).Value.ToString()) Else dataTable.Columns.Add("Unnamed Column " & (System.Threading.Interlocked.Increment(unnamed))) End If curRow = 1 Else dataTable.Columns.Add("Column " & (cols + 1)) End If Next While curRow < worksheet.Rows.Count columns = New String(cols - 1) {} For curCol = 0 To cols - 1 If worksheet.Rows(curRow).Cells(curCol).Value Is Nothing Then columns(curCol) = "" Else columns(curCol) = worksheet.Rows(curRow).Cells(curCol).Value.ToString() End If Next dataTable.Rows.Add(columns) curRow += 1 End While Return dataTable End Function End Class