789 lines
40 KiB
C#

using System;
using Consulenza.ReportWriter.Business;
using Consulenza.ReportWriter.Business.OBJ_PDF;
using System.Data;
using Consulenza.ReportWriter.Business.CHART_PDF;
using Consulenza.ReportWriter.Business.Entity;
using System.Collections.Generic;
using Consulenza.ReportCommon;
using System.Linq;
using ceTe.DynamicPDF;
namespace Consulenza.ReportWriter.Manager.Section.Unica
{
/// <summary>
/// S19.PatrimonioFideuramCategorieProdotto idSezione = 62
/// </summary>
public class S19 : Entity.Section
{
public S19(EnvironmentFacade environmentFacade, int idSection)
: base(environmentFacade, idSection)
{
try
{
Draw();
}
catch (Exception ex)
{
SectionLogger.Write("S19", 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) { TextHorizontalAlign = ceTe.DynamicPDF.TextAlign.Justify, FontSize = 7 });
AddElement(new SpacePDF(15));
#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) {HeaderFontSize = 7, FontSize = 7 });
tabellaPatrimonio.Columns.Add(new ColumnPDF("valore", 330, HorizontalAlignmentType.Sinistra, false, false, 7, ColumnType.Testo, "valore", string.Empty) { PaddingLeft = 5, FontSize = 7, HeaderFontSize = 7 });
AddElement(tabellaPatrimonio);
AddElement(new SpacePDF(20));
#endregion
#region Grafico a barre
//AddElement(new FormattedTextAreaPDF("Categoria", EnvironmentFacade.RendererFacade.XLeftLimit, 100) { BackGroundColor = ColorPDF.Standard_Grigio_SfondoColonnaTabella, FontBold = true, FontSize = 8, 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 = 8, 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("Categoria", 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[""];
var serieCollezione = new List<Serie> { new Serie { Name = "Categoria", Border = true } };
foreach (DataRow item in dati.Tables["categoria"].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["Categoria"].ToString(),
FontSizeLabelAxisX = 7,
FontBoldLabelAxisY = false
});
}
graficoBarre.SeriesCollection = serieCollezione;
if (isControvalore())
graficoBarre.RemoveWhiteSpaceToTheRightAxisX = true;
AddElement(graficoBarre);
#endregion
#region Nota del PatrimonioCasa
AddElement(new SpacePDF(20));
if (GetNote1().Length > 0)
{
AddElement(new FormattedTextAreaPDF(GetNote1(), EnvironmentFacade.RendererFacade.XLeftLimit) { FontSize = 6, TextHorizontalAlign = ceTe.DynamicPDF.TextAlign.Justify });
AddElement(new SpacePDF(10));
}
#endregion
}
if (presenzaTabella())
{
#region Testo introduttivo tabella prodotti
var testoTabellaProdotti = Helper.ReplaceVariables(getTesto2(), EnvironmentFacade.ReportEnvironment);
AddElement(new SpacePDF(5));
AddElement(new FormattedTextAreaPDF(testoTabellaProdotti, EnvironmentFacade.RendererFacade.XLeftLimit) { TextHorizontalAlign = ceTe.DynamicPDF.TextAlign.Justify, FontSize = 7 });
AddElement(new SpacePDF(17));
#endregion
#region Tabella Prodotti X Categoria
DataTable datasource = dati.Tables["ProdottoPerCategoria"];
for (int col = 0; col < datasource.Columns.Count; col++)
{
for (int row = 0; row < datasource.Rows.Count; row++)
{
if (datasource.Columns.Contains("ReplaceIfZero"))
datasource.Rows[row]["ReplaceIfZero"] = "";
}
}
var tabellaProdottiPerCategoria = new TablePDF(EnvironmentFacade.RendererFacade.XLeftLimit, datasource, dati.Tables["prodottoPerCategoriaFooter"])
{
Style = Style.ConsulenzaUnica,
Header = true,
Footer = true,
AlternateRow = false,
HeaderHeight = 30,
HeaderMargin = 2,
PageBreak = true
};
#region Columns e FooterColumns
// Modifica per Saving Map
tabellaProdottiPerCategoria.Columns.Add(new ColumnPDF("SavingMap", 15, HorizontalAlignmentType.Sinistra, false, false, 6, ColumnType.Immagine, "SavingMap", string.Empty) { DeltaYContent = 8, ScaleColumnTypeImage = 0.50F });
// Fine Modifica
tabellaProdottiPerCategoria.Columns.Add(new ColumnPDF("Immagine", 15 + 210, HorizontalAlignmentType.Sinistra, false, true, 7, ColumnType.Objectpdf, string.Empty, "Prodotto") {FontSize=7, HeaderFontSize=7, HeaderFontBold = true, DeltaYContent = 4, PaddingLeft = 6 });
tabellaProdottiPerCategoria.Columns.Add(new ColumnPDF("Tipologia", 130, HorizontalAlignmentType.Sinistra, false, true, 7, ColumnType.Testo, "Tipologia", "Tipologia") { HeaderFontSize = 7, FontSize=7, HeaderFontBold = true });
tabellaProdottiPerCategoria.Columns.Add(new ColumnPDF("Controvalore", 100, HorizontalAlignmentType.Sinistra, false, true, 7, ColumnType.Testo, "ControvaloreString", "Controvalore <br>attuale (€)") { HeaderFontSize = 7, HeaderFontBold = true, HeaderPaddingLeft = 25, PaddingRight = 4, FontSize = 7 });
tabellaProdottiPerCategoria.Columns.Add(new ColumnPDF("Peso", 50, HorizontalAlignmentType.Sinistra, false, true, 7, ColumnType.Testo, "Peso", "Peso (%)") { HeaderFontSize = 7, HeaderFontBold = true, PaddingRight = 4, HeaderPaddingLeft = 4, FontSize = 7 });
tabellaProdottiPerCategoria.FooterColumns.Add(new ColumnPDF("Totale", 370, HorizontalAlignmentType.Sinistra, false, false, 7, ColumnType.Testo) { FontSize = 7 });
tabellaProdottiPerCategoria.FooterColumns.Add(new ColumnPDF("Controvalore", 100, HorizontalAlignmentType.Destra, false, false, 7, ColumnType.Testo) { PaddingRight = 4, FontSize = 7 });
tabellaProdottiPerCategoria.FooterColumns.Add(new ColumnPDF("Peso", 50, HorizontalAlignmentType.Destra, false, false, 7, ColumnType.Testo) { FontSize = 7 });
int j = 0;
foreach (DataRow r in dati.Tables["prodottoPerCategoria"].Rows)
{
tabellaProdottiPerCategoria.Cells[3, j].HorizontalAlignment = HorizontalAlignmentType.Destra;
tabellaProdottiPerCategoria.Cells[4, j].HorizontalAlignment = HorizontalAlignmentType.Destra;
j++;
}
#endregion
#region Cells
int i = 0;
foreach (DataRow row in dati.Tables["prodottoPerCategoria"].Rows)
{
if (Convert.ToBoolean(row["IsTotal"]))
{
// Sfondo grigio per la riga identificata con IsTotal [quella di intestazione di macro categoria]
for (int c = 0; c < tabellaProdottiPerCategoria.Columns.Count; c++)
{
tabellaProdottiPerCategoria.Cells[c, i].BackgroundColor = ColorPDF.Standard_Grigio_SfondoColonnaTabella;
}
var listaOggetti = new List<ObjectPDF> {
new RectanglePDF(8, 8, new ColorPDF(row["CodiceHexCategoria"].ToString())){DeltaY = 1},
new FormattedTextAreaPDF {
Text = row["Prodotto"].ToString(),
FontBold = true,
FontColor = ColorPDF.Nero,
DeltaX = 12F,
FontSize = 7
},
};
tabellaProdottiPerCategoria.Cells[3, i].Value = Helper.FormatCurrency(row["ControvaloreString"].ToString());
tabellaProdottiPerCategoria.Cells[1, i].ValueObjectList.AddRange(listaOggetti);
}
else
{
var listaOggetti = new List<ObjectPDF>
{
new RectanglePDF(8, 8, ColorPDF.GetBy_AreaBisogno(row["CodiceAreaBisogno"].ToString())){DeltaY = 3},
new FormattedTextAreaPDF
{
Text = new AreaBisogno(row["CodiceAreaBisogno"].ToString()).Abbreviazione,
FontBold = true,
FontColor = ColorPDF.Bianco,
DeltaX = 2F,
FontSize = 7,
DeltaY = 1
},
new FormattedTextAreaPDF
{
Text = row["Prodotto"].ToString(),
FontBold = false,
FontColor = ColorPDF.Nero,
DeltaX = 12F,
FontSize=7,
DeltaY = 1
}
};
if (row[3].ToString() == "GP ET - Liquidità" && Convert.ToDecimal(row["Controvalore"]) < 0)
{
listaOggetti = new List<ObjectPDF>
{
new RectanglePDF(8, 8, ColorPDF.Bianco){DeltaY = 3},
new FormattedTextAreaPDF
{
Text = "-",
FontBold = true,
FontColor = ColorPDF.Nero,
DeltaX = 2F,
FontSize = 7,
DeltaY = 1
},
new FormattedTextAreaPDF
{
Text = row["Prodotto"].ToString(),
FontBold = false,
FontColor = ColorPDF.Nero,
DeltaX = 12F,
FontSize=7,
DeltaY = 1
}
};
}
tabellaProdottiPerCategoria.Cells[1, i].ValueObjectList.AddRange(listaOggetti);
}
i++;
}
#endregion
i = 0;
foreach (DataRow row in dati.Tables["prodottoPerCategoriaFooter"].Rows)
{
if (Convert.ToBoolean(row["IsTotal"]))
{
// Sfondo grigio per la riga identificata con IsTotal [quella di intestazione di macro categoria]
for (int c = 0; c < tabellaProdottiPerCategoria.FooterColumns.Count; c++)
{
tabellaProdottiPerCategoria.FooterCells[c, i].BackgroundColor = ColorPDF.Standard_Grigio_SfondoColonnaTabella;
tabellaProdottiPerCategoria.FooterCells[c, i].FontBold = true;
}
}
i++;
}
AddElement(tabellaProdottiPerCategoria);
if (GetNote2().Length > 0)
{
AddElement(new SpacePDF(10));
AddElement(new FormattedTextAreaPDF(GetNote2(), EnvironmentFacade.RendererFacade.XLeftLimit) { FontSize = 6, TextHorizontalAlign = TextAlign.Justify });
}
//if (dati.Tables["ccn"].Rows.Count > 0)
//{
// var tabellaCCN = new TablePDF(EnvironmentFacade.RendererFacade.XLeftLimit, dati.Tables["ccn"], dati.Tables["ccnFooter"])
// {
// Style = Style.ConsulenzaUnica,
// Header = true,
// //Footer = true,
// AlternateRow = false,
// HeaderHeight = 1,
// HeaderMargin = 2,
// PageBreak = true
// };
// tabellaCCN.Columns.Add(new ColumnPDF("Patrimonio", 350, HorizontalAlignmentType.Sinistra, false, false, 6, ColumnType.Testo));
// tabellaCCN.Columns.Add(new ColumnPDF("Controvalore", 100, HorizontalAlignmentType.Destra, false, false, 6, ColumnType.Decimale) { PaddingLeft = 2 });
// tabellaCCN.Columns.Add(new ColumnPDF("Peso", 70, HorizontalAlignmentType.Destra, false, false, 6, ColumnType.Decimale));
// tabellaCCN.FooterColumns.Add(new ColumnPDF("Patrimonio", 350, HorizontalAlignmentType.Sinistra, true, true, 6, ColumnType.Testo));
// tabellaCCN.FooterColumns.Add(new ColumnPDF("Controvalore", 100, HorizontalAlignmentType.Destra, true, true, 6, ColumnType.Decimale));
// tabellaCCN.FooterColumns.Add(new ColumnPDF("Peso", 70, HorizontalAlignmentType.Destra, true, true, 6, ColumnType.Decimale));
// AddElement(tabellaCCN);
//}
#endregion
}
}
protected sealed override DataTable GetDataTable()
{
return null;
}
protected override DataSet GetDataSet()
{
string asteriscoNota1 = GetNote1().Length > 0 ? "*" : "";
string asteriscoNota2 = presenzaGraficoBarre() ? (GetNote2().Length > 0 ? asteriscoNota1 + "*" : "") : (GetNote2().Length > 0 ? "*" : "");
const string stringReplaceIfZero = " ";
#region Servizi
var dataCategoria = datiSeiUnico.patrimonioUnit().patrimonioCasa.categoria;
var dataDettaglioProdotti = datiSeiUnico.patrimonioUnit().patrimonioCasa.dettaglioProdotti.dettaglioProdotti.ToList();
var displayInfo = datiSeiUnico.displayInfos().categoriaDisplayInfos.ToList();
var patrimoniofooter = datiSeiUnico.pianificazioneUnit().pianificazioneVerticale;
var patrimonioCasa = datiSeiUnico.patrimonioUnit().patrimonioCasa;
#endregion
#region Definizione Dataset
var ds = new DataSet();
ds.Tables.Add(new DataTable("patrimonio"));
ds.Tables.Add(new DataTable("categoria"));
ds.Tables.Add(new DataTable("prodotto"));
ds.Tables.Add(new DataTable("prodottoPerCategoria"));
ds.Tables.Add(new DataTable("prodottoPerCategoriaFooter"));
#endregion
#region Patrimonio casa
ds.Tables["patrimonio"].Columns.Add(new DataColumn("Descrizione", typeof(string)));
ds.Tables["patrimonio"].Columns.Add(new DataColumn("Valore", typeof(string)));
ds.Tables["patrimonio"].Rows.Add(
datiSeiUnico.FormatBanca("Patrimonio $/Banca/$ (€)" + asteriscoNota1),
Helper.FormatCurrency(datiSeiUnico.CASA_TOTALEPOSITIVO.ToString())
);
#endregion
#region Categorie di Prodotto
ds.Tables["categoria"].Columns.Add(new DataColumn("Categoria", typeof(string)));
ds.Tables["categoria"].Columns.Add(new DataColumn("Red", typeof(int)));
ds.Tables["categoria"].Columns.Add(new DataColumn("Green", typeof(int)));
ds.Tables["categoria"].Columns.Add(new DataColumn("Blue", typeof(int)));
ds.Tables["categoria"].Columns.Add(new DataColumn("Controvalore", typeof(decimal)));
ds.Tables["categoria"].Columns.Add(new DataColumn("Percentuale", typeof(string)));
ds.Tables["categoria"].Columns.Add(new DataColumn("Ordinamento", typeof(int)));
foreach (var valore in from c in displayInfo
join l in dataCategoria.distribuzione.elencoSlice on c.key equals l.codice
orderby c.value.order
select new
{
l.descrizione,
new ColorPDF(c.value.fill).Red,
new ColorPDF(c.value.fill).Green,
new ColorPDF(c.value.fill).Blue,
l.ctvCC,
l.pesoCC
})
{
ds.Tables["categoria"].Rows.Add(
valore.descrizione,
valore.Red,
valore.Green,
valore.Blue,
valore.ctvCC,
Helper.FormatDecimal((valore.pesoCC * 100).ToString(), 2)
);
}
#endregion
#region Prodotti
ds.Tables["prodotto"].Columns.Add(new DataColumn("CodiceAreaBisogno", typeof(string)));
ds.Tables["prodotto"].Columns.Add(new DataColumn("OrdinamentoCategoria", typeof(int)));
ds.Tables["prodotto"].Columns.Add(new DataColumn("CodiceHexCategoria", typeof(string)));
// Modifica per Saving Map
ds.Tables["prodotto"].Columns.Add(new DataColumn("SavingMap", typeof(string)));
// Fine Modifica
ds.Tables["prodotto"].Columns.Add(new DataColumn("Prodotto", typeof(string)));
ds.Tables["prodotto"].Columns.Add(new DataColumn("Categoria", typeof(string)));
ds.Tables["prodotto"].Columns.Add(new DataColumn("Tipologia", typeof(string)));
ds.Tables["prodotto"].Columns.Add(new DataColumn("Controvalore", typeof(decimal)));
ds.Tables["prodotto"].Columns.Add(new DataColumn("ControvaloreString", typeof(string)));
//ds.Tables["prodotto"].Columns.Add(new DataColumn("Peso", typeof(decimal)));
ds.Tables["prodotto"].Columns.Add(new DataColumn("Peso", typeof(string)));
ds.Tables["prodotto"].Columns.Add(new DataColumn("FontBold", typeof(bool)));
ds.Tables["prodotto"].Columns.Add(new DataColumn("ReplaceIfZero", typeof(string)));
ds.Tables["prodotto"].Columns.Add(new DataColumn("CanLastRow", typeof(bool)));
ds.Tables["prodotto"].Columns.Add(new DataColumn("IsTotal", typeof(bool)));
foreach (var itemCategoria in dataCategoria.distribuzionePerProdotti.listaProdotti)
{
if (itemCategoria.rappresentabile)
{
var itemPosizione = dataDettaglioProdotti.FirstOrDefault(o => o.chiavePosizionePortafoglio.Equals(itemCategoria.chiaveAggregazione));
var mapDisplayInfo = displayInfo.FirstOrDefault(o => o.key.Equals(dataCategoria.distribuzione.elencoSlice.FirstOrDefault(oo => oo.descrizione.Equals(itemCategoria.listaSlice[0].descrizione)).codice)).value;
var rowProdotti = ds.Tables["prodotto"].NewRow();
rowProdotti["CodiceAreaBisogno"] = itemPosizione.area;
rowProdotti["OrdinamentoCategoria"] = mapDisplayInfo.order;
rowProdotti["CodiceHexCategoria"] = mapDisplayInfo.fill;
rowProdotti["Prodotto"] = itemPosizione.prodotto.nomeProdotto;
rowProdotti["Categoria"] = itemCategoria.listaSlice[0].descrizione;
rowProdotti["Tipologia"] = itemPosizione.prodotto.alberatura.livello3;
rowProdotti["Controvalore"] = itemCategoria.listaSlice[0].ctv;
rowProdotti["ControvaloreString"] = Helper.FormatCurrency(itemCategoria.listaSlice[0].ctv.ToString());
rowProdotti["Peso"] = Helper.FormatDecimal((itemCategoria.listaSlice[0].pesoCC * 100).ToString(), 2);
if (itemPosizione.prodotto.codIsin == null)
rowProdotti["Peso"] = "-";
else
{
if ((itemPosizione.prodotto.codIsin.Equals("EURO10000007")
|| itemPosizione.prodotto.codIsin.Equals("EURO20000005")
|| itemPosizione.prodotto.codIsin.Equals("EURO00000009")) && itemCategoria.listaSlice[0].ctv < 0)
{
rowProdotti["Peso"] = "-";
}
}
// Modifica per Saving Map
if (itemPosizione.prodotto.savingMap)
//if (itemPosizione.prodotto.nomeProdotto.Substring(0, 2).ToUpper() == "FV")
rowProdotti["SavingMap"] = "SavingMap.png";
else
rowProdotti["SavingMap"] = "";
// Fine Modifica
rowProdotti["FontBold"] = false;
rowProdotti["ReplaceIfZero"] = stringReplaceIfZero;
rowProdotti["CanLastRow"] = true;
rowProdotti["IsTotal"] = false;
ds.Tables["prodotto"].Rows.Add(rowProdotti);
}
}
ds.Tables["prodotto"].AsEnumerable().OrderByDescending(o => o.Field<decimal>("Controvalore")).CopyToDataTable();
#endregion
#region Prodotti raggruppati per Categoria
ds.Tables["prodottoPerCategoria"].Columns.Add(new DataColumn("CodiceAreaBisogno", typeof(string)));
ds.Tables["prodottoPerCategoria"].Columns.Add(new DataColumn("OrdinamentoCategoria", typeof(int)));
ds.Tables["prodottoPerCategoria"].Columns.Add(new DataColumn("CodiceHexCategoria", typeof(string)));
ds.Tables["prodottoPerCategoria"].Columns.Add(new DataColumn("Prodotto", typeof(string)));
ds.Tables["prodottoPerCategoria"].Columns.Add(new DataColumn("Categoria", typeof(string)));
ds.Tables["prodottoPerCategoria"].Columns.Add(new DataColumn("Tipologia", typeof(string)));
ds.Tables["prodottoPerCategoria"].Columns.Add(new DataColumn("Controvalore", typeof(decimal)));
ds.Tables["prodottoPerCategoria"].Columns.Add(new DataColumn("ControvaloreString", typeof(string)));
ds.Tables["prodottoPerCategoria"].Columns.Add(new DataColumn("Peso", typeof(string)));
ds.Tables["prodottoPerCategoria"].Columns.Add(new DataColumn("FontBold", typeof(bool)));
ds.Tables["prodottoPerCategoria"].Columns.Add(new DataColumn("ReplaceIfZero", typeof(string)));
ds.Tables["prodottoPerCategoria"].Columns.Add(new DataColumn("CanLastRow", typeof(bool)));
ds.Tables["prodottoPerCategoria"].Columns.Add(new DataColumn("IsTotal", typeof(bool)));
var viewCategoria = new DataView(ds.Tables["prodotto"]) { Sort = "OrdinamentoCategoria" };
var dtCategoria = viewCategoria.ToTable(true, "Categoria", "OrdinamentoCategoria", "CodiceHexCategoria");
var categoria = string.Empty;
#region Prodotti delle Risorse Finanziarie
foreach (DataRow rowCategoria in dtCategoria.Rows)
{
categoria = rowCategoria["Categoria"].ToString();
// subset di prodotti filtrati per Area
var dt = ds.Tables["prodotto"].Select("Categoria='" + categoria + "'").OrderByDescending(o => o.Field<decimal>("Controvalore")).CopyToDataTable();
#region riga con background grigio di intestazione per ogni macrocategoria
DataRow rowProdottiPerCategoria = ds.Tables["prodottoPerCategoria"].NewRow();
decimal controvalore = dataCategoria.distribuzione.elencoSlice.FirstOrDefault(o => o.descrizione.Equals(rowCategoria["Categoria"].ToString())).ctvCC;
decimal var = dataCategoria.distribuzione.elencoSlice.FirstOrDefault(o => o.descrizione.Equals(rowCategoria["Categoria"].ToString())).pesoCC * 100;
rowProdottiPerCategoria["CodiceHexCategoria"] = rowCategoria["CodiceHexCategoria"];
rowProdottiPerCategoria["Prodotto"] = rowCategoria["Categoria"];
rowProdottiPerCategoria["Controvalore"] = controvalore;//dt.AsEnumerable().Sum(x => x.Field<decimal>("Controvalore"));
rowProdottiPerCategoria["ControvaloreString"] = Helper.FormatCurrency(controvalore.ToString()) + (categoria.Equals("Gestioni patrimoniali") ? asteriscoNota2 : "");
rowProdottiPerCategoria["Peso"] = Helper.FormatDecimal(var.ToString(), 2); //dt.AsEnumerable().Sum(x => x.Field<decimal>("Peso"));
rowProdottiPerCategoria["FontBold"] = true;
rowProdottiPerCategoria["ReplaceIfZero"] = stringReplaceIfZero;
rowProdottiPerCategoria["CanLastRow"] = false;
rowProdottiPerCategoria["IsTotal"] = true;
ds.Tables["prodottoPerCategoria"].Rows.Add(rowProdottiPerCategoria);
#endregion
// I prodotti della dtProdotti vengono mergiati sulla dtProdottiPerArea
ds.Tables["prodottoPerCategoria"].Merge(dt);
}
#endregion
#endregion
var dataDettaglioProdottiPatrimonioAltro = dataDettaglioProdotti.Where(x => x.area.ToLower().Equals("cc") && x.ctv != 0).OrderBy(x => x.area).ThenByDescending(x => x.ctv);
ds.Tables["prodottoPerCategoriaFooter"].Columns.Add(new DataColumn("Patrimonio", typeof(string)));
ds.Tables["prodottoPerCategoriaFooter"].Columns.Add(new DataColumn("Controvalore", typeof(string)));
ds.Tables["prodottoPerCategoriaFooter"].Columns.Add(new DataColumn("Peso", typeof(string)));
ds.Tables["prodottoPerCategoriaFooter"].Columns.Add(new DataColumn("FontBold", typeof(bool)));
ds.Tables["prodottoPerCategoriaFooter"].Columns.Add(new DataColumn("ReplaceIfZero", typeof(string)));
ds.Tables["prodottoPerCategoriaFooter"].Columns.Add(new DataColumn("CanLastRow", typeof(bool)));
ds.Tables["prodottoPerCategoriaFooter"].Columns.Add(new DataColumn("IsTotal", typeof(bool)));
if (dataDettaglioProdottiPatrimonioAltro.Any() || patrimoniofooter.partiteViaggianti != 0)
{
ds.Tables["prodottoPerCategoriaFooter"].Rows.Add(
"Totale risorse finanziarie",
Helper.FormatCurrency(datiSeiUnico.CASA_SUBTOTALE.ToString()) + asteriscoNota2,
Helper.FormatDecimal((dataCategoria.distribuzione.pesoCCTot * 100).ToString(), 2),
true,
stringReplaceIfZero,
true,
true
);
#region Operazioni in corso
if (patrimoniofooter.partiteViaggianti != 0)
{
var rowProdottiPatrimonioAltro = ds.Tables["prodottoPerCategoriaFooter"].NewRow();
rowProdottiPatrimonioAltro["Patrimonio"] = "Operazioni in corso";
rowProdottiPatrimonioAltro["Controvalore"] = Helper.FormatCurrency(datiSeiUnico.CASA_OC.ToString());
rowProdottiPatrimonioAltro["Peso"] = Helper.FormatDecimal("0", 2);
rowProdottiPatrimonioAltro["FontBold"] = false;
rowProdottiPatrimonioAltro["ReplaceIfZero"] = stringReplaceIfZero;
rowProdottiPatrimonioAltro["CanLastRow"] = false;
rowProdottiPatrimonioAltro["IsTotal"] = false;
ds.Tables["prodottoPerCategoriaFooter"].Rows.Add(rowProdottiPatrimonioAltro);
}
#endregion
#region CCN
foreach (var item in dataDettaglioProdottiPatrimonioAltro)
{
var rowProdottiPatrimonioAltro = ds.Tables["prodottoPerCategoriaFooter"].NewRow();
rowProdottiPatrimonioAltro["Patrimonio"] = item.prodotto.nomeProdotto;
rowProdottiPatrimonioAltro["Controvalore"] = Helper.FormatCurrency(item.ctv.ToString());
rowProdottiPatrimonioAltro["Peso"] = Helper.FormatDecimal("0", 2);
rowProdottiPatrimonioAltro["FontBold"] = false;
rowProdottiPatrimonioAltro["ReplaceIfZero"] = stringReplaceIfZero;
rowProdottiPatrimonioAltro["CanLastRow"] = false;
rowProdottiPatrimonioAltro["IsTotal"] = false;
ds.Tables["prodottoPerCategoriaFooter"].Rows.Add(rowProdottiPatrimonioAltro);
}
#endregion
}
// 20181010 AC
//decimal CASA_TOTALE = datiSeiUnico.CASA_TOTALE - datiSeiUnico.CASA_GPELIGO;
decimal CASA_TOTALE = datiSeiUnico.CASA_TOTALE - datiSeiUnico.CASA_GPELIGO - datiSeiUnico.CASA_TUOFOGLIO;
//--20181010 AC
ds.Tables["prodottoPerCategoriaFooter"].Rows.Add(
Helper.ReplaceVariables("Patrimonio $/Banca/$", base.EnvironmentFacade.ReportEnvironment),
Helper.FormatCurrency(CASA_TOTALE.ToString()) + asteriscoNota2,
dataDettaglioProdottiPatrimonioAltro.Any() || patrimoniofooter.partiteViaggianti != 0 ?
Helper.FormatDecimal("0", 2) :
Helper.FormatDecimal((dataCategoria.distribuzione.pesoCCTot * 100).ToString(), 2),
true,
stringReplaceIfZero,
true,
true);
return ds;
}
public virtual bool presenzaGraficoBarre() { return GetOption<Opzione4_1>().Valore; }
public virtual bool isControvalore() { return !GetOption<Opzione3>().Valore; }
public virtual bool presenzaContocorrenteInMonterio() { return true; }
public virtual bool presenzaTabella() { return GetOption<Opzione4_2>().Valore; }
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 getTesto2()
{
return GetText().Rows[0]["testo4"].ToString();
}
/// <summary>
/// Recupera la nota dinamica
/// </summary>
/// <param name="nota"></param>
/// <returns></returns>
public virtual string GetNote1()
{
string nota = "";
string token = "";
var categoria = datiSeiUnico.patrimonioUnit().patrimonioCasa.categoria;
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 = ", ";
}
//token = " ";
//if (CCN_CASA != 0 || GPELIGOFONDI_CASA != 0)
//{
// nota += token + "del patrimonio $/Banca/$";
// token = ", ";
//}
nota += ".";
token = " ";
}
decimal GC = (presenzaContocorrenteInMonterio() ? categoria.distribuzione.coverageCC : categoria.distribuzione.coverage) * 100;
decimal OC_CASA = datiSeiUnico.CASA_OC;
decimal CC_CASA = presenzaContocorrenteInMonterio() ? 0 : datiSeiUnico.CASA_CC;
decimal PNR_CASA = categoria.distribuzione.totaleNonRappr;
if (GC < 100)
{
nota += token + datiSeiUnico.FormatDecimal("Grado di copertura (%) della rappresentazione grafica per categorie 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);
}
public virtual string GetNote2()
{
string nota = "";
string token = "";
string asterisco = "";
decimal GPELIGOFONDI_CASA = datiSeiUnico.CASA_GPELIGOFONDI;
decimal GPELIGTITOLI_CASA = datiSeiUnico.CASA_GPELIGTITOLI;
// 20181010 AC
decimal TUOFOGLIO_CASA = datiSeiUnico.CASA_TUOFOGLIO;
//--20181010 AC
// 20181010 AC
//if (GPELIGTITOLI_CASA != 0 || GPELIGOFONDI_CASA != 0)
if (GPELIGOFONDI_CASA != 0 || GPELIGTITOLI_CASA != 0 || TUOFOGLIO_CASA != 0)
//--20181010 AC
{
asterisco = GetNote1().Length > 0 && presenzaGraficoBarre() ? "**" : "*";
nota += token + "(" + asterisco + ") Il controvalore esclude il saldo negativo";
token = " ";
// 20181010 AC
if (TUOFOGLIO_CASA != 0)
{
nota += token + datiSeiUnico.FormatDecimal("della liquidità sottostante Il Mio Foglio ({0} €)", TUOFOGLIO_CASA);
token = ", ";
}
//--20181010 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 += ".";
}
return nota;
}
}
}