From 14564014e1a1dda1408451b795aaafebd75d386f Mon Sep 17 00:00:00 2001 From: RPimienta Date: Thu, 14 Nov 2024 22:48:52 -0600 Subject: [PATCH] Dashboard ventas --- App_Code/ClsPaginas.vb | 1 + App_Code/ClsVentas.vb | 20 ++ Ventas/DashboardVentas.aspx | 352 +++++++++++++++++++++++++++++++++ Ventas/DashboardVentas.aspx.vb | 253 ++++++++++++++++++++++++ 4 files changed, 626 insertions(+) create mode 100644 Ventas/DashboardVentas.aspx create mode 100644 Ventas/DashboardVentas.aspx.vb diff --git a/App_Code/ClsPaginas.vb b/App_Code/ClsPaginas.vb index 2cfcde5e5..b3e65d94f 100644 --- a/App_Code/ClsPaginas.vb +++ b/App_Code/ClsPaginas.vb @@ -10917,6 +10917,7 @@ Public Class ClsPaginas PaginaDict.Add("/Ventas/CatPSSubProyectosVendedores.aspx".ToUpper(), 787) PaginaDict.Add("/Ventas/CatMotivosCancelacion.aspx".ToUpper(), 788) PaginaDict.Add("/Ventas/CatSelectivas.aspx".ToUpper(), 897) + PaginaDict.Add("/Ventas/DashboardVentas.aspx".ToUpper(), 789) #End Region #Region "VIA" diff --git a/App_Code/ClsVentas.vb b/App_Code/ClsVentas.vb index 58e6691f6..c01821bed 100644 --- a/App_Code/ClsVentas.vb +++ b/App_Code/ClsVentas.vb @@ -7464,6 +7464,26 @@ Public Class ClsVentas Return Retorno End Function + Public Function GetDashboardVentasGet(CveEmpresa As Integer, CveSubProyecto As Integer, Agrupador As Integer) As Boolean + + Dim Retorno As Boolean = False + DataAdapter("PA_Vta_DashboardVentasGet") + With SqlAdapter.SelectCommand.Parameters + .Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa + .Add("@CveSubProyecto", SqlDbType.Int).Value = CveSubProyecto + .Add("@Agrupador", SqlDbType.Int).Value = Agrupador + End With + Try + Dataset = New DataSet() + SqlAdapter.Fill(Dataset) + Retorno = True + Catch ex As Exception + OnError("Ocurrió un error al obtener el dashboard de ventas.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo()) + End Try + Return Retorno + + End Function + #Region "PRODUCTOS/SERVICIOS, SUBPROYECTOS Y VENDEDORES" Public Function GetPSSubProyectosVendedores(CveEmpresa As Integer) As Boolean diff --git a/Ventas/DashboardVentas.aspx b/Ventas/DashboardVentas.aspx new file mode 100644 index 000000000..d45d29431 --- /dev/null +++ b/Ventas/DashboardVentas.aspx @@ -0,0 +1,352 @@ +<%@ Page Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="DashboardVentas.aspx.vb" Inherits="Ventas_DashboardVentas" %> + + + + + + + + + Dashboard Ventas + + + + + + + + + + +
+
+
+ + +
+
+
+ Proyecto: +
+ +
+ SubProyecto: +
+ +
+ +
+ + + + + +
+
+
+
+ +
+
+
+ + +
+
+ + + + + + + + + + + + + +
+
+ + + + + + + + +
+
+
+
+ +
+
+
+ + Grafica +
+
+ + + +
+
+
+
+ loading +
+
+
+ +
+
+
+
+ + + + + + + + + + + +
+
+
+ <%-- + + + + + + + + + + + + + + + +
EneroFebreroMarzoAbrilMayoJunioJulioAgostoSeptiembreOctubreNoviembreDiciembre
--%> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ <%--
+
+
+ + + + + + + + + + + + + + + + +
EneroFebreroMarzoAbrilMayoJunioJulioAgostoSeptiembreOctubreNoviembreDiciembre
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
--%> + + + + + + + + + + + + + diff --git a/Ventas/DashboardVentas.aspx.vb b/Ventas/DashboardVentas.aspx.vb new file mode 100644 index 000000000..92680092c --- /dev/null +++ b/Ventas/DashboardVentas.aspx.vb @@ -0,0 +1,253 @@ + +Imports System.Activities.Statements +Imports System.Data +Imports Extensiones + +Partial Class Ventas_DashboardVentas + Inherits ClsPaginas + + Private Property DtVentasClasificacion As DataTable + Get + Return CType(ViewState("DtVentasClasificacion"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtVentasClasificacion") = value + End Set + End Property + + Private Property DtVentas As DataTable + Get + Return CType(ViewState("DtVentas"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtVentas") = value + End Set + End Property + + Private Property DtVentasClasificacionxMes As DataTable + Get + Return CType(ViewState("DtVentasClasificacionxMes"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtVentasClasificacionxMes") = value + End Set + End Property + + Private Property DtVentasGrafica As DataTable + Get + Return CType(ViewState("DtVentasGrafica"), DataTable) + End Get + Set(value As DataTable) + ViewState("DtVentasGrafica") = value + End Set + End Property + + Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load + If Not IsPostBack Then + CargaCombos() + End If + End Sub + + Private Sub CargaCombos() + CargarCentrosDeCosto(DdlProyecto, DdlSubProyecto, LblProyecto, LblSubProyecto, divProyecto:=DivProyecto, AplicaTodos:="Seleccione") + DdlSubProyecto.Items(0).Text = "Seleccione" + End Sub + + Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs) + CargaDatos() + UpDatos.Update() + End Sub + + Protected Sub CargaDatos() + Dim ObjVentas As New ClsVentas + If ObjVentas.GetDashboardVentasGet(UsuarioActual.CveEmpresa, DdlSubProyecto.SelectedValue.ToEntero, DdlAgrupador.SelectedValue.ToEntero) Then + Dim DsDatos = ObjVentas.DataSetResultados.Copy() + If DsDatos IsNot Nothing Then + 'DESGLOSE + DtVentasClasificacion = DsDatos.Tables(0) + DtVentas = DsDatos.Tables(1) + DtVentasClasificacionxMes = DsDatos.Tables(2) + DtVentasGrafica = DsDatos.Tables(3) + + DtVentasClasificacion.Columns.Add("PorcentajeVenta", GetType(Decimal)) + DtVentasClasificacion.Columns.Add("Ano2xAno1", GetType(Decimal)) + DtVentasClasificacion.Columns.Add("Ano2xPPTO", GetType(Decimal)) + + DtVentas.Columns.Add("Ano3xAno1", GetType(Decimal)) + DtVentas.Columns.Add("Ano3xAno2", GetType(Decimal)) + DtVentas.Columns.Add("CumplimientaRealVSPPTO", GetType(Decimal)) + DtVentas.Columns.Add("Ano3xPPTO", GetType(Decimal)) + + Dim AcumuladoAno1 As Decimal = 0 + Dim AcumuladoAno2 As Decimal = 0 + Dim AcumuladoAno3 As Decimal = 0 + Dim AcumuladoPPTO As Decimal = 0 + For Each Row As DataRow In DtVentas.Rows + AcumuladoAno1 += Row("TotalAno1").ToString().ToDecimal() + AcumuladoAno2 += Row("TotalAno2").ToString().ToDecimal() + AcumuladoAno3 += Row("TotalAno3").ToString().ToDecimal() + AcumuladoPPTO += Row("TotalAno3Presupuesto").ToString().ToDecimal() + + Row("Ano3xAno1") = (AcumuladoAno3 / AcumuladoAno1) - 1 + Row("Ano3xAno2") = (AcumuladoAno3 / AcumuladoAno2) - 1 + + Row("CumplimientaRealVSPPTO") = (Row("TotalAno3").ToString().ToDecimal() * 100) / Row("TotalAno3Presupuesto").ToString().ToDecimal() / 100 + + Row("Ano3xPPTO") = (AcumuladoAno3 / AcumuladoPPTO) - 1 + Next + + For Each Row As DataRow In DtVentasClasificacion.Rows + Row("Ano2xAno1") = If(Row("TotalAno1").ToString().ToDecimal() = 0, 0, (Row("TotalAno2").ToString().ToDecimal() - Row("TotalAno1").ToString().ToDecimal()) / Row("TotalAno1").ToString().ToDecimal()) + + Row("Ano2xPPTO") = (Row("TotalAno2").ToString().ToDecimal() - Row("TotalAno2Presupuesto").ToString().ToDecimal()) / Row("TotalAno2Presupuesto").ToString().ToDecimal() + + Row("PorcentajeVenta") = If(DtVentasClasificacion.SUMD("TotalAno2") = 0, 0, Row("TotalAno2").ToString().ToDecimal() / DtVentasClasificacion.SUMD("TotalAno2")) + Next + + GvVentasClasificacion.DataSource = DtVentasClasificacion + GvVentas.DataSource = DtVentas + GvVentasClasificacionxMes.DataSource = DtVentasClasificacionxMes + GvVentasAcumulado.DataSource = DtVentas + End If + End If + ObjVentas.Dispose() + + GvVentasClasificacion.Columns(1).HeaderText = Now.Year.ToString() + GvVentasClasificacion.Columns(2).HeaderText = (Now.Year - 1).ToString() + GvVentasClasificacion.Columns(4).HeaderText = $"PRESUPUESTO {Now.Year}" + GvVentasClasificacion.Columns(5).HeaderText = $"{Now.Year} VS {Now.Year - 1}" + GvVentasClasificacion.Columns(6).HeaderText = $"{Now.Year} VS PPTO" + + GvVentasClasificacionxMes.Columns(1).HeaderText = $"{Now.Year}-Enero" + GvVentasClasificacionxMes.Columns(2).HeaderText = $"{(Now.Year - 1)}-Enero" + GvVentasClasificacionxMes.Columns(3).HeaderText = $"{Now.Year}-Febrero" + GvVentasClasificacionxMes.Columns(4).HeaderText = $"{(Now.Year - 1)}-Febrero" + GvVentasClasificacionxMes.Columns(5).HeaderText = $"{Now.Year}-Marzo" + GvVentasClasificacionxMes.Columns(6).HeaderText = $"{(Now.Year - 1)}-Marzo" + GvVentasClasificacionxMes.Columns(7).HeaderText = $"{Now.Year}-Abril" + GvVentasClasificacionxMes.Columns(8).HeaderText = $"{(Now.Year - 1)}-Abril" + GvVentasClasificacionxMes.Columns(9).HeaderText = $"{Now.Year}-Mayo" + GvVentasClasificacionxMes.Columns(10).HeaderText = $"{(Now.Year - 1)}-Mayo" + GvVentasClasificacionxMes.Columns(11).HeaderText = $"{Now.Year}-Junio" + GvVentasClasificacionxMes.Columns(12).HeaderText = $"{(Now.Year - 1)}-Junio" + GvVentasClasificacionxMes.Columns(13).HeaderText = $"{Now.Year}-Julio" + GvVentasClasificacionxMes.Columns(14).HeaderText = $"{(Now.Year - 1)}-Julio" + GvVentasClasificacionxMes.Columns(15).HeaderText = $"{Now.Year}-Agosto" + GvVentasClasificacionxMes.Columns(16).HeaderText = $"{(Now.Year - 1)}-Agosto" + GvVentasClasificacionxMes.Columns(17).HeaderText = $"{Now.Year}-Septiembre" + GvVentasClasificacionxMes.Columns(18).HeaderText = $"{(Now.Year - 1)}-Septiembre" + GvVentasClasificacionxMes.Columns(19).HeaderText = $"{Now.Year}-Octubre" + GvVentasClasificacionxMes.Columns(20).HeaderText = $"{(Now.Year - 1)}-Octubre" + GvVentasClasificacionxMes.Columns(21).HeaderText = $"{Now.Year}-Noviembre" + GvVentasClasificacionxMes.Columns(22).HeaderText = $"{(Now.Year - 1)}-Noviembre" + GvVentasClasificacionxMes.Columns(23).HeaderText = $"{Now.Year}-Diciembre" + GvVentasClasificacionxMes.Columns(24).HeaderText = $"{(Now.Year - 1)}-Diciembre" + + 'GvVentasClasificacionxMes.Columns(1).HeaderText = $"{Now.Year}" + 'GvVentasClasificacionxMes.Columns(2).HeaderText = $"{(Now.Year - 1)}" + 'GvVentasClasificacionxMes.Columns(3).HeaderText = $"{Now.Year}" + 'GvVentasClasificacionxMes.Columns(4).HeaderText = $"{(Now.Year - 1)}" + 'GvVentasClasificacionxMes.Columns(5).HeaderText = $"{Now.Year}" + 'GvVentasClasificacionxMes.Columns(6).HeaderText = $"{(Now.Year - 1)}" + 'GvVentasClasificacionxMes.Columns(7).HeaderText = $"{Now.Year}" + 'GvVentasClasificacionxMes.Columns(8).HeaderText = $"{(Now.Year - 1)}" + 'GvVentasClasificacionxMes.Columns(9).HeaderText = $"{Now.Year}" + 'GvVentasClasificacionxMes.Columns(10).HeaderText = $"{(Now.Year - 1)}" + 'GvVentasClasificacionxMes.Columns(11).HeaderText = $"{Now.Year}" + 'GvVentasClasificacionxMes.Columns(12).HeaderText = $"{(Now.Year - 1)}" + 'GvVentasClasificacionxMes.Columns(13).HeaderText = $"{Now.Year}" + 'GvVentasClasificacionxMes.Columns(14).HeaderText = $"{(Now.Year - 1)}" + 'GvVentasClasificacionxMes.Columns(15).HeaderText = $"{Now.Year}" + 'GvVentasClasificacionxMes.Columns(16).HeaderText = $"{(Now.Year - 1)}" + 'GvVentasClasificacionxMes.Columns(17).HeaderText = $"{Now.Year}" + 'GvVentasClasificacionxMes.Columns(18).HeaderText = $"{(Now.Year - 1)}" + 'GvVentasClasificacionxMes.Columns(19).HeaderText = $"{Now.Year}" + 'GvVentasClasificacionxMes.Columns(20).HeaderText = $"{(Now.Year - 1)}" + 'GvVentasClasificacionxMes.Columns(21).HeaderText = $"{Now.Year}" + 'GvVentasClasificacionxMes.Columns(22).HeaderText = $"{(Now.Year - 1)}" + 'GvVentasClasificacionxMes.Columns(23).HeaderText = $"{Now.Year}" + 'GvVentasClasificacionxMes.Columns(24).HeaderText = $"{(Now.Year - 1)}" + + GvVentas.Columns(1).HeaderText = (Now.Year - 2).ToString() + GvVentas.Columns(2).HeaderText = (Now.Year - 1).ToString() + GvVentas.Columns(3).HeaderText = Now.Year.ToString() + GvVentas.Columns(4).HeaderText = $"PRESUPUESTO {Now.Year}" + GvVentas.Columns(5).HeaderText = $"CUMPLIMIENTO REAL VS PPTO {Now.Year}" + + GvVentasAcumulado.Columns(1).HeaderText = $"{Now.Year} VS {Now.Year - 2}" + GvVentasAcumulado.Columns(2).HeaderText = $"{Now.Year} VS {Now.Year - 1}" + GvVentasAcumulado.Columns(3).HeaderText = $"{Now.Year} VS PPTO" + + GvVentasClasificacion.DataBind() + GvVentas.DataBind() + GvVentasClasificacionxMes.DataBind() + GvVentasAcumulado.DataBind() + + CargaGraficas(DtVentasGrafica) + + 'Dim Ano3 = DateTime.Now.Year.ToString() + 'Dim Ano2 = (DateTime.Now.Year - 1).ToString() + 'Dim Ano1 = (DateTime.Now.Year - 2).ToString() + + 'Dim Dt As New DataTable() + 'Dt.Columns.Add("Mes") + 'Dt.Columns.Add(DateTime.Now.Year.ToString()) + 'Dt.Columns.Add((DateTime.Now.Year - 1).ToString()) + 'Dt.Columns.Add((DateTime.Now.Year - 2).ToString()) + 'Dt.Columns.Add("Presupuesto") + + 'For Each Dr As DataRow In DtVentas.Rows + ' Dim Row As DataRow = Dt.NewRow() + ' Row("Mes") = Dr("Mes").ToString() + ' Row(DateTime.Now.Year.ToString()) = Dr("TotalAno3").ToString().FormatoNumero + ' Row((DateTime.Now.Year - 1).ToString()) = Dr("TotalAno2").ToString().FormatoNumero + ' Row((DateTime.Now.Year - 2).ToString()) = Dr("TotalAno1").ToString().FormatoNumero + ' Row("Presupuesto") = Dr("TotalAno3Presupuesto").ToString().FormatoNumero + ' Dt.Rows.Add(Row) + 'Next + + 'Dim json As String = Newtonsoft.Json.JsonConvert.SerializeObject(Dt) + + 'RegistraScript($"CargaGrafica({json});console.log({json})", "22") + + End Sub + + Private Sub CargaGraficas(ByVal DtVentas As DataTable) + MuestraGrafica(div_ventas, DtVentas, "Ano", "Total", "", "", "gh2", "") + End Sub + + Private Sub MuestraGrafica(ByVal divcontainer As HtmlGenericControl, ByVal DTDatos As DataTable, ByVal ColTitle As String, ByVal ColValue As String, ByVal Titulo As String, ByVal SubTitulo As String, ByVal Optional Indicador As String = "gh", ByVal Optional XReferencia As String = "", ByVal Optional YReferencia As String = "") + Dim Info As String = "" + Dim SBJSScript As StringBuilder = New StringBuilder() + + If DTDatos.Rows.Count > 0 Then + + 'For Each DbRow As DataRow In DTDatos.Rows + ' Info = String.Format("{2}['{1}',{0}],", DbRow("TotalAno1"), DbRow(ColTitle), Info) + ' Info = String.Format("{2}['{1}',{0}],", DbRow("TotalAno2"), DbRow(ColTitle), Info) + ' Info = String.Format("{2}['{1}',{0}],", DbRow("TotalAno3"), DbRow(ColTitle), Info) + ' Info = String.Format("{2}['{1}',{0}],", DbRow("TotalAno3Presupuesto"), DbRow(ColTitle), Info) + 'Next + + 'For Each DbRow As DataRow In DTDatos.Rows + ' Info = String.Format("{2}['{1}',{0}],", DbRow("TotalAno1"), DateTime.Now.Year - 2, Info) + ' Info = String.Format("{2}['{1}',{0}],", DbRow("TotalAno2"), DateTime.Now.Year - 1, Info) + ' Info = String.Format("{2}['{1}',{0}],", DbRow("TotalAno3"), DateTime.Now.Year, Info) + ' Info = String.Format("{2}['{1}',{0}],", DbRow("TotalAno3Presupuesto"), $"PRESUPUESTO {Now.Year}", Info) + 'Next + + For Each DbRow As DataRow In DTDatos.Rows + Info = String.Format("{2}['{1}',{0}],", DbRow(ColValue), DbRow(ColTitle), Info) + Next + + If Info.Length > 0 Then + 'Info = Info.Remove(Info.Length - 1, 1) + SBJSScript.AppendFormat("graficahighcharts('{0}','{1}','{2}','{3}',[{4}],1,'{5}');", divcontainer.ClientID, Titulo, SubTitulo, YReferencia, Info, XReferencia) + End If + Else + SBJSScript.AppendFormat("graficahighcharts('{0}','{1}','{2}','{3}',[{4}],1,'{5}');", divcontainer.ClientID, Titulo, SubTitulo, YReferencia, " ", XReferencia) + End If + + RegistraScript(SBJSScript.ToString(), Indicador) + End Sub +End Class