Merhabalar ,
LOGO ürünü için fatura akış TSQL kodunu paylasıyorum. Parametrik yapıda çalışmakdadır.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EXECUTE USP_PIVOT_HAREKET @FIRMA = N'017' -- ÖRNEK 017 NOLU FİRMA
CREATE PROCEDURE [dbo].[USP_PIVOT_HAREKET]
@FIRMA NVARCHAR(5)
AS
BEGIN
DECLARE @SQL NVARCHAR(MAX);
SET @SQL = N'
SELECT LG_'+@FIRMA+'_01_INVOICE.DATE_ AS [Fatura Tarihi], LG_'+@FIRMA+'_01_INVOICE.FICHENO AS [Fatura Numarası],
LG_'+@FIRMA+'_CLCARD.CODE AS [Cari Kodu], LG_'+@FIRMA+'_CLCARD.DEFINITION_ AS [Cari Ünvanı],
LG_'+@FIRMA+'_01_PAYTRANS.DISCDUEDATE AS [Vade Tarihi], CASE
WHEN LG_'+@FIRMA+'_01_PAYTRANS.TRCODE=1 then ''Satınalma Faturası''
WHEN LG_'+@FIRMA+'_01_PAYTRANS.TRCODE=4 then ''Alınan Hizmet Faturası''
WHEN LG_'+@FIRMA+'_01_PAYTRANS.TRCODE=9 then ''Verilen Hizmet Faturası''
WHEN LG_'+@FIRMA+'_01_PAYTRANS.TRCODE=6 then ''Satınalma İade Faturası''
END AS [Fatura Türü], LG_'+@FIRMA+'_01_PAYTRANS.TOTAL AS Toplam,
case when LG_'+@FIRMA+'_01_PAYTRANS.CANCELLED=1 then ''İptal Fatura'' else ''Geçerli Belge'' end AS İptal,
case when LG_'+@FIRMA+'_01_PAYTRANS.TRCURR=0 then ''TL''
when LG_'+@FIRMA+'_01_PAYTRANS.TRCURR=1 then ''USD''
when LG_'+@FIRMA+'_01_PAYTRANS.TRCURR=20 then ''EURO'' end AS Döviz,
''Satış'' AS [Hareket Türü],
LG_'+@FIRMA+'_01_INVOICE.VAT,(SELECT SUM(AMOUNT) FROM LG_'+@FIRMA+'_01_STLINE WHERE INVOICEREF=LG_'+@FIRMA+'_01_INVOICE.LOGICALREF)MIKTAR
FROM LG_'+@FIRMA+'_01_INVOICE INNER JOIN
LG_'+@FIRMA+'_CLCARD ON LG_'+@FIRMA+'_01_INVOICE.CLIENTREF = LG_'+@FIRMA+'_CLCARD.LOGICALREF INNER JOIN
LG_'+@FIRMA+'_01_PAYTRANS ON LG_'+@FIRMA+'_01_INVOICE.LOGICALREF = LG_'+@FIRMA+'_01_PAYTRANS.FICHEREF
WHERE (LG_'+@FIRMA+'_01_PAYTRANS.TRCURR = 0) AND (LG_'+@FIRMA+'_01_PAYTRANS.TRCODE IN(1,4,6,9))
ORDER BY [Hareket Türü],[Fatura Tarihi],[Cari Ünvanı]'
EXECUTE(@SQL)
PRINT(@SQL)
END