using System;
using Consulenza.ReportWriter.Business;
using Consulenza.ReportWriter.Business.OBJ_PDF;
using System.Data;
using Consulenza.ReportWriter.Business.CHART_PDF;
using System.Collections.Generic;
using Consulenza.ReportCommon;
using Consulenza.ReportWriter.Business.Entity;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;
using ceTe.DynamicPDF;
using Consulenza.DataServices.fideuram.data.service;
namespace Consulenza.ReportWriter.Manager.Section.Unica
{
///
/// S17.PatrimonioFideuramRappresentazionePerValute idSezione = 60
///
public class S17 : Entity.Section
{
public S17(EnvironmentFacade environmentFacade, int idSection)
: base(environmentFacade, idSection)
{
try
{
Draw();
}
catch (Exception ex)
{
SectionLogger.Write("S17", ex.Message, SectionLoggerMessageLevel.E, EnvironmentFacade.ReportEnvironment);
}
}
///
///
/// m
protected override sealed void Draw()
{
float iDeltaX = 0;
var dati = GetDataSet();
//List listaOggettiDaRipetere;
AddElement(new SpacePDF(20));
if (dati.Tables["valute"].Rows.Count > 0 && presenzaGraficoBarre())
{
#region Testo introduttivo grafico
if (getTestoGrafico().Length > 0)
{
AddElement(new FormattedTextAreaPDF(getTestoGrafico(), EnvironmentFacade.RendererFacade.XLeftLimit) { FontSize = 7, TextHorizontalAlign = ceTe.DynamicPDF.TextAlign.Justify });
AddElement(new SpacePDF(20));
}
#endregion
#region Tabella patrimonio
var tabellaPatrimonio = new TablePDF(EnvironmentFacade.RendererFacade.XLeftLimit, dati.Tables["patrimonio"])
{
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,
MinorGridAxisY = true,
//MarginAxisY = 0,
ShowLineAxisX = true,
ShowLineAxisY = true,
PageBreak = true,
DinamicFloatXEtichettaLateraleBarra = true,
RemoveWhiteSpaceBetweenChartAndAxisX = true,
MarginAxisY = 0,
MarginAxisYFromTop = 0
};
graficoBarre.Headers.Add(new FormattedTextAreaPDF("Valute", 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("Distribuzione (%)", EnvironmentFacade.RendererFacade.XLeftLimit + 110, 410) { BackGroundColor = ColorPDF.Standard_Grigio_SfondoColonnaTabella, FontBold = true, FontSize = 7, FontColor = ColorPDF.ConsulenzaUnica_Rosso, BackGroundMarginLeft = 5 });
var serieCollezione = new List { new Serie { Name = "Valute", Border = true } };
DataTable dtValute = new DataTable();
dtValute = dati.Tables["valute"].AsEnumerable().OrderByDescending(o => o.Field("Percentuale")).ThenBy(R => R.Field("Valuta")).CopyToDataTable();
foreach (DataRow item in dati.Tables["valute"].Rows)
{
serieCollezione[0].Points.Add(new Point
{
ShowLabelAxisY = true,
LabelAxisY = Helper.FormatDecimal(item["Percentuale"].ToString(), 2),
FontSizeLabelAxisY = 7,
Color = new ColorPDF(Convert.ToInt32(item["Red"]), Convert.ToInt32(item["Green"]), Convert.ToInt32(item["Blue"])),
Value = Convert.ToDouble(item["Percentuale"]) == 0 ? 0.01 : Convert.ToDouble(item["Percentuale"]),
ShowLabelAxisX = true,
LabelAxisX = item["Valuta"].ToString(),
ImagePathLabelAsixX = string.Format("Flags\\{0}.png", item["Valuta"]),
ImageScaleLabelAsixX = 0.4F,
ImageDeltaXLabelAsixX = 55,
FontSizeLabelAxisX = 7,
FontBoldLabelAxisY = false
});
}
graficoBarre.SeriesCollection = serieCollezione;
AddElement(graficoBarre);
AddElement(new SpacePDF(20));
#endregion
#region Nota del Patrimonio Casa
if (GetNote1().Length > 0)
{
AddElement(new FormattedTextAreaPDF(GetNote1(), EnvironmentFacade.RendererFacade.XLeftLimit) { FontSize = 6, TextHorizontalAlign = TextAlign.Justify });
AddElement(new SpacePDF(15));
}
#endregion
}
if (dati.Tables["prodottiPerArea"].Rows.Count > 0)
{
#region Testo introduttivo Tabella Prodotti
//AddElement(new RepeaterPDF(listaOggettiDaRipetere));
//bool primesei = GetOption().DettaglioValute == DettaglioValute.PrimeSei;
AddElement(new FormattedTextAreaPDF(getTestoTabella(), EnvironmentFacade.RendererFacade.XLeftLimit) { FontSize = 7, TextHorizontalAlign = TextAlign.Justify });
AddElement(new SpacePDF(15));
#endregion
#region Tabella Prodotti X Area
#region largezza e visibilità colonne
var numeroColonneVisibili = dati.Tables["valute"].Rows.Count;
if (numeroColonneVisibili > 7)
numeroColonneVisibili = 7;
const int larghezzaColonnaImmagine = 15;
const int larghezzaColonnaControvalore = 70;
const int larghezzaColonnaSingolaValuta = 45;
var larghezzaColonnaDescrizione = 520 - (larghezzaColonnaImmagine + larghezzaColonnaControvalore) - (larghezzaColonnaSingolaValuta * numeroColonneVisibili);
#endregion
//DataView dtord = new DataView(dati.Tables["prodottiPerArea"]) { Sort = "OrdinamentoAreaBisogno, ControvaloreAttuale DESC" };
//var dd = dtord.ToTable();
var tabellaProdottiPerArea = new TablePDF(EnvironmentFacade.RendererFacade.XLeftLimit, dati.Tables["prodottiPerArea"])
{
Style = Style.ConsulenzaUnica,
Header = true,
Footer = true,
ShowSeparationLines = true,
HideLastSeparationLine = false,
AlternateRow = false,
HeaderHeight = 30,
PageBreak = true,
HeaderMargin = 2,
RowHeight = 25,
WhiteSpacesHorizontalSeparator = false
};
#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", larghezzaColonnaImmagine + larghezzaColonnaDescrizione - 13, HorizontalAlignmentType.Sinistra, false, false, 6, ColumnType.Objectpdf, string.Empty, string.Empty) { DeltaYContent = 5, PaddingLeft = 2, HeaderBackgroundColor = ColorPDF.Bianco });
//tabellaProdottiPerArea.Columns.Add(new ColumnPDF("Immagine", larghezzaColonnaImmagine, HorizontalAlignmentType.Sinistra, false, false, 6, ColumnType.Objectpdf, string.Empty, string.Empty) { DeltaYContent = 4, PaddingLeft = 2, HeaderBackgroundColor = ColorPDF.Bianco });
//tabellaProdottiPerArea.Columns.Add(new ColumnPDF("AreaProdotto", larghezzaColonnaDescrizione, HorizontalAlignmentType.Sinistra, false, true, 7, ColumnType.Testo, "DescrizioneProdotto", string.Empty) { BackgroundColor = ColorPDF.Bianco, HeaderBackgroundColor = ColorPDF.Bianco, HeaderFontColor = ColorPDF.Nero, HeaderFontSize = 7, HeaderPaddingRight = 5, PaddingRight = 3 });
tabellaProdottiPerArea.Columns.Add(new ColumnPDF("ControvaloreAttuale", larghezzaColonnaControvalore, HorizontalAlignmentType.Sinistra, false, true, 7, ColumnType.Decimale, "ControvaloreAttuale", "Controvalore
attuale (€)") { HeaderBackgroundColor = ColorPDF.Bianco, HeaderFontColor = ColorPDF.Nero, HeaderPaddingLeft = 4, PaddingRight = 4, HeaderFontSize = 7, FontSize = 6 });
int i = 0;
foreach (DataRow r in dati.Tables["prodottiPerArea"].Rows)
{
tabellaProdottiPerArea.Cells[2, i].HorizontalAlignment = HorizontalAlignmentType.Destra;
i++;
}
DataTable dt = new DataTable();
dt = dati.Tables["prodotti"].Clone();
dt.Columns.Remove("IsTotal");
dt.Columns.Remove("IsSubTotal");
DataColumnCollection dcc = dt.Columns;
for (int c = 0; c < numeroColonneVisibili; c++)
{
string valuta = "";
// Check
valuta = dcc[c + 10].ColumnName;
int paddingLeft = 3;
int headerGroupTextDeltaX = 16;
if (valuta.Equals("Altre"))
{
headerGroupTextDeltaX=10;
paddingLeft = 9;
}
tabellaProdottiPerArea.Columns.Add(new ColumnPDF(valuta, larghezzaColonnaSingolaValuta, HorizontalAlignmentType.Destra, false, true, 6, ColumnType.Testo, valuta, string.Format("{0} (%)", valuta))
{
HeaderBackgroundColor = ColorPDF.Bianco,
HeaderFontColor = ColorPDF.Nero,
HeaderPaddingRight = 5,
BackgroundColor = ColorPDF.Bianco,
PaddingRight = 5,
HeaderFontSize = 7,
FontSize = 6,
HeaderVerticalAlignment = VerticalAlignmentType.Basso,
HeaderGroupWidth = larghezzaColonnaSingolaValuta,
HeaderGroupPathImage = string.Format("Flags\\{0}.png", valuta),
HeaderGroupScaleImage = 0.4F,
HeaderGroupTextDeltaX = headerGroupTextDeltaX,
HeaderGroupTextDeltaY = -10,
HeaderPaddingLeft = paddingLeft,
HeaderGroupBorderLine = false
});
}
int o = 0;
foreach (DataRow rw in dati.Tables["prodottiPerArea"].Rows)
{
bool isTotal = Convert.ToBoolean(rw["IsTotal"]);
bool isSubTotal = Convert.ToBoolean(rw["IsSubTotal"]);
bool fontBold = Convert.ToBoolean(rw["FontBold"]);
if (isTotal || isSubTotal || fontBold)
{
for (int c = 0; c < tabellaProdottiPerArea.Columns.Count; c++)
{
tabellaProdottiPerArea.Cells[c, o].BackgroundColor = ColorPDF.Standard_Grigio_SfondoColonnaTabella;
tabellaProdottiPerArea.Cells[c, o].FontBold = true;
tabellaProdottiPerArea.Cells[c, o].FontColor = ColorPDF.Nero;
}
if (isTotal)
{
// Simboli dell'area di bisogno
switch (rw["CodiceAreaBisogno"].ToString().ToUpper())
{
case "EXT":
iDeltaX = 1.5F;
break;
case "INV":
iDeltaX = 2;
break;
case "PRE":
iDeltaX = 1.5F;
break;
case "RIS":
iDeltaX = 1.5F;
break;
case "LIQ":
iDeltaX = 1.8F;
break;
default:
iDeltaX = 2;
break;
}
var listaOggetti = new List
{
new RectanglePDF(8, 8, ColorPDF.GetBy_AreaBisogno(rw["CodiceAreaBisogno"].ToString())){DeltaY = 2.5F},
new FormattedTextAreaPDF
{
Text = new AreaBisogno(rw["CodiceAreaBisogno"].ToString()).Abbreviazione,
FontBold = true,
FontColor = ColorPDF.Bianco,
DeltaX = iDeltaX,
FontSize=7,
DeltaY = 1.0F
},
new FormattedTextAreaPDF
{
Text = new AreaBisogno(rw["CodiceAreaBisogno"].ToString()).Nome,
FontBold = true,
FontColor = ColorPDF.Nero,
DeltaX = 12F,
FontSize=6,
DeltaY = 1.5F
}
};
tabellaProdottiPerArea.Cells[1, o].ValueObjectList.AddRange(listaOggetti);
}
if (isSubTotal || fontBold)
{
var stringa = rw["DescrizioneProdotto"].ToString();
tabellaProdottiPerArea.Cells[1, o].ValueObject = new FormattedTextAreaPDF
{
Text = stringa,
FontBold = true,
FontColor = ColorPDF.Nero,
DeltaX = 2F,
FontSize = 6,
Width = larghezzaColonnaImmagine + larghezzaColonnaDescrizione + 5,
DeltaY = 1.5F
};
}
}
else
{
var stringa = rw["DescrizioneProdotto"].ToString();
float dY=stringa.Contains("Patrimonio") ? 1.5F : stringa.Length <= 40 ? 1.8F : 0.3F;
tabellaProdottiPerArea.Cells[1, o].ValueObject = new FormattedTextAreaPDF
{
Text = stringa,
FontBold = false,
FontColor = ColorPDF.Nero,
DeltaX = 2F,
FontSize = 6,
DeltaY = dY,
Width = dY>0.3F? larghezzaColonnaImmagine + larghezzaColonnaDescrizione:100
};
}
o++;
}
int a = 0;
foreach (var item in dati.Tables["prodottiPerArea"].Rows)
{
for (int b = 2; b < tabellaProdottiPerArea.Columns.Count; b++)
{
tabellaProdottiPerArea.Cells[b, a].HorizontalAlignment = HorizontalAlignmentType.Destra;
}
a++;
}
#endregion
int footer = dati.Tables["prodottiPerArea"].Rows.Count - 1;
for (int ii = 0; ii < dati.Tables["prodottiPerArea"].Columns.Count; ii++)
tabellaProdottiPerArea.Cells[ii, footer].YContentOffset = -1.0F;
AddElement(tabellaProdottiPerArea);
#endregion
}
}
///
/// Recupera i dati necessari alla Section restituendo un DataTable.
///
///
protected sealed override DataTable GetDataTable()
{
return null;
}
///
/// Recupera i dati necessari alla Section restituendo un DataSet.
///
///
protected sealed override DataSet GetDataSet()
{
#region dati
var ds = new DataSet();
ds.Tables.Add(new DataTable("patrimonio"));
ds.Tables.Add(new DataTable("valute"));
ds.Tables.Add(new DataTable("prodotti"));
ds.Tables["patrimonio"].Columns.Add(new DataColumn("Descrizione", typeof(string)));
ds.Tables["patrimonio"].Columns.Add(new DataColumn("Valore", typeof(string)));
ds.Tables["valute"].Columns.Add(new DataColumn("Valuta", typeof(string)));
ds.Tables["valute"].Columns.Add(new DataColumn("Red", typeof(int)));
ds.Tables["valute"].Columns.Add(new DataColumn("Green", typeof(int)));
ds.Tables["valute"].Columns.Add(new DataColumn("Blue", typeof(int)));
ds.Tables["valute"].Columns.Add(new DataColumn("Controvalore", typeof(decimal)));
ds.Tables["valute"].Columns.Add(new DataColumn("Percentuale", typeof(decimal)));
ds.Tables["valute"].Columns.Add(new DataColumn("Ordinamento", typeof(int)));
ds.Tables["prodotti"].Columns.Add(new DataColumn("CodiceAreaBisogno", typeof(string)));
ds.Tables["prodotti"].Columns.Add(new DataColumn("DescrizioneAreaBisogno", typeof(string)));
ds.Tables["prodotti"].Columns.Add(new DataColumn("OrdinamentoAreaBisogno", typeof(int)));
ds.Tables["prodotti"].Columns.Add(new DataColumn("DescrizioneProgetto", typeof(string)));
ds.Tables["prodotti"].Columns.Add(new DataColumn("DescrizioneProdotto", typeof(string)));
ds.Tables["prodotti"].Columns.Add(new DataColumn("ControvaloreAttuale", typeof(decimal)));
ds.Tables["prodotti"].Columns.Add(new DataColumn("FontBold", typeof(bool)));
ds.Tables["prodotti"].Columns.Add(new DataColumn("ReplaceIfZero", typeof(string)));
ds.Tables["prodotti"].Columns.Add(new DataColumn("CanLastRow", typeof(bool)));
ds.Tables["prodotti"].Columns.Add(new DataColumn("IsTotal", typeof(bool)));
ds.Tables["prodotti"].Columns.Add(new DataColumn("IsSubTotal", typeof(bool)));
ds.Tables["prodotti"].Columns.Add(new DataColumn("SavingMap", typeof(string)));
int ColumnsProdotti = 10;
const string stringReplaceIfZero = " ";
var patrimonioCasa = datiSeiUnico.patrimonioUnit().patrimonioCasa;
var esposizioneValutariaGrafico = !primeSei() ? patrimonioCasa.esposizioneValutariaTutte : patrimonioCasa.esposizioneValutaria;
var esposizioneValutaria = patrimonioCasa.esposizioneValutaria;
var dataDettaglioProdotti = datiSeiUnico.patrimonioUnit().patrimonioCasa.dettaglioProdotti.dettaglioProdotti;
var pianificazioneVerticale=datiSeiUnico.pianificazioneUnit().pianificazioneVerticale;
var displayInfo = datiSeiUnico.displayInfos();
#endregion
#region TabellaSintesi
//if (presenzaGraficoBarre())
{
ds.Tables["patrimonio"].Rows.Add(
datiSeiUnico.FormatBanca("Patrimonio $/Banca/$ (€)") + (GetNote1().Length > 0 ? "*" : ""),
Helper.FormatCurrency(datiSeiUnico.CASA_TOTALEPOSITIVO.ToString()));
ColorPDF coloreEur = new ColorPDF(displayInfo.espoValutariaDisplayInfos.First(o => o.key == "EUR").value.fill);
ColorPDF coloreNoEur = new ColorPDF(displayInfo.espoValutariaDisplayInfos.First(o => o.key == "NOEUR").value.fill);
var items = (from slice in esposizioneValutariaGrafico.distribuzione.elencoSlice
where slice.sliceRappresentabile
select new
{
codice = slice.codice,
descrizione = slice.descrizione,
Red = slice.codice.Equals("EUR") ? coloreEur.Red : coloreNoEur.Red,
Green = slice.codice.Equals("EUR") ? coloreEur.Green : coloreNoEur.Green,
Blue = slice.codice.Equals("EUR") ? coloreEur.Blue : coloreNoEur.Blue,
ctv = presenzaContocorrenteInMonterio() ? slice.ctvCC : slice.ctv,
peso = (presenzaContocorrenteInMonterio() ? slice.pesoCC : slice.peso) * 100,
}).OrderByDescending(o => Math.Abs(o.peso)).ThenBy(R => R.codice);
int ii = 0;
foreach (var itemValuta in from o in items where o.codice != "OTHER" select o)
{
ds.Tables["valute"].Rows.Add(
itemValuta.codice,
itemValuta.Red,
itemValuta.Green,
itemValuta.Blue,
itemValuta.ctv,
itemValuta.peso
);
ii++;
if (ii == 6 && primeSei())
break;
}
if (primeSei())
{
var other = (from o in items where o.codice == "OTHER" select o).LastOrDefault();
if (other != null)
{
ds.Tables["valute"].Rows.Add(
"Altre",
other.Red,
other.Green,
other.Blue,
other.ctv,
other.peso
);
}
ii = 0;
foreach (var slice in from o in items where o.codice != "OTHER" select o)
{
ds.Tables["prodotti"].Columns.Add(new DataColumn(slice.codice, typeof(string)));
ii++;
if (ii == 6)
break;
}
if (other != null)
{
ds.Tables["prodotti"].Columns.Add(new DataColumn("Altre", typeof(string)));
}
}
}
#endregion
#region TabellaDettaglio
if (presenzaTabellaDettaglio())
{
#region Prodotti (solo dati)
int j = 0;
if (!primeSei() /*|| !presenzaGraficoBarre()*/)
{
foreach (var slice in from o in esposizioneValutaria.distribuzione.elencoSlice
where o.codice != "OTHER" && o.sliceRappresentabile
orderby presenzaContocorrenteInMonterio() ? Math.Abs(o.ctvCC) : Math.Abs(o.ctv) descending
select o)
{
ds.Tables["prodotti"].Columns.Add(new DataColumn(slice.codice, typeof(string)));
j++;
if (j == 6)
break;
}
ds.Tables["prodotti"].Columns.Add(new DataColumn("Altre", typeof(string)));
}
foreach (var itemValuta in from o in esposizioneValutaria.distribuzionePerProdotti.listaProdotti select o)
{
var itemPosizione = dataDettaglioProdotti.FirstOrDefault(o => o.chiavePosizionePortafoglio.Equals(itemValuta.chiaveAggregazione));
var itemOrdinamento = displayInfo.areeDisplayInfos.LastOrDefault(o => o.key.ToLower() == itemPosizione.area.ToLower().Trim());
var rowProdotti = ds.Tables["prodotti"].NewRow();
rowProdotti["CodiceAreaBisogno"] = itemPosizione.area;
rowProdotti["OrdinamentoAreaBisogno"] = itemOrdinamento.value.order;
rowProdotti["DescrizioneAreaBisogno"] = itemPosizione.descAreaEstesa;
rowProdotti["DescrizioneProgetto"] = itemPosizione.nomeProgetto;
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["ControvaloreAttuale"] = itemPosizione.ctv;
rowProdotti["FontBold"] = false;
rowProdotti["ReplaceIfZero"] = stringReplaceIfZero;
rowProdotti["CanLastRow"] = true;
rowProdotti["IsTotal"] = false;
rowProdotti["IsSubTotal"] = false;
if (itemValuta.rappresentabile)
{
foreach (rsSliceLight slice in itemValuta.listaSlice.OrderByDescending(s => s.ctv))
{
if (ds.Tables["prodotti"].Columns.Contains(slice.descrizione))
{
if (itemValuta.tipoProdotto.Equals("CC") && !presenzaContocorrenteInMonterio())
{
for (int c = ColumnsProdotti; c < ds.Tables["prodotti"].Columns.Count; c++)
{
if (ds.Tables["prodotti"].Columns[c].ColumnName != "IsTotal" && ds.Tables["prodotti"].Columns[c].ColumnName != "IsSubTotal")
rowProdotti[c] = "n.a.";
}
break;
}
else
rowProdotti[slice.descrizione] = datiSeiUnico.FormatDecimal("{0}", slice.pesoSuPosizione * 100);
}
else if (slice.descrizione.Equals("OTHER"))
{
rowProdotti["Altre"] = datiSeiUnico.FormatDecimal("{0}", slice.pesoSuPosizione * 100);
}
}
}
else
{
for (int c = ColumnsProdotti; c < ds.Tables["prodotti"].Columns.Count; c++)
{
if (ds.Tables["prodotti"].Columns[c].ColumnName != "IsTotal" && ds.Tables["prodotti"].Columns[c].ColumnName != "IsSubTotal")
rowProdotti[c] = "n.d.";
}
}
ds.Tables["prodotti"].Rows.Add(rowProdotti);
}
#endregion
#region Prodotti raggruppati per area
var dtProdottiPerArea = ds.Tables["prodotti"].Clone(); // Clono la struttura
dtProdottiPerArea.TableName = "prodottiPerArea";
ds.Tables.Add(dtProdottiPerArea);
var viewAree = new DataView(ds.Tables["prodotti"]) { Sort = "OrdinamentoAreaBisogno" };
var dtAree = viewAree.ToTable(true, "CodiceAreaBisogno", "DescrizioneAreaBisogno", "OrdinamentoAreaBisogno");
//var viewProgetti = new DataView(ds.Tables["prodotti"]);
//var dtProgetti = viewProgetti.ToTable(true, "DescrizioneProgetto");
var area = string.Empty;
var progetto = string.Empty;
var chiaveprogetto = "";
foreach (DataRow rowAreaProgetto in dtAree.Rows)
{
area = rowAreaProgetto["CodiceAreaBisogno"].ToString();
if (new AreaBisogno(area).Visibile)
{
//Progetti
var viewProgetti = !area.ToLower().Equals("pre") ? new DataView(ds.Tables["prodotti"].Select("CodiceAreaBisogno='" + area + "'").OrderByDescending(o => o.Field("ControvaloreAttuale")).CopyToDataTable()) :
new DataView(ds.Tables["prodotti"].Select("CodiceAreaBisogno='" + area + "'").OrderBy(x => x.Field("DescrizioneProgetto")).CopyToDataTable());
var dtProgetti = viewProgetti.ToTable(true, "DescrizioneProgetto");
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();
// Subset di prodotti filtrati per Area/Progetto
var totalecontrovaloreArea = esposizioneValutaria.distribuzioneAree.FirstOrDefault(o => o.area == area && o.chiaveProgetto == null).distribuzione.totaleCtv;
var totCTV = pianificazioneVerticale.aree.FirstOrDefault(o => o.area == area).ctvArea;
//ds.Tables["prodotti"].Select("CodiceAreaBisogno='" + area + "'").CopyToDataTable().AsEnumerable().Sum(p => p.Field("ControvaloreProposto"));
var dtArea = ds.Tables["prodotti"].Select("CodiceAreaBisogno='" + area + "' AND " + string.Format("DescrizioneProgetto ='{0}'", itemProgetto["DescrizioneProgetto"].ToString().Replace("'", "''"))).OrderByDescending(o => o.Field("ControvaloreAttuale")).CopyToDataTable();
var dtAreaProgetto = ds.Tables["prodotti"].Select("CodiceAreaBisogno='" + area + "' AND " + string.Format("DescrizioneProgetto ='{0}'", itemProgetto["DescrizioneProgetto"].ToString().Replace("'", "''"))).CopyToDataTable();
chiaveprogetto = dataDettaglioProdotti.FirstOrDefault(o => o.nomeProgetto == progetto).codProgetto.ToString();
if (bIntestazioneArea)
{
#region riga con background grigio di intestazione per ogni area
rowProdottiPerArea = ds.Tables["prodottiPerArea"].NewRow();
rowProdottiPerArea["CodiceAreaBisogno"] = rowAreaProgetto["CodiceAreaBisogno"];
rowProdottiPerArea["DescrizioneProdotto"] = rowAreaProgetto["DescrizioneAreaBisogno"];
//rowProdottiPerArea["ControvaloreAttuale"] = totalecontrovaloreArea;
rowProdottiPerArea["ControvaloreAttuale"] = totCTV;
rowProdottiPerArea["OrdinamentoAreaBisogno"] = rowAreaProgetto["OrdinamentoAreaBisogno"];
rowProdottiPerArea["FontBold"] = true;
rowProdottiPerArea["ReplaceIfZero"] = stringReplaceIfZero;
rowProdottiPerArea["CanLastRow"] = false;
rowProdottiPerArea["IsTotal"] = true;
rowProdottiPerArea["IsSubTotal"] = false;
var pippo = esposizioneValutaria.distribuzioneAree.FirstOrDefault(o => o.area.Equals(rowAreaProgetto["CodiceAreaBisogno"]) && o.chiaveProgetto == null);
int ii = 0;
foreach (var item in pippo.distribuzione.elencoSlice)
{
if (item.sliceRappresentabile )
{
if (ds.Tables["prodotti"].Columns.Contains(item.descrizione) && ii <= 6)
{
ii++;
rowProdottiPerArea[item.descrizione] = Helper.FormatDecimal(((presenzaContocorrenteInMonterio() ? item.pesoCC : item.peso) * 100).ToString(), 2);
}
else if (item.descrizione.Equals("OTHER"))
{
rowProdottiPerArea["Altre"] = Helper.FormatDecimal(((presenzaContocorrenteInMonterio() ? item.pesoCC : item.peso) * 100).ToString(), 2);
}
//var perc = ;
//rowProdottiPerArea[item.codice] = perc; // dtArea.AsEnumerable().Sum(x => x.Field(item.codice));
//rowProdottiPerArea[item.codice + "String"] = Helper.FormatCurrency(rowProdottiPerArea[item.codice].ToString());
}
}
ds.Tables["prodottiPerArea"].Rows.Add(rowProdottiPerArea);
bIntestazioneArea = false;
#endregion
}
if (bItestazioneProgetto)
{
#region Riga con background grigio di intestazione per ogni Progetto
//var totaleprogetto = esposizioneValutaria.distribuzioneAree.FirstOrDefault(o => o.area == area && o.chiaveProgetto == chiaveprogetto).distribuzione.totaleCtv;
string[] notChAgg = { "PAT", "RA" };
var areeDisplayInfos = datiSeiUnico.displayInfos().areeDisplayInfos;
rsAggregatoPosizioni[] elencoAreeProgetti = datiSeiUnico.patrimonioUnit().patrimonioCasa.dettaglioProdotti.elencoAggregati.elencoAreeProgetti;
var areeProgetti = (from o in elencoAreeProgetti
join a in areeDisplayInfos on o.chiaveAggregazione.ToUpper() equals a.key.ToUpper()
where o.posizioniAggregate != null && !notChAgg.Contains(o.chiaveAggregazione)
orderby a.value.order ascending, o.ctvAttuale descending
select o);
decimal totaleprogetto=0;
foreach (rsAggregatoPosizioni areeProgetto in areeProgetti)
{
string codArea = areeProgetto.chiaveAggregazione;
// Test Fc 22/10/2018
//if ( codArea.Equals(rowAreaProgetto["CodiceAreaBisogno"]) )
// totaleprogetto = areeProgetto.ctvAttuale;
if (codArea.Equals(rowAreaProgetto["CodiceAreaBisogno"]) && areeProgetto.descrizione.Equals(progetto))
totaleprogetto = areeProgetto.ctvAttuale;
}
rowProdottiPerArea = ds.Tables["prodottiPerArea"].NewRow();
rowProdottiPerArea["CodiceAreaBisogno"] = rowAreaProgetto["CodiceAreaBisogno"];
rowProdottiPerArea["DescrizioneProdotto"] = progetto;
rowProdottiPerArea["OrdinamentoAreaBisogno"] = rowAreaProgetto["OrdinamentoAreaBisogno"];
rowProdottiPerArea["ControvaloreAttuale"] = totaleprogetto;
var pippopro = esposizioneValutaria.distribuzioneAree.FirstOrDefault(o => o.area.Equals(rowAreaProgetto["CodiceAreaBisogno"]) && o.chiaveProgetto == chiaveprogetto);
foreach (var item in pippopro.distribuzione.elencoSlice)
{
if (item.sliceRappresentabile)
{
if (ds.Tables["prodotti"].Columns.Contains(item.descrizione))
{
rowProdottiPerArea[item.descrizione] = Helper.FormatDecimal(((presenzaContocorrenteInMonterio() ? item.pesoCC : item.peso) * 100).ToString(), 2);
}
else if (item.descrizione.Equals("OTHER"))
{
rowProdottiPerArea["Altre"] = Helper.FormatDecimal(((presenzaContocorrenteInMonterio() ? item.pesoCC : item.peso) * 100).ToString(), 2);
}
//var perc = ;
//rowProdottiPerArea[item.codice] = perc; // dtArea.AsEnumerable().Sum(x => x.Field(item.codice));
//rowProdottiPerArea[item.codice + "String"] = Helper.FormatCurrency(rowProdottiPerArea[item.codice].ToString());
}
}
rowProdottiPerArea["FontBold"] = true;
rowProdottiPerArea["ReplaceIfZero"] = stringReplaceIfZero;
rowProdottiPerArea["CanLastRow"] = false;
rowProdottiPerArea["IsTotal"] = false;
rowProdottiPerArea["IsSubTotal"] = true;
ds.Tables["prodottiPerArea"].Rows.Add(rowProdottiPerArea);
#endregion
}
// I prodotti della dtProdotti vengono mergiati sulla dtProdottiPerArea
ds.Tables["prodottiPerArea"].Merge(dtArea);
}
}
}
var listReturn = new List();
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)
if (listReturn.Count() != 0)
{
DataRow rowProdottiPerArea = ds.Tables["prodottiPerArea"].NewRow();
rowProdottiPerArea["CodiceAreaBisogno"] = "";
rowProdottiPerArea["DescrizioneAreaBisogno"] = "";
rowProdottiPerArea["OrdinamentoAreaBisogno"] = Int32.MaxValue;
rowProdottiPerArea["DescrizioneProgetto"] = "";
rowProdottiPerArea["DescrizioneProdotto"] = "Totale risorse allocate";
rowProdottiPerArea["ControvaloreAttuale"] = datiSeiUnico.CASA_SUBTOTALE;
rowProdottiPerArea["FontBold"] = true;
rowProdottiPerArea["ReplaceIfZero"] = "";
rowProdottiPerArea["CanLastRow"] = false;
rowProdottiPerArea["IsTotal"] = false;
rowProdottiPerArea["IsSubTotal"] = false;
foreach (DataColumn dr in ds.Tables["prodottiPerArea"].Columns)
{
string columnName = !dr.ColumnName.Equals("Altre") ? dr.ColumnName : "OTHER";
var r = esposizioneValutaria.distribuzione.elencoSlice.LastOrDefault(o => o.codice == columnName);
if (r != null)
{
rowProdottiPerArea[dr.ColumnName] = datiSeiUnico.FormatDecimal("{0}", (presenzaContocorrenteInMonterio() ? r.pesoCC : r.peso) * 100);
}
};
ds.Tables["prodottiPerArea"].Rows.Add(rowProdottiPerArea);
// 20181010 AC
//#region OC + CCN + ELIGOFONDI + ELIGOTITOLI
#region OC + CCN + ELIGOFONDI + ELIGOTITOLI + ILTUOFOGLIO
//--20181010 AC
foreach (var item in listReturn)
{
rowProdottiPerArea = ds.Tables["prodottiPerArea"].NewRow();
rowProdottiPerArea["CodiceAreaBisogno"] = item.codArea;
rowProdottiPerArea["OrdinamentoAreaBisogno"] = Int32.MaxValue;
rowProdottiPerArea["DescrizioneAreaBisogno"] = item.descAreaEstesa;
rowProdottiPerArea["DescrizioneProgetto"] = item.nomeProgetto;
rowProdottiPerArea["DescrizioneProdotto"] = item.prodotto.nomeProdotto;
rowProdottiPerArea["ControvaloreAttuale"] = item.ctv;
rowProdottiPerArea["FontBold"] = false;
rowProdottiPerArea["ReplaceIfZero"] = stringReplaceIfZero;
rowProdottiPerArea["CanLastRow"] = true;
rowProdottiPerArea["IsTotal"] = false;
rowProdottiPerArea["IsSubTotal"] = false;
for (int c = ColumnsProdotti; c < ds.Tables["prodotti"].Columns.Count; c++)
{
if (ds.Tables["prodotti"].Columns[c].ColumnName != "IsTotal" && ds.Tables["prodotti"].Columns[c].ColumnName != "IsSubTotal")
rowProdottiPerArea[c] = "n.d.";
}
ds.Tables["prodottiPerArea"].Rows.Add(rowProdottiPerArea);
}
}
#endregion
#region footer
DataRow drFooter = ds.Tables["prodottiPerArea"].NewRow();
drFooter["CodiceAreaBisogno"] = "";
drFooter["DescrizioneAreaBisogno"] = "";
drFooter["OrdinamentoAreaBisogno"] = Int32.MaxValue;
drFooter["DescrizioneProgetto"] = "";
drFooter["DescrizioneProdotto"] = datiSeiUnico.FormatBanca("Patrimonio $/Banca/$");
drFooter["ControvaloreAttuale"] = datiSeiUnico.CASA_TOTALE;
drFooter["FontBold"] = true;
drFooter["ReplaceIfZero"] = "";
drFooter["CanLastRow"] = false;
drFooter["IsTotal"] = false;
drFooter["IsSubTotal"] = false;
foreach (DataColumn dr in ds.Tables["prodottiPerArea"].Columns)
{
string columnName = !dr.ColumnName.Equals("Altre") ? dr.ColumnName : "OTHER";
var r = esposizioneValutaria.distribuzione.elencoSlice.LastOrDefault(o => o.codice == columnName);
// 20181010 AC
if (r != null && /*presenzaContocorrenteInMonterio() && */(datiSeiUnico.CASA_CCN == 0 && datiSeiUnico.CASA_GPELIGO == 0 && datiSeiUnico.CASA_OC == 0 && datiSeiUnico.CASA_TUOFOGLIO == 0))
//--20181010 AC
{
drFooter[dr.ColumnName] = datiSeiUnico.FormatDecimal("{0}", (presenzaContocorrenteInMonterio() ? r.pesoCC : r.peso) * 100);
}
};
ds.Tables["prodottiPerArea"].Rows.Add(drFooter);
#endregion
#endregion
}
#endregion
return ds;
}
public virtual bool presenzaContocorrenteInMonterio()
{
return GetOption().Valore;
}
public virtual string getTestoGrafico()
{
return Helper.ReplaceVariables(GetText().Rows[0]["testo1"].ToString(), base.EnvironmentFacade.ReportEnvironment);
}
public virtual bool isControvalore()
{
return !GetOption().Valore;
}
public virtual string getTestoTabella()
{
return Helper.ReplaceVariables(GetText().Rows[0]["testo2"].ToString(), base.EnvironmentFacade.ReportEnvironment);
}
public virtual string GetNote1()
{
string nota = "";
string token = "";
var esposizioneValutaria = datiSeiUnico.patrimonioUnit().patrimonioCasa.esposizioneValutariaTutte;
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() ? esposizioneValutaria.distribuzione.coverageCC : esposizioneValutaria.distribuzione.coverage) * 100;
decimal OC_CASA = datiSeiUnico.CASA_OC;
decimal CC_CASA = presenzaContocorrenteInMonterio() ? 0 : datiSeiUnico.CASA_CC;
decimal PNR_CASA = esposizioneValutaria.distribuzione.totaleNonRappr;
if (GC < 100)
{
nota += token + datiSeiUnico.FormatDecimal("Grado di copertura (%) della rappresentazione grafica per esposizione valutaria 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 = ", ";
}
token = " ";
}
}
nota += ".";
token = " ";
}
nota = !nota.Equals("") ? "(*) " + nota : nota;
return datiSeiUnico.FormatBanca(nota);
}
public virtual bool primeSei()
{
return GetOption().DettaglioValute == DettaglioValute.PrimeSei;
}
public virtual bool presenzaGraficoBarre()
{
return GetOption().Valore;
}
public virtual bool presenzaTabellaDettaglio()
{
return GetOption().Valore; ;
}
}
}