using System; using Consulenza.ReportWriter.Business; using Consulenza.ReportWriter.Business.OBJ_PDF; using System.Data; using Consulenza.ReportCommon; using Consulenza.ReportWriter.Business.CHART_PDF; using System.Collections.Generic; using Consulenza.ReportWriter.Business.Entity; using System.Linq; namespace Consulenza.ReportWriter.Manager.Section.Unica { /// /// Scheda 6. Patrimonio finanziario: rappresentazione per asset class. IdSezione 49 /// public class S6 : Entity.Section { public S6(EnvironmentFacade environmentFacade, int idSection) : base(environmentFacade, idSection) { try { Draw(); } catch (Exception ex) { SectionLogger.Write("S6", ex.Message, SectionLoggerMessageLevel.E, EnvironmentFacade.ReportEnvironment); } } protected override sealed void Draw() { var dati = GetDataSet(); #region Testo introduttivo grafico AddElement(new SpacePDF(20)); AddElement(new FormattedTextAreaPDF(GetTesto1(), EnvironmentFacade.RendererFacade.XLeftLimit) { FontSize = 7, TextHorizontalAlign = ceTe.DynamicPDF.TextAlign.Justify }); AddElement(new SpacePDF(15)); #endregion #region Tabella Patrimonio var tabellaPatrimonio = new TablePDF(EnvironmentFacade.RendererFacade.XLeftLimit, dati.Tables[0]) { Style = Style.ConsulenzaUnica, Header = false, Footer = false, AlternateRow = false, RowHeight = 25 }; tabellaPatrimonio.Columns.Add(new ColumnPDF("descrizione", 190, HorizontalAlignmentType.Sinistra, true, true, 7, ColumnType.Testo, "descrizione", string.Empty)); tabellaPatrimonio.Columns.Add(new ColumnPDF("valore", 330, HorizontalAlignmentType.Sinistra, false, false, 7, ColumnType.Testo, "valore", string.Empty) { PaddingLeft = 5 }); AddElement(tabellaPatrimonio); AddElement(new SpacePDF(25)); #endregion #region Grafico a barre var graficoBarre = new StackedPDF(EnvironmentFacade.RendererFacade.XLeftLimit + 110, 1F) { HeightSingleBar = 25, Width = 400, LabelFormatAxisY = isControvalore() ? FormatType.Intero : FormatType.Decimale2, ShowLineAxisX = true, PageBreak = true, DinamicFloatXEtichettaLateraleBarra = true, MinorGridAxisY = true, RemoveWhiteSpaceToTheRightAxisX = true, RemoveWhiteSpaceBetweenChartAndAxisX = true, MarginAxisY = 0, MarginAxisYFromTop = 0 }; graficoBarre.Headers.Add(new FormattedTextAreaPDF("Asset class", EnvironmentFacade.RendererFacade.XLeftLimit, 100) { BackGroundColor = ColorPDF.Standard_Grigio_SfondoColonnaTabella, FontBold = true, FontSize = 7, FontColor = ColorPDF.ConsulenzaUnica_Rosso, AutoIncrementYWritable = false, BackGroundMarginLeft = 5 }); graficoBarre.Headers.Add(new FormattedTextAreaPDF(string.Format("Distribuzione ({0})", isControvalore() ? "€" : "%"), EnvironmentFacade.RendererFacade.XLeftLimit + 110, 410) { BackGroundColor = ColorPDF.Standard_Grigio_SfondoColonnaTabella, FontBold = true, FontSize = 7, FontColor = ColorPDF.ConsulenzaUnica_Rosso, BackGroundMarginLeft = 5 }); var dtGraficoBarre = dati.Tables[1]; List serieCollezione = new List(); serieCollezione.Add(new Serie { Name = "AssetClass", Border = true }); foreach (DataRow item in dtGraficoBarre.Rows) { serieCollezione[0].Points.Add(new Point { ShowLabelAxisY = true, LabelAxisY = isControvalore() ? Helper.FormatCurrency(item["Controvalore"].ToString()) : Helper.FormatDecimal(item["Percentuale"].ToString(), 2), FontSizeLabelAxisY = 7, Color = new ColorPDF(Convert.ToInt32(item["Red"]), Convert.ToInt32(item["Green"]), Convert.ToInt32(item["Blue"])), Value = isControvalore() ? (Convert.ToDouble(item["Controvalore"]) == 0 ? 0.01 : Convert.ToDouble(item["Controvalore"])) : Convert.ToDouble(item["Percentuale"]) == 0 ? 0.01 : Convert.ToDouble(item["Percentuale"]), // Convert.ToDouble(Helper.FormatPercentage(Convert.ToDecimal(item["Percentuale"]), 2)), ShowLabelAxisX = true, LabelAxisX = item["AssetClass"].ToString(), FontSizeLabelAxisX = 7, FontBoldLabelAxisY = false }); } graficoBarre.SeriesCollection = serieCollezione; AddElement(graficoBarre); #endregion #region Nota del PatrimonioFinanziario if (GetNote1().Length > 0) { AddElement(new SpacePDF(30)); AddElement(new FormattedTextAreaPDF(Helper.ReplaceVariables(GetNote1(), EnvironmentFacade.ReportEnvironment), EnvironmentFacade.RendererFacade.XLeftLimit) { FontSize = 6, TextHorizontalAlign = ceTe.DynamicPDF.TextAlign.Justify }); } #endregion } protected sealed override DataTable GetDataTable() { return null; } protected override DataSet GetDataSet() { var ds = new DataSet(); var displayInfo = datiSeiUnico.displayInfos().assetDisplayInfos.ToList(); #region Patrimonio finanziario var dtPatrimonio = new DataTable(); dtPatrimonio.Columns.Add(new DataColumn("Descrizione", typeof(string))); dtPatrimonio.Columns.Add(new DataColumn("Valore", typeof(string))); var totalePatrimonioFinanziario = datiSeiUnico.patrimonioUnit().patrimonioFinanziario.intermediario.totale; var testoPatrimonio = string.Format("Patrimonio finanziario complessivo (€)" + (GetNote1().Length > 0 ? "*" : "")); dtPatrimonio.Rows.Add(testoPatrimonio, Helper.FormatCurrency(datiSeiUnico.FNZ_TOTALEPOSITIVO.ToString())); ds.Tables.Add(dtPatrimonio); #endregion #region AssetClass var dtAssetClass = new DataTable(); dtAssetClass.Columns.Add(new DataColumn("AssetClass", typeof(string))); dtAssetClass.Columns.Add(new DataColumn("Red", typeof(int))); dtAssetClass.Columns.Add(new DataColumn("Green", typeof(int))); dtAssetClass.Columns.Add(new DataColumn("Blue", typeof(int))); dtAssetClass.Columns.Add(new DataColumn("Controvalore", typeof(decimal))); dtAssetClass.Columns.Add(new DataColumn("Percentuale", typeof(decimal))); dtAssetClass.Columns.Add(new DataColumn("Ordinamento", typeof(int))); var assetClass = datiSeiUnico.patrimonioUnit().patrimonioFinanziario.assetClass.distribuzione.elencoSlice; foreach (var itemDistribuzione in assetClass) { if (itemDistribuzione.sliceRappresentabile) { var mapDisplayInfo = displayInfo.FirstOrDefault(o => o.key.Equals(itemDistribuzione.codice)).value; var colore = new ColorPDF(mapDisplayInfo.fill); var ordinamento = mapDisplayInfo.order; var controvalore = presenzaContocorrenteInMonterio() ? itemDistribuzione.ctvCC : itemDistribuzione.ctv; var percentuale = (presenzaContocorrenteInMonterio() ? itemDistribuzione.pesoCC : itemDistribuzione.peso) * 100; dtAssetClass.Rows.Add(itemDistribuzione.descrizione, colore.Red, colore.Green, colore.Blue, controvalore, percentuale, ordinamento); } } ds.Tables.Add(dtAssetClass.AsEnumerable().OrderBy(r => r.Field("Ordinamento")).CopyToDataTable()); #endregion return ds; } public virtual bool presenzaContocorrenteInMonterio() { return GetOption().Valore; } public virtual bool isControvalore() { return !GetOption().Valore; } public virtual bool sliceNonRappresentabileCopertura() { var assetClass = datiSeiUnico.patrimonioUnit().patrimonioFinanziario.assetClass.distribuzione.elencoSlice; return assetClass.AsEnumerable().FirstOrDefault(o => !o.sliceRappresentabile) != null; } public virtual string GetTesto1() { return !isControvalore() ? Helper.ReplaceVariables(GetText().Rows[0]["testo1"].ToString(), base.EnvironmentFacade.ReportEnvironment) : Helper.ReplaceVariables(GetText().Rows[0]["testo2"].ToString(), base.EnvironmentFacade.ReportEnvironment); } public virtual string GetNote1() { string nota = ""; string token = ""; var assetClass = datiSeiUnico.patrimonioUnit().patrimonioFinanziario.assetClass; decimal CCN_CASA = datiSeiUnico.CASA_CCN; decimal GPELIGOFONDI_CASA = datiSeiUnico.CASA_GPELIGOFONDI; decimal GPELIGTITOLI_CASA = datiSeiUnico.CASA_GPELIGTITOLI; decimal CCN_TERZI = datiSeiUnico.TRZ_CCN; // 20181009 AC decimal TUOFOGLIO_CASA = datiSeiUnico.CASA_TUOFOGLIO; //--20181009 AC // 20181009 AC //if (CCN_CASA != 0 || GPELIGOFONDI_CASA != 0 || GPELIGTITOLI_CASA != 0 || CCN_TERZI != 0) if (CCN_CASA != 0 || GPELIGOFONDI_CASA != 0 || GPELIGTITOLI_CASA != 0 || CCN_TERZI != 0 || TUOFOGLIO_CASA != 0) //--20181009 AC { nota += token + "Il controvalore esclude il saldo negativo"; token = " "; if (CCN_CASA != 0) { nota += token + datiSeiUnico.FormatDecimal("dei conti correnti ({0} €)", CCN_CASA); token = ", "; } // 20181009 AC if (TUOFOGLIO_CASA != 0) { nota += token + datiSeiUnico.FormatDecimal("della liquidità sottostante Il Mio Foglio ({0} €)", TUOFOGLIO_CASA); token = ", "; } //--20181009 AC if (GPELIGOFONDI_CASA != 0) { nota += token + datiSeiUnico.FormatDecimal("della liquidità sottostante la GP Eligo Fondi ({0} €)", GPELIGOFONDI_CASA); token = ", "; } if (GPELIGTITOLI_CASA != 0) { nota += token + datiSeiUnico.FormatDecimal("della liquidità sottostante la GP Eligo Titoli ({0} €)", GPELIGTITOLI_CASA); token = ", "; } token = " "; if (CCN_CASA != 0 || GPELIGOFONDI_CASA != 0 || GPELIGTITOLI_CASA != 0) { nota += token + "del patrimonio $/Banca/$"; token = ", "; } if (CCN_TERZI != 0) { nota += token + datiSeiUnico.FormatDecimal("dei conti correnti ({0} €) del patrimonio altri Istituti", CCN_TERZI); token = ", "; } nota += "."; token = " "; } decimal GC = (presenzaContocorrenteInMonterio() ? assetClass.distribuzione.coverageCC : assetClass.distribuzione.coverage) * 100; decimal OC_CASA = datiSeiUnico.CASA_OC; decimal CC_CASA = presenzaContocorrenteInMonterio() ? 0 : datiSeiUnico.CASA_CC; decimal PNR_CASA = datiSeiUnico.patrimonioUnit().patrimonioCasa.assetClass.distribuzione.totaleNonRappr; decimal CC_TERZI = presenzaContocorrenteInMonterio() ? 0 : datiSeiUnico.TRZ_CC; decimal PNR_TERZI = datiSeiUnico.patrimonioUnit().patrimonioTerzi.assetClass.distribuzione.totaleNonRappr; if (GC < 100) { nota += token + datiSeiUnico.FormatDecimal("Grado di copertura (%) della rappresentazione grafica per asset class pari a {0}", GC); token = ": "; if (PNR_CASA != 0 || CC_CASA != 0 || OC_CASA != 0 || PNR_TERZI != 0 || CC_TERZI != 0) { nota += token + "non sono considerati"; token = " "; if (PNR_CASA != 0 || CC_CASA != 0 || OC_CASA != 0) { if (PNR_CASA != 0) { nota += token + datiSeiUnico.FormatDecimal("i prodotti non rappresentabili ({0} €)", PNR_CASA); token = ", "; } if (CC_CASA != 0) { nota += token + datiSeiUnico.FormatDecimal("i conti correnti ({0} €)", CC_CASA); token = ", "; } if (OC_CASA != 0) { nota += token + datiSeiUnico.FormatDecimal("gli importi relativi alle operazioni in corso ({0} €)", OC_CASA); token = ", "; } token = " "; nota += token + "del patrimonio $/Banca/$"; token = ", "; } if (PNR_TERZI != 0 || CC_TERZI != 0) { if (PNR_TERZI != 0) { nota += token + datiSeiUnico.FormatDecimal("i prodotti non rappresentabili ({0} €)", PNR_TERZI); token = ", "; } if (CC_TERZI != 0) { nota += token + datiSeiUnico.FormatDecimal("i conti correnti ({0} €)", CC_TERZI); token = ", "; } token = " "; nota += token + "del patrimonio altri Istituti"; token = ", "; } } nota += "."; token = " "; } nota = !nota.Equals("") ? "(*) " + nota : nota; return datiSeiUnico.FormatBanca(nota); } } }