USE [dbmov]
GO
/****** Object:  StoredProcedure [dbo].[paQryValesFcr]    Script Date: 16/02/2021 8:06:41 ******/
DROP PROCEDURE [dbo].[paQryValesFcr]
GO
/****** Object:  StoredProcedure [dbo].[paQryValesFcr]    Script Date: 16/02/2021 8:06:42 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
/**********************************************************************************
-- =============================================
-- Author:		<Hedinver Blanco>
-- Create date: <2020/01/22>
-- Description:	<subreporte de vales para Impresión de factura a crédito en facturación electrónica de syscom 30>
-- Called from:	
--Calls the following stored procedures:

* History ------------------------------------------------------------------------
* Author           	|Date        	|Version	|Reason
Hedinver Blanco		2020/01/22		1 			Se crea subreporte de vales para Impresión de factura a crédito en facturación electrónica de syscom 30
Hedinver Blanco		2020/09/09		2 			Se agrega campo de valor soldicom en detalle de vales(KP.KAR_SOL)
Hedinver Blanco		2020/11/23		3 			Se agrega campo de fecha de planilla (KP.KAR_FEC)
-- =============================================
***********************************************************************************/

CREATE PROCEDURE [dbo].[paQryValesFcr] @pmTipDoc VARCHAR(3),@pmFacturaIni INT,@pmFacturaFin INT,@pmIdCia CHAR(2)
 AS 
SELECT DISTINCT CR.CRE_FAC AS NumFactura,CR.CRE_TDC AS TipFactura,CR.CRE_CFA AS CiaFactura,'PLA' AS TipPla,CR.CRE_PLA AS Planilla, CR.CRE_CIA AS CiaPla,CR.CRE_NUM AS NumVale
	, CR.CRE_VAL AS VrVale	,CR.CRE_GAL AS CantGalones, CR.CRE_PRO AS CodProdVale, RF1.REF_DES AS ProdVale, CR.CRE_VEH AS PlacaVale, CR.CRE_OBS AS DescripcionVale
	, KP.KAR_PRE AS VrProdVale, KP.KAR_IVA AS ProdImpuesto, KP.KAR_CMC AS ProdGobal, KP.KAR_SOL ProdSoldicom, KP.KAR_FEC FechaDoc
FROM DBSAL.DBO.CREDITOS CR LEFT JOIN DBPAR.dbo.REFERENCIAS RF1 ON CR.CRE_PRO = RF1.REF_COD
	LEFT JOIN DBMOV.dbo.KARDEX KP ON KP.KAR_TIP='PLA' AND CR.CRE_PLA=KP.KAR_NUM AND CR.CRE_CIA=KP.KAR_CIA AND CR.CRE_PRO=KP.KAR_COD --Consulta para traer valor por producto de la planilla
 WHERE CR.CRE_TDC=@pmTipDoc AND CR.CRE_FAC BETWEEN @pmFacturaIni AND @pmFacturaFin AND CR.CRE_CFA=@pmIdCia
GO
