-- Stored procedure
-- =============================================
-- Author:		Simone D'Elia
-- Create date: Aprile 2022
-- Description: 
-- =============================================
-- [C6MartPeriodico].[PL_S172PreferenzeESG] 'S', 'VNZGPL53M04L781P'
CREATE procedure [C6Mart].[PL_FD181PreferenzeESG]
 -- Add the parameters for the stored procedure here
 @Rete char(1), 
 @CodiceFiscale varchar(16)
AS
BEGIN
SELECT esg.[rete]
      ,esg.[cod_fiscale]
      ,esg.[Preferenza_esg_cliente]
      ,esg.[ESG_E]
      ,esg.[ESG_S]
      ,esg.[ESG_G]
      ,esg.[obiettivo_ESG_minimo]
      ,esg.[ESG_Rating]
      ,esg.[ESG_E_perc]
      ,esg.[ESG_S_perc]
      ,esg.[ESG_G_perc]
	  ,case when isnull(ind.percESG,'0.00')>=25 and isnull(ind.percESG,'0.00')<50 then 'Almeno pari al 25%'
			when isnull(ind.percESG,'0.00')>=50 and isnull(ind.percESG,'0.00')<75 then 'Almeno pari al 50%'
			when isnull(ind.percESG,'0.00')>=75 then 'Almeno pari al 75%' else 'n.d.' end as Pref_Sost
	,'Y' as U_PREFSOST --Ulteriori Preferenze di Sostenibilità							   ----decommenta per ESG 2024
	,'20,00%' as SFDR_PERC																   ----decommenta per ESG 2024
	,'50,00%' as TAXO_PERC																   ----decommenta per ESG 2024
	,'-' as PAI_A	
	,'-' as PAI_S
	--,'Emissioni gas serra, Biodiversità, Acqua, Settore immobiliare' as PAI_A				   ----decommenta per ESG 2024
	--,'Questioni Sociali e dei Dipendenti' as PAI_S										   ----decommenta per ESG 2024
	,case when esg.[ESG_E]='Y' then '24.21' else '-' end AS E_PERC_OK--,CAST(ROUND(ISNULL(ESG_E_perc, 0.00), 2) AS decimal(6, 2)) AS E_PERC_OK				   ----decommenta per ESG 2024
    ,case when esg.[ESG_S]='Y' then '21.32' else '-' end AS S_PERC_OK--,CAST(ROUND(ISNULL(ESG_S_perc, 0.00), 2) AS decimal(6, 2)) AS S_PERC_OK				   ----decommenta per ESG 2024
    ,case when esg.[ESG_G]='Y' then '44.32' else '-' end AS G_PERC_OK--,CAST(ROUND(ISNULL(ESG_G_perc, 0.00), 2) AS decimal(6, 2)) AS G_PERC_OK				   ----decommenta per ESG 2024
  FROM [C6StampeCentralizzate].[C6Mart].[BrsClienteESG] esg
  left join c6staging.VAR_ADEGUATEZZA_INDICATORI ind
  on ind.rete=esg.rete and ind.CODICE_FISCALE=esg.cod_fiscale
WHERE 1 = 1
	AND esg.RETE = @Rete
	AND esg.COD_FISCALE = @CodiceFiscale
END