883 lines
48 KiB
C#

using System;
using Consulenza.ReportWriter.Business;
using Consulenza.ReportWriter.Business.OBJ_PDF;
using System.Data;
using System.Collections.Generic;
using Consulenza.ReportWriter.Business.CHART_PDF;
using Consulenza.ReportCommon;
using Consulenza.ReportWriter.Business.Entity;
using System.Linq;
using ceTe.DynamicPDF;
using Consulenza.DataServices.fideuram.data.service;
namespace Consulenza.ReportWriter.Manager.Section.Unica
{
/// <summary>
/// S15.PatrimonioFideuramRappresentazioneMacroAssetClass idSezione = 58
/// </summary>
public class S15 : Entity.Section
{
int larghezzaColonnaImmagine = 0;
int larghezzaColonnaMacroAsset_Small = 65;
int larghezzaColonnaMacroAsset_Large = 65;
Dictionary<string, int> larghezzaColonneMacroAsset_List = new Dictionary<string, int>();
bool presenzaColonnaControvaloreProdotto;
public S15(EnvironmentFacade environmentFacade, int idSection)
: base(environmentFacade, idSection)
{
try
{
Draw();
}
catch (Exception ex)
{
SectionLogger.Write("S15", ex.Message, SectionLoggerMessageLevel.E, EnvironmentFacade.ReportEnvironment);
}
}
protected override sealed void Draw()
{
var dati = GetDataSet();
AddElement(new SpacePDF(20));
if (presenzaGraficoBarre())
{
#region Testo introduttivo grafico
AddElement(new FormattedTextAreaPDF(getTesto1(), EnvironmentFacade.RendererFacade.XLeftLimit) {FontSize=7, TextHorizontalAlign = TextAlign.Justify });
AddElement(new SpacePDF(15));
#endregion
#region Tabella del Patrimonio
var tabellaPatrimonio = new TablePDF(EnvironmentFacade.RendererFacade.XLeftLimit, dati.Tables[0])
{
Style = Style.ConsulenzaUnica,
Header = false,
Footer = false,
AlternateRow = false,
RowHeight = 25,
WhiteSpacesHorizontalSeparator = true
};
tabellaPatrimonio.Columns.Add(new ColumnPDF("descrizione", 190, HorizontalAlignmentType.Sinistra, true, true, 7, ColumnType.Testo, "descrizione", string.Empty) { DeltaYContent = -2});
tabellaPatrimonio.Columns.Add(new ColumnPDF("valore", 330, HorizontalAlignmentType.Sinistra, false, false, 7, ColumnType.Testo, "valore", string.Empty) { PaddingLeft = 5, DeltaYContent = -2 });
AddElement(tabellaPatrimonio);
AddElement(new SpacePDF(15));
#endregion
#region Grafico a barre
//AddElement(new FormattedTextAreaPDF("Macro asset class", EnvironmentFacade.RendererFacade.XLeftLimit, 100) { BackGroundColor = ColorPDF.Standard_Grigio_SfondoColonnaTabella, FontBold = true, FontSize = 7, FontColor = ColorPDF.ConsulenzaUnica_Rosso, AutoIncrementYWritable = false, BackGroundMarginLeft = 5 });
//AddElement(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 });
//AddElement(new SpacePDF(10));
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("Macro asset class", EnvironmentFacade.RendererFacade.XLeftLimit, 100) { BackGroundColor = ColorPDF.Standard_Grigio_SfondoColonnaTabella, FontBold = true, FontSize = 7, FontColor = ColorPDF.ConsulenzaUnica_Rosso, AutoIncrementYWritable = false, BackGroundMarginLeft = 5, DeltaY = -3 });
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, DeltaY = -3 });
var dtGraficoBarre = dati.Tables[2];
var serieCollezione = new List<Serie> { new Serie { Name = "MacroAsset", 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"]),
ShowLabelAxisX = true,
LabelAxisX = item["MacroAsset"].ToString(),
FontSizeLabelAxisX = 7,
FontColorLabelAxisX = ColorPDF.Nero,
FontBoldLabelAxisY = false
});
}
graficoBarre.SeriesCollection = serieCollezione;
AddElement(graficoBarre);
#endregion
#region Nota del PatrimonioCasa
AddElement(new SpacePDF(20));
AddElement(new FormattedTextAreaPDF(GetNote1(), EnvironmentFacade.RendererFacade.XLeftLimit) { FontSize = 6, TextHorizontalAlign = TextAlign.Justify });
#endregion
AddElement(new SpacePDF(15));
}
if (presenzaTabella())
{
#region Testo introduttivo tabella prodotti
AddElement(new FormattedTextAreaPDF(getTesto2(), EnvironmentFacade.RendererFacade.XLeftLimit) {FontSize=7, TextHorizontalAlign = TextAlign.Justify });
AddElement(new SpacePDF(15));
#endregion
#region Tabella Prodotti per Area
#region larghezza e visibilità colonne
var larghezzaColonnaControvalore = presenzaColonnaControvaloreProdotto ? 80 : 0;
var larghezzaColonnaDescrizione = 520 - (larghezzaColonnaImmagine + larghezzaColonnaControvalore + (larghezzaColonneMacroAsset_List.Sum(o => o.Value)));
#endregion
var tabellaProdottiPerArea = new TablePDF(EnvironmentFacade.RendererFacade.XLeftLimit, dati.Tables[3], dati.Tables[4])
{
Style = Style.ConsulenzaUnica,
Header = true,
Footer = true,
AlternateRow = false,
ShowBorderContent = false,
ShowSeparationLines = false,
WhiteSpacesHorizontalSeparator = true,
HeaderMargin = 2,
RowHeight = 25
};
#region Columns e FooterColumns
// Modifica per Saving Map
tabellaProdottiPerArea.Columns.Add(new ColumnPDF("SavingMap", 13, HorizontalAlignmentType.Sinistra, false, false, 6, ColumnType.Immagine, "SavingMap", string.Empty) { DeltaYContent = 10, ScaleColumnTypeImage = 0.50F, HeaderBackgroundColor = ColorPDF.Bianco });
// Fine Modifica
tabellaProdottiPerArea.Columns.Add(new ColumnPDF("Immagine", larghezzaColonnaDescrizione-13, HorizontalAlignmentType.Sinistra, false, false, 6, ColumnType.Objectpdf, string.Empty, string.Empty) { DeltaYContent = 4, PaddingLeft = 2, HeaderBackgroundColor = ColorPDF.Bianco });
//tabellaProdottiPerArea.Columns.Add(new ColumnPDF("DescrizioneAreaProdotto", larghezzaColonnaDescrizione, HorizontalAlignmentType.Sinistra, false, false, 6, ColumnType.Testo, "DescrizioneProdotto", string.Empty) {HeaderBackgroundColor = ColorPDF.Bianco });
tabellaProdottiPerArea.FooterColumns.Add(new ColumnPDF("DescrizioneAreaProdotto", larghezzaColonnaDescrizione, HorizontalAlignmentType.Sinistra, false, true, 6, ColumnType.Testo));
if (presenzaColonnaControvaloreProdotto)
{
tabellaProdottiPerArea.Columns.Add(new ColumnPDF("ValoreProdotto", larghezzaColonnaControvalore, HorizontalAlignmentType.Sinistra, false, false, 6, ColumnType.Testo, "ValoreProdottoString", "Controvalore<br> attuale (€)") {HeaderPaddingLeft=4, HeaderBackgroundColor = ColorPDF.Bianco, HeaderFontColor = ColorPDF.Nero, HeaderFontSize = 6, PaddingRight = 6});
tabellaProdottiPerArea.FooterColumns.Add(new ColumnPDF("ValoreProdotto", larghezzaColonnaControvalore, HorizontalAlignmentType.Destra, false, true,6, ColumnType.Testo) { PaddingRight = 4 });
}
foreach (DataRow item in dati.Tables[2].Rows)
{
var colore = new ColorPDF(Convert.ToInt32(item["Red"]), Convert.ToInt32(item["Green"]), Convert.ToInt32(item["Blue"]));
if (item[0].Equals("Obbligazionario") || item[0].Equals("Azionario"))
tabellaProdottiPerArea.Columns.Add(new ColumnPDF(item["CodiceMacroAsset"].ToString(), larghezzaColonneMacroAsset_List[item["CodiceMacroAsset"].ToString()], HorizontalAlignmentType.Centrato, false, false, 6, ColumnType.Testo, item["CodiceMacroAsset"].ToString() + "String", item["MacroAsset"].ToString() + "<br>(" + (isControvalore() ? "€" : "%") + ")") { HeaderBackgroundColor = colore, BackgroundColor = colore, HeaderFontSize = 6, HeaderFontColor = ColorPDF.Bianco, FontColor = ColorPDF.Bianco, PaddingRight = 4, VerticalAlignment = VerticalAlignmentType.Centrato });
else if (item[0].Equals("Monetario Valute Estere"))
tabellaProdottiPerArea.Columns.Add(new ColumnPDF(item["CodiceMacroAsset"].ToString(), larghezzaColonneMacroAsset_List[item["CodiceMacroAsset"].ToString()], HorizontalAlignmentType.Centrato, false, false, 6, ColumnType.Testo, item["CodiceMacroAsset"].ToString() + "String", item["MacroAsset"].ToString() + " (" + (isControvalore() ? "€" : "%") + ")") { HeaderBackgroundColor = colore, BackgroundColor = colore, HeaderFontSize = 6, HeaderFontColor = ColorPDF.Nero, PaddingRight = 4, VerticalAlignment = VerticalAlignmentType.Centrato });
else
tabellaProdottiPerArea.Columns.Add(new ColumnPDF(item["CodiceMacroAsset"].ToString(), larghezzaColonneMacroAsset_List[item["CodiceMacroAsset"].ToString()], HorizontalAlignmentType.Centrato, false, false, 6, ColumnType.Testo, item["CodiceMacroAsset"].ToString() + "String", item["MacroAsset"].ToString() + "<br>(" + (isControvalore() ? "€" : "%") + ")") { HeaderBackgroundColor = colore, BackgroundColor = colore, HeaderFontSize = 6, HeaderFontColor = ColorPDF.Nero, PaddingRight = 4, VerticalAlignment = VerticalAlignmentType.Centrato });
tabellaProdottiPerArea.FooterColumns.Add(new ColumnPDF(item["CodiceMacroAsset"].ToString(), larghezzaColonneMacroAsset_List[item["CodiceMacroAsset"].ToString()], HorizontalAlignmentType.Destra, false, true, 6, ColumnType.Testo) { PaddingRight = 4 });
}
int a = 0;
foreach (var item in dati.Tables[3].Rows)
{
for (int b = 1; b < tabellaProdottiPerArea.Columns.Count; b++)
{
tabellaProdottiPerArea.Cells[b, a].HorizontalAlignment = HorizontalAlignmentType.Destra;
}
a++;
}
#endregion
#region Cells
int r = 0;
foreach (DataRow rw in dati.Tables[3].Rows)
{
var isTotal = Convert.ToBoolean(rw["IsTotal"]);
var isSubTotal = Convert.ToBoolean(rw["IsSubTotal"]);
// var codice=dati.Tables[2].AsEnumerable().Where(o=>o.Field<string>("CodiceAreaBisogno") == rw[""]
// var color = new ColorPDF();
if (isTotal || isSubTotal)
{
for (int c = 0; c < tabellaProdottiPerArea.Columns.Count; c++)
{
tabellaProdottiPerArea.Cells[c, r].BackgroundColor = ColorPDF.Standard_Grigio_SfondoColonnaTabella;
tabellaProdottiPerArea.Cells[c, r].FontBold = true;
tabellaProdottiPerArea.Cells[c, r].FontColor = ColorPDF.Nero;
}
if (isTotal)
{
// Simboli dell'area di bisogno
var listaOggetti = new List<ObjectPDF>
{
new RectanglePDF(8, 8, ColorPDF.GetBy_AreaBisogno(rw["CodiceAreaBisogno"].ToString())){DeltaY = 4},
new FormattedTextAreaPDF
{
Text = new AreaBisogno(rw["CodiceAreaBisogno"].ToString()).Abbreviazione,
FontBold = true,
FontColor = ColorPDF.Bianco,
DeltaX = 2F,
FontSize = 6,
DeltaY = 2
},
new FormattedTextAreaPDF
{
Text = new AreaBisogno(rw["CodiceAreaBisogno"].ToString()).Nome,
FontBold = true,
FontColor = ColorPDF.Nero,
DeltaX = 12F,
FontSize=6,
DeltaY = 2
}
};
tabellaProdottiPerArea.Cells[1, r].ValueObjectList.AddRange(listaOggetti);
}
if (isSubTotal)
{
var stringa = rw["DescrizioneProdotto"].ToString();
tabellaProdottiPerArea.Cells[1, r].ValueObject = new FormattedTextAreaPDF
{
Text = stringa,
FontBold = true,
FontColor = ColorPDF.Nero,
DeltaX = 2F,
DeltaY = 2,
FontSize = 6,
Width = larghezzaColonnaImmagine + larghezzaColonnaDescrizione + 5,
};
}
}
else
{
for (int c = 0; c < tabellaProdottiPerArea.Columns.Count; c++)
{
if (tabellaProdottiPerArea.Columns[c].Id == "OB" || tabellaProdottiPerArea.Columns[c].Id == "AZ")
tabellaProdottiPerArea.Cells[c, r].FontColor = ColorPDF.Bianco;
else
tabellaProdottiPerArea.Cells[c, r].FontColor = ColorPDF.Nero;
}
var stringa = rw["DescrizioneProdotto"].ToString();
tabellaProdottiPerArea.Cells[1, r].ValueObject = new FormattedTextAreaPDF
{
Text = stringa,
FontBold = false,
FontColor = ColorPDF.Nero,
DeltaX = 2F,
FontSize = 6,
DeltaY = 2,
Width = larghezzaColonnaImmagine + larghezzaColonnaDescrizione + 5 +
(presenzaColonnaControvaloreProdotto ? 0 : - 20)
};
}
if (presenzaColonnaControvaloreProdotto)
{
tabellaProdottiPerArea.Cells[3, r].HorizontalAlignment = HorizontalAlignmentType.Destra;
}
r++;
}
#endregion
AddElement(new SpacePDF(10));
AddElement(tabellaProdottiPerArea);
#endregion
}
}
protected sealed override DataTable GetDataTable()
{
return null;
}
protected override DataSet GetDataSet()
{
var ds = new DataSet();
#region dati
var dataMacroAsset = datiSeiUnico.patrimonioUnit().patrimonioCasa.macroAssetClass;
var dataDettaglioProdotti = datiSeiUnico.patrimonioUnit().patrimonioCasa.dettaglioProdotti.dettaglioProdotti.ToList();
var partiteViaggianti = datiSeiUnico.patrimonioUnit().patrimonioCasa.macroAssetClass.totaliPatrimonio.partiteViaggianti;
var patrimonioFideuram = datiSeiUnico.patrimonioUnit().patrimonioCasa.macroAssetClass.totaliPatrimonio.patrimonioTotaleRFA;
var patrimonioFideuramIntestazione = datiSeiUnico.patrimonioUnit().patrimonioCasa.macroAssetClass.totaliPatrimonio.risorseFinanziarie
+ datiSeiUnico.patrimonioUnit().patrimonioCasa.macroAssetClass.totaliPatrimonio.partiteViaggianti;
var pianificazione = datiSeiUnico.pianificazioneUnit().pianificazioneVerticale;
// var dataPiramideModello = datiSeiUnico.piramideModelloUnit().piramideModello.areaModello;//FARE
string risorseFinanziarieBF = datiSeiUnico.pianificazioneUnit().pianificazioneVerticale.risorseFinanziarieBF.ToString();
string Complessivo = datiSeiUnico.pianificazioneUnit().pianificazioneVerticale.sommaCtvAree.ToString();
var displayInfo = datiSeiUnico.displayInfos().macroAssetDisplayInfos.ToList();
var displayInfoAree = datiSeiUnico.displayInfos().areeDisplayInfos.ToList();
const string stringReplaceIfZero = " ";
#endregion
#region Patrimonio
var dtPatrimonio = new DataTable("dtPatrimonio");
dtPatrimonio.Columns.Add(new DataColumn("Descrizione", typeof(string)));
dtPatrimonio.Columns.Add(new DataColumn("Valore", typeof(string)));
var testoPatrimonio = string.Format("Patrimonio {0} (€){1}", Helper.ReplaceVariables("$/Banca/$", EnvironmentFacade.ReportEnvironment), (GetNote1().Length>0 ? "*" : ""));
dtPatrimonio.Rows.Add(testoPatrimonio, Helper.FormatCurrency(datiSeiUnico.CASA_TOTALEPOSITIVO.ToString()));
ds.Tables.Add(dtPatrimonio);
#endregion
#region Prodotti
#region Definizione DataTable
var dtProdotti = new DataTable("dtProdotti");
dtProdotti.Columns.Add(new DataColumn("SavingMap", typeof(string)));
dtProdotti.Columns.Add(new DataColumn("CodiceAreaBisogno", typeof(string)));
dtProdotti.Columns.Add(new DataColumn("DescrizioneAreaBisogno", typeof(string)));
dtProdotti.Columns.Add(new DataColumn("DescrizioneProgetto", typeof(string)));
dtProdotti.Columns.Add(new DataColumn("DescrizioneProdotto", typeof(string)));
dtProdotti.Columns.Add(new DataColumn("ValoreProdotto", typeof(decimal)));
dtProdotti.Columns.Add(new DataColumn("ValoreProdottoString", typeof(string)));
foreach (var item in dataMacroAsset.distribuzione.elencoSlice)
{
if (item.sliceRappresentabile)
{
dtProdotti.Columns.Add(new DataColumn(item.codice, typeof(string)));
dtProdotti.Columns.Add(new DataColumn(item.codice + "String", typeof(string)));
}
}
dtProdotti.Columns.Add(new DataColumn("OrdinamentoAreaBisogno", typeof(int)));
// Colonne di formattazione
dtProdotti.Columns.Add(new DataColumn("FontBold", typeof(bool)));
dtProdotti.Columns.Add(new DataColumn("ReplaceIfZero", typeof(string)));
dtProdotti.Columns.Add(new DataColumn("CanLastRow", typeof(bool)));
dtProdotti.Columns.Add(new DataColumn("IsTotal", typeof(bool)));
dtProdotti.Columns.Add(new DataColumn("IsSubTotal", typeof(bool)));
dtProdotti.Columns.Add(new DataColumn("CodiceProgetto", typeof(string)));
#endregion
#region Popolamento DataTable
const string labelProdottiNonRappresentabili = "n.d.";
foreach (var itemMacroAsset in dataMacroAsset.distribuzionePerProdotti.listaProdotti)
{
var itemPosizione = dataDettaglioProdotti.FirstOrDefault(o => o.chiavePosizionePortafoglio.Equals(itemMacroAsset.chiaveAggregazione));
//var itemPiramideModello = dataPiramideModello.FirstOrDefault(o => o.area.ToLower().Trim().Equals(itemPosizione.area.ToLower().Trim()));
var mapDisplayInfoAree = displayInfoAree.FirstOrDefault(o => o.key.Equals(itemPosizione.area.ToUpper())).value;
var colore = new ColorPDF(mapDisplayInfoAree.fill);
var ordinamento = mapDisplayInfoAree.order;
var flagProdottoRappresentabile = itemMacroAsset.rappresentabile;
var rowProdotti = dtProdotti.NewRow();
rowProdotti["CodiceAreaBisogno"] = itemPosizione.area;
rowProdotti["OrdinamentoAreaBisogno"] = ordinamento;//FARE
rowProdotti["DescrizioneAreaBisogno"] = itemPosizione.descAreaEstesa;
rowProdotti["DescrizioneProgetto"] = itemPosizione.nomeProgetto;
rowProdotti["CodiceProgetto"] = itemPosizione.codProgetto;
rowProdotti["DescrizioneProdotto"] = itemPosizione.prodotto.nomeProdotto;
if (itemPosizione.prodotto.savingMap)
//if (itemPosizione.prodotto.nomeProdotto.Substring(0, 2) == "FV")
rowProdotti["SavingMap"] = "SavingMap.png";
else
rowProdotti["SavingMap"] = "";
rowProdotti["ValoreProdotto"] = Math.Round(Convert.ToDecimal(itemPosizione.ctv), 2);
rowProdotti["ValoreProdottoString"] = Helper.FormatCurrency(rowProdotti["ValoreProdotto"].ToString());
foreach (var item in dataMacroAsset.distribuzione.elencoSlice)
{
if (item.sliceRappresentabile)
{
bool ccNA=itemPosizione.prodotto.tipoProdotto.ToUpper() == "CC" && !presenzaContocorrenteInMonterio();
//ccNA = false;//BugFix #4661
if (!ccNA)
{
rowProdotti[item.codice] = flagProdottoRappresentabile ? itemMacroAsset.listaSlice.Any(o => o.codice.Equals(item.codice)) ?
isControvalore() ?
Convert.ToDecimal(itemMacroAsset.listaSlice.FirstOrDefault(o => o.codice.Equals(item.codice)).ctv) :
Convert.ToDecimal(itemMacroAsset.listaSlice.FirstOrDefault(o => o.codice.Equals(item.codice)).pesoSuPosizione * 100) :
0 :
0;
}
else
{
rowProdotti[item.codice] = flagProdottoRappresentabile ? itemMacroAsset.listaSlice.Any(o => o.codice.Equals(item.codice)) ?
isControvalore() ?
"n.a." :
"n.a." :
"n.a." :
"n.a.";
}
rowProdotti[item.codice + "String"] = flagProdottoRappresentabile ?
Helper.FormatCurrency(rowProdotti[item.codice].ToString()) :
labelProdottiNonRappresentabili;
}
}
rowProdotti["FontBold"] = false;
rowProdotti["ReplaceIfZero"] = stringReplaceIfZero;
rowProdotti["CanLastRow"] = true;
rowProdotti["IsTotal"] = false;
rowProdotti["IsSubTotal"] = false;
dtProdotti.Rows.Add(rowProdotti);
}
#endregion
ds.Tables.Add(dtProdotti.AsEnumerable().OrderBy(o => o.Field<int>("OrdinamentoAreaBisogno")).CopyToDataTable());
#endregion
#region MacroAsset
var dtMacroAsset = new DataTable("dtMacroAsset");
dtMacroAsset.Columns.Add(new DataColumn("MacroAsset", typeof(string)));
dtMacroAsset.Columns.Add(new DataColumn("CodiceMacroAsset", typeof(string)));
dtMacroAsset.Columns.Add(new DataColumn("Controvalore", typeof(decimal)));
dtMacroAsset.Columns.Add(new DataColumn("Percentuale", typeof(decimal)));
dtMacroAsset.Columns.Add(new DataColumn("Red", typeof(int)));
dtMacroAsset.Columns.Add(new DataColumn("Green", typeof(int)));
dtMacroAsset.Columns.Add(new DataColumn("Blue", typeof(int)));
dtMacroAsset.Columns.Add(new DataColumn("Ordinamento", typeof(int)));
foreach (var itemDistribuzione in dataMacroAsset.distribuzione.elencoSlice)
{
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;
larghezzaColonneMacroAsset_List.Add(
itemDistribuzione.codice,
(itemDistribuzione.codice.Equals("OB") || itemDistribuzione.codice.Equals("FX")) ? larghezzaColonnaMacroAsset_Large : larghezzaColonnaMacroAsset_Small
);
dtMacroAsset.Rows.Add(itemDistribuzione.descrizione, itemDistribuzione.codice, controvalore, percentuale, colore.Red, colore.Green, colore.Blue, ordinamento);
}
}
ds.Tables.Add(dtMacroAsset.AsEnumerable().OrderBy(r => r.Field<int>("Ordinamento")).CopyToDataTable());
#endregion
#region Prodotti raggruppati per area
var dtProdottiPerArea = new DataTable();
dtProdottiPerArea = dtProdotti.Clone(); // Clono la struttura
dtProdottiPerArea.TableName = "dtProdottiPerArea";
// Aree
var viewAree = new DataView(dtProdotti) { Sort = "OrdinamentoAreaBisogno" };
var dtAree = viewAree.ToTable(true, "CodiceAreaBisogno", "DescrizioneAreaBisogno", "OrdinamentoAreaBisogno");
var area = string.Empty;
var progetto = string.Empty;
var codiceprogetto = string.Empty;
#region Prodotti delle Risorse Finanziarie
foreach (DataRow rowAreaProgetto in dtAree.Rows)
{
area = rowAreaProgetto["CodiceAreaBisogno"].ToString();
if (new AreaBisogno(area).Visibile)
{
//Progetti
var viewProgetti = area.ToLower().Equals("pre") ? new DataView(dtProdotti.Select("CodiceAreaBisogno='" + area + "'").OrderBy(x => x.Field<string>("DescrizioneProgetto")).CopyToDataTable()) :
new DataView(dtProdotti.Select("CodiceAreaBisogno='" + area + "'").OrderByDescending(x => x.Field<decimal>("ValoreProdotto")).CopyToDataTable());
var dtProgetti = viewProgetti.ToTable(true, "DescrizioneProgetto", "CodiceProgetto");
var bIntestazioneArea = true; // la riga di intestazione dell'area va stampata una sola volta.
var bItestazioneProgetto = area == "Inv" || area == "Pre"; // la riga di intestazione del progetto va stampata solo per area Inv e Pre.
DataRow rowProdottiPerArea;
foreach (DataRow itemProgetto in dtProgetti.Rows)
{
progetto = itemProgetto["DescrizioneProgetto"].ToString();
codiceprogetto = itemProgetto["CodiceProgetto"].ToString(); ;
// Subset di prodotti filtrati per Area/Progetto
// Modifica ES 18.05.2018
//var dtAreaProgetto = dtProdotti.Select("CodiceAreaBisogno='" + area + "' AND " + string.Format("DescrizioneProgetto ='{0}'", itemProgetto["DescrizioneProgetto"].ToString().Replace("'", "''")) + " AND CodiceProgetto='" + codiceprogetto + "'").OrderByDescending(x => x.Field<decimal>("ValoreProdotto")).CopyToDataTable();
var dtAreaProgetto = dtProdotti.Select("CodiceAreaBisogno='" + area + "' AND CodiceProgetto='" + codiceprogetto + "'").OrderByDescending(x => x.Field<decimal>("ValoreProdotto")).CopyToDataTable();
// Fine
if (bIntestazioneArea)
{
#region Riga con background grigio di intestazione per ogni Area
rowProdottiPerArea = dtProdottiPerArea.NewRow();
rowProdottiPerArea["CodiceAreaBisogno"] = rowAreaProgetto["CodiceAreaBisogno"];
rowProdottiPerArea["DescrizioneProdotto"] = rowAreaProgetto["DescrizioneAreaBisogno"];
rowProdottiPerArea["ValoreProdotto"] = presenzaContocorrenteInMonterio() ? dataMacroAsset.distribuzioneAree.FirstOrDefault(o => o.area.Equals(area)).distribuzione.totaleRapprCC : dataMacroAsset.distribuzioneAree.FirstOrDefault(o => o.area.Equals(area)).distribuzione.totaleRapprNoCC;
//rowProdottiPerArea["ValoreProdotto"] = dtArea.AsEnumerable().Sum(x => x.Field<decimal>("ValoreProdotto"));
rowProdottiPerArea["ValoreProdottoString"] = Helper.FormatCurrency(rowProdottiPerArea["ValoreProdotto"].ToString());
var pippo = dataMacroAsset.distribuzioneAree.FirstOrDefault(o => o.area.Equals(rowAreaProgetto["CodiceAreaBisogno"]) && o.chiaveProgetto == null);
if(pippo != null){
foreach (var item in pippo.distribuzione.elencoSlice)
{
if (item.sliceRappresentabile)
{
var controvalore = (presenzaContocorrenteInMonterio() ? item.ctvCC : item.ctv);
var perc = (presenzaContocorrenteInMonterio() ? item.pesoCC : item.peso) * 100;
rowProdottiPerArea[item.codice] = isControvalore() ? controvalore : perc; // dtArea.AsEnumerable().Sum(x => x.Field<decimal>(item.codice));
rowProdottiPerArea[item.codice + "String"] = Helper.FormatCurrency(rowProdottiPerArea[item.codice].ToString());
}
}
}
rowProdottiPerArea["FontBold"] = true;
rowProdottiPerArea["ReplaceIfZero"] = stringReplaceIfZero;
rowProdottiPerArea["CanLastRow"] = false;
rowProdottiPerArea["IsTotal"] = true;
rowProdottiPerArea["IsSubTotal"] = false;
dtProdottiPerArea.Rows.Add(rowProdottiPerArea);
bIntestazioneArea = false;
#endregion
}
if (bItestazioneProgetto)
{
#region Riga con background grigio di intestazione per ogni Progetto
rowProdottiPerArea = dtProdottiPerArea.NewRow();
rowProdottiPerArea["CodiceAreaBisogno"] = rowAreaProgetto["CodiceAreaBisogno"];
rowProdottiPerArea["DescrizioneProdotto"] = progetto;
rowProdottiPerArea["ValoreProdotto"] = dtAreaProgetto.AsEnumerable().Sum(x => x.Field<decimal>("ValoreProdotto"));
rowProdottiPerArea["ValoreProdottoString"] = Helper.FormatCurrency(rowProdottiPerArea["ValoreProdotto"].ToString());
var valoreprogetto = dataMacroAsset.distribuzioneAree.Where(o => o.area.Equals(area) && codiceprogetto == o.chiaveProgetto).FirstOrDefault();
if (valoreprogetto != null)
{
foreach (var item in valoreprogetto.distribuzione.elencoSlice)
{
if (item.sliceRappresentabile)
{
var controvalore = (presenzaContocorrenteInMonterio() ? item.ctvCC : item.ctv);
var perc = (presenzaContocorrenteInMonterio() ? item.pesoCC : item.peso) * 100;
rowProdottiPerArea[item.codice] = isControvalore() ? controvalore : perc; // dtArea.AsEnumerable().Sum(x => x.Field<decimal>(item.codice));
rowProdottiPerArea[item.codice + "String"] = Helper.FormatCurrency(rowProdottiPerArea[item.codice].ToString());
}
}
}
rowProdottiPerArea["FontBold"] = true;
rowProdottiPerArea["ReplaceIfZero"] = stringReplaceIfZero;
if(rowAreaProgetto["CodiceAreaBisogno"].ToString()=="Inv" || rowAreaProgetto["CodiceAreaBisogno"].ToString().Equals("Pre") )
rowProdottiPerArea["CanLastRow"] = true;
else
rowProdottiPerArea["CanLastRow"] = false;
rowProdottiPerArea["IsTotal"] = false;
rowProdottiPerArea["IsSubTotal"] = true;
dtProdottiPerArea.Rows.Add(rowProdottiPerArea);
#endregion
}
// I prodotti della dtProdotti vengono mergiati sulla dtProdottiPerArea
dtProdottiPerArea.Merge(dtAreaProgetto);
}
}
}
#endregion
ds.Tables.Add(dtProdottiPerArea);
#endregion
#region PatrimonioAltro (Footer Prodotti raggruppati per area)
int counter = 0;
int numeroColonneMacroAsset = ds.Tables[2].Rows.Count;
presenzaColonnaControvaloreProdotto = numeroColonneMacroAsset <= 5;
var indiceColonnaMacroAsset = presenzaColonnaControvaloreProdotto ? 3 : 2;
var dtProdottiPatrimonioAltro = new DataTable();
dtProdottiPatrimonioAltro.Columns.Add(new DataColumn("Colonna1", typeof(string))); //Descrizione
if (presenzaColonnaControvaloreProdotto)
dtProdottiPatrimonioAltro.Columns.Add(new DataColumn("Colonna2", typeof(string))); //ControvaloreProdotto
for (int i = 0; i <= ds.Tables[2].Rows.Count - 1; i++)
{
dtProdottiPatrimonioAltro.Columns.Add(new DataColumn(string.Format("Colonna{0}", i + indiceColonnaMacroAsset), typeof(string))); //Colonne MacroAsset dinamiche
}
dtProdottiPatrimonioAltro.Columns.Add(new DataColumn("FontBold", typeof(bool)));
dtProdottiPatrimonioAltro.Columns.Add(new DataColumn("BackgroundGray", typeof(bool)));
dtProdottiPatrimonioAltro.TableName = "dtProdottiPatrimonioAltro";
var listReturn = new List<rsPosizione>();
if(datiSeiUnico.CASA_OC !=0)
listReturn.Add(new rsPosizione { prodotto = new rsProdotto() { nomeProdotto = "Operazioni in corso" }, ctv = datiSeiUnico.CASA_OC });
foreach (var ccn in from o in dataDettaglioProdotti where o.area.ToLower().Equals("cc") && o.ctv !=0 orderby o.ctv select o) {
listReturn.Add(new rsPosizione { prodotto = new rsProdotto() { nomeProdotto = ccn.prodotto.nomeProdotto }, ctv = ccn.ctv });
}
foreach (var ef in from o in dataDettaglioProdotti where o.area.ToLower().Equals("self") && o.prodotto.codSottoprodotto.Equals("L191") && o.ctv != 0 orderby o.ctv select o)
{
listReturn.Add(new rsPosizione { prodotto = new rsProdotto() { nomeProdotto = ef.prodotto.nomeProdotto }, ctv = ef.ctv });
}
foreach (var et in from o in dataDettaglioProdotti where o.area.ToLower().Equals("self") && o.prodotto.codSottoprodotto.Equals("L192") && o.ctv != 0 orderby o.ctv select o)
{
listReturn.Add(new rsPosizione { prodotto = new rsProdotto() { nomeProdotto = et.prodotto.nomeProdotto }, ctv = et.ctv });
}
// 20181010 AC
foreach (var tf in from o in dataDettaglioProdotti where o.area.ToLower().Equals("self") && o.prodotto.codSottoprodotto.Equals("V301") && o.ctv != 0 orderby o.ctv select o)
{
listReturn.Add(new rsPosizione { prodotto = new rsProdotto() { nomeProdotto = tf.prodotto.nomeProdotto }, ctv = tf.ctv });
}
//--20181010 AC
if (listReturn.Count()!=0)
{
#region Totale risorse finanziarie
var rowProdottiPatrimonioAltro = dtProdottiPatrimonioAltro.NewRow();
rowProdottiPatrimonioAltro["Colonna1"] = "Totale risorse allocate";
if (presenzaColonnaControvaloreProdotto)
rowProdottiPatrimonioAltro["Colonna2"] = Helper.FormatCurrency(datiSeiUnico.CASA_SUBTOTALE.ToString());
counter = 0;
for (int i = 0; i <= ds.Tables[2].Rows.Count - 1; i++)
{
rowProdottiPatrimonioAltro[string.Format("Colonna{0}", i + indiceColonnaMacroAsset)] = isControvalore() ? Helper.FormatCurrency(ds.Tables[2].Rows[i]["Controvalore"].ToString()) : Helper.FormatDecimal(ds.Tables[2].Rows[i]["Percentuale"].ToString(), 2);
counter++;
}
rowProdottiPatrimonioAltro["FontBold"] = true;
rowProdottiPatrimonioAltro["BackgroundGray"] = true;
dtProdottiPatrimonioAltro.Rows.Add(rowProdottiPatrimonioAltro);
#endregion
// 20181010 AC
//#region OC + CCN + ELIGOFONDI + ELIGOTITOLI
#region OC + CCN + ELIGOFONDI + ELIGOTITOLI + ILTUOFOGLIO
//--20181010 AC
foreach (var item in listReturn)
{
rowProdottiPatrimonioAltro = dtProdottiPatrimonioAltro.NewRow();
rowProdottiPatrimonioAltro["Colonna1"] = item.prodotto.nomeProdotto;
if (presenzaColonnaControvaloreProdotto)
rowProdottiPatrimonioAltro["Colonna2"] = Helper.FormatCurrency(item.ctv.ToString());
for (int i = 0; i < counter; i++)
{
rowProdottiPatrimonioAltro[string.Format("Colonna{0}", i + indiceColonnaMacroAsset)] = labelProdottiNonRappresentabili;
}
rowProdottiPatrimonioAltro["FontBold"] = false;
rowProdottiPatrimonioAltro["BackgroundGray"] = false;
dtProdottiPatrimonioAltro.Rows.Add(rowProdottiPatrimonioAltro);
}
#endregion
#endregion
}
#region Totale patrimonio casa
var rowProdottiPatrimonioAltroPC = dtProdottiPatrimonioAltro.NewRow();
rowProdottiPatrimonioAltroPC["Colonna1"] = string.Format("Patrimonio {0}", Helper.ReplaceVariables("$/Banca/$", EnvironmentFacade.ReportEnvironment)).Replace("SIM", "");
if (presenzaColonnaControvaloreProdotto)
rowProdottiPatrimonioAltroPC["Colonna2"] = Helper.FormatCurrency(datiSeiUnico.CASA_TOTALE.ToString());
counter = 0;
for (int i = 0; i <= ds.Tables[2].Rows.Count - 1; i++)
{
rowProdottiPatrimonioAltroPC[string.Format("Colonna{0}", i + indiceColonnaMacroAsset)] = listReturn.Count != 0 ? "" :
(isControvalore() ? Helper.FormatCurrency(ds.Tables[2].Rows[i]["Controvalore"].ToString()) : Helper.FormatDecimal(ds.Tables[2].Rows[i]["Percentuale"].ToString(), 2));
counter++;
}
rowProdottiPatrimonioAltroPC["FontBold"] = true;
rowProdottiPatrimonioAltroPC["BackgroundGray"] = true;
dtProdottiPatrimonioAltro.Rows.Add(rowProdottiPatrimonioAltroPC);
#endregion
ds.Tables.Add(dtProdottiPatrimonioAltro);
return ds;
}
public virtual bool presenzaGraficoBarre(){return GetOption<Opzione4_1>().Valore;}
public virtual bool presenzaContocorrenteInMonterio(){return GetOption<Opzione4_2>().Valore;}
public virtual bool isControvalore(){return !GetOption<Opzione3>().Valore;}
public virtual bool presenzaTabella(){return GetOption<Opzione4_3>().Valore;}
public virtual string getTesto1() {
return !isControvalore() ?
Helper.ReplaceVariables(GetText().Rows[0]["testo1"].ToString(), EnvironmentFacade.ReportEnvironment) :
Helper.ReplaceVariables(GetText().Rows[0]["testo2"].ToString(), EnvironmentFacade.ReportEnvironment);
}
public virtual string getTesto2() {
return !isControvalore() ?
Helper.ReplaceVariables(GetText().Rows[0]["testo3"].ToString(), EnvironmentFacade.ReportEnvironment) :
Helper.ReplaceVariables(GetText().Rows[0]["testo4"].ToString(), EnvironmentFacade.ReportEnvironment);
}
public virtual string GetNote1()
{
string nota = "";
string token = "";
var macroAssetClass = datiSeiUnico.patrimonioUnit().patrimonioCasa.macroAssetClass;
decimal CCN_CASA = datiSeiUnico.CASA_CCN;
decimal GPELIGOFONDI_CASA = datiSeiUnico.CASA_GPELIGOFONDI;
decimal GPELIGTITOLI_CASA = datiSeiUnico.CASA_GPELIGTITOLI;
// 20181009 AC
decimal TUOFOGLIO_CASA = datiSeiUnico.CASA_TUOFOGLIO;
//--20181009 AC
// 20181009 AC
//if (CCN_CASA != 0 || GPELIGOFONDI_CASA != 0 || GPELIGTITOLI_CASA != 0
if (CCN_CASA != 0 || GPELIGOFONDI_CASA != 0 || GPELIGTITOLI_CASA != 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 = ", ";
}
nota += ".";
token = " ";
}
decimal GC = (presenzaContocorrenteInMonterio() ? macroAssetClass.distribuzione.coverageCC : macroAssetClass.distribuzione.coverage) * 100;
decimal OC_CASA = datiSeiUnico.CASA_OC;
decimal CC_CASA = presenzaContocorrenteInMonterio() ? 0 : datiSeiUnico.CASA_CC;
decimal PNR_CASA = macroAssetClass.distribuzione.totaleNonRappr;
if (GC < 100)
{
nota += token + datiSeiUnico.FormatDecimal("Grado di copertura (%) della rappresentazione grafica per macro asset class pari a {0}", GC);
token = ": ";
if (PNR_CASA != 0 || CC_CASA != 0 || OC_CASA != 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 = ", ";
}
}
}
nota += ".";
token = " ";
}
nota = !nota.Equals("") ? "(*) " + nota : nota;
return datiSeiUnico.FormatBanca(nota);
}
}
}