-- Schema: C6MartPeriodico
-- Stored Procedure: PL_MP_S173CapitaleProtetto








-- =============================================
-- Author:		<Federica Cianfa__INTERVENTO-MODIFICA>
-- Create date: <19/11/2014, Pomezia>
-- Description:	<La sp legge i dati dalla tb C6MartPeriodico.CAPPROT>
-- =============================================

-- [C6MartPeriodico].[PL_MP_S173CapitaleProtetto] 'F','VCCLNI27H65L483J'
CREATE procedure [C6MartPeriodico].[PL_MP_S173CapitaleProtetto]
	---- Add the parameters for the stored procedure here
	@Rete char(1), 
	@CodiceFiscale varchar(16)
AS
BEGIN  
  --SELECT  top 1		 
  --        'Interfund Capital Protection' AS DES_PROD,
  --        '001234.RS.S678' AS COD_CONF,
  --        '120,1040' AS QUOTA,
  --        '100,1234' AS NUMEROQUOTE,
  --        '12.025,22' AS CONTROVALORE,
  --        '31/03/2014' AS DATARIF,
  --        'Quota massima' AS DES_MAX,
  --        '125,4573' AS QUOTA_MAX, 
  --        '80' AS QUOTA_MAX_PERC,           
  --        '31/03/2013' AS DATARIF_MAX,
  --        'Quota e controvalore protetti*' AS DES_PROT,
  --        '100,3658' AS QUOTA_PROT,
  --        '100,1234' AS NUMEROQUOTE_PROT,
  --        '10.048,97' AS CONTROVALORE_PROT         
     SELECT 
	 DES_PROD
	,COD_CONF
	,QUOTA
	,NUMEROQUOTE
	,CONTROVALORE
	,DATARIF
	,DES_MAX
	,QUOTA_MAX
	,QUOTA_MAX_PERC
	,DATARIF_MAX
	,DES_PROT
	,QUOTA_PROT
	,NUMEROQUOTE_PROT
	,CONTROVALORE_PROT 
	,case 
	   when p.cod_interno = 'XY' and p.cod_sottoprodotto = 'L191' then 'GP Eligo Fondi'
	   when p.cod_interno = 'RS'								  then 'Fideuram Vita Insieme'
	   when p.cod_interno = 'RM'								  then 'Fideuram Vita Insieme Facile'
	   when p.cod_interno = 'RB'								  then 'Fideuram Vita Insieme Premium'
	   when p.cod_interno = 'RV'								  then 'Fideuram Vita Insieme Private'
	   else 'Interfund Crescita Protetta 80'
	end as DES_PROD_TIT -- Aggiunta per E-FOI80
	FROM C6MartPeriodico.CAPPROT cap
	
	inner join
	 
		c6martperiodico.patrimonio_bf p

	 on cap.rete = p.rete and cap.codfis = p.cod_fiscale and cap.cod_conf = p.id_contratto


	WHERE 1=1
	  AND cap.RETE = @Rete 
	  AND cap.CODFIS = @CodiceFiscale 
	  and p.isin = 'LU1106988527' 

	  order by controvalore desc


END
 








