Option Explicit On Option Strict On Imports System.Data Imports Extensiones Imports Microsoft.Reporting.WebForms Imports MoreLinq Partial Class General_RepIndicadorResumen Inherits ClsPaginas 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/{NowADS().Month}/{NowADS().Year}" TxtFechaF.Text = NowADS().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 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().ToDate, TxtFechaF.Text.Trim().ToDate, MinFecha, MaxFecha, -1, -1, -1, -1, -1, "-1", UsuarioActual.CveEmpresa, Grupo, CveUsuarioConsulta:=UsuarioActual.CveUsuario, TipoDocto:="Ing,Dev", TipoCambio:=1) Then GvVxP.DataSource = ObjVentas.DtResultados End If If ObjCompras.GetRepProductosServicios(-1, DdlSubProyecto.SelectedValue, "-1", -1, -1, TxtFechaI.Text.Trim().ToDate, TxtFechaF.Text.Trim().ToDate, -1, -1, -1, UsuarioActual.CveEmpresa, 5, -1, -1, "-1", "-1", -1, TipoCambio:=1, TipoDocto:="Fac", CveUsuarioConsulta:=UsuarioActual.CveUsuario, CveProveedorClasificacion:=192) Then GvCompProductores.DataSource = ObjCompras.DtResultados.FiltraParametros("", "Cantidad DESC") End If If ObjCitrus.GetIndicadores(UsuarioActual.CveEmpresa, TxtFechaI.Text.ToDate, TxtFechaF.Text.ToDate, 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() ObjCompras.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 = "Saldo" GvCxC.HeaderRow.Cells(2).Text = "Recuperado" End If Dim SaldoConjCxP As Decimal = 0D Dim SaldoCxC As Decimal = 0D '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 = "" + "Cantidad: " + "" + String.Format("{0:n} Kg", CType(GvVxP.DataSource, DataTable).SUM("Cantidad", "CodigoPS <> ''")) _ + "" + "Total: " + "" + 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 = "" + "Cantidad: " + "" + 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 = "" + "Importe: " + "" + 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 SaldoCxC = CType(GvCxC.DataSource, DataTable).SUMD("SaldoMN", "CveCliente IS NOT NULL") PLCxCTot.InnerHtml = "" + "Saldo: " + "" + String.Format("{0:c} MXN", SaldoCxC) Dim Recuper As Double = CType(GvCxC.DataSource, DataTable).SUMD("RecuperadoMN", "CveCliente IS NOT NULL") If (Recuper > 0) Then PLCxCTot.InnerHtml += "" + "Rec: " + "" + 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).SUMD("SaldoMN", "CveProveedor IS NOT NULL") SaldoConjCxP += SaldoCxP192 PLCxP192Tot.InnerHtml = "" + "Saldo: " + "" + 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).SUMD("SaldoMN", "CveProveedor IS NOT NULL") SaldoConjCxP += SaldoCxP PLCxPTot.InnerHtml = "" + "Saldo: " + "" + 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 LblSaldoTotal.InnerHtml = String.Format("{0:C} MXN", (SaldoCxC - SaldoConjCxP)) '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 If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.DBCampo("Orden") = "00ND" Then e.Row.CssClass = "Totales" e.Row.Cells(0).Text = "Total " + e.Row.DBCampo("Moneda") End If 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 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 = Colors.Length() 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 DirectCast(GvCompProductores.DataSource, DataTable).Rows If Not Dr("Orden").ToString = "00ND" Then Dim Row = DtCompProductores.NewRow() Row("Texto") = Dr("GPO").ToString Row("Cantidad") = Dr("Cantidad").ToString.FormatoNumero Row("Importe") = Dr("SubTotal").ToString.FormatoNumero Row("UnidadC") = "Kg" Row("UnidadI") = "MXN" DtCompProductores.Rows.Add(Row) End If 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