351 lines
16 KiB
VB.net
351 lines
16 KiB
VB.net
|
|
Imports System.Activities.Statements
|
|
Imports System.Data
|
|
Imports Extensiones
|
|
Imports Newtonsoft.Json.Linq
|
|
|
|
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
|
|
|
|
Private Property DtVentasReal As DataTable
|
|
Get
|
|
Return CType(ViewState("DtVentasReal"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DtVentasReal") = 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)
|
|
DtVentasReal = DsDatos.Tables(4)
|
|
|
|
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))
|
|
|
|
DtVentasReal.Columns.Add("Agrupador", GetType(String))
|
|
|
|
Dim sourceRow = DtVentasReal.Rows(0)
|
|
Dim desRow = DtVentasReal.NewRow()
|
|
desRow.ItemArray = CType(sourceRow.ItemArray.Clone(), Object())
|
|
DtVentasReal.Rows.Add(desRow)
|
|
|
|
Dim desRow2 = DtVentasReal.NewRow()
|
|
desRow2.ItemArray = CType(sourceRow.ItemArray.Clone(), Object())
|
|
DtVentasReal.Rows.Add(desRow2)
|
|
|
|
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
|
|
|
|
Dim index As Integer = 0
|
|
For Each Row As DataRow In DtVentasReal.Rows
|
|
Select Case index
|
|
Case 0
|
|
Row("Agrupador") = "Presupuesto 2024"
|
|
Case 1
|
|
Row("Agrupador") = "Promedio Venta Real"
|
|
Case 2
|
|
Row("Agrupador") = "Ventas Real"
|
|
End Select
|
|
index += 1
|
|
Next
|
|
|
|
GvVentasClasificacion.DataSource = DtVentasClasificacion
|
|
GvVentas.DataSource = DtVentas
|
|
GvVentasClasificacionxMes.DataSource = DtVentasClasificacionxMes
|
|
GvVentasAcumulado.DataSource = DtVentas
|
|
GvVentaReal.DataSource = DtVentasReal
|
|
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"
|
|
|
|
GvVentaReal.Columns(1).HeaderText = $"Prom-{Now.Year - 2}"
|
|
GvVentaReal.Columns(2).HeaderText = $"Prom-{Now.Year - 1}"
|
|
GvVentaReal.Columns(3).HeaderText = $"Prom-{Now.Year}"
|
|
GvVentaReal.Columns(4).HeaderText = $"Prom PPTO-{Now.Year}"
|
|
GvVentaReal.Columns(5).HeaderText = $"Ene-{Now.Year - 1}"
|
|
GvVentaReal.Columns(6).HeaderText = $"Feb"
|
|
GvVentaReal.Columns(7).HeaderText = $"Mar"
|
|
GvVentaReal.Columns(8).HeaderText = $"Abr"
|
|
GvVentaReal.Columns(9).HeaderText = $"May"
|
|
GvVentaReal.Columns(10).HeaderText = $"Jun"
|
|
GvVentaReal.Columns(11).HeaderText = $"Jul"
|
|
GvVentaReal.Columns(12).HeaderText = $"Ago"
|
|
GvVentaReal.Columns(13).HeaderText = $"Sep"
|
|
GvVentaReal.Columns(14).HeaderText = $"Oct"
|
|
GvVentaReal.Columns(15).HeaderText = $"Nov"
|
|
GvVentaReal.Columns(16).HeaderText = $"Dic"
|
|
GvVentaReal.Columns(17).HeaderText = $"Ene-{Now.Year}"
|
|
GvVentaReal.Columns(18).HeaderText = $"Feb"
|
|
GvVentaReal.Columns(19).HeaderText = $"Mar"
|
|
GvVentaReal.Columns(20).HeaderText = $"Abr"
|
|
GvVentaReal.Columns(21).HeaderText = $"May"
|
|
GvVentaReal.Columns(22).HeaderText = $"Jun"
|
|
GvVentaReal.Columns(23).HeaderText = $"Jul"
|
|
GvVentaReal.Columns(24).HeaderText = $"Ago"
|
|
GvVentaReal.Columns(25).HeaderText = $"Sep"
|
|
GvVentaReal.Columns(26).HeaderText = $"Oct"
|
|
GvVentaReal.Columns(27).HeaderText = $"Nov"
|
|
GvVentaReal.Columns(28).HeaderText = $"Dic"
|
|
|
|
|
|
GvVentasClasificacion.DataBind()
|
|
GvVentas.DataBind()
|
|
GvVentasClasificacionxMes.DataBind()
|
|
GvVentasAcumulado.DataBind()
|
|
GvVentaReal.DataBind()
|
|
|
|
CargaGraficaNEW(DtVentasGrafica)
|
|
|
|
End Sub
|
|
|
|
Protected Sub GvDatos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvVentaReal.RowDataBound
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
If e.Row.RowIndex = 0 Then
|
|
e.Row.Cells(1).Text = ""
|
|
e.Row.Cells(2).Text = ""
|
|
e.Row.Cells(3).Text = ""
|
|
e.Row.Cells(5).Text = ""
|
|
e.Row.Cells(6).Text = ""
|
|
e.Row.Cells(7).Text = ""
|
|
e.Row.Cells(8).Text = ""
|
|
e.Row.Cells(9).Text = ""
|
|
e.Row.Cells(10).Text = ""
|
|
e.Row.Cells(11).Text = ""
|
|
e.Row.Cells(12).Text = ""
|
|
e.Row.Cells(13).Text = ""
|
|
e.Row.Cells(14).Text = ""
|
|
e.Row.Cells(15).Text = ""
|
|
e.Row.Cells(16).Text = ""
|
|
|
|
ElseIf e.Row.RowIndex = 1 Then
|
|
e.Row.Cells(4).Text = ""
|
|
e.Row.Cells(5).Text = ""
|
|
e.Row.Cells(6).Text = ""
|
|
e.Row.Cells(7).Text = ""
|
|
e.Row.Cells(8).Text = ""
|
|
e.Row.Cells(9).Text = ""
|
|
e.Row.Cells(10).Text = ""
|
|
e.Row.Cells(11).Text = ""
|
|
e.Row.Cells(12).Text = ""
|
|
e.Row.Cells(13).Text = ""
|
|
e.Row.Cells(14).Text = ""
|
|
e.Row.Cells(15).Text = ""
|
|
e.Row.Cells(16).Text = ""
|
|
e.Row.Cells(17).Text = ""
|
|
e.Row.Cells(18).Text = ""
|
|
e.Row.Cells(19).Text = ""
|
|
e.Row.Cells(20).Text = ""
|
|
e.Row.Cells(21).Text = ""
|
|
e.Row.Cells(22).Text = ""
|
|
e.Row.Cells(23).Text = ""
|
|
e.Row.Cells(24).Text = ""
|
|
e.Row.Cells(25).Text = ""
|
|
e.Row.Cells(26).Text = ""
|
|
e.Row.Cells(27).Text = ""
|
|
e.Row.Cells(28).Text = ""
|
|
ElseIf e.Row.RowIndex = 2 Then
|
|
e.Row.Cells(1).Text = ""
|
|
e.Row.Cells(2).Text = ""
|
|
e.Row.Cells(3).Text = ""
|
|
e.Row.Cells(4).Text = ""
|
|
e.Row.Cells(17).Text = ""
|
|
e.Row.Cells(18).Text = ""
|
|
e.Row.Cells(19).Text = ""
|
|
e.Row.Cells(20).Text = ""
|
|
e.Row.Cells(21).Text = ""
|
|
e.Row.Cells(22).Text = ""
|
|
e.Row.Cells(23).Text = ""
|
|
e.Row.Cells(24).Text = ""
|
|
e.Row.Cells(25).Text = ""
|
|
e.Row.Cells(26).Text = ""
|
|
e.Row.Cells(27).Text = ""
|
|
e.Row.Cells(28).Text = ""
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub CargaGraficaNEW(ByVal D_T_Datos As DataTable)
|
|
Dim jsonData As JArray = New JArray()
|
|
|
|
For x As Integer = 1 To 12
|
|
Dim Mes As String = D_T_Datos.Columns(x).ColumnName
|
|
Dim obj As JObject = New JObject()
|
|
obj.Add(New JProperty("mes", Mes))
|
|
|
|
For y As Integer = 0 To D_T_Datos.Rows.Count - 1
|
|
obj.Add(New JProperty(D_T_Datos.Rows(y)(0).ToString(), D_T_Datos.Rows(y)(x).ToString()))
|
|
Next
|
|
|
|
jsonData.Add(obj)
|
|
Next
|
|
|
|
Dim jsonSeries As JArray = New JArray()
|
|
|
|
For y As Integer = 0 To D_T_Datos.Rows.Count - 1
|
|
Dim obj As JObject = New JObject(New JProperty(D_T_Datos.Rows(y)(0).ToString(), D_T_Datos.Rows(y)(0).ToString()))
|
|
jsonSeries.Add(obj)
|
|
Next
|
|
|
|
Dim jsdatos As String = jsonData.ToString()
|
|
Dim jsseries As String = jsonSeries.ToString()
|
|
RegistraScript($"generaGrafico({jsdatos},{jsseries});")
|
|
End Sub
|
|
|
|
End Class
|