USE [Inversiones_20190711]
GO
/****** Object:  StoredProcedure [dbo].[SP_RPT_RequisicionDePago]    Script Date: 7/31/2019 12:18:03 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Bladimir Cortez
-- Create date: 
-- Description:	
-- =============================================
ALTER PROCEDURE [dbo].[SP_RPT_RequisicionDePago] 
	-- Add the parameters for the stored procedure here
	@CodInv varchar(30)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
SELECT TOP (1000) [RPID]
      ,T1.[UID]
      ,T1.[UCodigo]
	  ,(SELECT S0.UNombre FROM USR0 S0 WHERE S0.UCodigo = T1.UCodigo) 'UNombre'
	  ,(SELECT S0.DEPNombre FROM DEP0 S0 WHERE S0.DEPID = (SELECT S1.DEPID FROM USR0 S1 WHERE S1.UCodigo=T1.UCodigo)) 'Departamento'
      ,T1.[CodInv]
      ,T1.[AFavorDe]
      ,T1.[FormaPagID]
	  ,(SELECT S0.Nombre FROM FPAG S0 WHERE S0.Codigo=T1.FormaPagID) 'FormaDePago'
      ,T1.[MontoPago]
      ,T1.[FechaPago]
      ,T1.[CodBanco]
	  ,(SELECT S0.NombreBanco FROM BAN0 S0 WHERE S0.CodBanco=T1.CodBanco) 'NombreBanco'
      ,T1.[NumCuenta]
	  ,(SELECT S0.TipoCuenta FROM BAN1 S0 WHERE S0.CodBanco=T1.CodBanco AND S0.NumCuenta=T1.NumCuenta) 'CodTipoCuenta'
	  ,(SELECT S0.Nombre FROM BAN2 S0 
		WHERE S0.Codigo=(SELECT S1.TipoCuenta FROM BAN1 S1 WHERE S1.CodBanco=T1.CodBanco AND S1.NumCuenta=T1.NumCuenta)) 'TipoCuenta'
      ,T1.[SaldoContable]
      ,T1.[Concepto]
	  ,T0.OFon
	  ,(SELECT S0.Descrip FROM OFON S0 WHERE S0.Codigo=T0.OFon) 'OrigenDeFondos'
  FROM [dbo].[RPAG] T1 
  LEFT JOIN [dbo].[PIN0] T0 ON T0.CodInv=T1.CodInv
  WHERE T1.CodInv=@CodInv
END
