Option Explicit On Option Strict On Imports System.Data Imports System.Drawing Imports Extensiones Imports Microsoft.Reporting.WebForms Partial Class AC_RepEstadoActividades Inherits ClsPaginas #Region "PROPIEDADES" 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 DtIngresos As DataTable Get DtIngresos = DirectCast(ViewState("DtIngresos"), DataTable) End Get Set(ByVal value As DataTable) ViewState("DtIngresos") = value End Set End Property Private Property DtGastos As DataTable Get DtGastos = DirectCast(ViewState("DtGastos"), DataTable) End Get Set(ByVal value As DataTable) ViewState("DtGastos") = 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 FechaI As String Get Return ViewState("FechaI").ToString End Get Set(value As String) ViewState("FechaI") = value End Set End Property Private Property FechaF As String Get Return ViewState("FechaF").ToString End Get Set(value As String) ViewState("FechaF") = value End Set End Property Private Property ReporteComplementario As Boolean Get ReporteComplementario = CBool(ViewState("ReporteComplementario").ToString) End Get Set(value As Boolean) ViewState("ReporteComplementario") = 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 ReporteComplementario = False Else ReporteComplementario = False DivTipo1.Visible = False DivTipo2.Visible = False LtTitulo.Text = "Estado de Resultados" End If TotalActual = 0 TotalAnterior = 0 'TxtFechaInicio.Text = DateSerial(Year(NowADS()), 1, 1).ToShortDateString 'TxtFechaFin.Text = NowADS().ToShortDateString CargaEjercicios() CargaDatos() If UsuarioActual.Empresa.GrupoEmpresa > 0 And UsuarioActual.CveRol = 1 Then DVConsolidado1.Visible = True DVConsolidado2.Visible = True End If If UsuarioActual.CveRol = 1 Then DVSubtotales1.Visible = True DVSubtotales2.Visible = True End If End If End Sub Private Sub CargaEjercicios() 'Dim ClsConta As New ClsContPAQi(UsuarioActual.Empresa) Dim ClsConta As New ClsContabilidad If ClsConta.GetEjercicios(UsuarioActual.CveEmpresa) Then DdlEjercicio.DataSource = ClsConta.DtResultados Else DdlEjercicio.DataSource = Nothing End If ClsConta.Dispose() DdlEjercicio.DataBind() DdlEjercicio.SelectedValueExist(UsuarioActual.Empresa.EjercicioActual.ToString) If DdlEjercicio.Items.Count = 0 Then DdlEjercicio.Items.Add(New ListItem(NowADS().Year.ToString, NowADS().Year.ToString)) End If DdlPeriodo.SelectedValue = NowADS().Month.ToString CargarCentrosDeCosto(DdlProyecto, DdlSubproyecto, LblProyecto, LblSubProyecto, divProyecto:=DivProyecto) End Sub Protected Sub DdlProyecto_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DdlProyecto.SelectedIndexChanged CargarSubProyecto(DdlSubproyecto, DdlProyecto.SelectedValue, "Todos") End Sub Private Sub CargaDatos() FechaI = String.Format("01/{0}/{1}", DdlPeriodo.SelectedValue.PadLeft(2, CChar("0")), DdlEjercicio.SelectedValue) FechaF = DateAdd(DateInterval.Day, -1, DateAdd(DateInterval.Month, 1, CDate(FechaI))).ToString("dd/MM/yyyy") Dim TipoReporte = DdlTipoReporte.SelectedValue.ToEntero 'If(ReporteComplementario, DdlTipoReporte.SelectedValue.ToEntero, 1) Dim CveSubProyecto As Integer = DdlSubproyecto.SelectedValue.ToEntero Dim CveProyecto As Integer = DdlProyecto.SelectedValue.ToEntero 'Dim ObjConta As New ClsContPAQi(UsuarioActual.Empresa) Dim ObjConta As New ClsContabilidad If ObjConta.GetEstadoActividades(FechaI.ToDate, FechaF.ToDate, TipoReporte, CveProyecto, CveSubProyecto, UsuarioActual.CveEmpresa, Opcion:=DdlOpcion.SelectedValue.ToEntero) Then DtDatos = ObjConta.DtResultados.FiltraParametros("(ImporteActual <> 0 OR ImporteAcumulado <> 0)") Else DtDatos = Nothing Alert("Ocurrio un error al cargar los datos del Estado de Actividades", TipoMensaje.MsgError) End If ObjConta.Dispose() If DtDatos IsNot Nothing Then CargaGrids() SumaTotales() End If End Sub Private Sub CargaGrids() DtIngresos = DtDatos.FiltraParametros("Tipo ='H' ") DtGastos = DtDatos.FiltraParametros("Tipo ='G' ") Dim Row As DataRow = DtIngresos.NewRow Dim TotalActual = 0.0, TotalAnterior = 0.0 If DtIngresos.Rows.Count > 0 Then For Each dr As DataRow In DtIngresos.FiltraParametros("NOT CtaMayor in (3,4)").Rows TotalActual += dr("ImporteActual").ToString.ToDouble TotalAnterior += dr("ImporteAcumulado").ToString.ToDouble Next Row.Item("Nombre") = "TOTAL INGRESOS " Row.Item("ImporteActual") = TotalActual.ToString Row.Item("PorcentajeActual") = "100.00" Row.Item("ImporteAcumulado") = TotalAnterior.ToString Row.Item("PorcentajeAcumulado") = "100.00" Row.Item("CtaMayor") = -1 DtIngresos.Rows.Add(Row) Else Row.Item("Nombre") = "TOTAL INGRESOS " Row.Item("ImporteActual") = "0.00" Row.Item("ImporteAcumulado") = "0.00" Row.Item("CtaMayor") = -1 DtIngresos.Rows.Add(Row) End If Dim T1 = TotalActual, T2 = TotalAnterior TotalActual = 0 TotalAnterior = 0 Row = DtGastos.NewRow If DtGastos.Rows.Count > 0 Then For Each dr As DataRow In DtGastos.FiltraParametros("NOT CtaMayor in (3,4)").Rows TotalActual += dr("ImporteActual").ToString.ToDouble TotalAnterior += dr("ImporteAcumulado").ToString.ToDouble Next Row.Item("Nombre") = "TOTAL GASTOS" Row.Item("ImporteActual") = TotalActual Row.Item("PorcentajeActual") = If(T1 > 0, (TotalActual * 100 / T1).ToString, "0").FormatoNumero Row.Item("ImporteAcumulado") = TotalAnterior.ToString Row.Item("PorcentajeAcumulado") = If(T2 > 0, (TotalAnterior * 100 / T2).ToString, "0").FormatoNumero Row.Item("CtaMayor") = -1 DtGastos.Rows.Add(Row) Else Row.Item("Nombre") = "TOTAL GASTOS" Row.Item("ImporteActual") = "0.00" Row.Item("ImporteAcumulado") = "0.00" Row.Item("CtaMayor") = -1 DtGastos.Rows.Add(Row) End If DtGastos.AcceptChanges() If DdlVerConSubTotales.SelectedValue.ToEntero = 1 Then Dim idxUtilidadBruta As Integer = 0 Dim idxUtilidadOperacion As Integer = 0 Dim idxUtilidadAntesImpuestos As Integer = 0 Dim IndexActual As Integer = 0 For Each dRow As DataRow In DtGastos.Rows If dRow("Codigo").ToString.Contains("6000000") Then 'Utilidad Bruta indice que se tomara idxUtilidadBruta = IndexActual IndexActual = IndexActual + 2 'Son mas dos por que se esta conciderando el row en blanco End If If dRow("Codigo").ToString.Contains("7000000") Then 'Utilidad de Operación idxUtilidadOperacion = IndexActual IndexActual = IndexActual + 2 'Son mas dos por que se esta conciderando el row en blanco End If If dRow("Nombre").ToString.Contains("TOTAL GASTOS") Then 'Utilidad antes de impuestos idxUtilidadAntesImpuestos = IndexActual End If IndexActual = IndexActual + 1 Next DtGastos.AcceptChanges() Dim UtilidadBrutaActual, UtilidadBrutaAcumulada, UtilidadBrutPorcentajeActual, UtilidadBrutPorcentajeAcumulado As Decimal Dim UtilidadOperacionActual, UtilidadOperacionAcumulada, UtilidadOperacionPorcentajeActual, UtilidadOperacionPorcentajeAcumulado As Decimal Dim UtilidadAntesImpuestosActual, UtilidadAntesImpuestosAcumulada, UtilidadAntesImpuestosPorcentajeActual, UtilidadAntesImpuestosPorcentajeAcumulado As Decimal Dim IngresoActual As Decimal = DtIngresos.SUMD("ImporteActual", " CtaMayor = 1 ") Dim IngresoAcumulado As Decimal = DtIngresos.SUMD("ImporteAcumulado", " CtaMayor = 1 ") Dim CostoActual As Decimal = DtGastos.SUMD("ImporteActual", " Codigo LIKE '5%' AND CtaMayor = 1 ") Dim CostoAcumulado As Decimal = DtGastos.SUMD("ImporteAcumulado", " Codigo LIKE '5%' AND CtaMayor = 1") Dim GastoActual As Decimal = DtGastos.SUMD("ImporteActual", " Codigo LIKE '6%' AND CtaMayor = 1 ") Dim GastoAcumulado As Decimal = DtGastos.SUMD("ImporteAcumulado", " Codigo LIKE '6%' AND CtaMayor = 1 ") Dim ResultadoIntegralActual As Decimal = DtGastos.SUMD("ImporteActual", " Codigo LIKE '7%' AND CtaMayor = 1 ") Dim ResultadoIntegralAcumulado As Decimal = DtGastos.SUMD("ImporteAcumulado", " Codigo LIKE '7%' AND CtaMayor = 1 ") UtilidadBrutaActual = IngresoActual - CostoActual UtilidadBrutaAcumulada = IngresoAcumulado - CostoAcumulado UtilidadOperacionActual = IngresoActual - CostoActual - GastoActual UtilidadOperacionAcumulada = IngresoAcumulado - CostoAcumulado - GastoAcumulado UtilidadAntesImpuestosActual = IngresoActual - CostoActual - GastoActual - ResultadoIntegralActual UtilidadAntesImpuestosAcumulada = IngresoAcumulado - CostoAcumulado - GastoAcumulado - ResultadoIntegralAcumulado UtilidadBrutPorcentajeActual = If(IngresoActual <> 0 And UtilidadBrutaActual <> 0, (UtilidadBrutaActual / IngresoActual * 100), 0) UtilidadBrutPorcentajeAcumulado = If(IngresoAcumulado <> 0 And UtilidadBrutaAcumulada <> 0, (UtilidadBrutaAcumulada / IngresoAcumulado * 100), 0) UtilidadOperacionPorcentajeActual = If(IngresoActual <> 0 And UtilidadOperacionActual <> 0, (UtilidadOperacionActual / IngresoActual * 100), 0) UtilidadOperacionPorcentajeAcumulado = If(IngresoAcumulado <> 0 And UtilidadOperacionAcumulada <> 0, (UtilidadOperacionAcumulada / IngresoAcumulado * 100), 0) UtilidadAntesImpuestosPorcentajeActual = If(IngresoActual <> 0 And UtilidadAntesImpuestosActual <> 0, (UtilidadAntesImpuestosActual / IngresoActual * 100), 0) UtilidadAntesImpuestosPorcentajeAcumulado = If(IngresoAcumulado <> 0 And UtilidadAntesImpuestosAcumulada <> 0, (UtilidadAntesImpuestosAcumulada / IngresoAcumulado * 100), 0) Dim dRowUtilidadBruta As DataRow = DtGastos.NewRow Dim dRowUtilidadBrutaVacio As DataRow = DtGastos.NewRow Dim dRowUtilidadOperacion As DataRow = DtGastos.NewRow Dim dRowUtilidadOperacionVacio As DataRow = DtGastos.NewRow Dim dRowUtilidadAntesImpuestos As DataRow = DtGastos.NewRow Dim dRowUtilidadAntesImpuestosVacio As DataRow = DtGastos.NewRow dRowUtilidadBruta("Nombre") = "Utilidad Bruta" dRowUtilidadBruta("ImporteActual") = UtilidadBrutaActual dRowUtilidadBruta("ImporteAcumulado") = UtilidadBrutaAcumulada dRowUtilidadBruta("CtaMayor") = -1 dRowUtilidadBruta("Orden") = "600" dRowUtilidadBruta("PorcentajeActual") = UtilidadBrutPorcentajeActual dRowUtilidadBruta("PorcentajeAcumulado") = UtilidadBrutPorcentajeAcumulado dRowUtilidadBrutaVacio("CtaMayor") = -1 dRowUtilidadBrutaVacio("Orden") = "600" dRowUtilidadOperacion("Nombre") = "Utilidad de Operación" dRowUtilidadOperacion("ImporteActual") = UtilidadOperacionActual dRowUtilidadOperacion("ImporteAcumulado") = UtilidadOperacionAcumulada dRowUtilidadOperacion("CtaMayor") = -1 dRowUtilidadOperacion("Orden") = "700" dRowUtilidadOperacion("PorcentajeActual") = UtilidadOperacionPorcentajeActual dRowUtilidadOperacion("PorcentajeAcumulado") = UtilidadOperacionPorcentajeAcumulado dRowUtilidadOperacionVacio("CtaMayor") = -1 dRowUtilidadOperacionVacio("Orden") = "700" dRowUtilidadAntesImpuestos("Nombre") = "Utilidad antes de impuestos" dRowUtilidadAntesImpuestos("ImporteActual") = UtilidadAntesImpuestosActual dRowUtilidadAntesImpuestos("ImporteAcumulado") = UtilidadAntesImpuestosAcumulada dRowUtilidadAntesImpuestos("CtaMayor") = -1 dRowUtilidadAntesImpuestos("Orden") = "790" dRowUtilidadAntesImpuestos("PorcentajeActual") = UtilidadAntesImpuestosPorcentajeActual dRowUtilidadAntesImpuestos("PorcentajeAcumulado") = UtilidadAntesImpuestosPorcentajeAcumulado dRowUtilidadAntesImpuestosVacio("CtaMayor") = -1 dRowUtilidadAntesImpuestosVacio("Orden") = "790" 'PorcentajeActual 'PorcentajeAcumulado DtGastos.Rows.InsertAt(dRowUtilidadBruta, idxUtilidadBruta) DtGastos.Rows.InsertAt(dRowUtilidadBrutaVacio, idxUtilidadBruta + 1) DtGastos.Rows.InsertAt(dRowUtilidadOperacion, idxUtilidadOperacion) DtGastos.Rows.InsertAt(dRowUtilidadOperacionVacio, idxUtilidadOperacion + 1) DtGastos.Rows.InsertAt(dRowUtilidadAntesImpuestos, idxUtilidadAntesImpuestos) DtGastos.Rows.InsertAt(dRowUtilidadAntesImpuestosVacio, idxUtilidadAntesImpuestos + 1) 'ImporteActual 'ImporteAcumulado DtGastos.AcceptChanges() End If GvIngresos.DataSource = DtIngresos GvIngresos.DataBind() GvGastos.DataSource = DtGastos GvGastos.DataBind() UpDatos.Update() End Sub Protected Sub Imprimir_click(sender As Object, e As EventArgs) Handles Imprimir.Click ImprimirReporte() End Sub Private Sub SumaTotales() 'Llena Lb´s Totales LbTotalActual.Text = TotalActual.ToString.FormatoNumero LbTotalAnterior.Text = TotalAnterior.ToString.FormatoNumero LbTotalActual.ForeColor = If(TotalActual < 0, Drawing.Color.Red, Color.Black) LbTotalAnterior.ForeColor = If(TotalAnterior < 0, Drawing.Color.Red, Color.Black) End Sub Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs) TotalActual = 0 TotalAnterior = 0 CargaDatos() End Sub #Region "GV´S ROW DATA BOUND" Protected Sub GvIngresos_RowDataBound(sender As Object, e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.DBCampo("CtaMayor").ToString.ToEntero < 0 And Not e.Row.DBCampo("Orden").ToString().Contiene("600", "700", "790") Then TotalActual += e.Row.DBCampo("ImporteActual").ToString.ToDouble TotalAnterior += e.Row.DBCampo("ImporteAcumulado").ToString.ToDouble 'e.Row.ControlStyle.BackColor = Drawing.Color.LightGray 'e.Row.ControlStyle.ForeColor = Drawing.Color.White e.Row.ControlStyle.Font.Bold = True ElseIf e.Row.DBCampo("CtaMayor").ToString.Contiene("3", "4") Then 'e.Row.CssClass = "SubTotales3" e.Row.ControlStyle.Font.Bold = True End If If e.Row.DBCampo("CtaMayor").ToString.ToEntero > 0 Then e.Row.FCHyperLink("HLActual").NavigateUrl = String.Format("/Contabilidad2/RepAnexoCatalogo.aspx?CveCuenta={0}&FF={1}&FI={2}&ER=1&CveProyecto={3}&CveSubProyecto={4}", e.Row.DBCampo("CveCuenta"), e.Row.DBCampo("FechaFActual").ToDate.ToShortDateString, e.Row.DBCampo("FechaInicial").ToDate.ToShortDateString, DdlProyecto.SelectedValue, DdlSubproyecto.SelectedValue) e.Row.FCHyperLink("HLAnterior").NavigateUrl = String.Format("/Contabilidad2/RepAnexoCatalogo.aspx?CveCuenta={0}&FF={1}&FI={2}&ER=1&CveProyecto={3}&CveSubProyecto={4}", e.Row.DBCampo("CveCuenta"), e.Row.DBCampo("FechaFActual").ToDate.ToShortDateString, e.Row.DBCampo("FechaInicial").ToDate.ToShortDateString, DdlProyecto.SelectedValue, DdlSubproyecto.SelectedValue) End If If e.Row.DBCampo("ImporteActual").ToString.ToDouble < 0 Then e.Row.FCHyperLink("HLActual").ForeColor = Drawing.Color.Red e.Row.FCLabel("LblPorcentajeActual").ForeColor = Drawing.Color.Red End If If e.Row.DBCampo("ImporteAcumulado").ToString.ToDouble < 0 Then e.Row.FCHyperLink("HLAnterior").ForeColor = Drawing.Color.Red e.Row.FCLabel("LblPorcentajeAcumulado").ForeColor = Drawing.Color.Red End If If e.Row.DBCampo("CtaMayor").ToEntero = -1 And e.Row.DBCampo("Nombre").ToString.Length > 0 Then e.Row.Attributes.Add("style", "border-top: thick solid; border-top-width: thin; border-top-color: #000;") End If End If End Sub Protected Sub GvGastos_RowDataBound(sender As Object, e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.DBCampo("CtaMayor").ToString.ToEntero < 0 And Not e.Row.DBCampo("Orden").ToString().Contiene("600", "700", "790") Then TotalActual -= e.Row.DBCampo("ImporteActual").ToString.ToDouble TotalAnterior -= e.Row.DBCampo("ImporteAcumulado").ToString.ToDouble 'e.Row.ControlStyle.BackColor = Drawing.Color.LightGray 'e.Row.ControlStyle.ForeColor = Drawing.Color.White e.Row.ControlStyle.Font.Bold = True ElseIf e.Row.DBCampo("CtaMayor").ToString.Contiene("3", "4") Then 'e.Row.CssClass = "SubTotales" e.Row.ControlStyle.Font.Bold = True End If If e.Row.DBCampo("CtaMayor").ToString.ToEntero > 0 Then e.Row.FCHyperLink("HLActual").NavigateUrl = String.Format("/Contabilidad2/RepAnexoCatalogo.aspx?CveCuenta={0}&FF={1}&FI={2}&ER=1&CveProyecto={3}&CveSubProyecto={4}", e.Row.DBCampo("CveCuenta"), e.Row.DBCampo("FechaFActual").ToDate.ToShortDateString, e.Row.DBCampo("FechaInicial").ToDate.ToShortDateString, DdlProyecto.SelectedValue, DdlSubproyecto.SelectedValue) e.Row.FCHyperLink("HLAnterior").NavigateUrl = String.Format("/Contabilidad2/RepAnexoCatalogo.aspx?CveCuenta={0}&FF={1}&FI={2}&ER=1&CveProyecto={3}&CveSubProyecto={4}", e.Row.DBCampo("CveCuenta"), e.Row.DBCampo("FechaFActual").ToDate.ToShortDateString, e.Row.DBCampo("FechaInicial").ToDate.ToShortDateString, DdlProyecto.SelectedValue, DdlSubproyecto.SelectedValue) End If If e.Row.DBCampo("ImporteActual").ToString.ToDouble < 0 Then e.Row.FCHyperLink("HLActual").ForeColor = Drawing.Color.Red e.Row.FCLabel("LblPorcentajeActual").ForeColor = Drawing.Color.Red End If If e.Row.DBCampo("ImporteAcumulado").ToString.ToDouble < 0 Then e.Row.FCHyperLink("HLAnterior").ForeColor = Drawing.Color.Red e.Row.FCLabel("LblPorcentajeAcumulado").ForeColor = Drawing.Color.Red End If If e.Row.DBCampo("CtaMayor").ToEntero = -1 And e.Row.DBCampo("Nombre").ToString.Length > 0 Then e.Row.Attributes.Add("style", "border-top: thick solid; border-top-width: thin; border-top-color: #000;") End If End If End Sub #End Region Protected Sub ImgExcel_Click(sender As Object, e As EventArgs) Handles ImgExcel.Click ImprimirReporte("Excel") End Sub Private Sub ImprimirReporte(Optional Formato As String = "PDF") Dim lrds As New List(Of ReportDataSource) Dim rds As New ReportDataSource rds.Name = "DataSet1" rds.Value = DtIngresos Dim rds2 As New ReportDataSource rds2.Name = "DataSet2" rds2.Value = DtGastos lrds.Add(rds) lrds.Add(rds2) Dim params As New List(Of ReportParameter) params.Add(New ReportParameter("TotalActual", TotalActual.ToString)) params.Add(New ReportParameter("TotalAnterior", TotalAnterior.ToString)) params.Add(New ReportParameter("lbTotalActual", LbTotalActual.Text)) params.Add(New ReportParameter("lbTotalAnterior", LbTotalAnterior.Text)) 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("pFirma1", "")) params.Add(New ReportParameter("pFirma2", "")) params.Add(New ReportParameter("periodo", String.Format("de {0} {1}", DdlPeriodo.SelectedItem.Text, DdlEjercicio.SelectedItem.Text))) params.Add(New ReportParameter("SubProyecto", DdlSubproyecto.SelectedItem.Text)) ImprimirPDF("AC/Reportes/RepEstadoActividadesConta2.rdlc", lrds, params, "EstadoActividades", Formato) ' UsuarioActual.Empresa.GrupoEmpresa End Sub End Class