/****** Object:  View [dbo].[V_BC_LANC_ORIGEM]    Script Date: 08/20/2012 17:10:39 ******/
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[V_BC_LANC_ORIGEM]'))
DROP VIEW [dbo].[V_BC_LANC_ORIGEM]
GO
GO

    
-- select * from V_BC_LANC_ORIGEM where cd_bc_lanc = 1371388  
CREATE VIEW [dbo].[V_BC_LANC_ORIGEM] AS  
	SELECT       
		 BC_LANC_BC_CHQ_LANC.CD_EMP,  
		 BC_LANC_BC_CHQ_LANC.CD_BC_LANC,   
		 'CHEQUE EMPRESA' AS DS_ORIGEM  
	FROM           
		BC_LANC_BC_CHQ_LANC LEFT OUTER JOIN BC_LANC_TRANSF ON  
		BC_LANC_BC_CHQ_LANC.CD_EMP = BC_LANC_TRANSF.CD_EMP AND  
		BC_LANC_BC_CHQ_LANC.CD_BC_LANC = BC_LANC_TRANSF.CD_BC_LANC_ORIG  
	WHERE  
		BC_LANC_TRANSF.CD_BC_LANC_ORIG IS NULL  
	UNION ALL  
	SELECT  
		CD_EMP,  
		CD_BC_LANC,   
		'CHEQUE DEPOSITO'  
	FROM  
		BC_LANC_CHQ_DEPOS  
	UNION ALL  
	SELECT  
		CD_EMP,  
		CD_BC_LANC,   
		'CHEQUE DESCONTO'  
	FROM  
		BC_LANC_CHQ_DESC  
	UNION ALL  
	SELECT  
		CD_EMP,  
		CD_BC_LANC,   
		'CHEQUE ENVIO COBRANÇA\DESCONTO'  
	FROM  
		BC_LANC_CHQ_DEST_ENV  
	UNION ALL  
	SELECT  
		CD_EMP,  
		CD_BC_LANC,   
		'CHEQUE ESTORNO'  
	FROM  
		BC_LANC_CHQ_DEST_ENV_CPL_ESTORNO  
	UNION ALL  
	SELECT  
		CD_EMP,  
		CD_BC_LANC,   
		'CHEQUE DEVOLUÇÃO'  
	FROM  
		BC_LANC_CHQ_DEVO  
	UNION ALL  
	SELECT  
		CD_EMP,  
		CD_BC_LANC,   
		'CHEQUE REDEPOSITO'  
	FROM  
		BC_LANC_CHQ_REDEPOS  
	UNION ALL  
	SELECT  
		CD_EMP,  
		CD_BC_LANC,   
		'RECEBIMENTO DUPLICATA'  
	FROM  
		RC_CRED_BC_LANC  
	UNION ALL  
	SELECT  
	 CD_EMP,  
	 CD_BC_LANC,   
	 'PAGAMENTO DUPLICATA'  
	FROM  
		PG_DEB_BC_LANC  
	UNION ALL  
	SELECT  
		CD_EMP,  
		CD_BC_LANC,   
		'PAGAMENTO DUPLICATA EM LOTE'  
	FROM  
		PG_DEB_LOTE_BC_LANC  
	UNION ALL  
	SELECT  
		CD_EMP,  
		CD_BC_LANC,   
		'CHEQUE CUSTODIA'  
	FROM  
		BC_LANC_CHQ_LANC_CUSTODIA  
	UNION ALL  
	SELECT  
		CD_EMP,  
		CD_BC_LANC,   
		'CHEQUE LOTE'  
	FROM  
		BC_LANC_CHQ_LANC  
	UNION ALL  
	SELECT  
		CD_EMP,  
		CD_BC_LANC_ORIG,   
		'TRANSFERENCIA ENTRE CONTAS ORIGEM'  
	FROM  
		BC_LANC_TRANSF  
	UNION ALL  
	SELECT  
		CD_EMP,  
		CD_BC_LANC_DEST,   
		'TRANSFERENCIA ENTRE CONTAS DESTINO'  
	FROM  
		BC_LANC_TRANSF  
	  
	UNION ALL  
	SELECT  
		CD_EMP,  
		CD_BC_LANC,   
		'RECEBIMENTO DE DUPLICATAS EM LOTE'  
	FROM  
		RC_CRED_LOTE_BC_LANC  
	  
	UNION ALL  
	SELECT  
		CD_EMP,  
		CD_BC_LANC,   
		'RECEBIMENTO DE CHEQUE EM COBRANÇA'  
	FROM  
		BC_LANC_CHQ_DEST_ENV_CPL  
	UNION ALL
	SELECT
	  CD_EMP,  
	  CD_BC_LANC,   
	 'BANCARIO MANUAL' 
	FROM 
		BC_LANC 
	WHERE 
		ORIG_LANC = 1
	UNION ALL
	SELECT
	  CD_EMP,  
	  CD_BC_LANC,   
	 'RECEBIMENTO CARTAO CREDITO\DEBITO' 
	FROM 
		BC_LANC_RC_ADM_CARTAO_MOV 