Empatiden ziyade nezaket ile ilerlersek sanırım sonuca ulaşabiliriz.
SQL'deki view kodu:
SELECT '320' AS FİRMA, CASE INV.TRCODE WHEN 8 THEN 'SATIS' WHEN 3 THEN 'SATIS IADE' END AS TUR, INV.DATE_ AS 'FATURA TARIHI', MONTH(INV.DATE_) AS 'FAT AY',
INV.FICHENO AS 'FATURA NO', INV.DOCODE AS 'BELGE NO', C.CODE AS 'CARİ KODU', C.DEFINITION_ AS 'CARİ ADI', I.CODE AS 'MALZ KODU', I.NAME AS 'MALZ ADI',
STL.PRICE AS 'BİRİM FİYAT', CASE INV.TRCODE WHEN 8 THEN STL.AMOUNT WHEN 3 THEN STL.AMOUNT * - 1 END AS 'MIKTAR',
ROUND(CASE INV.TRCODE WHEN 8 THEN STL.PRICE * STL.AMOUNT WHEN 3 THEN STL.PRICE * STL.AMOUNT * - 1 END, 2) AS 'BRUT TOPLAM',
ROUND(CASE INV.TRCODE WHEN 8 THEN STL.DISTDISC WHEN 3 THEN STL.DISTDISC * - 1 END, 2) AS 'IND TOPLAM', ROUND(CASE WHEN INV.TRCURR IN (1, 20)
THEN (CASE INV.TRCODE WHEN 8 THEN STL.DISTDISC WHEN 3 THEN STL.DISTDISC * - 1 END)
/ STL.TRRATE ELSE (CASE INV.TRCODE WHEN 8 THEN STL.DISTDISC WHEN 3 THEN STL.DISTDISC * - 1 END) END, 2) AS 'İNDİRİM İD TOPLAM',
ROUND(CASE INV.TRCODE WHEN 8 THEN STL.DISTEXP WHEN 3 THEN STL.DISTEXP * - 1 END, 2) AS 'MASRAF TOPLAM', ROUND(CASE WHEN INV.TRCURR IN (1, 20)
THEN (CASE INV.TRCODE WHEN 8 THEN STL.DISTEXP WHEN 3 THEN STL.DISTEXP * - 1 END)
/ STL.TRRATE ELSE (CASE INV.TRCODE WHEN 8 THEN STL.DISTEXP WHEN 3 THEN STL.DISTEXP * - 1 END) END, 2) AS 'MASRAF İD TOPLAM',
ROUND((CASE INV.TRCODE WHEN 8 THEN STL.PRICE * STL.AMOUNT WHEN 3 THEN STL.PRICE * STL.AMOUNT * - 1 END)
+ (CASE INV.TRCODE WHEN 8 THEN STL.DISTEXP WHEN 3 THEN STL.DISTEXP * - 1 END)
- (CASE INV.TRCODE WHEN 8 THEN STL.DISTDISC WHEN 3 THEN STL.DISTDISC * - 1 END), 2) AS 'NET TOPLAM', ROUND(CASE WHEN INV.TRCURR IN (1, 20)
THEN (((CASE INV.TRCODE WHEN 8 THEN STL.PRICE * STL.AMOUNT WHEN 3 THEN STL.PRICE * STL.AMOUNT * - 1 END)
+ (CASE INV.TRCODE WHEN 8 THEN STL.DISTEXP WHEN 3 THEN STL.DISTEXP * - 1 END))
- (CASE INV.TRCODE WHEN 8 THEN STL.DISTDISC WHEN 3 THEN STL.DISTDISC * - 1 END))
/ STL.TRRATE ELSE ((CASE INV.TRCODE WHEN 8 THEN STL.PRICE * STL.AMOUNT WHEN 3 THEN STL.PRICE * STL.AMOUNT * - 1 END)
+ (CASE INV.TRCODE WHEN 8 THEN STL.DISTEXP WHEN 3 THEN STL.DISTEXP * - 1 END))
- (CASE INV.TRCODE WHEN 8 THEN STL.DISTDISC WHEN 3 THEN STL.DISTDISC * - 1 END) END, 2) AS 'İD NET TOPLAM', ROUND(CASE WHEN INV.TRCURR IN (1, 20)
THEN (CASE INV.TRCODE WHEN 8 THEN STL.PRICE * STL.AMOUNT WHEN 3 THEN STL.PRICE * STL.AMOUNT * - 1 END)
/ STL.TRRATE ELSE (CASE INV.TRCODE WHEN 8 THEN STL.PRICE * STL.AMOUNT WHEN 3 THEN STL.PRICE * STL.AMOUNT * - 1 END) END, 2) AS 'İD BRÜT TOPLAM',
CASE WHEN INV.TRCURR = 0 THEN 'TL' WHEN INV.TRCURR = 160 THEN 'TL' WHEN INV.TRCURR = 1 THEN 'USD' WHEN INV.TRCURR = 20 THEN 'EUR' END AS 'İD TÜRÜ',
STL.SOURCEINDEX AS 'AMBAR'
FROM dbo.LG_320_01_INVOICE AS INV WITH (NOLOCK) INNER JOIN
dbo.LG_320_CLCARD AS C WITH (NOLOCK) ON C.LOGICALREF = INV.CLIENTREF INNER JOIN
dbo.LG_320_01_STLINE AS STL WITH (NOLOCK) ON STL.INVOICEREF = INV.LOGICALREF INNER JOIN
dbo.LG_320_ITEMS AS I WITH (NOLOCK) ON I.LOGICALREF = STL.STOCKREF