diff --git a/src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/pagoPA/KPIPagamenti/Dto/KPIPagamentiMatriceDto.cs b/src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/pagoPA/KPIPagamenti/Dto/KPIPagamentiMatriceDto.cs index ee5043d..05bc71e 100644 --- a/src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/pagoPA/KPIPagamenti/Dto/KPIPagamentiMatriceDto.cs +++ b/src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/pagoPA/KPIPagamenti/Dto/KPIPagamentiMatriceDto.cs @@ -35,7 +35,7 @@ public sealed class KPIPagamentiMatriceDto public string? KpiOutcome { get; set; } [HeaderPagoPA(caption: "dl_event_tms", Order = 11)] - public DateTime? DlEventTms { get; set; } + public long? DlEventTms { get; set; } [HeaderPagoPA(caption: "dl_ingestion_tms", Order = 11)] public long? DlIngestionTms { get; set; } diff --git a/src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/pagoPA/KPIPagamenti/Dto/KPIPagamentiScontoDto.cs b/src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/pagoPA/KPIPagamenti/Dto/KPIPagamentiScontoDto.cs index 5ceed87..0c629d0 100644 --- a/src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/pagoPA/KPIPagamenti/Dto/KPIPagamentiScontoDto.cs +++ b/src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/pagoPA/KPIPagamenti/Dto/KPIPagamentiScontoDto.cs @@ -5,33 +5,34 @@ namespace PortaleFatture.BE.Infrastructure.Common.pagoPA.KPIPagamenti.Dto; public sealed class KPIPagamentiScontoDto { - public string? RecipientName { get; set; } + public string? RecipientName { get; set; } [HeaderPagoPA(caption: "psp_name", Order = 0)] public string? PSPName { get; set; } [HeaderPagoPA(caption: "psp_id", Order = 1)] - public string? PspId { get; set; } - + public string? PspId { get; set; } + + [HeaderPagoPA(caption: "recipient_id", Order = 10)] public string? RecipientId { get; set; } [HeaderPagoPA(caption: "year_quarter", Order = 2)] public string? YearQuarter { get; set; } [HeaderPagoPA(caption: "trx_total", Order = 3)] - public long TrxTotal { get; set; } + public long? TrxTotal { get; set; } [HeaderPagoPA(caption: "value_total", Order = 4)] - public decimal ValueTotal { get; set; } + public decimal? ValueTotal { get; set; } [HeaderPagoPA(caption: "KpiOk", Order = 5)] - public int KpiOk { get; set; } + public int? KpiOk { get; set; } [HeaderPagoPA(caption: "PercSconto", Order = 5)] - public decimal PercSconto { get; set; } + public decimal? PercSconto { get; set; } [HeaderPagoPA(caption: "value_discount", Order = 6)] - public decimal ValueDiscount { get; set; } + public decimal? ValueDiscount { get; set; } [JsonIgnore] [HeaderPagoPA(caption: "LinkReport", Order = 7)] @@ -43,4 +44,13 @@ public sealed class KPIPagamentiScontoDto [HeaderPagoPA(caption: "FlagMQ", Order = 9)] public bool? FlagMQ { get; set; } + + [HeaderPagoPA(caption: "value_total_recipient_id", Order = 11)] + public decimal? RecipientValueTotal { get; set; } = null; + + [HeaderPagoPA(caption: "trx_total_recipient_id", Order = 12)] + public long? RecipientTrxTotal { get; set; } = null; + + [HeaderPagoPA(caption: "value_discount_recipient_id", Order = 13)] + public decimal? RecipientValueDiscount { get; set; } = null; } \ No newline at end of file diff --git a/src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/pagoPA/KPIPagamenti/Dto/KPIPagamentiScontoExcelDto.cs b/src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/pagoPA/KPIPagamenti/Dto/KPIPagamentiScontoExcelDto.cs index 589308a..4b79605 100644 --- a/src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/pagoPA/KPIPagamenti/Dto/KPIPagamentiScontoExcelDto.cs +++ b/src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/pagoPA/KPIPagamenti/Dto/KPIPagamentiScontoExcelDto.cs @@ -15,10 +15,10 @@ public sealed class KPIPagamentiScontoExcelDto public string? YearQuarter { get; set; } [HeaderPagoPA(caption: "Totale ", Order = 7)] - public decimal Totale { get; set; } + public decimal? Totale { get; set; } [HeaderPagoPA(caption: "TotaleSconto", Order = 10)] - public decimal TotaleSconto { get; set; } + public decimal? TotaleSconto { get; set; } [HeaderPagoPA(caption: "Link", Order = 11)] public string? Link { get; set; } @@ -33,7 +33,7 @@ public sealed class KPIPagamentiScontoExcelDto public string? PspId { get; set; } [HeaderPagoPA(caption: "trx_total", Order = 6)] - public long TrxTotal { get; set; } + public long? TrxTotal { get; set; } [HeaderPagoPA(caption: "KpiOk", Order = 8)] public int? KpiOk { get; set; } diff --git a/src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/pagoPA/KPIPagamenti/Extensions/KPIPagamentiExtensions.cs b/src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/pagoPA/KPIPagamenti/Extensions/KPIPagamentiExtensions.cs index ab6f597..6a67def 100644 --- a/src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/pagoPA/KPIPagamenti/Extensions/KPIPagamentiExtensions.cs +++ b/src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/pagoPA/KPIPagamenti/Extensions/KPIPagamentiExtensions.cs @@ -40,8 +40,8 @@ public static IEnumerable Map(this IEnumerable< actualValue.Name = ff.RecipientName; actualValue.RecipientId = ff.RecipientId; - actualValue.Totale += ff.ValueTotal; - actualValue.TotaleSconto+= ff.ValueDiscount; + actualValue.Totale += ff.ValueTotal == null ? 0 : ff.ValueTotal.Value; + actualValue.TotaleSconto+= ff.ValueDiscount == null ? 0 : ff.ValueDiscount.Value; actualValue.YearQuarter = ff.YearQuarter; actualValue.Link = ff.LinkReport; actualValue.KpiList = ff.KpiList; diff --git a/src/Presentation/PortaleFatture.BE.Api/Modules/pagoPA/FinancialReports/Extensions/FinancialReportsExtensions.cs b/src/Presentation/PortaleFatture.BE.Api/Modules/pagoPA/FinancialReports/Extensions/FinancialReportsExtensions.cs index 43c443c..716b24f 100644 --- a/src/Presentation/PortaleFatture.BE.Api/Modules/pagoPA/FinancialReports/Extensions/FinancialReportsExtensions.cs +++ b/src/Presentation/PortaleFatture.BE.Api/Modules/pagoPA/FinancialReports/Extensions/FinancialReportsExtensions.cs @@ -1,7 +1,5 @@ using System.Data; using System.Text.RegularExpressions; -using DocumentFormat.OpenXml.Office2010.CustomUI; -using Microsoft.IdentityModel.Logging; using PortaleFatture.BE.Api.Modules.pagoPA.FinancialReports.Dto; using PortaleFatture.BE.Api.Modules.pagoPA.FinancialReports.Request; using PortaleFatture.BE.Core.Auth; @@ -12,6 +10,7 @@ using PortaleFatture.BE.Infrastructure.Common.pagoPA.Documenti.Common; using PortaleFatture.BE.Infrastructure.Common.pagoPA.FinancialReports.Dto; using PortaleFatture.BE.Infrastructure.Common.pagoPA.FinancialReports.Queries; +using PortaleFatture.BE.Infrastructure.Common.pagoPA.KPIPagamenti.Dto; using PortaleFatture.BE.Infrastructure.Gateway.Storage.pagoPA; namespace PortaleFatture.BE.Api.Modules.pagoPA.FinancialReports.Extensions; @@ -227,7 +226,7 @@ public static FinancialReportQuartersQuery Map(this FinancialReportsQuartersRequ Quantità = item.Quantita, Sconti = null, Totale = group.Sum(i => i.Importo), - ContractId = item.ContractId + ContractId = item.ContractId }; if (item != group.First()) @@ -248,14 +247,14 @@ public static FinancialReportQuartersQuery Map(this FinancialReportsQuartersRequ foreach (var check in totalChecks) { var item = check; - var sconto = sconti != null ? sconti.Where(x => x.YearQuarter == yearQuarter && x.RecipientId == check.ContractId).Select(x=> x.ValueDiscount) : []; + var sconto = sconti != null ? sconti.Where(x => x.YearQuarter == yearQuarter && x.RecipientId == check.ContractId).Select(x => x.ValueDiscount) : []; if (check.Totale != null) { item.Sconti = sconto.FirstOrDefault(); item.TotaleScontato = check.Totale - item.Sconti; - } - } - + } + } + totalChecks.Add(new CheckFinance { Numero = "Totale Risultato", @@ -267,13 +266,39 @@ public static FinancialReportQuartersQuery Map(this FinancialReportsQuartersRequ dataSet.Tables.Add(totalChecks!.FillTable(tableName!)); //kpi-pagamenti - var scontoLista = scontiList != null? scontiList.Where(x => x.YearQuarter == yearQuarter) : []; - if(!scontoLista.IsNullNotAny()) + var scontoLista = scontiList != null ? scontiList.Where(x => x.YearQuarter == yearQuarter).ToList() : []; + if (!scontoLista.IsNullNotAny()) { tableName = yearQuarter!.TableName(2); - tableNames.Add(tableName!); - dataSet.Tables.Add(scontoLista!.FillTable(tableName!)); - } + tableNames.Add(tableName!); + + var aggregatedData = scontoLista + .GroupBy(item => new { item.YearQuarter, item.RecipientId, item.FlagMQ }) + .Select(group => new KPIPagamentiScontoDto + { + YearQuarter = group.Key.YearQuarter, + RecipientId = group.Key.RecipientId, + RecipientTrxTotal = group.Sum(item => item.TrxTotal), + RecipientValueTotal = group.Sum(item => item.ValueTotal), + RecipientValueDiscount = group.Sum(item => item.ValueDiscount), + FlagMQ = group.Key.FlagMQ, + PercSconto = null, + KpiOk = null, + TrxTotal = null, + + }) + .ToList(); + + scontoLista.AddRange(aggregatedData); + + var orderedList = scontoLista + .OrderBy(x => x.RecipientId) + .ThenBy(x => x.PSPName == null ? 1 : 0) + .ThenBy(x => x.PSPName) + .ToList(); + + dataSet.Tables.Add(orderedList!.FillTable(tableName!)); + } } } } diff --git a/src/Presentation/PortaleFatture.BE.Api/Modules/pagoPA/KPIPagamenti/Extensions/KPIPagamentiExtensions.cs b/src/Presentation/PortaleFatture.BE.Api/Modules/pagoPA/KPIPagamenti/Extensions/KPIPagamentiExtensions.cs index 2c722f1..5716810 100644 --- a/src/Presentation/PortaleFatture.BE.Api/Modules/pagoPA/KPIPagamenti/Extensions/KPIPagamentiExtensions.cs +++ b/src/Presentation/PortaleFatture.BE.Api/Modules/pagoPA/KPIPagamenti/Extensions/KPIPagamentiExtensions.cs @@ -20,7 +20,7 @@ public static IEnumerable Map(this IEnumerablex.TrxTotal), + TrxTotal = sc!.Posizioni!.Sum(x=>x.TrxTotal==null?0: x.TrxTotal.Value), FlagMQ = sc!.FlagMQ, }); foreach (var pos in sc!.Posizioni!)