Merhaba,
Sanırım bu işini görür herhalde
Kolay gelsin.
SELECT
------------CARI HESAP BILGILERI
STFICHE.FICHENO AS IRSALIYE_NO,
INVOICE.FICHENO AS FATURA_NO,
INVOICE.DATE_ AS TARIH,
INVOICE.DOCODE AS BELGE_NO,
CARI_HESAP_KODU=CLCARD.CODE ,
CARI_HESAP_UNVANI= CLCARD.DEFINITION_ ,
ISNULL (PAYPLANS.CODE,'PEŞİN') AS ODEME_PLANI_KODU,
ISNULL (PAYPLANS.DEFINITION_,'PEŞİN') AS ODEME_PLANI_ACIKLAMASI,
STFICHE.TRADINGGRP AS TICARI_ISLEM_GRUP_KODU,
L_TRADGRP.GDEF AS TICARI_ISLEM_GRUP_ACIKLAMASI,
---------GENEL GRUPLANDIRMALAR
L_CAPIDIV.NAME AS ISYERI,
L_CAPIDEPT.NAME AS BOLUM,
L_CAPIFACTORY.NAME AS FABRIKA,
L_CAPIWHOUSE.NAME AS AMBAR,
----------------
INVOICE.SPECODE AS FATURA_OZEL_KODU,
INVOICE.CYPHCODE AS FATURA_YETKI_KODU,
LG_SLSMAN.CODE AS SATIŞ_ELEMANI_KODU,
LG_SLSMAN.DEFINITION_ AS SATIŞ_ELEMANI_ADI,
------------SATIR DETAYLARI
KODU=CASE STLINE.LINETYPE WHEN 4 THEN SRVCARD.CODE
ELSE ITEMS.CODE END,
ACIKLAMA=ITEMS.NAME ,
CASE WHEN STLINE.LINETYPE=0 THEN
'Malzeme'
WHEN STLINE.LINETYPE=2 THEN
'İndirim'
WHEN STLINE.LINETYPE=4 THEN
'Hizmet'
Else
'Başka' END AS SATIR_TURU,
--------------------- MIKTAR----
STLINE.AMOUNT AS MIKTAR,
NET_MIKTAR= CASE WHEN STLINE.TRCODE IN (2,3)
THEN STLINE.AMOUNT*-1
ELSE STLINE.AMOUNT END,
STLINE.PLNAMOUNT AS PLANLANAN_MIKTAR,
--------------------BIRIMLER---
UNITSETL.CODE AS BIRIM_KODU,
UNITSETF.CODE AS BIRIM_SETI_KODU,
STLINE.UINFO2 AS CEVRIM_KATSYISI_2,
----------------------ANA DOVIZ CINSINE GÖRE TOPLAM DEĞERLER---
STLINE.PRICE AS BIRIM_FIYAT,
STLINE.VAT AS KDV,
STLINE.TOTAL AS TUTAR,
STLINE.VATMATRAH AS KDV_MATRAHI,
STLINE.LINENET AS SATIR_NET_TUTARI,
NET_SATIS_TUTARI= (CASE WHEN STLINE.TRCODE IN (2,3)
THEN STLINE.LINENET*-1
ELSE STLINE.LINENET END)+(STLINE.DIFFPRICE),
----------------------RAPORLAMA DÖVİZ CİNSİNE GÖRE TOPLAM DEĞERLER---
STFICHE.REPORTRATE AS RAPORLAMA_DOVIZ_KURU,
RD_BIRIM_FIYATI=CASE STLINE.REPORTRATE WHEN 0 THEN 0 ELSE STLINE.PRICE/STLINE.REPORTRATE END,
RD_TUTARI=CASE STLINE.REPORTRATE WHEN 0 THEN 0 ELSE STLINE.TOTAL/STLINE.REPORTRATE END,
RD_KDV=CASE STLINE.REPORTRATE WHEN 0 THEN 0 ELSE STLINE.VAT/STLINE.REPORTRATE END,
RD_NET_SATIR_TUTARI=CASE STLINE.REPORTRATE WHEN 0 THEN 0 ELSE STLINE.LINENET/STLINE.REPORTRATE END,
RD_NET_ALIM_TUTARI=(CASE STLINE.REPORTRATE WHEN 0 THEN 0 ELSE (CASE WHEN STLINE.TRCODE IN (2,3)
THEN STLINE.LINENET*-1
ELSE STLINE.LINENET END)+(STLINE.DIFFPRICE)/(STLINE.REPORTRATE) END),
----------------------İŞLEM DÖVİZ CİNSİNE GÖRE TOPLAM DEĞRLER---
ISLEM_DVZ_TURU=CASE STLINE.TRCURR WHEN 0 THEN 'TL' ELSE L_CURRENCYLIST.CURCODE END,
ISLEM_DVZ_BIRIM_FIYATI=CASE STLINE.TRRATE WHEN 0 THEN 0 ELSE STLINE.PRICE/STLINE.TRRATE END,
ISLEM_DVZ_KDV=CASE STLINE.TRRATE WHEN 0 THEN 0 ELSE STLINE.VAT/STLINE.TRRATE END,
ISLEM_DVZ_TUTAR =CASE STLINE.TRRATE WHEN 0 THEN 0 ELSE STLINE.TOTAL/STLINE.TRRATE END,
ISLEM_DVZ_NET_ALIM_TUTARI=(CASE STLINE.TRRATE WHEN 0 THEN 0 ELSE (CASE WHEN STLINE.TRCODE IN (2,3)
THEN STLINE.LINENET*-1
ELSE STLINE.LINENET END)+(STLINE.DIFFPRICE)/(STLINE.TRRATE) END),
-------------SATIR DETAYLARI----
STLINE.SPECODE AS SATIR_OZEL_KODU,
SPECODE.DEFINITION_ AS SATIR_OZEL_KODU_ACIKLAMASI,
STLINE.DELVRYCODE AS TESLIMAT_KODU,
SPECODES.DEFINITION_ AS TESLIMAT_ACIKLAMASI,
STLINE.OUTPUTIDCODE AS CIKIS_IZLEME_NUMARASI,
------SİPARİŞ FİŞİ SATIRLARI---
ORFICHE.FICHENO AS SIPARIS_FIS_NO,
ORFICHE.DATE_ AS SIPARIS_FIS_TARIHI,
----SATIR ODEME PLANLARI----
PAYPLANS2.CODE AS SATIR_ODEME_PLANI_KODU,
PAYPLANS2.DEFINITION_ AS SATIR_ODEME_PLANI_ACIKLAMASI,
-----OTV------
STLINE.ADDTAXRATE AS OTV_ORANI,
STLINE.ADDTAXCONVFACT AS OTV_TUTARI,
STLINE.ADDTAXAMOUNT AS HESAPLANAN_OTV,
STLINE.ADDTAXPRCOST AS OTV_MALİYETI,
STLINE.ADDTAXRETCOST AS OTV_IADE_MALIYETI,
STLINE.ADDTAXRETCOSTCURR AS RD_OTV_MALIYETI,
STLINE.ADDTAXPRCOSTCURR AS RD_OTV_IADE_MALIYETI,
----IADE ISLEMLERI VE MALIYETLENDIRME SONUCU OLUŞAN BILGILER----
IADE_ISLEMI_MALIYET_TURU=CASE STLINE.RETCOSTTYPE WHEN 0 THEN 'Çıkış'
WHEN 1 THEN 'O anki'
WHEN 2 THEN 'Tutar' END,
STLINE.RETCOST AS IADE_FISLERI_ICIN_IADE_MALIYETI,
RETCOSTCURR AS IADE_FISLERI_ICIN_DOVIZLI_IADE_MALIYETI,
STLINE.OUTCOST AS CIKIS_FISLERI_CIKIS_MALIYETI,
STLINE.OUTCOSTCURR AS CIKIS_FISLERI_DOVIZLI_CIKIS_MALIYETI,
STLINE.RETAMOUNT AS IADE_MIKTARI,
-----------------------FATURA DETAY ALANINDA GIRILEN BILGILER---
CLC1.CODE AS SEVKIYAT_HESABI_KODU,
CLC1.DEFINITION_ AS SEVKIYAT_HESABI_UNVANI,
CLC2.CODE AS SEVLIYAT_ADRESI_KODU,
CLC2.DEFINITION_ AS SEVKIYAT_ADRESI_ACIKLAMASI,
STFICHE.GENEXP1 AS ACIKLAMA_1,
STFICHE.GENEXP2 AS ACIKLAMA_2,
STFICHE.GENEXP3 AS ACIKLAMA_3,
STFICHE.GENEXP4 AS ACIKLAMA_4,
STFICHE.DOCTRACKINGNR AS DOKUMAN_IZLEME_NUMARASI,
STFICHE.SHPTYPCOD AS SEVKIYAT_TURU,
L_SHPTYPES.SDEF AS SEVKIYAT_TURU_ACIKLAMASI,
STFICHE.SHPAGNCOD AS TAŞIYICI_KODU,
L_SHPAGENT.TITLE AS TASIYICI_ACIKLAMASI,
STFICHE.TRACKNR AS PAKET_KOLI_NO,
-----------------REFERANSLAR
STFICHE.DISTORDERREF AS DAGITIM_EMRI_REFERANSI
FROM
LG_001_01_STLINE STLINE
LEFT JOIN LG_001_01_STFICHE STFICHE WITH (NOLOCK) ON STLINE.STFICHEREF = STFICHE.LOGICALREF
LEFT JOIN LG_001_01_INVOICE INVOICE WITH (NOLOCK) ON INVOICE.LOGICALREF=STFICHE.INVOICEREF
LEFT JOIN LG_001_CLCARD CLCARD (NOLOCK) ON CLCARD.LOGICALREF=STFICHE.CLIENTREF
LEFT JOIN LG_001_PAYPLANS PAYPLANS (NOLOCK) ON PAYPLANS.LOGICALREF=STFICHE.PAYDEFREF
LEFT JOIN L_TRADGRP (NOLOCK) ON L_TRADGRP.GCODE=STFICHE.TRADINGGRP
LEFT JOIN L_CAPIDIV (NOLOCK) ON L_CAPIDIV.NR=STFICHE.BRANCH AND L_CAPIDIV.FIRMNR='001'
LEFT JOIN L_CAPIDEPT (NOLOCK) ON L_CAPIDEPT.NR=STFICHE.DEPARTMENT AND L_CAPIDEPT.FIRMNR='001'
LEFT JOIN L_CAPIFACTORY (NOLOCK)ON L_CAPIFACTORY.NR=STFICHE.FACTORYNR AND L_CAPIFACTORY.FIRMNR='001'
LEFT JOIN L_CAPIWHOUSE (NOLOCK)ON L_CAPIWHOUSE.NR=STFICHE.SOURCEINDEX AND L_CAPIWHOUSE.FIRMNR='001'
LEFT JOIN LG_001_SHIPINFO SHIPINFO (NOLOCK) ON SHIPINFO.LOGICALREF=STFICHE.SHIPINFOREF
LEFT JOIN LG_SLSMAN ON STFICHE.SALESMANREF = LG_SLSMAN.LOGICALREF AND LG_SLSMAN.FIRMNR='001'
LEFT JOIN LG_001_CLCARD CLC1 (NOLOCK) ON STFICHE.RECVREF=CLC1.LOGICALREF
LEFT JOIN LG_001_CLCARD CLC2 (NOLOCK) ON STFICHE.SHIPINFOREF=CLC2.LOGICALREF
LEFT JOIN L_SHPTYPES (NOLOCK) ON L_SHPTYPES.SCODE=STFICHE.SHPTYPCOD
LEFT JOIN L_SHPAGENT (NOLOCK) ON L_SHPAGENT.CODE=STFICHE.SHPAGNCOD
LEFT JOIN LG_001_ITEMS ITEMS (NOLOCK) ON ITEMS.LOGICALREF=STLINE.STOCKREF AND STLINE.LINETYPE IN (0,8)
LEFT JOIN LG_001_SRVCARD SRVCARD (NOLOCK) ON SRVCARD.LOGICALREF=STLINE.STOCKREF AND STLINE.LINETYPE=4
LEFT JOIN LG_001_ITMUNITA ITMUNITA (NOLOCK) ON ITMUNITA.UNITLINEREF=STLINE.UOMREF AND ITMUNITA.ITEMREF=STLINE.STOCKREF
LEFT JOIN LG_001_UNITSETL UNITSETL (NOLOCK) ON STLINE.UOMREF = UNITSETL.LOGICALREF
LEFT JOIN LG_001_UNITSETF UNITSETF (NOLOCK) ON STLINE.USREF = UNITSETF.LOGICALREF
LEFT JOIN LG_001_SPECODES SPECODES (NOLOCK) ON SPECODES.SPECODE=STLINE.DELVRYCODE AND SPECODES.CODETYPE=3 AND SPECODES.SPECODETYPE=0
LEFT JOIN LG_001_SPECODES SPECODE (NOLOCK) ON SPECODE.SPECODE=STLINE.SPECODE AND SPECODES.CODETYPE=1 AND SPECODES.SPECODETYPE=19
LEFT JOIN LG_001_01_ORFLINE ORFLINE (NOLOCK) ON STLINE.ORDTRANSREF = ORFLINE.LOGICALREF
LEFT JOIN LG_001_01_ORFICHE ORFICHE (NOLOCK) ON STLINE.ORDFICHEREF = ORFICHE.LOGICALREF
LEFT JOIN LG_001_PAYPLANS PAYPLANS2 (NOLOCK) ON PAYPLANS2.LOGICALREF=STLINE.PAYDEFREF
LEFT JOIN L_CURRENCYLIST (NOLOCK) ON L_CURRENCYLIST.CURTYPE=STLINE.TRCURR and L_CURRENCYLIST.FIRMNR='001'
WHERE
INVOICE.CANCELLED=0
AND STLINE.LINETYPE IN (0,2,4,8)
AND INVOICE.TRCODE IN (2,3,7,8,9,10,14)
AND (STFICHE.BILLED=1 OR STFICHE.BILLED IS NULL)