﻿-- =============================================
-- Author:		<Mohammed, Ebid>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
--  [C6MartPeriodico].[PL_S43LineaSelfBF]  'F','GSTGPL59P03B586G'
CREATE procedure [C6MartPeriodico].[PL_S43LineaSelfBF] 
	@Rete char(1), 
	@CodiceFiscale varchar(16)
AS
BEGIN
	SELECT  
	distinct
		 codconf as NumContratto,
		 isnull(ctv,0) as Controvalore,
--INIZIO Intervento Eligo Titoli		 
		 NomeProdotto as NomeProdotto,
--FINE   Intervento Eligo Titoli		 		 
		 dbo.ToShortDateString(cast(datasott as varchar))  as DataSott,
		 CodInterno,
		 CodSottoProdotto,
		 apc.is_APC as isAPC
	FROM       
		C6MartPeriodico.ANAG_SELF LS	
		--aggiunta apc103
		left join C6MartPeriodico.WSEICC apc
on 
	apc.RETE=@Rete
	and	apc.cod_fiscale=@CodiceFiscale
	and ls.CodConf = apc.CODCONFPR
	--(case when PATRBF.tipo_prodotto='CC' then apc.CODCONFC else apc.CODCONFPR end)
	--fine aggiunta apc103
	WHERE 
		LS.rete= @Rete
		AND LS.codfis= @CodiceFiscale
		AND isnull(ctv,0) < 0
END