Logo Cari hesap Durum Raporu

Cari Hesapların Son alacak ve borç durumları ile son yapılan alacak / borç işlemimin tarihlerini verir
hareketsiz cariler listelenmez

SELECT  
CLCARD.LOGICALREF,
    CLCARD.CODE AS [CARİ KODU],
    CLCARD.DEFINITION_ AS [CARİ ÜNVANI],
(select TOP 1 case when (sum(DEBIT)- sum(CREDIT)) > 0 then ROUND(sum(DEBIT) - sum(CREDIT),2) ELSE 0  END  from LV_120_01_CLEKSTRE 
	where TRCURR = 0 and CLIENTREF = CLCARD.LOGICALREF and CANCELLED = 0)AS [BORÇ BAKİYE],
	(select TOP 1 case when (sum(CREDIT)-sum(DEBIT)) > 0 then ROUND(sum(CREDIT)-sum(DEBIT),2) ELSE 0 END  from LV_120_01_CLEKSTRE 
	where TRCURR = 0 and CLIENTREF = CLCARD.LOGICALREF and CANCELLED = 0)AS [ALACAK BAKİYE],
    (SELECT TOP 1 DATE_ FROM LG_120_01_CLFLINE WHERE  SIGN = 0 AND CLIENTREF=CLCARD.LOGICALREF AND CANCELLED = 0 ORDER BY DATE_ DESC) AS [SON BORC TARIHI],
    (SELECT TOP 1 DATE_ FROM LG_120_01_CLFLINE WHERE  SIGN = 1 AND CLIENTREF=CLCARD.LOGICALREF AND CANCELLED = 0 ORDER BY DATE_ DESC) AS [SON ALACAK TARIHI]
FROM  LG_120_01_CLFLINE AS CLFLINE INNER JOIN LG_120_CLCARD AS CLCARD ON CLFLINE.CLIENTREF = CLCARD.LOGICALREF
WHERE  CANCELLED = 0 
GROUP BY CLCARD.CODE, CLCARD.DEFINITION_,CLCARD.LOGICALREF