355 lines
16 KiB
VB.net
355 lines
16 KiB
VB.net
Option Strict On
|
|
Option Explicit On
|
|
|
|
Imports Microsoft.Reporting.WebForms
|
|
Imports Extensiones
|
|
Imports System.Data
|
|
|
|
Partial Class Compras_RepComprasAF
|
|
Inherits ClsPaginas
|
|
|
|
#Region "PROPIEDADES"
|
|
|
|
Private Property TCEspecifico As Double
|
|
Get
|
|
If ViewState("TCEspecifico") Is Nothing Then
|
|
Return -1
|
|
Else
|
|
Return DirectCast(ViewState("TCEspecifico"), Double)
|
|
End If
|
|
End Get
|
|
Set(value As Double)
|
|
ViewState("TCEspecifico") = value
|
|
End Set
|
|
End Property
|
|
Private Property DTDatos As DataTable
|
|
Get
|
|
If ViewState("DTDatos") Is Nothing Then
|
|
Return New DataTable
|
|
Else
|
|
Return DirectCast(ViewState("DTDatos"), DataTable)
|
|
End If
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DTDatos") = value
|
|
End Set
|
|
End Property
|
|
Private Property Agrupador As String
|
|
Get
|
|
Return ViewState("Agrupador").ToString
|
|
End Get
|
|
|
|
Set(value As String)
|
|
ViewState("Agrupador") = value
|
|
End Set
|
|
End Property
|
|
|
|
#End Region
|
|
|
|
Private Sub Compras_RepComprasAFaspx_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
If Not IsPostBack Then
|
|
CargaCombos()
|
|
'DdlPS.ddl.Visible = False
|
|
End If
|
|
End Sub
|
|
|
|
#Region "CARGAS"
|
|
|
|
Private Sub CargaCombos()
|
|
txtFechaI.Text = $"01/{Now.Month}/{Now.Year}"
|
|
|
|
DdlProveedores.DataSource = GlobalDTCompProveedores(UsuarioActual.CveEmpresa)
|
|
DdlProveedores.DataBind()
|
|
|
|
DdlMonedas.DataSource = GlobalDTMonedas()
|
|
DdlMonedas.DataBind()
|
|
|
|
DdlTipoActivoFijo.DataSource = GlobalDTTipoActivoFijo(UsuarioActual.CveEmpresa).FiltraParametros("", "TipoActivoFijo")
|
|
DdlTipoActivoFijo.DataBind()
|
|
|
|
DdlClasificacion.DataSource = GlobalDTClasificaciones(UsuarioActual.CveEmpresa).FiltraParametros(" Codigo = '' OR Codigo IS NULL ", Orderby:="Clasificacion")
|
|
DdlClasificacion.DataBind()
|
|
|
|
|
|
Dim ObjClasificacion As New ClsClasificaciones
|
|
|
|
If ObjClasificacion.GetClasificacion2ProductoServicio(UsuarioActual.CveEmpresa) Then
|
|
DdlClasificacion2.DataSource = ObjClasificacion.DtResultados
|
|
Else
|
|
DdlClasificacion2.DataSource = Nothing
|
|
End If
|
|
|
|
ObjClasificacion.Dispose()
|
|
DdlClasificacion2.DataBind()
|
|
|
|
DdlActivoFijo.DataSource = GlobalDTActivoFijos(UsuarioActual.CveEmpresa)
|
|
DdlActivoFijo.DataBind()
|
|
|
|
CargarCentrosDeCosto(DdlProyecto, DdlSubProyecto, LblProyecto, LblSubProyecto, divProyecto:=DivProyecto)
|
|
|
|
CargaPS(-1)
|
|
|
|
End Sub
|
|
|
|
Private Sub DdlTipoActivoFijo_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlTipoActivoFijo.SelectedIndexChanged
|
|
DdlSubTipoActivoFijo.Items.Clear()
|
|
DdlSubTipoActivoFijo.DataSource = GlobalDTSubTipoActivoFijo(UsuarioActual.CveEmpresa).FiltraParametros(String.Format("CveTipoActivoFijo = {0}", DdlTipoActivoFijo.SelectedValue), "SubTipoActivoFijo")
|
|
DdlSubTipoActivoFijo.DataBind()
|
|
DdlSubTipoActivoFijo.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
DdlSubTipoActivoFijo.SelectedIndex = 0
|
|
End Sub
|
|
|
|
Protected Sub DdlProyecto_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlProyecto.SelectedIndexChanged
|
|
CargarSubProyecto(DdlSubProyecto, DdlProyecto.SelectedValue)
|
|
End Sub
|
|
Protected Sub BtnConsultar_Click(sender As Object, e As System.EventArgs) Handles BtnConsultar.Click
|
|
CargaDatos()
|
|
UPDatos.Update()
|
|
End Sub
|
|
|
|
Private Sub CargaDatos()
|
|
Dim ObjCompras As New ClsCompras()
|
|
Dim FechaI, FechaF As String
|
|
Dim CvePS As Integer = If(DdlPS.txtValue.Value = "", -1, DdlPS.txtValue.Value.ToString.ToEntero)
|
|
FechaI = If(IsDate(txtFechaI.Text.Trim()), txtFechaI.Text.Trim(), "-1")
|
|
FechaF = If(IsDate(txtFechaF.Text.Trim()), txtFechaF.Text.Trim(), "-1")
|
|
If RblTipoCambio.SelectedValue.ToEntero = 3 And TxtEspecifico.Text <> "" Then
|
|
TCEspecifico = TxtEspecifico.Text.ToDouble
|
|
Else
|
|
TCEspecifico = -1
|
|
End If
|
|
|
|
If ObjCompras.GetRepComprasAF(FechaI, FechaF, DdlProveedores.SelectedValue.ToEntero, DdlMonedas.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, DdlGrupo.SelectedValue.ToEntero,
|
|
DdlProyecto.SelectedValue.ToEntero, DdlSubProyecto.SelectedValue.ToEntero, RblTipoCambio.SelectedValue.ToEntero, TCEspecifico,
|
|
DdlClasificacion.SelectedValue.ToEntero, DdlActivoFijo.SelectedValue.ToEntero, DdlTipoActivoFijo.SelectedValue.ToEntero, DdlSubTipoActivoFijo.SelectedValue.ToEntero,
|
|
CvePS, CveUsuarioConsulta:=UsuarioActual.CveUsuario, CveClasificacion2:=DdlClasificacion2.SelectedValue.ToEntero, CveTipoCompraAF:=DdlTipoCompra.SelectedValue.ToEntero) Then
|
|
|
|
DTDatos = ObjCompras.DtResultados
|
|
GvDatos.DataSource = ObjCompras.DtResultados
|
|
Else
|
|
DTDatos = Nothing
|
|
GvDatos.DataSource = Nothing
|
|
End If
|
|
ObjCompras.Dispose()
|
|
GvDatos.DataBind()
|
|
Agrupador = DdlGrupo.SelectedItem.Text
|
|
End Sub
|
|
|
|
|
|
#End Region
|
|
|
|
#Region "GRIDVIEWROW"
|
|
|
|
Protected Sub GvDatos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvDatos.RowDataBound
|
|
If e.Row.RowType = DataControlRowType.Header Then
|
|
e.Row.Cells(0).Text = DdlGrupo.SelectedItem.Text
|
|
End If
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
Dim FechaI, FechaF As String
|
|
FechaI = If(IsDate(txtFechaI.Text.Trim()), txtFechaI.Text.Trim(), "-1")
|
|
FechaF = If(IsDate(txtFechaF.Text.Trim()), txtFechaF.Text.Trim(), "-1")
|
|
Dim PS As String = DdlPS.txtText.Value
|
|
Dim CvePS As Integer = DdlPS.txtValue.Value.ToEntero
|
|
|
|
|
|
If e.Row.DBCampo("Orden") = "1" Then
|
|
Dim Liga As String = $"/Compras/RepComprasAFDetalle.aspx?GPO={DdlGrupo.SelectedValue}&Anio={e.Row.DBCampo("Anio")}&Mes={e.Row.DBCampo("Mes")}&AnioMes={ e.Row.DBCampo("AnioMes")}&Fecha={e.Row.DBCampo("Fecha")}&CveProveedor={ e.Row.DBCampo("CveProveedor")}&CveActivoFijo={e.Row.DBCampo("CveActivoFijo")}&CveTipoActivoFijo={e.Row.DBCampo("CveTipoActivoFijo")}&CveSubTipoActivoFijo={e.Row.DBCampo("CveSubTipoActivoFijo")}&CveProyecto={ DdlProyecto.SelectedValue}&CveSubProyecto={DdlSubProyecto.SelectedValue}&CvePS={ If(CvePS > 0, CvePS.ToString, e.Row.DBCampo("CvePS").ToString) }&CveClasificacion={e.Row.DBCampo("CveClasificacion")}&CveMoneda={ e.Row.DBCampo("CveMoneda")}&FechaI={FechaI}&FechaF={FechaF}&PS={PS}&CveClasificacion2={e.Row.DBCampo("CveClasificacion2")}&CveTipoCompraAF={DdlTipoCompra.SelectedValue}"
|
|
e.Row.Cells(0).Text = String.Format("<a class='{0}' target='_blank' href='{1}'>{2}</a>", "Texto", Liga, e.Row.DataKey("GPO").ToString)
|
|
Else
|
|
e.Row.BackColor = Drawing.Color.LightGray
|
|
Dim Liga As String = $"/Compras/RepComprasAFDetalle.aspx?GPO=-1&Anio={e.Row.DBCampo("Anio")}&Mes={e.Row.DBCampo("Mes")}&AnioMes={ e.Row.DBCampo("AnioMes")}&Fecha={e.Row.DBCampo("Fecha")}&CveProveedor={ e.Row.DBCampo("CveProveedor")}&CveActivoFijo={e.Row.DBCampo("CveActivoFijo")}&CveTipoActivoFijo={e.Row.DBCampo("CveTipoActivoFijo")}&CveSubTipoActivoFijo={e.Row.DBCampo("CveSubTipoActivoFijo")}&CveProyecto={ DdlProyecto.SelectedValue}&CveSubProyecto={DdlSubProyecto.SelectedValue}&CvePS={ If(CvePS > 0, CvePS.ToString, e.Row.DBCampo("CvePS").ToString)}&CveClasificacion={e.Row.DBCampo("CveClasificacion")}&CveMoneda={ e.Row.DBCampo("CveMoneda")}&FechaI={FechaI}&FechaF={FechaF}&PS={PS}&CveClasificacion2={e.Row.DBCampo("CveClasificacion2")}&CveTipoCompraAF={DdlTipoCompra.SelectedValue}"
|
|
|
|
e.Row.Cells(0).Text = String.Format("<a style='font-weight:bold' class='{0}' target='_blank' href='{1}'>{2}</a>", "Texto", Liga, e.Row.DataKey("Moneda").ToString)
|
|
|
|
End If
|
|
|
|
End If
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "IMPRESIONES"
|
|
Private Sub LnkExportar_Click(sender As Object, e As EventArgs) Handles LnkExportar.Click
|
|
GenerarPDF("Excel")
|
|
End Sub
|
|
Private Sub LinkPDF_Click(sender As Object, e As EventArgs) Handles LinkPDF.Click
|
|
GenerarPDF()
|
|
End Sub
|
|
|
|
Private Sub GenerarPDF(Optional Formato As String = "PDF")
|
|
Dim ObjTareas As New ClsOIEventos
|
|
Dim params As New List(Of ReportParameter)
|
|
Dim Imagen As New System.IO.FileInfo($"{UsuarioActual.Empresa.Ruta}/Logo.png")
|
|
|
|
Dim FechaI, FechaF As String
|
|
FechaI = If(txtFechaI.Text = "" Or txtFechaI.Text = "__/__/____", "-1", txtFechaI.Text)
|
|
FechaF = If(txtFechaF.Text = "" Or txtFechaF.Text = "__/__/____", "-1", txtFechaF.Text)
|
|
|
|
'AgrupadoPor
|
|
params.Add(New ReportParameter("AgrupadoPor", FiltrosUsados()))
|
|
params.Add(New ReportParameter("GPO", DdlGrupo.SelectedItem.Text))
|
|
params.Add(New ReportParameter("Titulo", "REPORTE COMPRAS ACTIVOS FIJOS"))
|
|
params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa))
|
|
params.Add(New ReportParameter("FechaInicio", FechaI))
|
|
params.Add(New ReportParameter("FechaFin", FechaF))
|
|
params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre))
|
|
params.Add(New ReportParameter("FechaImpresion", Now.ToDateTime.ToShortDateString))
|
|
|
|
params.Add(New ReportParameter("LogoPath", If(Imagen.Exists, $"file://{Imagen.FullName}", "")))
|
|
ImprimirPDF("Empresas\Grales\Formatos\RepComprasAF.rdlc", DTDatos, params, "ReporteComprasAF_" & Now.ToString("yyyyMMddmmss"), Formato:=Formato)
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "TIPO CAMBIO/ FILTROS USADOS"
|
|
Private Sub RblTipoCambio_SelectedIndexChanged(sender As Object, e As EventArgs) Handles RblTipoCambio.SelectedIndexChanged
|
|
If RblTipoCambio.SelectedValue.ToEntero = 3 Then
|
|
Dim TipoCambio As Double
|
|
LiEspecifico.Visible = True
|
|
TipoCambio = GlobalTipoCambio(Now)
|
|
TxtEspecifico.Text = TipoCambio.ToString
|
|
Else
|
|
LiEspecifico.Visible = False
|
|
End If
|
|
UpBodyTipoCambio.Update()
|
|
End Sub
|
|
|
|
Private Function FiltrosUsados() As String
|
|
Dim filtro As String = "<b>Filtros:</b> "
|
|
Dim ListaFiltros As New List(Of String)
|
|
Dim Contador As Integer = 0
|
|
If txtFechaI.Text.Length > 0 Then
|
|
ListaFiltros.Add("FechaI: " & txtFechaI.Text)
|
|
End If
|
|
If txtFechaF.Text.Length > 0 Then
|
|
ListaFiltros.Add("FechaF: " & txtFechaF.Text)
|
|
End If
|
|
If DdlTipoActivoFijo.SelectedIndex > 0 Then
|
|
ListaFiltros.Add("Tipo: " & DdlTipoActivoFijo.SelectedItem.Text)
|
|
End If
|
|
If DdlSubTipoActivoFijo.SelectedIndex > 0 Then
|
|
ListaFiltros.Add("SubTipo: " & DdlSubTipoActivoFijo.SelectedItem.Text)
|
|
End If
|
|
If DdlActivoFijo.SelectedIndex > 0 Then
|
|
ListaFiltros.Add("AF: " & DdlActivoFijo.SelectedItem.Text)
|
|
End If
|
|
If DdlMonedas.SelectedIndex > 0 Then
|
|
ListaFiltros.Add("Moneda: " & DdlMonedas.SelectedItem.Text)
|
|
End If
|
|
If DdlProyecto.SelectedIndex > 0 Then
|
|
ListaFiltros.Add("Proyecto: " & DdlProyecto.SelectedItem.Text)
|
|
End If
|
|
If DdlSubProyecto.SelectedIndex > 0 Then
|
|
ListaFiltros.Add("SubProyecto: " & DdlSubProyecto.SelectedItem.Text)
|
|
End If
|
|
If DdlProveedores.SelectedIndex > 0 Then
|
|
ListaFiltros.Add("Proveedor: " & DdlProveedores.SelectedItem.Text)
|
|
End If
|
|
If DdlPS.txtValue.Value.ToEntero > 0 Then
|
|
ListaFiltros.Add("Producto: " & DdlPS.txtText.Value)
|
|
End If
|
|
If DdlClasificacion.SelectedIndex > 0 Then
|
|
ListaFiltros.Add("Clasificación: " & DdlClasificacion.SelectedItem.Text)
|
|
End If
|
|
|
|
If DdlClasificacion2.SelectedIndex > 0 Then
|
|
ListaFiltros.Add("Clasificación: " & DdlClasificacion2.SelectedItem.Text)
|
|
End If
|
|
|
|
For Each s As String In ListaFiltros
|
|
If Contador > 0 Then
|
|
filtro = filtro & ", " & s
|
|
Else
|
|
filtro = filtro & " " & s
|
|
End If
|
|
Contador = Contador + 1
|
|
Next
|
|
Return filtro
|
|
End Function
|
|
#End Region
|
|
|
|
#Region "GRAFICA"
|
|
|
|
Protected Sub LnkVerGrafica_Click(sender As Object, e As EventArgs)
|
|
If Not DTDatos IsNot Nothing AndAlso DTDatos.Rows.Count > 0 Then
|
|
Alert("No hay datos disponibles", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
|
|
LblTituloGrafica.Text = $"Agrupado por: {Agrupador}"
|
|
RegistraScript("$('#DivModalGrafica').modal('show')")
|
|
CambioGrafica()
|
|
End Sub
|
|
|
|
Private Sub CambioGrafica()
|
|
Dim Dt As New DataTable()
|
|
Dt.Columns.Add("Texto")
|
|
Dt.Columns.Add("Valor")
|
|
Dt.Columns.Add("Color")
|
|
Dt.Columns.Add("Moneda")
|
|
Dim RowColorIndex As Integer = 0
|
|
For Each Dr As DataRow In DTDatos.Rows
|
|
If Dr("Orden").ToString = "1" Then
|
|
Dim Row As DataRow = Nothing
|
|
Row = Dt.NewRow()
|
|
Row("Texto") = $"{Dr("GPO").ToString} {GlobalDTMonedas().FiltraParametros($"CveMoneda = {Dr("CveMoneda").ToString}").Rows(0)("Abreviatura").ToString}"
|
|
Select Case DdlVer.SelectedValue.ToEntero
|
|
Case 1
|
|
Row("Valor") = Dr("Total").ToString.FormatoNumero
|
|
Case 2
|
|
Row("Valor") = Dr("Cantidad").ToString.FormatoNumero
|
|
End Select
|
|
Row("Color") = Colors(RowColorIndex)
|
|
Row("Moneda") = Dr("Moneda").ToString
|
|
Dt.Rows.Add(Row)
|
|
RowColorIndex += 1
|
|
If RowColorIndex >= Colors.Length Then RowColorIndex = 0
|
|
End If
|
|
Next
|
|
|
|
Dim query = From s In Dt.AsEnumerable() Select New With {.Texto = s("Texto").ToString(), .Valor = s("Valor").ToString().ToDouble(), .Color = s("Color").ToString(), .Moneda = s("Moneda").ToString()}
|
|
Dim json As String = Newtonsoft.Json.JsonConvert.SerializeObject(query)
|
|
Select Case DdlGrafica.SelectedValue.ToEntero
|
|
Case 1
|
|
RegistraScript($"CargaGraficaBarras({json})", "22")
|
|
Case 2
|
|
RegistraScript($"CargaGraficaPastel({json})", "22")
|
|
End Select
|
|
UPModalProd.Update()
|
|
End Sub
|
|
Protected Sub DdlGrafica_SelectedIndexChanged(sender As Object, e As EventArgs)
|
|
CambioGrafica()
|
|
End Sub
|
|
|
|
Protected Sub DdlVer_SelectedIndexChanged(sender As Object, e As EventArgs)
|
|
CambioGrafica()
|
|
End Sub
|
|
|
|
#End Region
|
|
Protected Sub DdlClasificacion_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlClasificacion.SelectedIndexChanged
|
|
CargaPS(DdlClasificacion.SelectedValue.ToEntero)
|
|
End Sub
|
|
Private Sub CargaPS(CveClasificacion As Integer)
|
|
|
|
DdlPS.setEsWebService(If(UsuarioActual.Empresa.Funcionalidad(105).ToString = "1", True, False))
|
|
|
|
If Not UsuarioActual.Empresa.Funcionalidad(105).ToString = "1" Then
|
|
DdlPS.ddl.Items.Clear()
|
|
|
|
If CveClasificacion > 0 Then
|
|
DdlPS.ddl.DataSource = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa, CveClasificacion:=CveClasificacion, Estatus:=1)
|
|
End If
|
|
|
|
|
|
DdlPS.ddl.DataBind()
|
|
DdlPS.ddl.Items.Insert(0, New ListItem("*** Actualizar listado de Productos o Servicios ***", "-2"))
|
|
DdlPS.ddl.Items.Insert(0, New ListItem("Seleccione el Producto", "-1"))
|
|
Else
|
|
DdlPS.ddlWS.Attributes.Add("data-cveclasificacion", DdlClasificacion.SelectedValue)
|
|
DdlPS.SelectedText = "Todos"
|
|
DdlPS.SelectedValue = "-1"
|
|
End If
|
|
|
|
End Sub
|
|
End Class
|