Imports System.Data Imports Extensiones Partial Class Acumuladores_RepRecolecciones Inherits ClsPaginas #Region "Propiedades" Private Property CveEntregaAlmacen As Integer Get If Not ViewState("CveEntregaAlmacen") Is Nothing Then Return ViewState("CveEntregaAlmacen").ToString.ToEntero Else Return -1 End If End Get Set(value As Integer) ViewState("CveEntregaAlmacen") = value End Set End Property Private Property DTRecoleccion As DataTable Get If ViewState("DTRecoleccion") Is Nothing Then ViewState("DTRecoleccion") = InitDTRecoleccion() End If Return CType(ViewState("DTRecoleccion"), DataTable) End Get Set(ByVal value As DataTable) ViewState("DTRecoleccion") = CType(value, DataTable) End Set End Property Private Property Actualizar As Boolean Get If Not ViewState("Actualizar") Is Nothing Then Return DirectCast(ViewState("Actualizar"), Boolean) Else Return False End If End Get Set(value As Boolean) ViewState("Actualizar") = value End Set End Property Private Property DTPSDefinidos As DataTable Get If ViewState("DTPSDefinidos") Is Nothing Then ViewState("DTPSDefinidos") = New DataTable() End If Return CType(ViewState("DTPSDefinidos"), DataTable) End Get Set(ByVal value As DataTable) ViewState("DTPSDefinidos") = CType(value, DataTable) End Set End Property #End Region Private Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not Page.IsPostBack Then InicializaCombos() CargaDatos() End If End Sub Private Sub InicializaCombos() CargaPS() TxtFechaI.Text = NowADS().AddMonths(-1).ToShortDateString TxtFechaF.Text = NowADS().AddMonths(1).ToShortDateString CargarCentrosDeCosto(Nothing, DdlSubProyecto, Nothing, LblSubProyecto) DdlAlmacenOrigen.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen IN (4)") DdlAlmacenOrigen.DataBind() DdlAlmacenDestino.DataSource = GlobalDTAlmacenUsuarios(UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1).FiltraParametros("CveTipoAlmacen IN (22) and Almacen like '%sado%' and CveAlmacen IN (449,616,628)") ' alm,. matriz,nav,obr recep sados DdlAlmacenDestino.DataBind() End Sub Private Sub CargaDatos() Dim ObjGeneral As New ClsGenerales If ObjGeneral.GetInvEntregaAlmacenRuta(DdlSubProyecto.SelectedValue.ToEntero, TxtFechaI.Text.ToDate, TxtFechaF.Text.ToDate, UsuarioActual.CveEmpresa, 3, DdlEstatus.SelectedValue.ToEntero) Then GvR.DataSource = ObjGeneral.DtResultados End If ObjGeneral.Dispose() UPGv.DataBind() UpGral.Update() End Sub Protected Sub gvR_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.DBCampo("CveMovimientoEntrada") = "" Then e.Row.FCHyperLink("HplR").Visible = True e.Row.FCLabel("LblRef").ToolTip = e.Row.DBCampo("CveEntregaAlmacen") e.Row.FCHyperLink("HplR").NavigateUrl = "/Inventarios/EntradasSalidas.aspx?CveEntregaAlmacen=" & e.Row.DBCampo("CveEntregaAlmacen") End If If e.Row.DBCampo("CveMovimientoEntrada") <> "" AndAlso e.Row.DBCampo("CveMovimientoTraslado") = "" Then Dim LnkEditar As LinkButton = e.Row.FCLinkButton("LnkGvDatosRecoleccionEditar") 'If e.Row.DBCampo("Estatus") = "0" OrElse e.Row.DBCampo("Estatus") = "" Then LnkEditar.Visible = True 'End If End If End If End Sub Protected Sub LnkGvDatosRecoleccionEditar_Click(ByVal sender As Object, ByVal e As EventArgs) Dim LnkEliminar As LinkButton = CType(sender, LinkButton) Dim GvRow As GridViewRow = CType(LnkEliminar.NamingContainer, GridViewRow) CveEntregaAlmacen = GvRow.DataKey("CveEntregaAlmacen").ToEntero() CargaDatosRecoleccionDetallePS() LtlModalRecoleccionTitulo.Text = "Definición de tamaños" BtnModalRecoleccionGuardar.Text = "Guardar" UpModalRecoleccion.Update() RegistraScript("$('#DivModalRecoleccion').modal('show');") End Sub Protected Sub DdlProducto_ValueChanged(ByVal sender As Object, ByVal e As EventArgs) ElProductoChange() End Sub Private Sub ElProductoChange() DdlModalRecoleccionUnidad.Items.Clear() DdlModalRecoleccionUnidad.DataSource = GlobalDTProductosServiciosEquivalencias(DdlProducto2.SelectedValue.ToEntero(), -1, UsuarioActual.CveEmpresa) DdlModalRecoleccionUnidad.DataBind() UpModalRecoleccion.Update() End Sub Private Sub CargaDatosRecoleccionDetallePS() Dim ObjGenerales As New ClsGenerales() Dim Str As New StringBuilder Str.Append("Productos Definidos
") If ObjGenerales.GetEntregaAlmacenRutaDetalle(CveEntregaAlmacen) Then DTPSDefinidos = ObjGenerales.DtResultados.Copy() End If ObjGenerales.Dispose() For Each dr As DataRow In DTPSDefinidos.Rows Str.AppendFormat(" {0} - {1}
", dr("Cantidad"), dr("CodigoPS")) 'HdnPSRecoleccion.Value = dr("CvePS").ToString 'HdnCantidadRecoleccion.Value = dr("Cantidad").ToString Next LblProductosCargados.Text = Str.ToString GvModalPSRecoleccion.DataSource = DTRecoleccion GvModalPSRecoleccion.DataBind() UpModalRecoleccion.Update() End Sub Private Function InitDTRecoleccion() As DataTable Dim Columnaid = New DataColumn() With {.ColumnName = "CveEntregaAlmacenDetalle", .DataType = Type.GetType("System.Int32"), .AutoIncrement = True, .AutoIncrementSeed = 1, .AutoIncrementStep = 1} Dim DT As DataTable = New DataTable() DT.Columns.Add(Columnaid) DT.Columns.Add("CveEntregaAlmacen", System.Type.[GetType]("System.Int32")) DT.Columns.Add("CvePS", System.Type.[GetType]("System.Int32")) DT.Columns.Add("Cantidad", System.Type.[GetType]("System.Double")) DT.Columns.Add("CveUnidadMedida", System.Type.[GetType]("System.Int32")) DT.Columns.Add("CveUsuario", System.Type.[GetType]("System.Int32")) DT.Columns.Add("FechaIng", System.Type.[GetType]("System.DateTime")) DT.Columns.Add("CodigoPS", System.Type.[GetType]("System.String")) DT.Columns.Add("Abreviatura", System.Type.[GetType]("System.String")) Return DT End Function Private Sub CargaPS() Dim lista As New List(Of String) Dim Filtro As String = "" For Each drow As DataRow In GlobalDTAcumTamaños(UsuarioActual.CveEmpresa).Rows If drow("CvePSCargo").ToString.ToEntero > 0 Then lista.Add(drow("CvePSCargo").ToString) End If Next If lista.Count > 0 Then Filtro = "CvePS in(" & String.Join(",", lista) & ")" DdlProducto2.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa).FiltraParametros(Filtro) DdlProducto2.DataBind() DdlProducto2.Items.Insert(0, New ListItem("Seleccione", "-1")) End If End Sub Protected Sub LnkModalAgregarPS_Click(ByVal sender As Object, ByVal e As EventArgs) Dim dRow As DataRow = DTRecoleccion.NewRow() dRow("CveEntregaAlmacen") = CveEntregaAlmacen dRow("CvePS") = DdlProducto2.SelectedValue.ToEntero() dRow("Cantidad") = TxtModalRecoleccionCantidad.Text.ToEntero() dRow("CveUnidadMedida") = DdlModalRecoleccionUnidad.SelectedValue.ToEntero() dRow("CveUsuario") = UsuarioActual.CveUsuario dRow("FechaIng") = NowADS() dRow("CodigoPS") = DdlProducto2.SelectedItem.Text dRow("Abreviatura") = If(DdlModalRecoleccionUnidad.SelectedItem IsNot Nothing, DdlModalRecoleccionUnidad.SelectedItem.Text, "") DTRecoleccion.Rows.Add(dRow) LimpiarControlesPS() CargaDatosRecoleccionDetallePS() End Sub Private Sub LimpiarControlesPS() TxtModalRecoleccionCantidad.Text = "" DdlModalRecoleccionUnidad.Items.Clear() 'DdlProducto2.txtText.Value = "" 'DdlProducto2.txtValue.Value = "" UpModalRecoleccion.Update() End Sub Private Sub BtnModalRecoleccionGuardar_Click(sender As Object, e As EventArgs) Handles BtnModalRecoleccionGuardar.Click Dim Cantidad As Decimal = DTPSDefinidos.SUMD("Cantidad") Dim CantidadDefinido As Decimal = 0 For Each gvr As GridViewRow In GvModalPSRecoleccion.Rows CantidadDefinido += gvr.DataKey("Cantidad").ToDecimal Next If CantidadDefinido <> Cantidad Then Alert("La cantidad definida no es la correcta", TipoMensaje.MsgAdvertencia) Exit Sub End If Dim ObjInventario As New ClsInventarios Dim ObjConta As New ClsContabilidad(ObjInventario.IniciaTransacSQL) Dim ObjGral As New ClsGenerales(ObjInventario.IniciaTransacSQL) Dim ErrorMovInv As Boolean = False Dim Fecha As DateTime = NowADS() Dim Concepto As String = "Traspaso Recolección" Dim CveMovimientoSalida As Integer = ObjInventario.AddMovimiento(DdlAlmacenOrigen.SelectedValue.ToEntero, 45, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, CveEntregaAlmacen:=CveEntregaAlmacen, Modulo:="clasifUsados") Dim FolioSalida As Integer = ObjInventario.Folio For Each Row As DataRow In DTPSDefinidos.Rows Dim CveUM As Integer = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CvePS:=Row("CvePS").ToString().ToEntero()).FiltroPrimeroValor("CveUnidadMedida", "").ToEntero If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, Row("Cantidad").ToString().ToDecimal, CveUM, Row("CvePS").ToString().ToEntero(), 0) Then ErrorMovInv = True End If Next Dim CveMovimientoEntrada As Integer = ObjInventario.AddMovimiento(DdlAlmacenDestino.SelectedValue.ToEntero, 42, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, CveMovimientoRelacionado:=CveMovimientoSalida, CveEntregaAlmacen:=CveEntregaAlmacen, Modulo:="clasifUsados") 'HdnPSRecoleccion For Each gvr As GridViewRow In GvModalPSRecoleccion.Rows Dim CveMovtoDetalle As Integer If ObjInventario.AddMovimientoDetalle(CveMovimientoEntrada, gvr.DataKey("Cantidad").ToDecimal, gvr.DataKey("CveUnidadMedida").ToEntero, gvr.DataKey("CvePS").ToEntero, 0) Then CveMovtoDetalle = ObjInventario.CveMovimientoDetalle Else ErrorMovInv = True End If Next If ObjInventario.GetMovimientosDetalle(CveMovimientoSalida, UsuarioActual.CveEmpresa) Then Dim Cont As Integer = 0 Dim dttSalida As DataTable = ObjInventario.DtResultados If Not ErrorMovInv Then Dim CvePrePoliza As Integer = ObjConta.AddPrePolizas("Inventario/TraspasoAlmacen", 53, 0, 0, 1, Fecha, Concepto, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Dim importe As Decimal = dttSalida.SUMD("Total").RoundSQL Dim Contabilizable As Boolean = False If Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, True, importe, importe, 68, Concepto, Concepto, CveMovimientoAlmacen:=CveMovimientoSalida, Contabilizable:=Contabilizable) Then ErrorMovInv = True End If If Not ErrorMovInv AndAlso Not ObjConta.AddPrePolizasDetalle(CvePrePoliza, False, importe, importe, 68, Concepto, Concepto, CveMovimientoAlmacen:=CveMovimientoEntrada, Contabilizable:=Contabilizable) Then ErrorMovInv = True End If If Not ErrorMovInv Then If ObjConta.ValidacionesPrePoliza(CvePrePoliza, UsuarioActual) Then If ObjConta.ValorPolizaDescuadre > 0 Then 'MsgError = ObjMov.MensajePolizaDescuadre ErrorMovInv = True 'GuardaLogAD($"Bancos/Transferencias | Error:{ObjMov.MensajePolizaDescuadre} Diferencia:{ObjMov.ValorDiferencia} | CvePrePoliza:{CvePrePoliza}", "LogPrePolizas") End If Else ErrorMovInv = True End If End If If Not ErrorMovInv Then ObjGral.UpdateInvEntregaAlmacenEstatus(CveEntregaAlmacen, UsuarioActual.CveEmpresa, 1) End If End If End If If Not ErrorMovInv Then ObjInventario.Commit() GvModalPSRecoleccion.DataBind() DTRecoleccion.Clear() RegistraScript("$('#DivModalRecoleccion').modal('hide');") Dim MensajeAlert As 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))) Alert(MensajeAlert.ToString) CargaDatos() Else ObjInventario.RollBack() End If End Sub Protected Sub LnkModalGvModalPSRecoleccionEliminar_Click(sender As Object, e As EventArgs) Dim LnkEliminar As LinkButton = CType(sender, LinkButton) Dim GvRow As GridViewRow = CType(LnkEliminar.NamingContainer, GridViewRow) Dim CveEntregaAlmacenDetalle = GvRow.DataKey("CveEntregaAlmacenDetalle").ToEntero() Dim drss As DataRow() = DTRecoleccion.Select($"CveEntregaAlmacenDetalle = {CveEntregaAlmacenDetalle}") If drss.Count > 0 Then DTRecoleccion.Rows.Remove(drss(0)) End If DTRecoleccion.AcceptChanges() GvModalPSRecoleccion.DataSource = DTRecoleccion GvModalPSRecoleccion.DataBind() End Sub Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs) CargaDatos() End Sub End Class