344 lines
19 KiB
C#
344 lines
19 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Data;
|
|
|
|
namespace PDFGenerator.BusinessLayer.DataSection
|
|
{
|
|
public class DSFD133AreeBisognoPrincProd : IDataSection
|
|
{
|
|
public DSFD133AreeBisognoPrincProd()
|
|
{
|
|
//
|
|
// TODO: Add constructor logic here
|
|
//
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Recupera i dati per la stampa della S133.
|
|
/// </summary>
|
|
/// <param name="tabelleSessione"></param>
|
|
/// <param name="querySql"></param>
|
|
/// <param name="dataThread"></param>
|
|
/// <returns></returns>
|
|
public DataSectionResult getDataSection(List<SessionStruct> tabelleSessione, string querySql, DataThread dataThread)
|
|
{
|
|
DataSetS133 dataset133 = new DataSetS133();
|
|
FormatNum conv = new FormatNum();
|
|
DataSectionResult dsr = new DataSectionResult();
|
|
|
|
Random rnd = new Random();
|
|
DataTable dt = new DataTable();
|
|
|
|
bool _mostracolonnacopertura = false;
|
|
|
|
if (dataThread.Patrimoniobancafideuramctv != 0)
|
|
{
|
|
|
|
Decimal ctvTotale = 0;
|
|
//Decimal ctvCC = 0;
|
|
Decimal ctvNA = 0;
|
|
|
|
dt = SectionManager.GetDataSection(tabelleSessione, querySql, dataThread);
|
|
|
|
decimal residuo = 100;
|
|
decimal valorePercMaggiore = 0;
|
|
DataSetS133.GraficoFarfallaRow tupla_maggiore = null;
|
|
|
|
//Se il cliente ha solo CC presso BF la query ritorna solo 2 righe e non bisogna visualizzare niente
|
|
if (dt.Rows.Count > 3)
|
|
{
|
|
|
|
#region Tabella del GraficoPiramide
|
|
|
|
decimal totaleRisorseAllocate = 0;
|
|
int iOrderNeedArea = 0;
|
|
|
|
foreach (DataRow row in dt.Rows)
|
|
{
|
|
// escludo risorse non allocate (na), contocorrente (cc) , pro, pre1 e pre2
|
|
if (row["needarea"].ToString().ToLower() != "na" && row["needarea"].ToString().ToLower() != "cc" && row["needarea"].ToString().ToLower() != "pro" && row["needarea"].ToString().ToLower() != "pre1" && row["needarea"].ToString().ToLower() != "pre2")
|
|
{
|
|
|
|
//Grafico Piramide
|
|
DataSetS133.GraficoPiramideRow rowDSS133GraficoPiramide;
|
|
rowDSS133GraficoPiramide = dataset133.GraficoPiramide.NewGraficoPiramideRow();
|
|
rowDSS133GraficoPiramide.AreaBisogno = row["needarea"].ToString();
|
|
rowDSS133GraficoPiramide.Controvalore = conv.ConvertNum(row["controvaloreAttuale"].ToString());
|
|
totaleRisorseAllocate += Convert.ToDecimal(row["controvaloreAttuale"]);
|
|
rowDSS133GraficoPiramide.Rischio = row["var_needareaString"] == DBNull.Value ? conv.ConvertNum(row["var_needarea"].ToString()) : row["var_needareaString"].ToString();
|
|
rowDSS133GraficoPiramide.Copertura = row["copertura_needareaString"] == DBNull.Value ? conv.ConvertNum(row["copertura_needarea"].ToString()) : row["copertura_needareaString"].ToString();
|
|
|
|
if ((Convert.ToDecimal(rowDSS133GraficoPiramide.Controvalore) == 0) || (Convert.ToDecimal(rowDSS133GraficoPiramide.Controvalore) == 0M) || (Convert.ToDecimal(rowDSS133GraficoPiramide.Controvalore) == 0M))
|
|
{
|
|
rowDSS133GraficoPiramide.Rischio = "0,00";
|
|
rowDSS133GraficoPiramide.Copertura = "100,00";
|
|
}
|
|
|
|
dataset133.GraficoPiramide.AddGraficoPiramideRow(rowDSS133GraficoPiramide);
|
|
|
|
|
|
//Grafico Farfalla
|
|
DataSetS133.GraficoFarfallaRow rowDSS133GraficoFarfalla;
|
|
rowDSS133GraficoFarfalla = dataset133.GraficoFarfalla.NewGraficoFarfallaRow();
|
|
|
|
if (dataThread.TipoReport.ToUpper() == "MONITORAGGIO")
|
|
{
|
|
object percentualeAttualeTotale = null;
|
|
//Recupero la percentuale attuale da dataThread.PesoPercentuale (presa da li per far combaciare i valori con S82 , S82BIS)
|
|
if (dataThread.PesoPercentuale != null)
|
|
{
|
|
DataView dwPeso = new DataView(dataThread.PesoPercentuale);
|
|
DataTable dtPeso = dwPeso.ToTable();
|
|
percentualeAttualeTotale = dtPeso.Compute("Sum(PesoPercentuale)", "AreaBisogno='" + row["needarea"].ToString() + "'");
|
|
rowDSS133GraficoFarfalla.PercentualeAttuale = percentualeAttualeTotale != null && percentualeAttualeTotale.ToString() == string.Empty ? 0 : Convert.ToDecimal(percentualeAttualeTotale);
|
|
}
|
|
else
|
|
rowDSS133GraficoFarfalla.PercentualeAttuale = 0;
|
|
|
|
}
|
|
else if (dataThread.TipoReport.ToUpper() == "DIAGNOSI")
|
|
{
|
|
rowDSS133GraficoFarfalla.PercentualeAttuale = row["percentualeAttuale"] == DBNull.Value ? 0 : decimal.Round(Convert.ToDecimal(row["percentualeAttuale"]), 2);
|
|
if (rowDSS133GraficoFarfalla.PercentualeAttuale > valorePercMaggiore)
|
|
{
|
|
tupla_maggiore = rowDSS133GraficoFarfalla;
|
|
valorePercMaggiore = rowDSS133GraficoFarfalla.PercentualeAttuale;
|
|
}
|
|
residuo -= rowDSS133GraficoFarfalla.PercentualeAttuale;
|
|
}
|
|
|
|
rowDSS133GraficoFarfalla.PercentualeModello = row["percentualeModello"] == DBNull.Value ? 0 : Convert.ToDecimal(row["percentualeModello"]);
|
|
rowDSS133GraficoFarfalla.NeedArea = row["needarea"].ToString().ToLower();
|
|
rowDSS133GraficoFarfalla.OrderNeedArea = iOrderNeedArea++;
|
|
|
|
dataset133.GraficoFarfalla.AddGraficoFarfallaRow(rowDSS133GraficoFarfalla);
|
|
}
|
|
|
|
}
|
|
|
|
//V Approssimazione diagnosi
|
|
if (dataThread.TipoReport.ToUpper() == "DIAGNOSI")
|
|
{
|
|
if (residuo != 0 && tupla_maggiore != null)
|
|
{
|
|
tupla_maggiore.PercentualeAttuale += residuo;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Risorse Allocate
|
|
DataSetS133.RisorseAllocateRow rowDSS133RisorseAllocate;
|
|
rowDSS133RisorseAllocate = dataset133.RisorseAllocate.NewRisorseAllocateRow();
|
|
rowDSS133RisorseAllocate.Descrizione = "TOTALE RISORSE ALLOCATE";
|
|
rowDSS133RisorseAllocate.Controvalore = conv.ConvertNum(totaleRisorseAllocate);
|
|
//V Cambiato il puntamento alla query per prendere il var della piramide invece che quello complessivo che tiene conto delle risorse non associate
|
|
rowDSS133RisorseAllocate.Rischio = dt.Rows[0]["var_tot_pirString"] == DBNull.Value ? conv.ConvertNum(dt.Rows[0]["var_tot_pir"].ToString()) : dt.Rows[0]["var_tot_pirString"].ToString();
|
|
|
|
rowDSS133RisorseAllocate.Copertura = dt.Rows[0]["copertura_tot_pirString"] == DBNull.Value ? conv.ConvertNum(dt.Rows[0]["copertura_tot_pir"].ToString()) : dt.Rows[0]["copertura_tot_pirString"].ToString();
|
|
|
|
if (Convert.ToDecimal(rowDSS133RisorseAllocate.Controvalore) == 0)
|
|
{
|
|
rowDSS133RisorseAllocate.Rischio = "0,00";
|
|
rowDSS133RisorseAllocate.Copertura = "100,00";
|
|
}
|
|
//
|
|
|
|
|
|
#endregion
|
|
|
|
#region Risorse non allocate
|
|
|
|
decimal rischioRisorsenonAllocate = 0;
|
|
decimal coperturaRisorseNonAllocate = -1;
|
|
decimal ctvRisorseNonAllocate = 0;
|
|
DataSetS133.RisorseNonAllocateRow rowDSS133RisorseNonAllocate;
|
|
rowDSS133RisorseNonAllocate = dataset133.RisorseNonAllocate.NewRisorseNonAllocateRow();
|
|
rowDSS133RisorseNonAllocate.Descrizione = "Risorse non allocate";
|
|
|
|
DataRow[] drRisorseNonAllocate = dt.Select(" NeedArea='Na'");
|
|
if (drRisorseNonAllocate.Length > 0)
|
|
{
|
|
|
|
rowDSS133RisorseNonAllocate.Controvalore = conv.ConvertNum(drRisorseNonAllocate[0]["controvaloreAttuale"]);
|
|
ctvRisorseNonAllocate = drRisorseNonAllocate[0]["controvaloreAttuale"] == DBNull.Value ? 0 : Convert.ToDecimal(drRisorseNonAllocate[0]["controvaloreAttuale"]);
|
|
if (ctvRisorseNonAllocate != 0)
|
|
{
|
|
|
|
rischioRisorsenonAllocate = drRisorseNonAllocate[0]["var_needarea"] == DBNull.Value ? 0 : Convert.ToDecimal(drRisorseNonAllocate[0]["var_needarea"]);
|
|
coperturaRisorseNonAllocate = drRisorseNonAllocate[0]["copertura_needarea"] == DBNull.Value ? 0 : Convert.ToDecimal(drRisorseNonAllocate[0]["copertura_needarea"]);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
rowDSS133RisorseNonAllocate.Controvalore = conv.ConvertNum(ctvRisorseNonAllocate);
|
|
rowDSS133RisorseNonAllocate.Rischio = conv.ConvertNum(rischioRisorsenonAllocate);
|
|
rowDSS133RisorseNonAllocate.Copertura = conv.ConvertNum(coperturaRisorseNonAllocate);
|
|
|
|
//V lo setto per le approsimazioni
|
|
ctvNA = ctvRisorseNonAllocate;
|
|
|
|
// In caso in cui le risorse non allocate siano uguali a 0 non deve essere mostrata la riga;
|
|
// non deve essere mostrata nemmeno la riga delle risorse allocate, ma direttamente delle risorse finanziarie
|
|
if (ctvRisorseNonAllocate != 0M)
|
|
{
|
|
dataset133.RisorseAllocate.AddRisorseAllocateRow(rowDSS133RisorseAllocate);
|
|
dataset133.RisorseNonAllocate.AddRisorseNonAllocateRow(rowDSS133RisorseNonAllocate);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Risorse Finanziarie
|
|
// totale delle Risorse Finanziarie
|
|
DataSetS133.RisorseFinanziarieRow rowDSS133RisorseFinanziarie;
|
|
rowDSS133RisorseFinanziarie = dataset133.RisorseFinanziarie.NewRisorseFinanziarieRow();
|
|
rowDSS133RisorseFinanziarie.Descrizione = "TOTALE RISORSE FINANZIARIE";
|
|
rowDSS133RisorseFinanziarie.Controvalore = conv.ConvertNum(totaleRisorseAllocate + ctvRisorseNonAllocate);
|
|
rowDSS133RisorseFinanziarie.Rischio = dt.Rows[0]["var_risfinString"] == DBNull.Value ? conv.ConvertNum(dt.Rows[0]["var_risfin"].ToString()) : dt.Rows[0]["var_risfinString"].ToString(); //D //conv.ConvertNum(ptfTotaleBF.misureRischio.varp);
|
|
rowDSS133RisorseFinanziarie.Copertura = dt.Rows[0]["copertura_risfinString"] == DBNull.Value ? conv.ConvertNum(dt.Rows[0]["copertura_risfin"].ToString()) : dt.Rows[0]["copertura_risfinString"].ToString(); //D
|
|
|
|
//V Setto copertura = 100 e var = 0 nel caso il ctv sia uguale a 0
|
|
if (totaleRisorseAllocate + ctvRisorseNonAllocate == 0)
|
|
{
|
|
rowDSS133RisorseFinanziarie.Rischio = "0,00";
|
|
rowDSS133RisorseFinanziarie.Copertura = "100,00";
|
|
}
|
|
|
|
dataset133.RisorseFinanziarie.AddRisorseFinanziarieRow(rowDSS133RisorseFinanziarie);
|
|
|
|
#endregion
|
|
|
|
#region Conto Corrente
|
|
|
|
decimal ctvContoCorrente = 0;
|
|
DataSetS133.ContoCorrenteRow rowDSS133ContoCorrente;
|
|
rowDSS133ContoCorrente = dataset133.ContoCorrente.NewContoCorrenteRow();
|
|
rowDSS133ContoCorrente.Descrizione = "C/C a saldo negativo";
|
|
ctvContoCorrente = dataThread.ContoCorrente;
|
|
rowDSS133ContoCorrente.Controvalore = conv.ConvertNum(ctvContoCorrente);
|
|
rowDSS133ContoCorrente.Rischio = "0,00";
|
|
rowDSS133ContoCorrente.Copertura = "100,00";
|
|
dataset133.ContoCorrente.AddContoCorrenteRow(rowDSS133ContoCorrente);
|
|
|
|
|
|
#endregion
|
|
|
|
#region Linea Self Negativa
|
|
|
|
// MIOFOGLIO 20181129 QUI VA CHIAMATA LA [C6MartPeriodico].[PL_S43LineaSelfBF] (VEDI DSS160)
|
|
DataTable dt_B = null;
|
|
|
|
if (dataThread.Periodico)
|
|
dt_B = SectionManager.GetDataSection(tabelleSessione, "[C6MartPeriodico].[PL_S43LineaSelfBF]", dataThread);
|
|
else
|
|
dt_B = SectionManager.GetDataSection(tabelleSessione, "[C6Mart].[PL_S43LineaSelfBF]", dataThread);
|
|
DataSetS133.LineaSelfRow dr_B;
|
|
|
|
#region New Section Data Load
|
|
decimal ctvLineaSelfNegativa = 0;
|
|
|
|
foreach (DataRow row in dt_B.Rows)
|
|
{
|
|
dr_B = dataset133.LineaSelf.NewLineaSelfRow();
|
|
dr_B.Descrizione = row["CodInterno"].Equals("XY") ? "Liquidità negativa \"Linee GP Eligo\"" : string.Format("Liquidità negativa \"{0}\"", row["NomeProdotto"]);
|
|
ctvLineaSelfNegativa += Convert.ToDecimal(row["ControValore"]);
|
|
dr_B.Controvalore = conv.ConvertNum(Convert.ToDecimal(row["ControValore"]));
|
|
dr_B.Rischio = "n.c.";
|
|
dr_B.Copertura = "100,00";
|
|
|
|
// acquisire anche i due campi nuovi (CodInterno e CodSottoprodotto)??
|
|
dr_B.CodInterno = row["CodInterno"].ToString();
|
|
dr_B.CodSottoprodotto = row["CodSottoprodotto"].ToString();
|
|
|
|
dataset133.LineaSelf.AddLineaSelfRow(dr_B);
|
|
}
|
|
#endregion
|
|
//decimal ctvLineaSelfNegativa = 0;
|
|
//DataSetS133.LineaSelfRow rowDSS133LineaSelfNegativa;
|
|
//rowDSS133LineaSelfNegativa = dataset133.LineaSelf.NewLineaSelfRow();
|
|
//rowDSS133LineaSelfNegativa.Descrizione = "Liquidità negativa \"Linee GP Eligo\" ";
|
|
//ctvLineaSelfNegativa = dataThread.TotalSelfNegCurrentAccountValue;
|
|
//rowDSS133LineaSelfNegativa.Controvalore = conv.ConvertNum(ctvLineaSelfNegativa);
|
|
//rowDSS133LineaSelfNegativa.Rischio = "n.c.";
|
|
//rowDSS133LineaSelfNegativa.Copertura = "100,00";
|
|
//dataset133.LineaSelf.AddLineaSelfRow(rowDSS133LineaSelfNegativa);
|
|
|
|
//--MIOFOGLIO 20181129
|
|
|
|
#endregion
|
|
|
|
#region PartiteViaggianti
|
|
DataSetS133.PartiteViaggiantiRow rowDSS133PartiteViaggianti;
|
|
rowDSS133PartiteViaggianti = dataset133.PartiteViaggianti.NewPartiteViaggiantiRow();
|
|
rowDSS133PartiteViaggianti.Descrizione = Resource.PartiteViaggianti;
|
|
decimal totalePartiteViaggianti = dataThread.PartiteViaggiantiInvestimento + dataThread.PartiteViaggiantiDisinvestimento;
|
|
rowDSS133PartiteViaggianti.ControValore = conv.ConvertNum(totalePartiteViaggianti);
|
|
if (totalePartiteViaggianti != 0)
|
|
dataset133.PartiteViaggianti.AddPartiteViaggiantiRow(rowDSS133PartiteViaggianti);
|
|
|
|
#endregion
|
|
|
|
#region Totale Patrimonio
|
|
DataSetS133.TotalePatrimonioRow rowDSS133TotalePatrimonio;
|
|
rowDSS133TotalePatrimonio = dataset133.TotalePatrimonio.NewTotalePatrimonioRow();
|
|
rowDSS133TotalePatrimonio.Descrizione = "TOTALE PATRIMONIO";
|
|
|
|
decimal totalePatrimonio = totaleRisorseAllocate + ctvContoCorrente + totalePartiteViaggianti + ctvRisorseNonAllocate + ctvLineaSelfNegativa;
|
|
rowDSS133TotalePatrimonio.ControValore = conv.ConvertNum(totalePatrimonio);
|
|
|
|
//V Settato per le approsimazioni
|
|
ctvTotale = totaleRisorseAllocate;
|
|
|
|
//Hazem
|
|
if (dt.Rows[0]["var_totString"] != DBNull.Value)
|
|
rowDSS133TotalePatrimonio.Rischio = dt.Rows[0]["var_totString"].ToString();
|
|
else
|
|
rowDSS133TotalePatrimonio.Rischio = conv.ConvertNum(dt.Rows[0]["var_tot"]);
|
|
|
|
if (dt.Rows[0]["copertura_totString"] != DBNull.Value)
|
|
rowDSS133TotalePatrimonio.Copertura = dt.Rows[0]["copertura_totString"].ToString();
|
|
else
|
|
rowDSS133TotalePatrimonio.Copertura = conv.ConvertNum(dt.Rows[0]["copertura_tot"]);
|
|
|
|
|
|
dataset133.TotalePatrimonio.AddTotalePatrimonioRow(rowDSS133TotalePatrimonio);
|
|
|
|
|
|
#endregion
|
|
|
|
#region Resulset
|
|
|
|
// verifico se nel datatable GraficoPiramide almeno 1 grado copertura è diverso da 100 e il grado di copertura delle risorse non allocate è diverso da 100
|
|
// se si verrà disegnata la colonna relativa al grado di coperura.
|
|
DataTable dtMostraColonnaCopertura;
|
|
DataView dwMostraColonnaCopertura = new DataView(dataset133.GraficoPiramide);
|
|
dwMostraColonnaCopertura.RowFilter = "Copertura <> '100,00'";
|
|
dtMostraColonnaCopertura = dwMostraColonnaCopertura.ToTable();
|
|
_mostracolonnacopertura = (dtMostraColonnaCopertura.Rows.Count > 0 || (coperturaRisorseNonAllocate != 100M && coperturaRisorseNonAllocate != -1M));
|
|
|
|
DataSetS133.ResultSetRow rowDSS133ResultSet;
|
|
rowDSS133ResultSet = dataset133.ResultSet.NewResultSetRow();
|
|
rowDSS133ResultSet.MostraColonnaCopertura = _mostracolonnacopertura;
|
|
dataset133.ResultSet.AddResultSetRow(rowDSS133ResultSet);
|
|
|
|
#endregion
|
|
|
|
}
|
|
//V condizione presente nella S57 non riportata nella bis
|
|
dataThread.TotaleS57 = ctvTotale + ctvNA + dataThread.ContoCorrente - dataThread.PatrimonioNonRappresentabile;
|
|
}
|
|
|
|
|
|
dsr.DatiSezione = dataset133;
|
|
dsr.Esito = dataset133.GraficoPiramide.Rows.Count;
|
|
|
|
|
|
return dsr;
|
|
|
|
}
|
|
}
|
|
}
|