USE [dbmov]
GO
/****** Object:  StoredProcedure [dbo].[paQryFactcon_Cr]    Script Date: 16/02/2021 8:06:42 ******/
DROP PROCEDURE [dbo].[paQryFactcon_Cr]
GO
/****** Object:  StoredProcedure [dbo].[paQryFactcon_Cr]    Script Date: 16/02/2021 8:06:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:	Heiman Daza
-- Create date(dd/MM/yyyy): 16/08/2018
-- Description:	Impresión de factura contado para facturación electrónica de syscom 30
-- Modificate date(dd/MM/yyyy): 19/11/2018
-- Description: Hedinver Blanco - Se agregan alias a los campos
-- =============================================
CREATE PROCEDURE [dbo].[paQryFactcon_Cr] @pmTipDoc VARCHAR(3),@pmFacturaIni INT,@pmFacturaFin INT,@pmIdCia CHAR(2)
 AS
SELECT FACTURAS.FAC_TIP AS TipoFact,FACTURAS.FAC_NUM AS NumeroFact,FACTURAS.FAC_CIA AS CiaFact,FACTURAS.FAC_FEC AS FechaFact,FACTURAS.FAC_PED
AS Pedido,FACTURAS.FAC_VAL AS Valor,FACTURAS.FAC_IVA AS VrIva,FACTURAS.FAC_DCT AS VrDescuento,FACTURAS.FAC_RET AS VrRetencion,FACTURAS.FAC_FLE
AS VrFletes,FACTURAS.FAC_NET AS VrNeto,FACTURAS.FAC_VDV AS VrPagado,FACTURAS.FAC_VEH AS Vehiculo,FACTURAS.FAC_ICA AS VrIca
--Productos
,KARDEX.KAR_ITM AS Item,KARDEX.KAR_COD AS CodProducto,KARDEX.KAR_SAL AS CantSalida,KARDEX.KAR_PRE AS PrecioUnitario,KARDEX.KAR_IVA AS PorcentajeIva
,KARDEX.KAR_VDS AS DesctoSalidas,TIPOS_DOC.TIP_PRE AS Prefijo,REFERENCIAS.REF_DES AS DescripcionProducto, U.UNI_DES AS Unidad
--Documento
,INFDOC.DOC_CMP AS TipoComprobante,INFDOC.DOC_NCP AS NumComprobante,INFDOC.DOC_DEV AS Anulado,INFDOC.DOC_NDV AS NumDevolucion
,INFDOC.DOC_OBS AS Observacion,NIT.NIT_NOM AS Vendedor,INFDOC.DOC_PO1 AS PorcentajeIca
--Factura Electronica
,Trn_Face.Prefijo AS PrefijoFace ,Trn_Face.NumFace,Trn_Face.CUFE,Trn_Face.CUFE_QR,Trn_Face.Resolucion,Trn_Face.RangoNum,Trn_Face.FecVigencia,
Trn_Face.FechaValidacion
--Cliente
,CLIFCO.CFC_NIT AS NitCliente,CLIFCO.CFC_NOM AS NomCliente,CLIFCO.CFC_DIR AS DirCliente,CLIFCO.CFC_TEL AS TelCliente,CLIFCO.CFC_DV AS DigVerifica
,CLIFCO.CFC_CIU AS CiudadCliente
FROM
DBMOV.dbo.FACTURAS FACTURAS LEFT JOIN DBMOV.dbo.KARDEX KARDEX ON FACTURAS.FAC_TIP = KARDEX.KAR_TIP AND FACTURAS.FAC_NUM = KARDEX.KAR_NUM AND FACTURAS.FAC_CIA = KARDEX.KAR_CIA
LEFT JOIN DBPAR.dbo.TIPOS_DOC TIPOS_DOC ON FACTURAS.FAC_TIP = TIPOS_DOC.TIP_COD
LEFT JOIN DBMOV.dbo.INFDOC INFDOC ON FACTURAS.FAC_TIP = INFDOC.DOC_TIP AND FACTURAS.FAC_NUM = INFDOC.DOC_NUM AND FACTURAS.FAC_CIA = INFDOC.DOC_CIA
LEFT JOIN DBPAR.dbo.CONCEPTOS CONCEPTOS ON FACTURAS.FAC_CON = CONCEPTOS.CON_COD
LEFT JOIN DBACC.dbo.COMPANIAS COMPANIAS ON FACTURAS.FAC_CIA = COMPANIAS.CIA_COD
LEFT JOIN DBMOV.dbo.FACCLI FACCLI ON FACTURAS.FAC_NUM = FACCLI.CLI_FAC AND FACTURAS.FAC_CIA = FACCLI.CLI_CIA
LEFT JOIN DBPAR.dbo.NIT NIT ON FACTURAS.FAC_VEN = NIT.NIT_NIT
LEFT JOIN DBPAR.dbo.CONSDOC CONSDOC ON FACTURAS.FAC_TIP = CONSDOC.CON_TIP AND FACTURAS.FAC_CIA = CONSDOC.CON_CIA
LEFT JOIN DBMOV.dbo.Trn_Face Trn_Face ON FACTURAS.FAC_TIP = Trn_Face.TipDoc AND FACTURAS.FAC_NUM = Trn_Face.Documento AND FACTURAS.FAC_CIA = Trn_Face.IdCia
LEFT JOIN DBPAR.dbo.REFERENCIAS REFERENCIAS ON KARDEX.KAR_COD = REFERENCIAS.REF_COD
LEFT JOIN DBPAR.dbo.CLIFCO CLIFCO ON FACCLI.CLI_NIT = CLIFCO.CFC_NIT
LEFT JOIN DBPAR.dbo.UNIDADES U ON REFERENCIAS.REF_UNI=U.UNI_COD -- unidad de medida 20-07-2020
WHERE FACTURAS.FAC_TIP=@pmTipDoc AND FACTURAS.FAC_NUM BETWEEN @pmFacturaIni AND @pmFacturaFin AND FACTURAS.FAC_CIA=@pmIdCia
ORDER BY FACTURAS.FAC_CIA,FACTURAS.FAC_NUM,KARDEX.KAR_ITM
GO
