398 lines
16 KiB
VB.net
398 lines
16 KiB
VB.net
Option Explicit On
|
|
Option Strict On
|
|
|
|
Imports System.Data
|
|
Imports Extensiones
|
|
Imports System.IO
|
|
Imports iTextSharp.text
|
|
Imports iTextSharp.text.html.simpleparser
|
|
Imports iTextSharp.text.pdf
|
|
Imports Microsoft.Reporting.WebForms
|
|
|
|
Partial Class AC_RepVariacionHaciendaPublica
|
|
Inherits ClsPaginas
|
|
|
|
#Region "PROPIEDADES"
|
|
Private Property DtTemp As DataTable
|
|
Get
|
|
DtTemp = DirectCast(ViewState("DtTemp"), DataTable)
|
|
End Get
|
|
|
|
Set(ByVal value As DataTable)
|
|
ViewState("DtTemp") = value
|
|
End Set
|
|
End Property
|
|
Private Property DtDatos As DataTable
|
|
Get
|
|
DtDatos = DirectCast(ViewState("DtDatos"), DataTable)
|
|
End Get
|
|
|
|
Set(ByVal value As DataTable)
|
|
ViewState("DtDatos") = value
|
|
End Set
|
|
End Property
|
|
Private Property TotalActual As Double
|
|
Get
|
|
TotalActual = ViewState("TotalActual").ToString.ToDouble
|
|
End Get
|
|
Set(value As Double)
|
|
ViewState("TotalActual") = value
|
|
End Set
|
|
End Property
|
|
Private Property TotalAnterior As Double
|
|
Get
|
|
TotalAnterior = ViewState("TotalAnterior").ToString.ToDouble
|
|
End Get
|
|
Set(value As Double)
|
|
ViewState("TotalAnterior") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property FechaDel As String
|
|
Get
|
|
FechaDel = ViewState("FechaDel").ToString
|
|
End Get
|
|
Set(value As String)
|
|
ViewState("FechaDel") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property FechaAl As String
|
|
Get
|
|
FechaAl = ViewState("FechaAl").ToString
|
|
End Get
|
|
Set(value As String)
|
|
ViewState("FechaAl") = 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
|
|
If UsuarioActual.Empresa.UsaAC Then
|
|
|
|
TxtFechaDel.Text = DateSerial(Year(Now), Month(Now), 1).ToShortDateString
|
|
TxtFechaAl.Text = Date.Now.ToShortDateString
|
|
|
|
CargaDatos()
|
|
|
|
BtnConsultar.Enabled = True
|
|
Else
|
|
Alert("La empresa no usa Armonización Contable", TipoMensaje.MsgError)
|
|
End If
|
|
|
|
End If
|
|
End Sub
|
|
|
|
#Region "CARGA DATOS Y GRID"
|
|
Private Sub CargaDatos()
|
|
Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa)
|
|
|
|
Dim FechaInicio = If(TxtFechaDel.Text = "" Or TxtFechaDel.Text = "__/__/____", Date.Now, TxtFechaDel.Text.ToDate)
|
|
Dim FechaFin = If(TxtFechaAl.Text = "" Or TxtFechaAl.Text = "__/__/____", Date.Now, TxtFechaAl.Text.ToDate)
|
|
|
|
FechaDel = TxtFechaDel.Text
|
|
FechaAl = TxtFechaAl.Text
|
|
|
|
If ObjConta.GetVariacionHaciendaPublica(FechaInicio, FechaFin) Then
|
|
DtTemp = ObjConta.DtResultados
|
|
Else
|
|
DtTemp = Nothing
|
|
Alert("Ocurrio un error al cargar los datos del Estado de Variación de Hacienda Pública", TipoMensaje.MsgError)
|
|
End If
|
|
|
|
ObjConta.Dispose()
|
|
|
|
If DtTemp IsNot Nothing AndAlso DtTemp.Rows.Count > 0 Then
|
|
CreaDT()
|
|
End If
|
|
|
|
'GvDatos.Caption = String.Format("<div class='Titulos' style='width:100%; height:45px;'>{0}<br/>Estado de Variación de Hacienda Pública<br/>Del {1} Al {2}</div>", UsuarioActual.Empresa.Empresa, TxtFechaDel.Text, TxtFechaAl.Text)
|
|
|
|
'CargaGrid()
|
|
|
|
End Sub
|
|
|
|
Private Sub CreaDT()
|
|
DtDatos = New DataTable
|
|
|
|
'COLUMNAS DEL REPORTE (GRID)
|
|
DtDatos.Columns.Add("Concepto", GetType(String))
|
|
DtDatos.Columns.Add("Contribuido", GetType(String))
|
|
DtDatos.Columns.Add("GeneradoAnteriores", GetType(String))
|
|
DtDatos.Columns.Add("GeneradoActual", GetType(String))
|
|
DtDatos.Columns.Add("Ajustes", GetType(String))
|
|
DtDatos.Columns.Add("Total", GetType(String))
|
|
|
|
'DATOS QUE OCUPAMOS PARA LLENAR GRID
|
|
DtDatos.Columns.Add("Nivel", GetType(String))
|
|
DtDatos.Columns.Add("ImporteActual", GetType(String))
|
|
DtDatos.Columns.Add("ImporteAnterior", GetType(String))
|
|
DtDatos.Columns.Add("ResultadoActual", GetType(String))
|
|
DtDatos.Columns.Add("ResultadoAnterior", GetType(String))
|
|
|
|
LlenaDT()
|
|
End Sub
|
|
Private Sub LlenaDT()
|
|
|
|
Dim Total1, Total2, Total3, Total4, Total5 As New Double
|
|
|
|
Dim Row As DataRow = Nothing
|
|
|
|
Row = DtDatos.NewRow
|
|
Row("Nivel") = "0"
|
|
Row("Concepto") = String.Format("RECTIFICACIONES DE RESULTADOS DE EJERCICIOS ANTERIORES", Year(TxtFechaDel.Text.ToDate) - 1)
|
|
DtDatos.Rows.Add(Row)
|
|
|
|
'LLENAMOS PRIMERA PARTE, AÑO ANTERIOR - PARTE 1 (PT1)
|
|
For Each dr As DataRow In DtTemp.Rows
|
|
Row = DtDatos.NewRow
|
|
|
|
'DETALLES
|
|
Row("Concepto") = dr("Nombre")
|
|
|
|
If dr("Sup").ToString = "PATRIMONIO CONTRIBUIDO" Then
|
|
Row("Contribuido") = If(dr("ImporteAnterior").ToString.ToDouble <> 0, dr("ImporteAnterior").ToString.FormatoNumero, "")
|
|
Total1 += dr("ImporteAnterior").ToString.ToDouble
|
|
End If
|
|
|
|
If dr("Sup").ToString = "PATRIMONIO GENERADO" Then
|
|
Row("GeneradoAnteriores") = If(dr("ImporteAnterior").ToString.ToDouble <> 0, dr("ImporteAnterior").ToString.FormatoNumero, "")
|
|
Total2 += dr("ImporteAnterior").ToString.ToDouble
|
|
End If
|
|
|
|
'CAMPOS VACIOS POR MIENTRAS
|
|
Row("GeneradoActual") = ""
|
|
Row("Ajustes") = ""
|
|
|
|
Row("Total") = If(dr("ImporteAnterior").ToString.ToDouble <> 0, dr("ImporteAnterior").ToString.FormatoNumero, "")
|
|
Total5 += Row("Total").ToString.ToDouble
|
|
|
|
Row("Nivel") = "1"
|
|
|
|
|
|
|
|
|
|
'CASOS ESPECIALES
|
|
If dr("CtaMayor").ToString = "3" Then
|
|
'CAMBIOS NOMBRE - PATRIMONIO CONTRIBUIDO
|
|
If dr("Codigo").ToString.Substring(0, 5) = "00031" Then
|
|
Row("Concepto") = String.Format("PATRIMONIO NETO INICIAL AJUSTADO DEL EJERCICIO {0}", dr("Anterior"))
|
|
End If
|
|
|
|
'CAMBIOS NOMBRE - PATRIMONIO GENERADO
|
|
If dr("Codigo").ToString.Substring(0, 5) = "00032" Then
|
|
Row("Concepto") = String.Format("VARIACIONES DE LA HACIENDA PUBLICA/PATRIMONIO NETO DEL EJERCICIO {0}", dr("Anterior"))
|
|
End If
|
|
|
|
Row("Nivel") = "0"
|
|
End If
|
|
|
|
DtDatos.Rows.Add(Row)
|
|
Next
|
|
|
|
|
|
Row = DtDatos.NewRow
|
|
Row("Nivel") = "0"
|
|
Row("Concepto") = String.Format("HACIENDA PUBLICA/PATRIMONIO NETO FINAL DEL EJERCICIO", Year(TxtFechaDel.Text.ToDate) - 1)
|
|
Row("Contribuido") = Total1.ToString.FormatoNumero
|
|
Row("GeneradoAnteriores") = Total2.ToString.FormatoNumero
|
|
Row("GeneradoActual") = Total3.ToString.FormatoNumero
|
|
Row("Ajustes") = Total4.ToString.FormatoNumero
|
|
Row("Total") = (Total1 + Total2 + Total3 + Total4).ToString.FormatoNumero
|
|
DtDatos.Rows.Add(Row)
|
|
|
|
'LLENAMOS SEGUNDA PARTE, AÑO ACTUAL - PARTE 2 (PT2)
|
|
For Each dr As DataRow In DtTemp.Rows
|
|
Row = DtDatos.NewRow
|
|
|
|
'DETALLES
|
|
Row("Concepto") = dr("Nombre")
|
|
|
|
If dr("Sup").ToString = "PATRIMONIO CONTRIBUIDO" Then
|
|
Row("Contribuido") = If(dr("ImporteActual").ToString.ToDouble <> 0, dr("ImporteActual").ToString.FormatoNumero, "")
|
|
Total1 += dr("ImporteActual").ToString.ToDouble
|
|
End If
|
|
|
|
If dr("Sup").ToString = "PATRIMONIO GENERADO" Then
|
|
|
|
If dr("Codigo").ToString.Substring(0, 5) = "00321" Then
|
|
Row("GeneradoActual") = If(dr("ResultadoActual").ToString.ToDouble <> 0, dr("ResultadoActual").ToString.FormatoNumero, "")
|
|
Total3 += dr("ResultadoActual").ToString.ToDouble
|
|
Row("Total") = If(dr("ResultadoActual").ToString.ToDouble <> 0, dr("ResultadoActual").ToString.FormatoNumero, "")
|
|
Else
|
|
Row("GeneradoActual") = If(dr("ImporteActual").ToString.ToDouble <> 0, dr("ImporteActual").ToString.FormatoNumero, "")
|
|
Total3 += dr("ImporteActual").ToString.ToDouble
|
|
Row("Total") = If(dr("ImporteActual").ToString.ToDouble <> 0, dr("ImporteActual").ToString.FormatoNumero, "")
|
|
End If
|
|
|
|
End If
|
|
|
|
'CAMPOS VACIOS POR MIENTRAS
|
|
Row("GeneradoAnteriores") = ""
|
|
Row("Ajustes") = ""
|
|
|
|
|
|
Total5 += Row("Total").ToString.ToDouble
|
|
|
|
Row("Nivel") = "1"
|
|
|
|
|
|
'CASOS ESPECIALES
|
|
If dr("CtaMayor").ToString = "3" Then
|
|
'CAMBIOS NOMBRE - PATRIMONIO CONTRIBUIDO
|
|
If dr("Codigo").ToString.Substring(0, 5) = "00031" Then
|
|
Row("Concepto") = String.Format("CAMBIOS EN LA HACIENDA PUBLICA/PATRIMONIO NETO DEL EJERCICIO {0}", dr("Actual"))
|
|
End If
|
|
|
|
'CAMBIOS NOMBRE - PATRIMONIO GENERADO
|
|
If dr("Codigo").ToString.Substring(0, 5) = "00032" Then
|
|
Row("Concepto") = String.Format("VARIACIONES DE LA HACIENDA PUBLICA/PATRIMONIO NETO DEL EJERCICIO {0}", dr("Actual"))
|
|
End If
|
|
|
|
Row("Nivel") = "0"
|
|
End If
|
|
|
|
DtDatos.Rows.Add(Row)
|
|
Next
|
|
|
|
|
|
Row = DtDatos.NewRow
|
|
Row("Nivel") = "0"
|
|
Row("Concepto") = String.Format("SALDO NETO EN LA HACIENDA PUBLICA/PATRIMONIO ", Year(TxtFechaDel.Text.ToDate))
|
|
Row("Contribuido") = Total1.ToString.FormatoNumero
|
|
Row("GeneradoAnteriores") = Total2.ToString.FormatoNumero
|
|
Row("GeneradoActual") = Total3.ToString.FormatoNumero
|
|
Row("Ajustes") = Total4.ToString.FormatoNumero
|
|
Row("Total") = (Total1 + Total2 + Total3 + Total4).ToString.FormatoNumero
|
|
DtDatos.Rows.Add(Row)
|
|
|
|
|
|
CargaGrid()
|
|
End Sub
|
|
Private Sub CargaGrid()
|
|
GvDatos.DataSource = DtDatos
|
|
GvDatos.DataBind()
|
|
UpDatos.Update()
|
|
End Sub
|
|
#End Region
|
|
|
|
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs)
|
|
CargaDatos()
|
|
End Sub
|
|
|
|
|
|
Protected Sub GvDatos_RowDataBound(sender As Object, e As GridViewRowEventArgs)
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
|
|
If e.Row.DBCampo("Nivel") = "0" Then
|
|
e.Row.Font.Bold = True
|
|
CType(e.Row.FindControl("Concepto"), HtmlControl).Attributes.Add("style", "margin-top:15px;")
|
|
Else
|
|
CType(e.Row.FindControl("Concepto"), HtmlControl).Attributes.Add("style", "margin-left: 20px; margin-top:5px;")
|
|
End If
|
|
|
|
End If
|
|
End Sub
|
|
|
|
|
|
Protected Sub BtnImprimir_Click(sender As Object, e As EventArgs) Handles BtnImprimir.Click
|
|
If Not IsNothing(DtDatos) Then
|
|
ImprimirReporte() 'Descarga reporte en PDF
|
|
Else
|
|
Alert("No se ha encontrado información para el reporte", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
'Using sw As New StringWriter()
|
|
' Using hw As New HtmlTextWriter(sw)
|
|
|
|
' Dim style As StringBuilder = New StringBuilder()
|
|
' style.Append("<style> ")
|
|
' style.Append(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory & "Styles\EstilosExcel.css"))
|
|
' style.Append(" </style> ")
|
|
' 'To Export all pages
|
|
' 'Gv.AllowPaging = False
|
|
' 'Gv.DataBind()
|
|
' Tbl.RenderControl(hw)
|
|
' Dim sr As New StringReader(sw.ToString())
|
|
' Dim pdfDoc As New Document(PageSize.A2, 10.0F, 10.0F, 10.0F, 0.0F)
|
|
' Dim htmlparser As New HTMLWorker(pdfDoc)
|
|
' PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
|
|
' pdfDoc.Open()
|
|
' htmlparser.Parse(sr)
|
|
' pdfDoc.Close()
|
|
|
|
' Response.ContentType = "application/pdf"
|
|
' Response.AddHeader("content-disposition", "attachment;filename=FlujoDeEfectivo.pdf")
|
|
' Response.Cache.SetCacheability(HttpCacheability.NoCache)
|
|
' Response.Write(style.ToString)
|
|
' Response.Write(pdfDoc)
|
|
' Response.[End]()
|
|
' End Using
|
|
'End Using
|
|
End Sub
|
|
'No quitar porque no funciona el exporta PDF
|
|
Public Overrides Sub VerifyRenderingInServerForm(control As Control)
|
|
' Verifies that the control is rendered
|
|
End Sub
|
|
|
|
'Protected Sub GvDatos_RowCreated(sender As Object, e As GridViewRowEventArgs) Handles GvDatos.RowCreated
|
|
' If (e.Row.RowType = DataControlRowType.Header) Then
|
|
' Dim HeaderGrid As GridView = DirectCast(sender, GridView)
|
|
' Dim HeaderGridRow As GridViewRow = New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert)
|
|
' Dim HeaderCell As TableCell = New TableCell()
|
|
' HeaderCell.Text = String.Format("<div class='Titulos' style='width:100%; height:45px;'>{0}<br/>Estado de Variación de Hacienda Pública<br/>Del {1} Al {2}</div>", UsuarioActual.Empresa.Empresa, TxtFechaDel.Text, TxtFechaAl.Text)
|
|
' HeaderCell.ColumnSpan = GvDatos.Columns.Count
|
|
' HeaderCell.HorizontalAlign = HorizontalAlign.Center
|
|
' HeaderGridRow.Cells.Add(HeaderCell)
|
|
|
|
|
|
' GvDatos.Controls(0).Controls.AddAt(0, HeaderGridRow)
|
|
' End If
|
|
|
|
' If (e.Row.RowType = DataControlRowType.Footer) Then
|
|
' Dim HeaderGrid As GridView = DirectCast(sender, GridView)
|
|
' Dim HeaderGridRow As GridViewRow = New GridViewRow(0, 0, DataControlRowType.Footer, DataControlRowState.Insert)
|
|
' Dim HeaderCell As TableCell = New TableCell()
|
|
' HeaderCell.Text = "<table><tr> <td colspan='3' style='height:30px;'> <br/><br/><br/><br/></td></tr><tr><td >_________________________________<br/>C.P. Izelda Angulo Peraza</td><td style='width:75px'> </td><td > _________________________________<br/>Lic. Juan Fortino Leon Robinson</td></tr><tr><td>Subdirector de Contabilidad</td><td style='width:75px'> </td><td>Director General</td></table>"
|
|
' HeaderCell.ColumnSpan = GvDatos.Columns.Count
|
|
' HeaderCell.HorizontalAlign = HorizontalAlign.Center
|
|
' HeaderGridRow.Cells.Add(HeaderCell)
|
|
|
|
' e.Row.Cells.Clear()
|
|
' e.Row.Cells.Add(HeaderCell)
|
|
|
|
' End If
|
|
|
|
'End Sub
|
|
|
|
Protected Sub ImgExcel_Click(sender As Object, e As EventArgs) Handles ImgExcel.Click
|
|
'GvDatos.ExportToExcel("123456" & Now.ToShortDateString)
|
|
If Not IsNothing(DtDatos) Then
|
|
ImprimirReporte("Excel") 'Descarga reporte en Excel
|
|
Else
|
|
Alert("No se ha encontrado información para el reporte", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
End Sub
|
|
|
|
'Descarga reporte en PDF o Excel
|
|
Private Sub ImprimirReporte(Optional Formato As String = "PDF")
|
|
'ubicacion del rdlc
|
|
Dim reportpath As String = "AC/Reportes/VariacionHaciendaPublica.rdlc"
|
|
|
|
Dim fileName As String = "EdoVariacionHaciendaPublica"
|
|
'parametros a enviar al reporte
|
|
Dim params As New List(Of ReportParameter)
|
|
|
|
params.Add(New ReportParameter("pEmp", UsuarioActual.Empresa.Empresa))
|
|
Dim Imagen As New System.IO.FileInfo($"{UsuarioActual.Empresa.Ruta}/Logo.png")
|
|
params.Add(New ReportParameter("pImg", If(Imagen.Exists, $"file://{Imagen.FullName}", "")))
|
|
params.Add(New ReportParameter("pFechaIni", TxtFechaDel.Text))
|
|
params.Add(New ReportParameter("pFechaFin", TxtFechaAl.Text))
|
|
params.Add(New ReportParameter("pFirma1", String.Format("ING. Soraida Mesinas Reyes{0} Subdirector de Contabilidad", vbCrLf)))
|
|
params.Add(New ReportParameter("pFirma2", String.Format("ING. Soraida Mesinas Reyes{0} Director General", vbCrLf)))
|
|
ImprimirPDF(reportpath, DtDatos, params, fileName, Formato)
|
|
'MasterReporteador.Visible = True
|
|
End Sub
|
|
|
|
End Class
|