Files
SIG/General/RepIndicadorResumen.aspx.vb
MLopez f427d5707d E172 Indicador Resumen agrupar productos por clasificación
SE MODIFICÓ PA_Vtas_GetRepPS en SIG_Resp_MLR
- Nuevo grupo 28: Clasificación - PS
2023-01-21 12:28:29 -07:00

480 lines
26 KiB
VB.net

Imports System.Data
Imports Extensiones
Imports Microsoft.Reporting.WebForms
Imports MoreLinq
Partial Class General_RepIndicadorResumen
Inherits ClsPaginas
#Region "propiedades"
#If False Then
Private Property DtColor As DataTable
Get
If ViewState("DtColor") Is Nothing Then
Return New DataTable
Else
Return DirectCast(ViewState("DtColor"), DataTable)
End If
End Get
Set(value As DataTable)
ViewState("DtColor") = value
End Set
End Property
#End If
#End Region
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
CargaCombos()
CargaDatos()
End If
End Sub
Private Sub CargaCombos()
'Carga SubProyectos
CargarCentrosDeCosto(Nothing, DdlSubProyecto, Nothing, lblSubProyecto)
TxtFechaI.Text = $"01/{Now.Month}/{Now.Year}"
TxtFechaF.Text = Now.ToString("dd/MM/yyyy")
'CreaDataTableColor()
End Sub
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs) Handles btnConsultar.Click
CargaDatos()
End Sub
Protected Sub LnkExportarPDF_Click(sender As Object, e As EventArgs) Handles LnkExportarPDF.Click
UPPMov.GenerarReportePDF("Reporte Resumen de Indicadores", TxtFechaI.Text, TxtFechaF.Text)
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
Private Sub CargaDatos()
Dim ObjVentas As New ClsVentas
Dim ObjCompras As New ClsCompras
Dim ObjMovtos As New ClsMovimientos
Dim ObjCitrus As New ClsCGame
Dim Grupo As Integer = 28 'Clasificación - PS
If ObjVentas.GetRepProductosServicios(-1, DdlSubProyecto.SelectedValue.ToEntero, -1, -1, -1, TxtFechaI.Text.Trim(), TxtFechaF.Text.Trim(), MinFecha, MaxFecha, -1,
-1, -1, -1, -1, "-1", UsuarioActual.CveEmpresa, Grupo, CveUsuarioConsulta:=UsuarioActual.CveUsuario, TipoDocto:="Ing", TipoCambio:=1) Then
GvVxP.DataSource = ObjVentas.DtResultados
End If
If ObjCitrus.GetIndicadores(UsuarioActual.CveEmpresa, TxtFechaI.Text, TxtFechaF.Text, UsuarioActual.CveUsuario, DdlSubProyecto.SelectedValue.ToEntero) Then
'Compras Productores
GvCompProductores.DataSource = ObjCitrus.DTSetResultados.Tables(0).FiltraParametros("", "RazonSocial ASC")
'CxP Productores
GvCxP192.DataSource = ObjCitrus.DTSetResultados.Tables(1).FiltraParametros("", "CveMoneda,Saldo DESC")
'CxP NO productores
GvCxP.DataSource = ObjCitrus.DTSetResultados.Tables(2).FiltraParametros("", "CveMoneda,Saldo DESC")
'Gastos (Compras acreedores)
GvCompAcreed.DataSource = ObjCitrus.DTSetResultados.Tables(3).FiltraParametros("", "CveMoneda,SubTotal DESC")
'Cuentas x Cobrar
GvCxC.DataSource = ObjCitrus.DTSetResultados.Tables(4).FiltraParametros("", "CveMoneda,Saldo DESC")
End If
ObjVentas.Dispose()
ObjCitrus.Dispose()
GvVxP.DataBind()
GvCompProductores.DataBind()
GvCompAcreed.DataBind()
GvCxP192.DataBind()
GvCxP.DataBind()
GvCxC.DataBind()
If GvCxC.DataSource IsNot Nothing Then
GvCxC.HeaderRow.Cells(1).Text = "<a href=""/CxC/RepCxC.aspx"" target=""_blank"">Saldo</a>"
GvCxC.HeaderRow.Cells(2).Text = "<a href=""/Ventas/RepRecuperacion.aspx"" target=""_blank"">Recuperado</a>"
End If
Dim SaldoConjCxP = 0
'Mostrar gráficos y totales en portlets solo si hay datos en su respectiva tabla
If GvVxP.Rows.Count > 0 Then
UPGraficaVxP.Visible = True
PLVxPTot.InnerHtml = "<span style=""font-weight:800"">" + "Cantidad: " + "</span>" + String.Format("{0:n} Kg", CType(GvVxP.DataSource, DataTable).SUM("Cantidad", "CodigoPS <> ''")) _
+ "<span style=""font-weight:800; margin-left:1em"">" + "Total: " + "</span>" + String.Format("{0:c} MXN", CType(GvVxP.DataSource, DataTable).SUM("SubTotalMN", "CodigoPS <> ''"))
Else
UPGraficaVxP.Visible = False
PLVxPTot.InnerHtml = Nothing
End If
If GvCompProductores.Rows.Count > 0 Then
UPGraficaCompProductores.Visible = True
PLCompProductoresTot.InnerHtml = "<span style=""font-weight:800"">" + "Cantidad: " + "</span>" + String.Format("{0:n} Kg", CType(GvCompProductores.DataSource, DataTable).SUM("Cantidad", ""))
Else
UPGraficaCompProductores.Visible = False
PLCompProductoresTot.InnerHtml = Nothing
End If
If GvCompAcreed.Rows.Count > 0 Then
UPGraficaCompAcreed.Visible = True
PLGastosTot.InnerHtml = "<span style=""font-weight:800"">" + "Importe: " + "</span>" + String.Format("{0:c} MXN", CType(GvCompAcreed.DataSource, DataTable).SUM("SubTotalMN", "CveClasificacion IS NOT NULL"))
Else
UPGraficaCompAcreed.Visible = False
PLGastosTot.InnerHtml = Nothing
End If
If GvCxC.Rows.Count > 0 Then
UPGraficaCxC.Visible = True
PLCxCTot.InnerHtml = "<span style=""font-weight:800"">" + "Saldo: " + "</span>" + String.Format("{0:c} MXN", CType(GvCxC.DataSource, DataTable).SUM("SaldoMN", "CveCliente IS NOT NULL"))
Dim Recuper As Double = CType(GvCxC.DataSource, DataTable).SUM("RecuperadoMN", "CveCliente IS NOT NULL")
If (Recuper > 0) Then PLCxCTot.InnerHtml += "<span style="" font-weight:800; margin-left:1em"">" + "Rec: " + "</span>" + String.Format("{0:c} MXN", Recuper)
Else
UPGraficaCxC.Visible = False
PLCxCTot.InnerHtml = Nothing
End If
If GvCxP192.Rows.Count > 0 Then
UPGraficaCxP192.Visible = True
Dim SaldoCxP192 = CType(GvCxP192.DataSource, DataTable).SUM("SaldoMN", "CveProveedor IS NOT NULL")
SaldoConjCxP += SaldoCxP192
PLCxP192Tot.InnerHtml = "<span style=""font-weight:800"">" + "Saldo: " + "</span>" + String.Format("{0:c} MXN", SaldoCxP192)
Else
UPGraficaCxP192.Visible = False
PLCxP192Tot.InnerHtml = Nothing
End If
If GvCxP.Rows.Count > 0 Then
UPGraficaCxP.Visible = True
Dim SaldoCxP = CType(GvCxP.DataSource, DataTable).SUM("SaldoMN", "CveProveedor IS NOT NULL")
SaldoConjCxP += SaldoCxP
PLCxPTot.InnerHtml = "<span style=""font-weight:800"">" + "Saldo: " + "</span>" + String.Format("{0:c} MXN", SaldoCxP)
Else
UPGraficaCxP.Visible = False
PLCxPTot.InnerHtml = Nothing
End If
If SaldoConjCxP > 0 Then
UPSaldoCxP.Visible = True
PLSaldoCxPTot.InnerHtml = String.Format("{0:c} MXN", SaldoConjCxP)
Else
UPSaldoCxP.Visible = False
PLSaldoCxPTot.InnerHtml = Nothing
End If
'Si no había datos en ninguna tabla no cargar función de gráficos
If GvVxP.Rows.Count = 0 _
AndAlso GvCompProductores.Rows.Count = 0 _
AndAlso GvCompAcreed.Rows.Count = 0 _
AndAlso GvCxC.Rows.Count = 0 _
AndAlso GvCxP192.Rows.Count = 0 _
AndAlso GvCxP.Rows.Count = 0 _
Then Exit Sub
Graficas()
End Sub
Protected Sub GvVxP_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvVxP.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.DBCampo("Orden") = "" Then
e.Row.CssClass = "Totales"
Else
If e.Row.DBCampo("CodigoPS") = "" Then
e.Row.CssClass = "SubTotales"
End If
End If
End If
End Sub
Protected Sub GvCxP192_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvCxP192.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.DBCampo("CveProveedor") = "" Then
e.Row.CssClass = "Totales"
End If
End If
End Sub
Protected Sub GvCxP_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvCxP.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.DBCampo("CveProveedor") = "" Then
e.Row.CssClass = "Totales"
End If
End If
End Sub
Dim CompProductoresTotales As Decimal() = New Decimal(5 - 1) {}
Protected Sub GvCompProductores_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvCompProductores.RowDataBound
'Esto tambien se podría meter en el Stored Procedure
If e.Row.RowType = DataControlRowType.DataRow Then
CompProductoresTotales(0) += Convert.ToDecimal(IfNull(DataBinder.Eval(e.Row.DataItem, "Cantidad"), 0))
CompProductoresTotales(1) += Convert.ToDecimal(IfNull(DataBinder.Eval(e.Row.DataItem, "SubTotal"), 0))
CompProductoresTotales(2) += Convert.ToDecimal(IfNull(DataBinder.Eval(e.Row.DataItem, "PUPromedioKG"), 0))
CompProductoresTotales(3) += Convert.ToDecimal(IfNull(DataBinder.Eval(e.Row.DataItem, "Saldo"), 0))
CompProductoresTotales(4) += Convert.ToDecimal(IfNull(DataBinder.Eval(e.Row.DataItem, "Abonado"), 0))
ElseIf e.Row.RowType = DataControlRowType.Footer Then
'Movemos el pie a la primera fila de la tabla
Dim footerRow As GridViewRow = e.Row
GvCompProductores.Controls(0).Controls.Remove(footerRow)
GvCompProductores.Controls(0).Controls.AddAt(1, footerRow)
'Ahora se registran los datos
e.Row.Cells(0).Text = "Totales"
e.Row.Cells(1).Text = CompProductoresTotales(0).ToString("N")
e.Row.Cells(2).Text = CompProductoresTotales(1).ToString("C")
e.Row.Cells(3).Text = (CompProductoresTotales(2) / GvCompProductores.Rows.Count).ToString("C") 'Promedio
e.Row.Cells(4).Text = CompProductoresTotales(3).ToString("C")
e.Row.Cells(5).Text = CompProductoresTotales(4).ToString("C")
For i As Integer = 1 To e.Row.Cells.Count - 1
e.Row.Cells(i).CssClass = "margenbound"
Next
End If
End Sub
Protected Sub GvComprasAcreed_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvCompAcreed.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.DBCampo("CveClasificacion") = "" Then
e.Row.CssClass = "Totales"
End If
End If
End Sub
Protected Sub GvCxC_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvCxC.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.DBCampo("CveCliente") = "" Then
e.Row.CssClass = "Totales"
End If
End If
End Sub
#If False Then
Private Sub CreaDataTableColor()
DtColor = New DataTable
DtColor.Columns.Add("Color")
DtColor.Rows.Add("#FF0F00")
DtColor.Rows.Add("#FF6600")
DtColor.Rows.Add("#FF9E01")
DtColor.Rows.Add("#FCD202")
DtColor.Rows.Add("#F8FF01")
DtColor.Rows.Add("#B0DE09")
DtColor.Rows.Add("#04D215")
DtColor.Rows.Add("#0D8ECF")
DtColor.Rows.Add("#0D52D1")
DtColor.Rows.Add("#2A0CD0")
DtColor.Rows.Add("#8A0CCF")
DtColor.Rows.Add("#CD0D74")
DtColor.Rows.Add("#754DEB")
DtColor.Rows.Add("#DDDDDD")
DtColor.Rows.Add("#999999")
DtColor.Rows.Add("#333333")
DtColor.Rows.Add("#000000")
End Sub
#End If
Private Sub Graficas()
Dim DtVxP, DtCxP192, DtCxP, DtCompProductores, DtCompAcreed, DtCxC, DtCxCR As New DataTable
'Dim RowColorIndex As Integer = 0
'Ventas x Producto
DtVxP.Reset()
DtVxP.Columns.Add("Texto")
DtVxP.Columns.Add("Valor")
'DtVxP.Columns.Add("Color")
DtVxP.Columns.Add("Unidad")
'RowColorIndex = 0
For Each Dr As DataRow In CType(GvVxP.DataSource, DataTable).FiltraParametros("", "SubTotalMN DESC").Rows
If Not Dr("CodigoPS").ToString = "" Then
Dim Row = DtVxP.NewRow()
Row("Texto") = Dr("GPO").ToString
Row("Valor") = Dr("SubTotalMN").ToString.FormatoNumero
Row("Unidad") = "MXN" '$"{GlobalDTMonedas().FiltraParametros($"CveMoneda = {Dr("CveMoneda").ToString}").Rows(0)("Abreviatura").ToString}"
DtVxP.Rows.Add(Row)
'RowColorIndex += 1
'If RowColorIndex = 17 Then
' RowColorIndex = 0
'End If
End If
Next
Dim vxp = From s In DtVxP.AsEnumerable() Select New With {.Texto = s("Texto").ToString(), .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim group_vxp = vxp.GroupBy(Function(x) x.Texto).[Select](Function(g) New With {
.Texto = g.Key,
.Valor = Math.Round(g.Sum(Function(x) x.Valor), 2),
.Unidad = "MXN"
}).ToDataTable
Dim top_vxp = From s In group_vxp.AsEnumerable().Take(10) Select New With {.Texto = s("Texto").ToString(), .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim resto_vxp = From s In group_vxp.AsEnumerable().Skip(10) Select New With {.Texto = "Otros", .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim group_resto_vxp = resto_vxp.GroupBy(Function(x) x.Texto).[Select](Function(g) New With {
.Texto = "Otros",
.Valor = Math.Round(g.Sum(Function(x) x.Valor), 2),
.Unidad = "MXN"
})
Dim query_vxp = top_vxp.Union(group_resto_vxp).OrderByDescending(Function(x) x.Valor)
'Dim query_vxp = top_vxp.Concat(From e In resto_vxp Group e By e.Texto Into gpo = Group)
'Dim group_resto_vxp = From e In resto_vxp Group e By e.Texto Into gpo = Group
'Dim group_resto_vxp = resto_vxp.GroupBy(Function(e) New With {Key e.Texto, Key e.Valor, Key e.Color, Key e.Unidad}).ToList()
'Compras Productores ProveedorClasificacion=192
DtCompProductores.Reset()
DtCompProductores.Columns.Add("Texto")
DtCompProductores.Columns.Add("Cantidad")
DtCompProductores.Columns.Add("Importe")
DtCompProductores.Columns.Add("UnidadC")
DtCompProductores.Columns.Add("UnidadI")
For Each Dr As DataRow In GvCompProductores.DataSource.Rows
Dim Row = DtCompProductores.NewRow()
Row("Texto") = Dr("RazonSocial").ToString
Row("Cantidad") = Dr("Cantidad").ToString.FormatoNumero
Row("Importe") = Dr("SubTotal").ToString.FormatoNumero
Row("UnidadC") = "Kg"
Row("UnidadI") = "MXN"
DtCompProductores.Rows.Add(Row)
Next
Dim comp_productores = From s In DtCompProductores.AsEnumerable() Select New With {.Texto = s("Texto").ToString(), .Cantidad = s("Cantidad").ToString().ToDouble(), .Importe = s("Importe").ToString().ToDouble(), .UnidadC = s("UnidadC").ToString(), .UnidadI = s("UnidadI").ToString()}
Dim group_comp_productores = comp_productores.GroupBy(Function(x) x.Texto).[Select](Function(g) New With {
.Texto = g.Key,
.Cantidad = Math.Round(g.Sum(Function(x) x.Cantidad), 2),
.Importe = Math.Round(g.Sum(Function(x) x.Importe), 2),
.UnidadC = "Kg",
.UnidadI = "MXN"
}).ToDataTable
Dim top_comp_productores = From s In group_comp_productores.AsEnumerable().Take(10) Select New With {.Texto = s("Texto").ToString(), .Cantidad = s("Cantidad").ToString().ToDouble(), .Importe = s("Importe").ToString().ToDouble(), .UnidadC = s("UnidadC").ToString(), .UnidadI = s("UnidadI").ToString()}
Dim resto_comp_productores = From s In group_comp_productores.AsEnumerable().Skip(10) Select New With {.Texto = "Otros", .Cantidad = s("Cantidad").ToString().ToDouble(), .Importe = s("Importe").ToString().ToDouble(), .UnidadC = s("UnidadC").ToString(), .UnidadI = s("UnidadI").ToString()}
Dim group_resto_comp_productores = resto_comp_productores.GroupBy(Function(x) x.Texto).[Select](Function(g) New With {
.Texto = "Otros",
.Cantidad = Math.Round(g.Sum(Function(x) x.Cantidad), 2),
.Importe = Math.Round(g.Sum(Function(x) x.Importe), 2),
.UnidadC = "Kg",
.UnidadI = "MXN"
})
Dim query_comp_productores = top_comp_productores.Union(group_resto_comp_productores).OrderByDescending(Function(x) x.Cantidad)
'Compras TipoProveedor=1 Acreedores (Gastos)
DtCompAcreed.Reset()
DtCompAcreed.Columns.Add("Texto")
DtCompAcreed.Columns.Add("Valor")
DtCompAcreed.Columns.Add("Unidad")
For Each Dr As DataRow In CType(GvCompAcreed.DataSource, DataTable).FiltraParametros("", "SubTotalMN DESC").Rows
If Dr("CveClasificacion").ToString <> "" Then
Dim Row = DtCompAcreed.NewRow()
Row("Texto") = Dr("Clasificacion").ToString
Row("Valor") = Dr("SubTotalMN").ToString.FormatoNumero
Row("Unidad") = "MXN" 'Dr("Moneda").ToString
DtCompAcreed.Rows.Add(Row)
End If
Next
Dim comp_acreed = From s In DtCompAcreed.AsEnumerable() Select New With {.Texto = s("Texto").ToString(), .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim group_comp_acreed = comp_acreed.GroupBy(Function(x) x.Texto).[Select](Function(g) New With {
.Texto = g.Key,
.Valor = Math.Round(g.Sum(Function(x) x.Valor), 2),
.Unidad = "MXN"
}).ToDataTable
Dim top_comp_acreed = From s In group_comp_acreed.AsEnumerable().Take(10) Select New With {.Texto = s("Texto").ToString(), .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim resto_comp_acreed = From s In group_comp_acreed.AsEnumerable().Skip(10) Select New With {.Texto = "Otros", .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim group_resto_comp_acreed = resto_comp_acreed.GroupBy(Function(x) x.Texto).[Select](Function(g) New With {
.Texto = "Otros",
.Valor = Math.Round(g.Sum(Function(x) x.Valor), 2),
.Unidad = "MXN"
})
Dim query_comp_acreed = top_comp_acreed.Union(group_resto_comp_acreed).OrderByDescending(Function(x) x.Valor)
'Cuentas por cobrar x Cliente -- Saldo
DtCxC.Reset()
DtCxC.Columns.Add("Texto")
DtCxC.Columns.Add("Valor")
DtCxC.Columns.Add("Unidad")
For Each Dr As DataRow In CType(GvCxC.DataSource, DataTable).FiltraParametros("", "SaldoMN DESC").Rows
If Not Dr("CveCliente").ToString = "" Then
Dim Row = DtCxC.NewRow()
Row("Texto") = Dr("RazonSocial").ToString
Row("Valor") = Dr("SaldoMN").ToString.FormatoNumero
Row("Unidad") = "MXN" '$"{GlobalDTMonedas().FiltraParametros($"CveMoneda = {Dr("CveMoneda").ToString}").Rows(0)("Abreviatura").ToString}"
DtCxC.Rows.Add(Row)
End If
Next
Dim cxc = From s In DtCxC.AsEnumerable() Select New With {.Texto = s("Texto").ToString(), .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim group_cxc = cxc.GroupBy(Function(x) x.Texto).[Select](Function(g) New With {
.Texto = g.Key,
.Valor = Math.Round(g.Sum(Function(x) x.Valor), 2),
.Unidad = "MXN"
}).ToDataTable
Dim top_cxc = From s In group_cxc.AsEnumerable().Take(10) Select New With {.Texto = s("Texto").ToString(), .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim resto_cxc = From s In group_cxc.AsEnumerable().Skip(10) Select New With {.Texto = "Otros", .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim group_resto_cxc = resto_cxc.GroupBy(Function(x) x.Texto).[Select](Function(g) New With {
.Texto = "Otros",
.Valor = Math.Round(g.Sum(Function(x) x.Valor), 2),
.Unidad = "MXN"
})
Dim query_cxc = top_cxc.Union(group_resto_cxc) '.OrderByDescending(Function(x) x.Valor)
'Alert(Newtonsoft.Json.JsonConvert.SerializeObject(CxC.Rows))
'Cuentas por cobrar x Cliente -- Recuperado
DtCxCR.Reset()
DtCxCR.Columns.Add("Texto")
DtCxCR.Columns.Add("Valor")
DtCxCR.Columns.Add("Unidad")
For Each Dr As DataRow In CType(GvCxC.DataSource, DataTable).FiltraParametros("", "SaldoMN DESC").Rows
If Not Dr("CveCliente").ToString = "" Then
Dim Row = DtCxCR.NewRow()
Row("Texto") = Dr("RazonSocial").ToString
Row("Valor") = Dr("RecuperadoMN").ToString.FormatoNumero
Row("Unidad") = "MXN" '$"{GlobalDTMonedas().FiltraParametros($"CveMoneda = {Dr("CveMoneda").ToString}").Rows(0)("Abreviatura").ToString}"
DtCxCR.Rows.Add(Row)
End If
Next
Dim cxcr = From s In DtCxCR.AsEnumerable() Select New With {.Texto = s("Texto").ToString(), .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim group_cxcr = cxcr.GroupBy(Function(x) x.Texto).[Select](Function(g) New With {
.Texto = g.Key,
.Valor = Math.Round(g.Sum(Function(x) x.Valor), 2),
.Unidad = "MXN"
}).ToDataTable
Dim top_cxcr = From s In group_cxcr.AsEnumerable().Take(10) Select New With {.Texto = s("Texto").ToString(), .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim resto_cxcr = From s In group_cxcr.AsEnumerable().Skip(10) Select New With {.Texto = "Otros", .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim group_resto_cxcr = resto_cxcr.GroupBy(Function(x) x.Texto).[Select](Function(g) New With {
.Texto = "Otros",
.Valor = Math.Round(g.Sum(Function(x) x.Valor), 2),
.Unidad = "MXN"
})
Dim query_cxcr = top_cxcr.Union(group_resto_cxcr) '.OrderByDescending(Function(x) x.Valor)
'CxP proveedores
DtCxP192.Reset()
DtCxP192.Columns.Add("Texto")
DtCxP192.Columns.Add("Valor")
DtCxP192.Columns.Add("Unidad")
For Each Dr As DataRow In CType(GvCxP192.DataSource, DataTable).FiltraParametros("", "SaldoMN DESC").Rows
If Not Dr("CveProveedor").ToString = "" Then
Dim Row = DtCxP192.NewRow()
Row("Texto") = Dr("RazonSocial").ToString
Row("Valor") = Dr("SaldoMN").ToString.FormatoNumero
Row("Unidad") = "MXN"
DtCxP192.Rows.Add(Row)
End If
Next
Dim cxp192 = From s In DtCxP192.AsEnumerable() Select New With {.Texto = s("Texto").ToString(), .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim group_cxp192 = cxp192.GroupBy(Function(x) x.Texto).[Select](Function(g) New With {
.Texto = g.Key,
.Valor = Math.Round(g.Sum(Function(x) x.Valor), 2),
.Unidad = "MXN"
}).ToDataTable
Dim top_cxp192 = From s In group_cxp192.AsEnumerable().Take(10) Select New With {.Texto = s("Texto").ToString(), .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim resto_cxp192 = From s In group_cxp192.AsEnumerable().Skip(10) Select New With {.Texto = "Otros", .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim group_resto_cxp192 = resto_cxp192.GroupBy(Function(x) x.Texto).[Select](Function(g) New With {
.Texto = "Otros",
.Valor = Math.Round(g.Sum(Function(x) x.Valor), 2),
.Unidad = "MXN"
})
Dim query_cxp192 = top_cxp192.Union(group_resto_cxp192).OrderByDescending(Function(x) x.Valor)
'CxP NO proveedor
DtCxP.Reset()
DtCxP.Columns.Add("Texto")
DtCxP.Columns.Add("Valor")
DtCxP.Columns.Add("Unidad")
For Each Dr As DataRow In CType(GvCxP.DataSource, DataTable).FiltraParametros("", "SaldoMN DESC").Rows
If Not Dr("CveProveedor").ToString = "" Then
Dim Row = DtCxP.NewRow()
Row("Texto") = Dr("RazonSocial").ToString
Row("Valor") = Dr("SaldoMN").ToString.FormatoNumero
Row("Unidad") = "MXN"
DtCxP.Rows.Add(Row)
End If
Next
Dim cxp = From s In DtCxP.AsEnumerable() Select New With {.Texto = s("Texto").ToString(), .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim group_cxp = cxp.GroupBy(Function(x) x.Texto).[Select](Function(g) New With {
.Texto = g.Key,
.Valor = Math.Round(g.Sum(Function(x) x.Valor), 2),
.Unidad = "MXN"
}).ToDataTable
Dim top_cxp = From s In group_cxp.AsEnumerable().Take(10) Select New With {.Texto = s("Texto").ToString(), .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim resto_cxp = From s In group_cxp.AsEnumerable().Skip(10) Select New With {.Texto = "Otros", .Valor = s("Valor").ToString().ToDouble(), .Unidad = s("Unidad").ToString()}
Dim group_resto_cxp = resto_cxp.GroupBy(Function(x) x.Texto).[Select](Function(g) New With {
.Texto = "Otros",
.Valor = Math.Round(g.Sum(Function(x) x.Valor), 2),
.Unidad = "MXN"
})
Dim query_cxp = top_cxp.Union(group_resto_cxp).OrderByDescending(Function(x) x.Valor)
'Serializar datos agrupándolos por su respectivo DataTable, todos en un solo JSON
Dim json As String = Newtonsoft.Json.JsonConvert.SerializeObject(New With {.VxP = query_vxp, .CompProductores = query_comp_productores, .CompAcreed = query_comp_acreed, .CxC = query_cxc, .CxCR = query_cxcr, .CxP192 = query_cxp192, .CxP = query_cxp})
'Alert(json)
RegistraScript($"CargaGraficas({json})", "sdkp24223")
UPPMov.Update()
End Sub
End Class