IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[QMUH_EFATURA]'))
DROP VIEW [dbo].[QMUH_EFATURA]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[QMUH_EFATURA]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[QMUH_EFATURA] AS  SELECT  CASE WHEN TURADI IN (''ALĨ'',''ALIS'') THEN   
           CAST(51 AS INT)                              
        ELSE CASE WHEN TURADI IN (''SATĨ ƯADE'',''SATIS IADE'') THEN 
           CAST(54 AS INT)                                            
        ELSE CASE WHEN TURADI IN (''ALĨ ƯADE'',''ALIS IADE'') THEN   
           CAST(53 AS INT)                                            
        ELSE CAST(52 AS INT) END END END FISTURID, ISNULL(DOVIZKODU,''TL'') FATURADOVIZI,ISNULL(FATURA.EFATURAACIKLAMA, FATURA.ACIKLAMA) ACIKLAMA,FATURA.EFATURAACIKLAMA2,FATURA.FATID, 
 ISNULL(FATURA.EDEVLETDURUM,1) EDEVLETDURUM,FATURA.EDEVLET_ILETIMYONTEMI,FATURA.CARIID AS CARIID,FATURA.UUID,FATURA.FATNO,FATURA.EFATNO,FATURA.EFATURADURUM, 
 FATURA.TARIH,FATURA.SAAT,ROUND(FATURA.TOPLAM,2) AS FATURATOPLAM,
 ROUND(FATURA.GTOPLAM,2) AS GENELTOPLAM, 
 ROUND(((ISNULL(FATURA.SIND,0)+ISNULL(FATURA.IND1,0)+ISNULL(FATURA.IND2,0)+ISNULL(FATURA.IND3,0))),2) AS FATURAINDIRIM, 
 ROUND((FATURA.KDV),2) AS FATURAKDV,
 ROUND((FATURA.GTOPLAM-FATURA.KDV),2) AS FATURANETTOPLAM,  
 FATURA.UNVANI,ISNULL(FATURA.ADRES1,'''') FATURADRES,ISNULL(FATURA.ADRES2,'''') FATURADRES2,ISNULL(FATURA.ADRES3,'''') AS FATURADRES3,FATURA.VD, 
 FATURA.VDNO,  FATURA.TEL TEL1, FATURA.FAX, FATURA.EMAIL, FATURA.WEB, FATURA.EFATURAZARF, EFATURAINDYOK, EFATURA_LOG,
 EFATURA_SONGONTAR, /*DOVIZKODU*/ ''TL'' AS DOVIZ, EFATURA_ENTREFNO, SUBEID, CASE WHEN ISNULL(DOVIZKURU,1) = 0 THEN 1 ELSE ISNULL(DOVIZKURU,1) END AS KUR,  ISNULL(EFATTURU,0) AS EFATTURU,
 EFATURA_CEVAPACK,EFATURA_CEVAPTARIHI,EFATURA_CEVAPREFNO,EFATURA_CEVAP_UUID,EFATURA_CEVAPNO,  FATURA.KDVACIKLAMA,FATURA.KDVSIZLIKKODU, FATURA.SIPARISNO, FATURA.SIPARISTARIHI, FATURA.IRSALIYENO,FATURA.IRSALIYETARIHI, 
 EFATURA_PKUTUSU, EFATURA_KABULREDNOTU, SUBEID GSUBEID, EFATURAACIKLAMA, VADE,
 DONEMBASI , DONEMSONU , EVRAKREFNO , 
   MUKELLEFKODU , MUKELLEFADI 
 FROM FATURA AS FATURA 
 WHERE 
    (FATURA.TURADI = ''ALĨ''	 
  OR FATURA.TURADI = ''ALIS''	 
  OR FATURA.TURADI = ''SATĨ ƯADE'' 
	   OR FATURA.TURADI = ''SATIS IADE''
  OR FATURA.TURADI = ''SATĨ''	 
  OR FATURA.TURADI = ''ALĨ ƯADE'' 
  OR FATURA.TURADI = ''SATIS''	 
  OR FATURA.TURADI = ''ALIS IADE'' 
  OR FATURA.TURADI = ''PERAKENDE'') AND	 
  (ISNULL(FATURA.EFATURADURUM,0) > 0) AND ISNULL(FATURA.FIPTAL,0)=0 '
GO