Files
SIG/Contabilidad2/RepAnexoCatalogoMensual.aspx.vb
2023-10-09 11:55:07 -07:00

410 lines
21 KiB
VB.net

Option Explicit On
Option Strict On
Imports System.Data
Imports DocumentFormat.OpenXml.EMMA
Imports DocumentFormat.OpenXml.Office2010.ExcelAc
Imports Extensiones
Partial Class Contabilidad2_RepAnexoCatalogoMensual
Inherits ClsPaginas
#Region " PROPIEDADES "
Public Property CveCuenta As Integer
Get
Return ViewState("CveCuenta").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("CveCuenta") = value
End Set
End Property
Private Property listacolores As List(Of String)
Get
Return DirectCast(ViewState("listacolores"), List(Of String))
End Get
Set(value As List(Of String))
ViewState("listacolores") = value
End Set
End Property
Private Property listaCampos As List(Of String())
Get
Return DirectCast(ViewState("listaCampos"), List(Of String()))
End Get
Set(value As List(Of String()))
ViewState("listaCampos") = value
End Set
End Property
#End Region
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
listacolores = New List(Of String)
listaCampos = New List(Of String())
listacolores.Add("#FF0F00")
listacolores.Add("#FF6600")
listacolores.Add("#F8FF01")
listacolores.Add("#04D215")
listacolores.Add("#2A0CD0")
listacolores.Add("#8A0CCF")
listacolores.Add("#CD0D74")
listacolores.Add("#754DEB")
listacolores.Add("#DDDDDD")
listacolores.Add("#999999")
listacolores.Add("#000000")
listacolores.Add("#FF0F00")
Dim EjercicioParametro, SubProyectoParametro, DivisorParametro, Periodo, TRCU As Integer
CveCuenta = IfNull(Request("CveCuenta"), "-1").ToString.ToEntero
EjercicioParametro = IfNull(Request("Ejercicio"), "-1").ToString.ToEntero
SubProyectoParametro = IfNull(Request("CveSubProyecto"), "-1").ToString.ToEntero
DivisorParametro = IfNull(Request("Divisor"), "-1").ToString.ToEntero
Periodo = IfNull(Request("Periodo"), "-1").ToString.ToEntero
TRCU = IfNull(Request("TRCU"), "-1").ToString.ToEntero
InicializaValores()
DdlEjercicio.SelectedValueExist(EjercicioParametro.ToString)
DdlSubproyecto.SelectedValueExist(SubProyectoParametro.ToString)
DdlDivisor.SelectedValueExist(DivisorParametro.ToString)
DdlPeriodo.SelectedValueExist(Periodo)
DdlTri.SelectedValueExist(TRCU)
If CveCuenta > 0 Then
DdlCuentas.SelectedValueExist(CveCuenta)
CargaDatos()
End If
End If
End Sub
#Region " INICIALIZA VALORES "
Private Sub InicializaValores()
CargaCombos()
End Sub
Private Sub CargaCombos()
Dim Conta As New ClsContabilidad
If Conta.GetEjercicios(UsuarioActual.CveEmpresa) Then
DdlEjercicio.DataSource = Conta.DtResultados
Else
DdlEjercicio.DataSource = Nothing
End If
Dim strGlobal As String = ""
If Conta.GetCuentas(-1, "-1", -1, UsuarioActual.CveEmpresa) Then
Dim dr As DataRow = Conta.DtResultados.FiltroPrimero("Codigo IN ('_GLOBAL')")
If dr IsNot Nothing Then strGlobal = dr.Item(0).ToString
DdlCuentas.DataSource = Conta.DtResultados
End If
Conta.Dispose()
DdlCuentas.DataBind()
DdlEjercicio.DataBind()
DdlEjercicio.SelectedValueExist(NowADS().Year.ToString)
CargarCentrosDeCosto(DdlProyecto, DdlSubproyecto, LblProyecto, LblSubProyecto, divProyecto:=DivProyecto)
End Sub
#End Region
#Region " CARGA DATOS "
Protected Sub BtnCargaAsignados_Click(sender As Object, e As EventArgs) Handles BtnCargaAsignados.Click
CargaDatos()
End Sub
Private Sub CargaDatos()
If Not DdlCuentas.SelectedValue.ToEntero > 0 Then
Alert("Debe de seleccionar una cuenta.")
Exit Sub
End If
Dim Conta As New ClsContabilidad
If Conta.GetAnexoCatalogoMensual(DdlCuentas.SelectedValue.ToEntero, DdlEjercicio.SelectedValue.ToEntero, DdlSubproyecto.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, DdlDivisor.SelectedValue.ToEntero, UsuarioActual.CveUsuario, DdlPeriodo.SelectedValue.ToEntero) Then
GvMensual2.DataSource = Conta.DtResultados
Else
GvMensual2.DataSource = Nothing
End If
GvMensual2.DataBind()
If DdlTri.SelectedValue.ToEntero = 0 Then
GvMensual2.Columns(9).Visible = False
GvMensual2.Columns(20).Visible = False
GvMensual2.Columns(31).Visible = False
GvMensual2.Columns(41).Visible = False
GvMensual2.Columns(13).Visible = False
GvMensual2.Columns(27).Visible = False
GvMensual2.Columns(42).Visible = False
ElseIf DdlTri.SelectedValue.ToEntero = 1 Then
GvMensual2.Columns(9).Visible = True
GvMensual2.Columns(20).Visible = True
GvMensual2.Columns(31).Visible = True
GvMensual2.Columns(41).Visible = True
GvMensual2.Columns(13).Visible = False
GvMensual2.Columns(27).Visible = False
GvMensual2.Columns(42).Visible = False
ElseIf DdlTri.SelectedValue.ToEntero = 2 Then
GvMensual2.Columns(9).Visible = False
GvMensual2.Columns(20).Visible = False
GvMensual2.Columns(31).Visible = False
GvMensual2.Columns(41).Visible = False
GvMensual2.Columns(13).Visible = True
GvMensual2.Columns(27).Visible = True
GvMensual2.Columns(42).Visible = True
End If
UpMensual.Update()
If GvMensual2.Rows.Count > 0 Then
LnkExportar.Visible = True
UpAcciones.Update()
End If
Conta.Dispose()
End Sub
#End Region
#Region " GV ROW DATABOUND "
Protected Sub GvMensual1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvMensual2.RowDataBound
If e.Row.RowType = DataControlRowType.Header Then
setgrafica(e)
End If
If e.Row.RowType = DataControlRowType.DataRow Then
'If e.Row.RowIndex = 0 Then
' e.Row.Style.Add("font-weight", "bold")
'End If
setgrafica(e)
If e.Row.DataKey("Level") = "0" Then
e.Row.CssClass = "Totales"
ElseIf e.Row.DataKey("Level") = "1" Then
e.Row.CssClass = "SubTotales"
End If
'If e.Row.DBCampo("TipoCuenta").Contiene("3", "4") Then
' e.Row.CssClass = "Totales"
'ElseIf e.Row.DBCampo("TipoCuenta").Contiene("1") Then
' e.Row.CssClass = "SubTotales"
'End If
Dim Enero, Febrero, Marzo, Abril, Mayo, Junio, Julio, Agosto, Septiembre, Octubre, Noviembre, Diciembre As Decimal
Enero = e.Row.DBCampo("Enero").ToDecimal()
Febrero = e.Row.DBCampo("Febrero").ToDecimal()
Marzo = e.Row.DBCampo("Marzo").ToDecimal()
Abril = e.Row.DBCampo("Abril").ToDecimal()
Mayo = e.Row.DBCampo("Mayo").ToDecimal()
Junio = e.Row.DBCampo("Junio").ToDecimal()
Julio = e.Row.DBCampo("Julio").ToDecimal()
Agosto = e.Row.DBCampo("Agosto").ToDecimal()
Septiembre = e.Row.DBCampo("Septiembre").ToDecimal()
Octubre = e.Row.DBCampo("Octubre").ToDecimal()
Noviembre = e.Row.DBCampo("Noviembre").ToDecimal()
Diciembre = e.Row.DBCampo("Diciembre").ToDecimal()
Dim CveCunetaRow As Integer = e.Row.DataKey("CveCuenta").ToEntero
For x = 2 To GvMensual2.Columns.Count - 1
If e.Row.Cells(x).Text.Replace("%", "").ToDecimal = 0 Then
e.Row.Cells(x).Text = "-"
ElseIf e.Row.Cells(x).Text.Replace("%", "").ToDecimal < 0 Then
e.Row.Cells(x).ForeColor = Drawing.Color.OrangeRed
End If
If x = 2 Then
e.Row.Cells(x).Text = $"<a { If(Enero < 0, "style='color:Red;'", "style='color:#337ab7;'") } target='_blank' href='./RepAnexoCatalogo.aspx?CveCuenta={CveCunetaRow}&FF={ $"01/01/{DdlEjercicio.SelectedValue}".ToDate.LastDayOfMonth.ToShortDateString }&FI=01/01/{DdlEjercicio}&ER=1&CveSubProyecto={DdlSubproyecto.SelectedValue}' >{ If(DdlDivisor.SelectedValue.ToEntero > 1, Enero.ToString("###,###,##0"), Enero.ToString("###,###,###.00")) }</a>"
End If
If x = 3 Then
e.Row.Cells(x).Text = $"<a { If(Febrero < 0, "style='color:Red;'", "style='color:#337ab7;'") } target='_blank' href='./RepAnexoCatalogo.aspx?CveCuenta={CveCunetaRow}&FF={ $"01/02/{DdlEjercicio.SelectedValue}".ToDate.LastDayOfMonth.ToShortDateString }&FI=01/02/{DdlEjercicio}&ER=1&CveSubProyecto={DdlSubproyecto.SelectedValue}' >{ If(DdlDivisor.SelectedValue.ToEntero > 1, Febrero.ToString("###,###,##0"), Febrero.ToString("###,###,###.00")) }</a>"
End If
If x = 6 Then
e.Row.Cells(x).Text = $"<a { If(Marzo < 0, "style='color:Red;'", "style='color:#337ab7;'") } target='_blank' href='./RepAnexoCatalogo.aspx?CveCuenta={CveCunetaRow}&FF={ $"01/03/{DdlEjercicio.SelectedValue}".ToDate.LastDayOfMonth.ToShortDateString }&FI=01/03/{DdlEjercicio}&ER=1&CveSubProyecto={DdlSubproyecto.SelectedValue}' >{ If(DdlDivisor.SelectedValue.ToEntero > 1, Marzo.ToString("###,###,##0"), Marzo.ToString("###,###,###.00")) }</a>"
End If
If x = 10 Then
e.Row.Cells(x).Text = $"<a { If(Abril < 0, "style='color:Red;'", "style='color:#337ab7;'") } target='_blank' href='./RepAnexoCatalogo.aspx?CveCuenta={CveCunetaRow}&FF={ $"01/04/{DdlEjercicio.SelectedValue}".ToDate.LastDayOfMonth.ToShortDateString }&FI=01/04/{DdlEjercicio}&ER=1&CveSubProyecto={DdlSubproyecto.SelectedValue}' >{ If(DdlDivisor.SelectedValue.ToEntero > 1, Abril.ToString("###,###,##0"), Abril.ToString("###,###,###.00")) }</a>"
End If
If x = 14 Then
e.Row.Cells(x).Text = $"<a { If(Mayo < 0, "style='color:Red;'", "style='color:#337ab7;'") } target='_blank' href='./RepAnexoCatalogo.aspx?CveCuenta={CveCunetaRow}&FF={ $"01/05/{DdlEjercicio.SelectedValue}".ToDate.LastDayOfMonth.ToShortDateString }&FI=01/05/{DdlEjercicio}&ER=1&CveSubProyecto={DdlSubproyecto.SelectedValue}' >{ If(DdlDivisor.SelectedValue.ToEntero > 1, Mayo.ToString("###,###,##0"), Mayo.ToString("###,###,###.00")) }</a>"
End If
If x = 17 Then
e.Row.Cells(x).Text = $"<a { If(Junio < 0, "style='color:Red;'", "style='color:#337ab7;'") } target='_blank' href='./RepAnexoCatalogo.aspx?CveCuenta={CveCunetaRow}&FF={ $"01/06/{DdlEjercicio.SelectedValue}".ToDate.LastDayOfMonth.ToShortDateString }&FI=01/06/{DdlEjercicio}&ER=1&CveSubProyecto={DdlSubproyecto.SelectedValue}' >{ If(DdlDivisor.SelectedValue.ToEntero > 1, Junio.ToString("###,###,##0"), Junio.ToString("###,###,###.00")) }</a>"
End If
If x = 21 Then
e.Row.Cells(x).Text = $"<a { If(Julio < 0, "style='color:Red;'", "style='color:#337ab7;'") } target='_blank' href='./RepAnexoCatalogo.aspx?CveCuenta={CveCunetaRow}&FF={ $"01/07/{DdlEjercicio.SelectedValue}".ToDate.LastDayOfMonth.ToShortDateString }&FI=01/07/{DdlEjercicio}&ER=1&CveSubProyecto={DdlSubproyecto.SelectedValue}' >{ If(DdlDivisor.SelectedValue.ToEntero > 1, Julio.ToString("###,###,##0"), Julio.ToString("###,###,###.00")) }</a>"
End If
If x = 24 Then
e.Row.Cells(x).Text = $"<a { If(Agosto < 0, "style='color:Red;'", "style='color:#337ab7;'") } target='_blank' href='./RepAnexoCatalogo.aspx?CveCuenta={CveCunetaRow}&FF={ $"01/08/{DdlEjercicio.SelectedValue}".ToDate.LastDayOfMonth.ToShortDateString }&FI=01/08/{DdlEjercicio}&ER=1&CveSubProyecto={DdlSubproyecto.SelectedValue}' >{ If(DdlDivisor.SelectedValue.ToEntero > 1, Agosto.ToString("###,###,##0"), Agosto.ToString("###,###,###.00")) }</a>"
End If
If x = 28 Then
e.Row.Cells(x).Text = $"<a { If(Septiembre < 0, "style='color:Red;'", "style='color:#337ab7;'") } target='_blank' href='./RepAnexoCatalogo.aspx?CveCuenta={CveCunetaRow}&FF={ $"01/09/{DdlEjercicio.SelectedValue}".ToDate.LastDayOfMonth.ToShortDateString }&FI=01/09/{DdlEjercicio}&ER=1&CveSubProyecto={DdlSubproyecto.SelectedValue}' >{ If(DdlDivisor.SelectedValue.ToEntero > 1, Septiembre.ToString("###,###,##0"), Septiembre.ToString("###,###,###.00")) }</a>"
End If
If x = 32 Then
e.Row.Cells(x).Text = $"<a { If(Octubre < 0, "style='color:Red;'", "style='color:#337ab7;'") } target='_blank' href='./RepAnexoCatalogo.aspx?CveCuenta={CveCunetaRow}&FF={ $"01/10/{DdlEjercicio.SelectedValue}".ToDate.LastDayOfMonth.ToShortDateString }&FI=01/10/{DdlEjercicio}&ER=1&CveSubProyecto={DdlSubproyecto.SelectedValue}' >{ If(DdlDivisor.SelectedValue.ToEntero > 1, Octubre.ToString("###,###,##0"), Octubre.ToString("###,###,###.00")) }</a>"
End If
If x = 35 Then
e.Row.Cells(x).Text = $"<a { If(Noviembre < 0, "style='color:Red;'", "style='color:#337ab7;'") } target='_blank' href='./RepAnexoCatalogo.aspx?CveCuenta={CveCunetaRow}&FF={ $"01/11/{DdlEjercicio.SelectedValue}".ToDate.LastDayOfMonth.ToShortDateString }&FI=01/11/{DdlEjercicio}&ER=1&CveSubProyecto={DdlSubproyecto.SelectedValue}' >{ If(DdlDivisor.SelectedValue.ToEntero > 1, Noviembre.ToString("###,###,##0"), Noviembre.ToString("###,###,###.00")) }</a>"
End If
If x = 38 Then
e.Row.Cells(x).Text = $"<a { If(Diciembre < 0, "style='color:Red;'", "style='color:#337ab7;'") } target='_blank' href='./RepAnexoCatalogo.aspx?CveCuenta={CveCunetaRow}&FF={ $"01/12/{DdlEjercicio.SelectedValue}".ToDate.LastDayOfMonth.ToShortDateString }&FI=01/12/{DdlEjercicio}&ER=1&CveSubProyecto={DdlSubproyecto.SelectedValue}' >{ If(DdlDivisor.SelectedValue.ToEntero > 1, Diciembre.ToString("###,###,##0"), Diciembre.ToString("###,###,###.00")) }</a>"
End If
Next
If Enero = 0 Then
e.Row.Cells(2).Text = "-"
End If
End If
End Sub
Public Sub setgrafica(e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
'Dim Lista2 As New List(Of String)
'Lista2.Add($"['{"Enero"}',{e.Row.DBCampo("Enero").ToDecimal()}]")
'Lista2.Add($"['{"Febrero"}',{e.Row.DBCampo("Febrero").ToDecimal()}]")
'Lista2.Add($"['{"Marzo"}',{e.Row.DBCampo("Marzo").ToDecimal()}]")
'Lista2.Add($"['{"Abril"}',{e.Row.DBCampo("Abril").ToDecimal()}]")
'Lista2.Add($"['{"Mayo"}',{e.Row.DBCampo("Mayo").ToDecimal()}]")
'Lista2.Add($"['{"Junio"}',{e.Row.DBCampo("Junio").ToDecimal()}]")
'Lista2.Add($"['{"Julio"}',{e.Row.DBCampo("Julio").ToDecimal()}]")
'Lista2.Add($"['{"Agosto"}',{e.Row.DBCampo("Agosto").ToDecimal()}]")
'Lista2.Add($"['{"Septiembre"}',{e.Row.DBCampo("Septiembre").ToDecimal()}]")
'Lista2.Add($"['{"Octubre"}',{e.Row.DBCampo("Octubre").ToDecimal()}]")
'Lista2.Add($"['{"Noviembre"}',{e.Row.DBCampo("Noviembre").ToDecimal()}]")
'Lista2.Add($"['{"Diciembre"}',{e.Row.DBCampo("Diciembre").ToDecimal()}]")
Dim ListaDatos As New List(Of String)
Dim ListaCategorias As New List(Of String)
ListaDatos.Add(e.Row.DBCampo("Enero").ToDecimal.ToString("###########0.00"))
ListaDatos.Add(e.Row.DBCampo("Febrero").ToDecimal.ToString("###########0.00"))
ListaDatos.Add(e.Row.DBCampo("Marzo").ToDecimal.ToString("###########0.00"))
ListaDatos.Add(e.Row.DBCampo("Abril").ToDecimal.ToString("###########0.00"))
ListaDatos.Add(e.Row.DBCampo("Mayo").ToDecimal.ToString("###########0.00"))
ListaDatos.Add(e.Row.DBCampo("Junio").ToDecimal.ToString("###########0.00"))
ListaDatos.Add(e.Row.DBCampo("Julio").ToDecimal.ToString("###########0.00"))
ListaDatos.Add(e.Row.DBCampo("Agosto").ToDecimal.ToString("###########0.00"))
ListaDatos.Add(e.Row.DBCampo("Septiembre").ToDecimal.ToString("###########0.00"))
ListaDatos.Add(e.Row.DBCampo("Octubre").ToDecimal.ToString("###########0.00"))
ListaDatos.Add(e.Row.DBCampo("Noviembre").ToDecimal.ToString("###########0.00"))
ListaDatos.Add(e.Row.DBCampo("Diciembre").ToDecimal.ToString("###########0.00"))
ListaCategorias.Add($"""Enero""")
ListaCategorias.Add($"""Febrero""")
ListaCategorias.Add($"""Marzo""")
ListaCategorias.Add($"""Abril""")
ListaCategorias.Add($"""Mayo""")
ListaCategorias.Add($"""Junio""")
ListaCategorias.Add($"""Junio""")
ListaCategorias.Add($"""Agosto""")
ListaCategorias.Add($"""Septiembre""")
ListaCategorias.Add($"""Octubre""")
ListaCategorias.Add($"""Noviembre""")
ListaCategorias.Add($"""Diciembre""")
Dim Titulo As String = e.Row.FCLabel("LblNombre").Text
Dim SubTitulo As String = ""
Dim YReferencia As String = "Valor"
Dim Info As String = ""
Dim XReferencia As String = "Periodos"
Dim Promedio As String = ""
'e.Row.FCHyperLink("Hypgrafica").Attributes.Add("data-values", Newtonsoft.Json.JsonConvert.SerializeObject(lista))
'If e.Row.DataKey("Tipo").ToEntero <> 1 Then
'Dim Info = String.Join(",", Lista2)
'e.Row.FCHyperLink("Hypgrafica").Attributes.Add("onclick", "$('#DivModalGrafica').modal('show'); " &
' String.Format("graficahighchartsFinan('{0}','{1}','{2}','{3}',[{4}],1,'{5}','{6}',[{8}],[{7}],'{9}','{10}');", chartdiv2.ClientID, "", "", "$", Info, "", 0, "", "", e.Row.DBCampo("Nombre"), e.Row.FCHyperLink("Hypgrafica").ClientID))
e.Row.FCHyperLink("hpl2").Attributes.Add("onclick", "$('#DivModalGrafica').modal('show'); " &
String.Format("graficahighchartsFinan('{0}','{1}','{2}','{3}',[{4}],'{5}','{5}','{6}',[{8}],[{7}],'{9}','{10}');", chartdiv2.ClientID, Titulo, SubTitulo, YReferencia, Info, XReferencia, Promedio, "", "", e.Row.FCCheckBox("chkgraf").ClientID, e.Row.FCHyperLink("hpl2").ClientID))
e.Row.FCCheckBox("chkgraf").InputAttributes.Add("class", "chksel")
e.Row.FCCheckBox("chkgraf").InputAttributes.Add("data-name", e.Row.FCLabel("LblNombre").Text)
e.Row.FCCheckBox("chkgraf").InputAttributes.Add("data-data", $"[{String.Join(",", ListaDatos)}]")
e.Row.FCCheckBox("chkgraf").InputAttributes.Add("data-categorias", $"[{String.Join(",", ListaCategorias)}]")
End If
If e.Row.RowType = DataControlRowType.Header Then
e.Row.FCHyperLink("hpl2").Attributes.Add("onclick", "$('#DivModalGrafica').modal('show'); " &
String.Format("graficahighchartsFinan('{0}','{1}','{2}','{3}',[{4}],'{5}','{5}','{6}',[{8}],[{7}],'{9}','{10}' );", chartdiv2.ClientID, "Selección multiple", "", "Valores", "", "Periodos", "", "", "", "", e.Row.FCHyperLink("hpl2").ClientID))
End If
'Else
' e.Row.FCHyperLink("hpl2").Visible = False
'End If
End Sub
#End Region
Private Sub LnkExportar_Click(sender As Object, e As EventArgs) Handles LnkExportar.Click
Dim SbFiltros As New StringBuilder()
SbFiltros.AppendFormat("Fecha Inicio: {0} Fecha Fin: {1}|", $"01/01/{DdlEjercicio.SelectedValue}", $"31/12/{DdlEjercicio.SelectedValue}")
SbFiltros.AppendFormat("Cuenta : {0}|", DdlCuentas.SelectedItem.Text)
SbFiltros.AppendFormat("Centro Costo : {0}|", If(DdlSubproyecto.SelectedValue.ToEntero > 0, DdlSubproyecto.SelectedItem.Text, "Todos"))
SbFiltros.AppendFormat("Divisor : {0}|", DdlDivisor.SelectedItem.Text)
GvMensual2.ExportToExcelGembox("AnexoCatálogoMensual", UsuarioActual, "Anexo del Catálogo - Mensual", DatosFiltros:=SbFiltros.ToString())
End Sub
Public Overrides Sub VerifyRenderingInServerForm(control As Control)
' Verifies that the control is rendered
End Sub
'Protected Sub DdlGrafica_SelectedIndexChanged(sender As Object, e As EventArgs)
' RegistraScript("recargaGrafica();")
'End Sub
End Class