Files
SIG/Acumuladores/RepRecolecciones.aspx.vb
2024-02-15 13:41:26 -07:00

293 lines
12 KiB
VB.net

Imports System.Data
Imports CrystalDecisions.Shared.Json
Imports Extensiones
Imports Modelos
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
#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 (21) and Almacen like '%sado%'")
DdlAlmacenDestino.DataBind()
End Sub
Private Sub CargaDatos()
Dim ObjGeneral As New ClsGenerales
If (ObjGeneral.GetInvEntregaAlmacenRuta(-1, TxtFechaI.Text.ToDate, TxtFechaF.Text.ToDate, UsuarioActual.CveEmpresa, 2, -1)) 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
Dim LnkEditar As LinkButton = e.Row.FCLinkButton("LnkGvDatosRecoleccionEditar")
If e.Row.DataKey("Estatus") = "0" OrElse e.Row.DataKey("Estatus") = "" Then
LnkEditar.Visible = True
End If
' If e.Row.DataKey("Estatus") = "1" Then
e.Row.FCHyperLink("HplR").Visible = True
e.Row.FCHyperLink("HplR").NavigateUrl = "/Inventarios/EntradasSalidas.aspx?CveEntregaAlmacen=" & e.Row.DBCampo("CveEntregaAlmacen")
'End If
If e.Row.DataKey("CveTimbre") <> "" Then
e.Row.FCCheckBox("Chk").Visible = False
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()
Dim CveDireccionOrigen As Integer = GvRow.DataKey("CveDireccionOrigen").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 <br/>")
If ObjGenerales.GetEntregaAlmacenRutaDetalle(CveEntregaAlmacen) Then
For Each dr As DataRow In ObjGenerales.DtResultados.Rows
Str.AppendFormat(" {0} - {1}<br/>", dr("Cantidad"), dr("CodigoPS"))
HdnPSRecoleccion.Value = dr("CvePS").ToString
HdnCantidadRecoleccion.Value = dr("Cantidad").ToString
Next
LblProductosCargados.Text = Str.ToString
End If
ObjGenerales.Dispose()
GvModalPSRecoleccion.DataSource = DTRecoleccion
GvModalPSRecoleccion.DataBind()
UpModalRecoleccion.Update()
End Sub
Private Function InitDTRecoleccion() As DataTable
Dim DT As DataTable = New DataTable()
DT.Columns.Add("CveEntregaAlmacenDetalle", System.Type.[GetType]("System.Int32"))
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("CveEntregaAlmacenDetalle") = -1
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") = 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 = HdnCantidadRecoleccion.Value.ToDecimal
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 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, 26, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1)
Dim FolioSalida As Integer = ObjInventario.Folio
Dim CveMovimientoEntrada As Integer = ObjInventario.AddMovimiento(DdlAlmacenDestino.SelectedValue.ToEntero, 27, 1, Fecha, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, -1, -1, -1, -1, CveMovimientoRelacionado:=CveMovimientoSalida)
Dim CveUM As Integer = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CvePS:=HdnPSRecoleccion.Value.ToEntero).FiltroPrimeroValor("CveUnidadMedida", "").ToEntero
If Not ObjInventario.AddMovimientoDetalle(CveMovimientoSalida, HdnCantidadRecoleccion.Value.ToDecimal, CveUM, HdnPSRecoleccion.Value.ToEntero, 0) Then
ErrorMovInv = True
End If
'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
End If
End If
If Not ErrorMovInv Then
ObjInventario.Commit()
Dim MensajeAlert As New StringBuilder
MensajeAlert.Append("Se realizó con éxito el traspaso.")
MensajeAlert.AppendFormat("<br/> Folio de Salida: <b><a href=""/Inventarios/EntradasSalidas.aspx?CveMovimiento={1}"" class='Texto' target=""_blank"">{0}</a></b>", FolioSalida, CveMovimientoSalida)
'MensajeAlert.AppendFormat("<br/><a target='_blank' class='Texto' href='/Compras/PopUpVerFactura.aspx?P={0}'>Imprimir Reporte</a>", Encripta(String.Format("OP=Alm&CveMovimiento={0}", CveMovimientoSalida)))
Alert(MensajeAlert.ToString)
Else
ObjInventario.RollBack()
End If
End Sub
End Class